Mercurial > repos > blastem
annotate render_fbdev.c @ 2195:40290a923886
Implement Game Gear start button and region register
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 21 Aug 2022 22:56:32 -0700 |
parents | 2fd0a8cb1c80 |
children |
rev | line source |
---|---|
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 /* |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 Copyright 2013 Michael Pavone |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 This file is part of BlastEm. |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 */ |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include <stdlib.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include <stdio.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include <string.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include <math.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include <linux/fb.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #include <linux/input.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 #include <linux/kd.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #include <alsa/asoundlib.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 #include <sys/types.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 #include <sys/stat.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 #include <sys/ioctl.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 #include <sys/mman.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 #include <fcntl.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 #include <unistd.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 #include <pthread.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 #include <dirent.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 #include "render.h" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 #include "blastem.h" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 #include "genesis.h" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 #include "bindings.h" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 #include "util.h" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 #include "paths.h" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 #include "ppm.h" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 #include "png.h" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 #include "config.h" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 #include "controller_info.h" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 #include <EGL/egl.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 #include <GLES2/gl2.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 #ifdef USE_MALI |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 //Mali GLES headers don't seem to define GLchar for some reason |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 typedef char GLchar; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 #define MAX_EVENT_POLL_PER_FRAME 2 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 static EGLContext main_context; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 static int main_width, main_height, windowed_width, windowed_height, is_fullscreen; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 static uint8_t render_gl = 1; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 static uint8_t scanlines = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 static uint32_t last_frame = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 static snd_pcm_uframes_t buffer_samples; |
1954
2fd0a8cb1c80
Properly initialize Genesis reset cycle on startup. Fixes crash in GDB remote debugger when stepping past the first two instructions
Michael Pavone <pavone@retrodev.com>
parents:
1786
diff
changeset
|
53 static size_t buffer_bytes; |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 static unsigned int output_channels, sample_rate; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 static uint8_t quitting = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 static void render_close_audio() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 |
1954
2fd0a8cb1c80
Properly initialize Genesis reset cycle on startup. Fixes crash in GDB remote debugger when stepping past the first two instructions
Michael Pavone <pavone@retrodev.com>
parents:
1786
diff
changeset
|
65 static snd_pcm_t *audio_handle; |
2fd0a8cb1c80
Properly initialize Genesis reset cycle on startup. Fixes crash in GDB remote debugger when stepping past the first two instructions
Michael Pavone <pavone@retrodev.com>
parents:
1786
diff
changeset
|
66 static void *output_buffer; |
2fd0a8cb1c80
Properly initialize Genesis reset cycle on startup. Fixes crash in GDB remote debugger when stepping past the first two instructions
Michael Pavone <pavone@retrodev.com>
parents:
1786
diff
changeset
|
67 void render_do_audio_ready(audio_source *src) |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 if (src->front_populated) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 fatal_error("Audio source filled up a buffer a second time before other sources finished their first\n"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 int16_t *tmp = src->front; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 src->front = src->back; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 src->back = tmp; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 src->front_populated = 1; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 src->buffer_pos = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 |
1954
2fd0a8cb1c80
Properly initialize Genesis reset cycle on startup. Fixes crash in GDB remote debugger when stepping past the first two instructions
Michael Pavone <pavone@retrodev.com>
parents:
1786
diff
changeset
|
78 if (!all_sources_ready()) { |
2fd0a8cb1c80
Properly initialize Genesis reset cycle on startup. Fixes crash in GDB remote debugger when stepping past the first two instructions
Michael Pavone <pavone@retrodev.com>
parents:
1786
diff
changeset
|
79 return; |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 } |
1954
2fd0a8cb1c80
Properly initialize Genesis reset cycle on startup. Fixes crash in GDB remote debugger when stepping past the first two instructions
Michael Pavone <pavone@retrodev.com>
parents:
1786
diff
changeset
|
81 mix_and_convert(output_buffer, buffer_bytes, NULL); |
2fd0a8cb1c80
Properly initialize Genesis reset cycle on startup. Fixes crash in GDB remote debugger when stepping past the first two instructions
Michael Pavone <pavone@retrodev.com>
parents:
1786
diff
changeset
|
82 |
2fd0a8cb1c80
Properly initialize Genesis reset cycle on startup. Fixes crash in GDB remote debugger when stepping past the first two instructions
Michael Pavone <pavone@retrodev.com>
parents:
1786
diff
changeset
|
83 int frames = snd_pcm_writei(audio_handle, output_buffer, buffer_samples); |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 if (frames < 0) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 frames = snd_pcm_recover(audio_handle, frames, 0); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 if (frames < 0) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 fprintf(stderr, "Failed to write samples: %s\n", snd_strerror(frames)); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 int render_width() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 return main_width; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 int render_height() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 return main_height; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 int render_fullscreen() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 return 1; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 uint32_t red_shift, blue_shift, green_shift; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 return r << red_shift | g << green_shift | b << blue_shift; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 static GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], un_width, un_height, at_pos; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 static GLfloat vertex_data_default[] = { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 -1.0f, -1.0f, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 1.0f, -1.0f, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 -1.0f, 1.0f, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 1.0f, 1.0f |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 }; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 static GLfloat vertex_data[8]; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 static const GLushort element_data[] = {0, 1, 2, 3}; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 static const GLchar shader_prefix[] = |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 #ifdef USE_GLES |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 "#version 100\n"; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 #else |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 "#version 110\n" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 "#define lowp\n" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 "#define mediump\n" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 "#define highp\n"; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 static GLuint load_shader(char * fname, GLenum shader_type) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 char const * parts[] = {get_home_dir(), "/.config/blastem/shaders/", fname}; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 char * shader_path = alloc_concat_m(3, parts); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 FILE * f = fopen(shader_path, "rb"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 free(shader_path); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 GLchar * text; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 long fsize; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 if (f) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 fsize = file_size(f); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 text = malloc(fsize); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 if (fread(text, 1, fsize, f) != fsize) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 warning("Error reading from shader file %s\n", fname); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 free(text); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 return 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 shader_path = path_append("shaders", fname); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 uint32_t fsize32; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 text = read_bundled_file(shader_path, &fsize32); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 free(shader_path); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 if (!text) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 warning("Failed to open shader file %s for reading\n", fname); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 return 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 fsize = fsize32; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 if (strncmp(text, "#version", strlen("#version"))) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 GLchar *tmp = text; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 text = alloc_concat(shader_prefix, tmp); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 free(tmp); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 fsize += strlen(shader_prefix); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 GLuint ret = glCreateShader(shader_type); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 free(text); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 glCompileShader(ret); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 GLint compile_status, loglen; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 if (!compile_status) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 glGetShaderiv(ret, GL_INFO_LOG_LENGTH, &loglen); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 text = malloc(loglen); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 glGetShaderInfoLog(ret, loglen, NULL, text); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 warning("Shader %s failed to compile:\n%s\n", fname, text); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 free(text); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 glDeleteShader(ret); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 return 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 return ret; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
190 #define MAX_FB_LINES 590 |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
191 static uint32_t texture_buf[MAX_FB_LINES * LINEBUF_SIZE * 2]; |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 #ifdef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 #define RENDER_FORMAT SDL_PIXELFORMAT_ARGB8888 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 #else |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 #ifdef USE_GLES |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 #define INTERNAL_FORMAT GL_RGBA |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 #define SRC_FORMAT GL_RGBA |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 #define RENDER_FORMAT SDL_PIXELFORMAT_ABGR8888 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 #else |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 #define INTERNAL_FORMAT GL_RGBA8 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 #define SRC_FORMAT GL_BGRA |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 #define RENDER_FORMAT SDL_PIXELFORMAT_ARGB8888 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 static void gl_setup() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 tern_val def = {.ptrval = "linear"}; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 char *scaling = tern_find_path_default(config, "video\0scaling\0", def, TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 GLint filter = strcmp(scaling, "linear") ? GL_NEAREST : GL_LINEAR; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 glGenTextures(3, textures); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 for (int i = 0; i < 3; i++) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 glBindTexture(GL_TEXTURE_2D, textures[i]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 if (i < 2) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 //TODO: Fixme for PAL + invalid display mode |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, 512, 512, 0, SRC_FORMAT, GL_UNSIGNED_BYTE, texture_buf); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 uint32_t blank = 255 << 24; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, 1, 1, 0, SRC_FORMAT, GL_UNSIGNED_BYTE, &blank); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 glGenBuffers(2, buffers); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 def.ptrval = "default.v.glsl"; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 vshader = load_shader(tern_find_path_default(config, "video\0vertex_shader\0", def, TVAL_PTR).ptrval, GL_VERTEX_SHADER); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 def.ptrval = "default.f.glsl"; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 fshader = load_shader(tern_find_path_default(config, "video\0fragment_shader\0", def, TVAL_PTR).ptrval, GL_FRAGMENT_SHADER); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 program = glCreateProgram(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 glAttachShader(program, vshader); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 glAttachShader(program, fshader); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 glLinkProgram(program); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 GLint link_status; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 glGetProgramiv(program, GL_LINK_STATUS, &link_status); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 if (!link_status) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 fputs("Failed to link shader program\n", stderr); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 exit(1); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 un_textures[0] = glGetUniformLocation(program, "textures[0]"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 un_textures[1] = glGetUniformLocation(program, "textures[1]"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 un_width = glGetUniformLocation(program, "width"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 un_height = glGetUniformLocation(program, "height"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 at_pos = glGetAttribLocation(program, "pos"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 static void gl_teardown() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 glDeleteProgram(program); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 glDeleteShader(vshader); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 glDeleteShader(fshader); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 glDeleteBuffers(2, buffers); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 glDeleteTextures(3, textures); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 static uint8_t texture_init; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 static void render_alloc_surfaces() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 if (texture_init) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 return; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 texture_init = 1; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 if (render_gl) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 gl_setup(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 static void free_surfaces(void) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 texture_init = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 static char * caption = NULL; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 static char * fps_caption = NULL; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 static void render_quit() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 render_close_audio(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 free_surfaces(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
287 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
288 if (render_gl) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
289 gl_teardown(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 //FIXME: replace with EGL equivalent |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 //SDL_GL_DeleteContext(main_context); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
292 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
295 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 static float config_aspect() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
298 static float aspect = 0.0f; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 if (aspect == 0.0f) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 char *config_aspect = tern_find_path_default(config, "video\0aspect\0", (tern_val){.ptrval = "4:3"}, TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 if (strcmp("stretch", config_aspect)) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 aspect = 4.0f/3.0f; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
303 char *end; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 float aspect_numerator = strtof(config_aspect, &end); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
305 if (aspect_numerator > 0.0f && *end == ':') { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 float aspect_denominator = strtof(end+1, &end); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
307 if (aspect_denominator > 0.0f && !*end) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
308 aspect = aspect_numerator / aspect_denominator; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
310 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
311 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 aspect = -1.0f; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 return aspect; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 static void update_aspect() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 //reset default values |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 memcpy(vertex_data, vertex_data_default, sizeof(vertex_data)); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
323 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 if (config_aspect() > 0.0f) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
325 float aspect = (float)main_width / main_height; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
326 if (fabs(aspect - config_aspect()) < 0.01f) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 //close enough for government work |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 return; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
331 if (render_gl) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
332 for (int i = 0; i < 4; i++) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 if (aspect > config_aspect()) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 vertex_data[i*2] *= config_aspect()/aspect; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 vertex_data[i*2+1] *= aspect/config_aspect(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
338 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
339 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
340 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
341 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
342 //TODO: Maybe do some stuff for non-integer scaling in raw fbdev copy |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
343 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
345 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
346 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
347 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 static uint8_t scancode_map[128] = { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 [KEY_A] = 0x1C, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
351 [KEY_B] = 0x32, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
352 [KEY_C] = 0x21, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
353 [KEY_D] = 0x23, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
354 [KEY_E] = 0x24, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
355 [KEY_F] = 0x2B, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
356 [KEY_G] = 0x34, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
357 [KEY_H] = 0x33, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 [KEY_I] = 0x43, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 [KEY_J] = 0x3B, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
360 [KEY_K] = 0x42, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
361 [KEY_L] = 0x4B, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
362 [KEY_M] = 0x3A, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
363 [KEY_N] = 0x31, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
364 [KEY_O] = 0x44, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
365 [KEY_P] = 0x4D, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
366 [KEY_Q] = 0x15, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
367 [KEY_R] = 0x2D, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
368 [KEY_S] = 0x1B, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
369 [KEY_T] = 0x2C, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
370 [KEY_U] = 0x3C, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
371 [KEY_V] = 0x2A, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 [KEY_W] = 0x1D, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
373 [KEY_X] = 0x22, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 [KEY_Y] = 0x35, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 [KEY_Z] = 0x1A, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
376 [KEY_1] = 0x16, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 [KEY_2] = 0x1E, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
378 [KEY_3] = 0x26, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
379 [KEY_4] = 0x25, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
380 [KEY_5] = 0x2E, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
381 [KEY_6] = 0x36, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 [KEY_7] = 0x3D, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 [KEY_8] = 0x3E, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
384 [KEY_9] = 0x46, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 [KEY_0] = 0x45, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
386 [KEY_ENTER] = 0x5A, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
387 [KEY_ESC] = 0x76, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 [KEY_SPACE] = 0x29, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 [KEY_TAB] = 0x0D, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 [KEY_BACKSPACE] = 0x66, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 [KEY_MINUS] = 0x4E, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 [KEY_EQUAL] = 0x55, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
393 [KEY_LEFTBRACE] = 0x54, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
394 [KEY_RIGHTBRACE] = 0x5B, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
395 [KEY_BACKSLASH] = 0x5D, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 [KEY_SEMICOLON] = 0x4C, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
397 [KEY_APOSTROPHE] = 0x52, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 [KEY_GRAVE] = 0x0E, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 [KEY_COMMA] = 0x41, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 [KEY_DOT] = 0x49, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 [KEY_SLASH] = 0x4A, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 [KEY_CAPSLOCK] = 0x58, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 [KEY_F1] = 0x05, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
404 [KEY_F2] = 0x06, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 [KEY_F3] = 0x04, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 [KEY_F4] = 0x0C, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
407 [KEY_F5] = 0x03, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 [KEY_F6] = 0x0B, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
409 [KEY_F7] = 0x83, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
410 [KEY_F8] = 0x0A, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 [KEY_F9] = 0x01, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 [KEY_F10] = 0x09, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
413 [KEY_F11] = 0x78, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
414 [KEY_F12] = 0x07, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
415 [KEY_LEFTCTRL] = 0x14, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
416 [KEY_LEFTSHIFT] = 0x12, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
417 [KEY_LEFTALT] = 0x11, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
418 [KEY_RIGHTCTRL] = 0x18, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
419 [KEY_RIGHTSHIFT] = 0x59, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
420 [KEY_RIGHTALT] = 0x17, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 [KEY_INSERT] = 0x81, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 [KEY_PAUSE] = 0x82, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 [KEY_SYSRQ] = 0x84, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
424 [KEY_SCROLLLOCK] = 0x7E, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 [KEY_DELETE] = 0x85, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 [KEY_LEFT] = 0x86, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
427 [KEY_HOME] = 0x87, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 [KEY_END] = 0x88, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 [KEY_UP] = 0x89, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 [KEY_DOWN] = 0x8A, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
431 [KEY_PAGEUP] = 0x8B, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
432 [KEY_PAGEDOWN] = 0x8C, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 [KEY_RIGHT] = 0x8D, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 [KEY_NUMLOCK] = 0x77, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
435 [KEY_KPSLASH] = 0x80, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 [KEY_KPASTERISK] = 0x7C, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
437 [KEY_KPMINUS] = 0x7B, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
438 [KEY_KPPLUS] = 0x79, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
439 [KEY_KPENTER] = 0x19, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
440 [KEY_KP1] = 0x69, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
441 [KEY_KP2] = 0x72, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
442 [KEY_KP3] = 0x7A, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
443 [KEY_KP4] = 0x6B, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
444 [KEY_KP5] = 0x73, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
445 [KEY_KP6] = 0x74, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
446 [KEY_KP7] = 0x6C, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
447 [KEY_KP8] = 0x75, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
448 [KEY_KP9] = 0x7D, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
449 [KEY_KP0] = 0x70, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
450 [KEY_KPDOT] = 0x71, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
451 }; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
452 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
453 #include "special_keys_evdev.h" |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
454 static uint8_t sym_map[128] = { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
455 [KEY_A] = 'a', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
456 [KEY_B] = 'b', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 [KEY_C] = 'c', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
458 [KEY_D] = 'd', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
459 [KEY_E] = 'e', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
460 [KEY_F] = 'f', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
461 [KEY_G] = 'g', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 [KEY_H] = 'h', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
463 [KEY_I] = 'i', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
464 [KEY_J] = 'j', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
465 [KEY_K] = 'k', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
466 [KEY_L] = 'l', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
467 [KEY_M] = 'm', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
468 [KEY_N] = 'n', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
469 [KEY_O] = 'o', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
470 [KEY_P] = 'p', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
471 [KEY_Q] = 'q', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
472 [KEY_R] = 'r', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
473 [KEY_S] = 's', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
474 [KEY_T] = 't', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
475 [KEY_U] = 'u', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
476 [KEY_V] = 'v', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 [KEY_W] = 'w', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 [KEY_X] = 'x', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 [KEY_Y] = 'y', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
480 [KEY_Z] = 'z', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 [KEY_1] = '1', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
482 [KEY_2] = '2', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
483 [KEY_3] = '3', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 [KEY_4] = '4', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 [KEY_5] = '5', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 [KEY_6] = '6', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 [KEY_7] = '7', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 [KEY_8] = '8', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
489 [KEY_9] = '9', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 [KEY_0] = '0', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 [KEY_ENTER] = '\r', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
492 [KEY_SPACE] = ' ', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 [KEY_TAB] = '\t', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 [KEY_BACKSPACE] = '\b', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
495 [KEY_MINUS] = '-', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 [KEY_EQUAL] = '=', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 [KEY_LEFTBRACE] = '[', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 [KEY_RIGHTBRACE] = ']', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 [KEY_BACKSLASH] = '\\', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 [KEY_SEMICOLON] = ';', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 [KEY_APOSTROPHE] = '\'', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 [KEY_GRAVE] = '`', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
503 [KEY_COMMA] = ',', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
504 [KEY_DOT] = '.', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
505 [KEY_SLASH] = '/', |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
506 [KEY_ESC] = RENDERKEY_ESC, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
507 [KEY_F1] = RENDERKEY_F1, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
508 [KEY_F2] = RENDERKEY_F2, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
509 [KEY_F3] = RENDERKEY_F3, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
510 [KEY_F4] = RENDERKEY_F4, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
511 [KEY_F5] = RENDERKEY_F5, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
512 [KEY_F6] = RENDERKEY_F6, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
513 [KEY_F7] = RENDERKEY_F7, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
514 [KEY_F8] = RENDERKEY_F8, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
515 [KEY_F9] = RENDERKEY_F9, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
516 [KEY_F10] = RENDERKEY_F10, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
517 [KEY_F11] = RENDERKEY_F11, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
518 [KEY_F12] = RENDERKEY_F12, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
519 [KEY_LEFTCTRL] = RENDERKEY_LCTRL, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
520 [KEY_LEFTSHIFT] = RENDERKEY_LSHIFT, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
521 [KEY_LEFTALT] = RENDERKEY_LALT, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
522 [KEY_RIGHTCTRL] = RENDERKEY_RCTRL, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
523 [KEY_RIGHTSHIFT] = RENDERKEY_RSHIFT, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
524 [KEY_RIGHTALT] = RENDERKEY_RALT, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
525 [KEY_DELETE] = RENDERKEY_DEL, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
526 [KEY_LEFT] = RENDERKEY_LEFT, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
527 [KEY_HOME] = RENDERKEY_HOME, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
528 [KEY_END] = RENDERKEY_END, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
529 [KEY_UP] = RENDERKEY_UP, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
530 [KEY_DOWN] = RENDERKEY_DOWN, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
531 [KEY_PAGEUP] = RENDERKEY_PAGEUP, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
532 [KEY_PAGEDOWN] = RENDERKEY_PAGEDOWN, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
533 [KEY_RIGHT] = RENDERKEY_RIGHT, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
534 [KEY_KPSLASH] = 0x80, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
535 [KEY_KPASTERISK] = 0x7C, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
536 [KEY_KPMINUS] = 0x7B, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
537 [KEY_KPPLUS] = 0x79, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
538 [KEY_KPENTER] = 0x19, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
539 [KEY_KP1] = 0x69, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
540 [KEY_KP2] = 0x72, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
541 [KEY_KP3] = 0x7A, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
542 [KEY_KP4] = 0x6B, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
543 [KEY_KP5] = 0x73, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
544 [KEY_KP6] = 0x74, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
545 [KEY_KP7] = 0x6C, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
546 [KEY_KP8] = 0x75, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
547 [KEY_KP9] = 0x7D, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
548 [KEY_KP0] = 0x70, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
549 [KEY_KPDOT] = 0x71, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
550 }; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
551 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
552 static drop_handler drag_drop_handler; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
553 void render_set_drag_drop_handler(drop_handler handler) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
554 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
555 drag_drop_handler = handler; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
556 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
557 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
558 char* render_joystick_type_id(int index) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
559 { |
1786
2b661c1e431f
Remove some commented out code in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1785
diff
changeset
|
560 return strdup(""); |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
561 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
562 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
563 static uint32_t overscan_top[NUM_VID_STD] = {2, 21}; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
564 static uint32_t overscan_bot[NUM_VID_STD] = {1, 17}; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
565 static uint32_t overscan_left[NUM_VID_STD] = {13, 13}; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
566 static uint32_t overscan_right[NUM_VID_STD] = {14, 14}; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
567 static vid_std video_standard = VID_NTSC; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
568 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
569 typedef enum { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
570 DEV_NONE, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
571 DEV_KEYBOARD, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
572 DEV_MOUSE, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
573 DEV_GAMEPAD |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
574 } device_type; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
575 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
576 static int32_t mouse_x, mouse_y, mouse_accum_x, mouse_accum_y; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
577 static int32_t handle_event(device_type dtype, int device_index, struct input_event *event) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
578 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
579 switch (event->type) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
580 case EV_KEY: |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
581 //code is key, value is 1 for keydown, 0 for keyup |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
582 if (dtype == DEV_KEYBOARD && event->code < 128) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
583 //keyboard key that we might have a mapping for |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
584 if (event->value) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
585 handle_keydown(sym_map[event->code], scancode_map[event->code]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
586 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
587 handle_keyup(sym_map[event->code], scancode_map[event->code]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
588 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
589 } else if (dtype == DEV_MOUSE && event->code >= BTN_MOUSE && event->code < BTN_JOYSTICK) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
590 //mosue button |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
591 if (event->value) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
592 handle_mousedown(device_index, event->code - BTN_LEFT); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
593 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
594 handle_mouseup(device_index, event->code - BTN_LEFT); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
595 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
596 } else if (dtype == DEV_GAMEPAD && event->code >= BTN_GAMEPAD && event->code < BTN_DIGI) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
597 //gamepad button |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
598 if (event->value) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
599 handle_joydown(device_index, event->code - BTN_SOUTH); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
600 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
601 handle_joyup(device_index, event->code - BTN_SOUTH); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
602 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
603 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
604 break; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
605 case EV_REL: |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
606 if (dtype == DEV_MOUSE) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
607 switch(event->code) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
608 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
609 case REL_X: |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
610 mouse_accum_x += event->value; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
611 break; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
612 case REL_Y: |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
613 mouse_accum_y += event->value; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
614 break; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
615 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
616 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
617 break; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
618 case EV_ABS: |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
619 //TODO: Handle joystick axis/hat motion, absolute mouse movement |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
620 break; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
621 case EV_SYN: |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
622 if (dtype == DEV_MOUSE && (mouse_accum_x || mouse_accum_y)) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
623 mouse_x += mouse_accum_x; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
624 mouse_y += mouse_accum_y; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
625 if (mouse_x < 0) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
626 mouse_x = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
627 } else if (mouse_x >= main_width) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
628 mouse_x = main_width - 1; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
629 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
630 if (mouse_y < 0) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
631 mouse_y = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
632 } else if (mouse_y >= main_height) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
633 mouse_y = main_height - 1; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
634 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
635 handle_mouse_moved(device_index, mouse_x, mouse_y, mouse_accum_x, mouse_accum_y); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
636 mouse_accum_x = mouse_accum_y = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
637 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
638 break; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
639 /* |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
640 case SDL_JOYHATMOTION: |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
641 handle_joy_dpad(find_joystick_index(event->jhat.which), event->jhat.hat, event->jhat.value); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
642 break; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
643 case SDL_JOYAXISMOTION: |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
644 handle_joy_axis(find_joystick_index(event->jaxis.which), event->jaxis.axis, event->jaxis.value); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
645 break;*/ |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
646 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
647 return 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
648 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
649 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
650 #define MAX_DEVICES 16 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
651 static int device_fds[MAX_DEVICES]; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
652 static device_type device_types[MAX_DEVICES]; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
653 static int cur_devices; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
654 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
655 static void drain_events() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
656 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
657 struct input_event events[64]; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
658 int index_by_type[3] = {0,0,0}; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
659 for (int i = 0; i < cur_devices; i++) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
660 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
661 int bytes = sizeof(events); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
662 int device_index = index_by_type[device_types[i]-1]++; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
663 while (bytes == sizeof(events)) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
664 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
665 bytes = read(device_fds[i], events, sizeof(events)); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
666 if (bytes > 0) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
667 int num_events = bytes / sizeof(events[0]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
668 for (int j = 0; j < num_events; j++) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
669 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
670 handle_event(device_types[i], device_index, events + j); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
671 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
672 } else if (bytes < 0 && errno != EAGAIN && errno != EWOULDBLOCK) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
673 perror("Failed to read evdev events"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
674 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
675 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
676 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
677 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
678 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
679 static char *vid_std_names[NUM_VID_STD] = {"ntsc", "pal"}; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
680 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
681 static void init_audio() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
682 { |
1780
fc9bea5ee079
Fix off-by-one error in evdev init code and allow ALSA device to be specified in config
Michael Pavone <pavone@retrodev.com>
parents:
1779
diff
changeset
|
683 char *device_name = tern_find_path_default(config, "audio\0alsa_device\0", (tern_val){.ptrval="default"}, TVAL_PTR).ptrval; |
fc9bea5ee079
Fix off-by-one error in evdev init code and allow ALSA device to be specified in config
Michael Pavone <pavone@retrodev.com>
parents:
1779
diff
changeset
|
684 int res = snd_pcm_open(&audio_handle, device_name, SND_PCM_STREAM_PLAYBACK, 0); |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
685 if (res < 0) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
686 fatal_error("Failed to open ALSA device: %s\n", snd_strerror(res)); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
687 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
688 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
689 snd_pcm_hw_params_t *params; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
690 snd_pcm_hw_params_alloca(¶ms); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
691 res = snd_pcm_hw_params_any(audio_handle, params); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
692 if (res < 0) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
693 fatal_error("No playback configurations available: %s\n", snd_strerror(res)); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
694 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
695 res = snd_pcm_hw_params_set_access(audio_handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
696 if (res < 0) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
697 fatal_error("Failed to set access type: %s\n", snd_strerror(res)); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
698 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
699 res = snd_pcm_hw_params_set_format(audio_handle, params, SND_PCM_FORMAT_S16_LE); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
700 if (res < 0) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
701 //failed to set, signed 16-bit integer, try floating point |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
702 res = snd_pcm_hw_params_set_format(audio_handle, params, SND_PCM_FORMAT_FLOAT_LE); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
703 if (res < 0) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
704 fatal_error("Failed to set an acceptable format: %s\n", snd_strerror(res)); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
705 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
706 mix = mix_f32; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
707 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
708 mix = mix_s16; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
709 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
710 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
711 char * rate_str = tern_find_path(config, "audio\0rate\0", TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
712 sample_rate = rate_str ? atoi(rate_str) : 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
713 if (!sample_rate) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
714 sample_rate = 48000; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
715 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
716 snd_pcm_hw_params_set_rate_near(audio_handle, params, &sample_rate, NULL); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
717 output_channels = 2; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
718 snd_pcm_hw_params_set_channels_near(audio_handle, params, &output_channels); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
719 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
720 char * samples_str = tern_find_path(config, "audio\0buffer\0", TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
721 buffer_samples = samples_str ? atoi(samples_str) : 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
722 if (!buffer_samples) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
723 buffer_samples = 512; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
724 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
725 snd_pcm_hw_params_set_period_size_near(audio_handle, params, &buffer_samples, NULL); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
726 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
727 int dir = 1; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
728 unsigned int periods = 2; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
729 snd_pcm_hw_params_set_periods_near(audio_handle, params, &periods, &dir); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
730 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
731 res = snd_pcm_hw_params(audio_handle, params); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
732 if (res < 0) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
733 fatal_error("Failed to set ALSA hardware params: %s\n", snd_strerror(res)); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
734 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
735 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
736 printf("Initialized audio at frequency %d with a %d sample buffer, ", (int)sample_rate, (int)buffer_samples); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
737 if (mix == mix_s16) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
738 puts("signed 16-bit int format"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
739 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
740 puts("32-bit float format"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
741 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
742 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
743 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
744 int fbfd; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
745 uint32_t *framebuffer; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
746 uint32_t fb_stride; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
747 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
748 EGLDisplay egl_display; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
749 EGLSurface main_surface; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
750 uint8_t egl_setup(void) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
751 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
752 //Mesa wants the fbdev file descriptor as the display |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
753 egl_display = eglGetDisplay((EGLNativeDisplayType)fbfd); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
754 if (egl_display == EGL_NO_DISPLAY) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
755 //Mali (and possibly others) seems to just want EGL_DEFAULT_DISPLAY |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
756 egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
757 if (egl_display == EGL_NO_DISPLAY) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
758 warning("eglGetDisplay failed with error %X\n", eglGetError()); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
759 return 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
760 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
761 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
762 EGLint major, minor; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
763 if (!eglInitialize(egl_display, &major, &minor)) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
764 warning("eglInitialize failed with error %X\n", eglGetError()); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
765 return 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
766 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
767 printf("EGL version %d.%d\n", major, minor); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
768 EGLint num_configs; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
769 EGLConfig config; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
770 EGLint const config_attribs[] = { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
771 EGL_RED_SIZE, 5, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
772 EGL_GREEN_SIZE, 5, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
773 EGL_BLUE_SIZE, 5, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
774 EGL_CONFORMANT, EGL_OPENGL_ES2_BIT, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
775 EGL_NONE |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
776 }; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
777 if (!eglChooseConfig(egl_display, config_attribs, &config, 1, &num_configs)) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
778 num_configs = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
779 warning("eglChooseConfig failed with error %X\n", eglGetError()); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
780 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
781 if (!num_configs) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
782 warning("Failed to choose an EGL config\n"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
783 goto error; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
784 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
785 EGLint const context_attribs[] = { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
786 #ifdef EGL_CONTEXT_MAJOR_VERSION |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
787 EGL_CONTEXT_MAJOR_VERSION, 2, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
788 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
789 EGL_NONE |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
790 }; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
791 main_context = eglCreateContext(egl_display, config, EGL_NO_CONTEXT, context_attribs); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
792 if (main_context == EGL_NO_CONTEXT) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
793 warning("Failed to create EGL context %X\n", eglGetError()); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
794 goto error; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
795 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
796 #ifdef USE_MALI |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
797 struct mali_native_window native_window = { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
798 .width = main_width, |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
799 .height = main_height |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
800 }; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
801 main_surface = eglCreateWindowSurface(egl_display, config, &native_window, NULL); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
802 #else |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
803 main_surface = eglCreateWindowSurface(egl_display, config, (EGLNativeWindowType)NULL, NULL); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
804 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
805 if (main_surface == EGL_NO_SURFACE) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
806 warning("Failed to create EGL surface %X\n", eglGetError()); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
807 goto post_context_error; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
808 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
809 if (eglMakeCurrent(egl_display, main_surface, main_surface, main_context)) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
810 return 1; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
811 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
812 eglDestroySurface(egl_display, main_surface); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
813 post_context_error: |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
814 eglDestroyContext(egl_display, main_context); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
815 error: |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
816 eglTerminate(egl_display); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
817 return 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
818 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
819 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
820 static pthread_mutex_t buffer_lock = PTHREAD_MUTEX_INITIALIZER; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
821 static pthread_cond_t buffer_cond = PTHREAD_COND_INITIALIZER; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
822 static uint8_t buffer_ready; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
823 static uint32_t *copy_buffer; |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
824 static uint32_t last_width, last_width_scale, last_height, last_height_scale; |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
825 static uint32_t max_multiple; |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
826 |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
827 static uint32_t mix_pixel(uint32_t last, uint32_t cur, float ratio) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
828 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
829 float a,b,c,d; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
830 a = (last & 255) * ratio; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
831 b = (last >> 8 & 255) * ratio; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
832 c = (last >> 16 & 255) * ratio; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
833 d = (last >> 24 & 255) * ratio; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
834 ratio = 1.0f - ratio; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
835 a += (cur & 255) * ratio; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
836 b += (cur >> 8 & 255) * ratio; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
837 c += (cur >> 16 & 255) * ratio; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
838 d += (cur >> 24 & 255) * ratio; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
839 return ((int)d) << 24 | ((int)c) << 16 | ((int)b) << 8 | ((int)a); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
840 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
841 static void do_buffer_copy(void) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
842 { |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
843 uint32_t width_multiple = main_width / last_width_scale; |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
844 uint32_t height_multiple = main_height / last_height_scale; |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
845 uint32_t multiple = width_multiple < height_multiple ? width_multiple : height_multiple; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
846 if (max_multiple && multiple > max_multiple) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
847 multiple = max_multiple; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
848 } |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
849 height_multiple = last_height_scale * multiple / last_height; |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
850 uint32_t *cur_line = framebuffer + (main_width - last_width_scale * multiple)/2; |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
851 cur_line += fb_stride * (main_height - last_height_scale * multiple) / (2 * sizeof(uint32_t)); |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
852 uint32_t *src_line = copy_buffer; |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
853 if (height_multiple * last_height == multiple * last_height_scale) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
854 if (last_width == last_width_scale) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
855 for (uint32_t y = 0; y < last_height; y++) |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
856 { |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
857 for (uint32_t i = 0; i < height_multiple; i++) |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
858 { |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
859 uint32_t *cur = cur_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
860 uint32_t *src = src_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
861 for (uint32_t x = 0; x < last_width ; x++) |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
862 { |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
863 uint32_t pixel = *(src++); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
864 for (uint32_t j = 0; j < multiple; j++) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
865 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
866 *(cur++) = pixel; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
867 } |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
868 } |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
869 |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
870 cur_line += fb_stride / sizeof(uint32_t); |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
871 } |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
872 src_line += LINEBUF_SIZE; |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
873 } |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
874 } else { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
875 float scale_multiple = ((float)(last_width_scale * multiple)) / (float)last_width; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
876 float remaining = 0.0f; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
877 uint32_t last_pixel = 0; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
878 for (uint32_t y = 0; y < last_height; y++) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
879 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
880 for (uint32_t i = 0; i < height_multiple; i++) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
881 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
882 uint32_t *cur = cur_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
883 uint32_t *src = src_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
884 for (uint32_t x = 0; x < last_width ; x++) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
885 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
886 uint32_t pixel = *(src++); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
887 float count = scale_multiple; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
888 if (remaining > 0.0f) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
889 *(cur++) = mix_pixel(last_pixel, pixel, remaining); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
890 count -= 1.0f - remaining; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
891 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
892 for (; count >= 1; count -= 1.0f) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
893 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
894 *(cur++) = pixel; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
895 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
896 remaining = count; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
897 last_pixel = pixel; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
898 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
899 |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
900 cur_line += fb_stride / sizeof(uint32_t); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
901 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
902 src_line += LINEBUF_SIZE; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
903 } |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
904 } |
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
905 } else { |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
906 float height_scale = ((float)(last_height_scale * multiple)) / (float)last_height; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
907 float height_remaining = 0.0f; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
908 uint32_t *last_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
909 if (last_width == last_width_scale) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
910 for (uint32_t y = 0; y < last_height; y++) |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
911 { |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
912 float hcount = height_scale; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
913 if (height_remaining > 0.0f) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
914 uint32_t *cur = cur_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
915 uint32_t *src = src_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
916 uint32_t *last = last_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
917 for (uint32_t x = 0; x < last_width ; x++) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
918 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
919 uint32_t mixed = mix_pixel(*(last++), *(src++), height_remaining); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
920 for (uint32_t j = 0; j < multiple; j++) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
921 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
922 *(cur++) = mixed; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
923 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
924 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
925 hcount -= 1.0f - height_remaining; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
926 cur_line += fb_stride / sizeof(uint32_t); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
927 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
928 for(; hcount >= 1; hcount -= 1.0f) |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
929 { |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
930 uint32_t *cur = cur_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
931 uint32_t *src = src_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
932 for (uint32_t x = 0; x < last_width ; x++) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
933 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
934 uint32_t pixel = *(src++); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
935 for (uint32_t j = 0; j < multiple; j++) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
936 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
937 *(cur++) = pixel; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
938 } |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
939 } |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
940 |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
941 cur_line += fb_stride / sizeof(uint32_t); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
942 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
943 height_remaining = hcount; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
944 last_line = src_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
945 src_line += LINEBUF_SIZE; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
946 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
947 } else { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
948 float scale_multiple = ((float)(last_width_scale * multiple)) / (float)last_width; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
949 float remaining = 0.0f; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
950 uint32_t last_pixel = 0; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
951 for (uint32_t y = 0; y < last_height; y++) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
952 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
953 float hcount = height_scale; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
954 if (height_remaining > 0.0f) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
955 uint32_t *cur = cur_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
956 uint32_t *src = src_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
957 uint32_t *last = last_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
958 |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
959 for (uint32_t x = 0; x < last_width; x++) |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
960 { |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
961 uint32_t pixel = mix_pixel(*(last++), *(src++), height_remaining); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
962 float count = scale_multiple; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
963 if (remaining > 0.0f) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
964 *(cur++) = mix_pixel(last_pixel, pixel, remaining); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
965 count -= 1.0f - remaining; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
966 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
967 for (; count >= 1.0f; count -= 1.0f) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
968 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
969 *(cur++) = pixel; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
970 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
971 remaining = count; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
972 last_pixel = pixel; |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
973 } |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
974 hcount -= 1.0f - height_remaining; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
975 cur_line += fb_stride / sizeof(uint32_t); |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
976 } |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
977 |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
978 for (; hcount >= 1.0f; hcount -= 1.0f) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
979 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
980 uint32_t *cur = cur_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
981 uint32_t *src = src_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
982 for (uint32_t x = 0; x < last_width ; x++) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
983 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
984 uint32_t pixel = *(src++); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
985 float count = scale_multiple; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
986 if (remaining > 0.0f) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
987 *(cur++) = mix_pixel(last_pixel, pixel, remaining); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
988 count -= 1.0f - remaining; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
989 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
990 for (; count >= 1; count -= 1.0f) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
991 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
992 *(cur++) = pixel; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
993 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
994 remaining = count; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
995 last_pixel = pixel; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
996 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
997 |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
998 cur_line += fb_stride / sizeof(uint32_t); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
999 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1000 height_remaining = hcount; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1001 last_line = src_line; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1002 src_line += LINEBUF_SIZE; |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1003 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1004 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1005 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1006 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1007 static void *buffer_copy(void *data) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1008 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1009 pthread_mutex_lock(&buffer_lock); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1010 for(;;) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1011 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1012 while (!buffer_ready) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1013 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1014 pthread_cond_wait(&buffer_cond, &buffer_lock); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1015 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1016 buffer_ready = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1017 do_buffer_copy(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1018 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1019 return 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1020 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1021 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1022 static pthread_t buffer_copy_handle; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1023 static uint8_t copy_use_thread; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1024 void window_setup(void) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1025 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1026 fbfd = open("/dev/fb0", O_RDWR); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1027 struct fb_fix_screeninfo fixInfo; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1028 struct fb_var_screeninfo varInfo; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1029 ioctl(fbfd, FBIOGET_FSCREENINFO, &fixInfo); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1030 ioctl(fbfd, FBIOGET_VSCREENINFO, &varInfo); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1031 printf("Resolution: %d x %d\n", varInfo.xres, varInfo.yres); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1032 printf("Framebuffer size: %d, line stride: %d\n", fixInfo.smem_len, fixInfo.line_length); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1033 main_width = varInfo.xres; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1034 main_height = varInfo.yres; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1035 fb_stride = fixInfo.line_length; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1036 tern_val def = {.ptrval = "audio"}; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1037 char *sync_src = tern_find_path_default(config, "system\0sync_source\0", def, TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1038 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1039 const char *vsync; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1040 def.ptrval = "off"; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1041 vsync = tern_find_path_default(config, "video\0vsync\0", def, TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1042 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1043 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1044 tern_node *video = tern_find_node(config, "video"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1045 if (video) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1046 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1047 for (int i = 0; i < NUM_VID_STD; i++) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1048 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1049 tern_node *std_settings = tern_find_node(video, vid_std_names[i]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1050 if (std_settings) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1051 char *val = tern_find_path_default(std_settings, "overscan\0top\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1052 if (val) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1053 overscan_top[i] = atoi(val); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1054 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1055 val = tern_find_path_default(std_settings, "overscan\0bottom\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1056 if (val) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1057 overscan_bot[i] = atoi(val); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1058 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1059 val = tern_find_path_default(std_settings, "overscan\0left\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1060 if (val) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1061 overscan_left[i] = atoi(val); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1062 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1063 val = tern_find_path_default(std_settings, "overscan\0right\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1064 if (val) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1065 overscan_right[i] = atoi(val); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1066 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1067 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1068 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1069 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1070 render_gl = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1071 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1072 char *gl_enabled_str = tern_find_path_default(config, "video\0gl\0", def, TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1073 uint8_t gl_enabled = strcmp(gl_enabled_str, "off") != 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1074 if (gl_enabled) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1075 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1076 render_gl = egl_setup(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1077 blue_shift = 16; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1078 green_shift = 8; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1079 red_shift = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1080 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1081 if (!render_gl) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1082 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1083 framebuffer = mmap(NULL, fixInfo.smem_len, PROT_READ|PROT_WRITE, MAP_SHARED, fbfd, 0); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1084 red_shift = varInfo.red.offset; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1085 green_shift = varInfo.green.offset; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1086 blue_shift = varInfo.blue.offset; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1087 def.ptrval = "0"; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1088 max_multiple = atoi(tern_find_path_default(config, "video\0fbdev\0max_multiple\0", def, TVAL_PTR).ptrval); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1089 def.ptrval = "true"; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1090 copy_use_thread = strcmp(tern_find_path_default(config, "video\0fbdev\0use_thread\0", def, TVAL_PTR).ptrval, "false"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1091 if (copy_use_thread) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1092 pthread_create(&buffer_copy_handle, NULL, buffer_copy, NULL); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1093 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1094 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1095 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1096 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1097 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1098 update_aspect(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1099 render_alloc_surfaces(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1100 def.ptrval = "off"; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1101 scanlines = !strcmp(tern_find_path_default(config, "video\0scanlines\0", def, TVAL_PTR).ptrval, "on"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1102 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1103 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1104 void restore_tty(void) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1105 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1106 ioctl(STDIN_FILENO, KDSETMODE, KD_TEXT); |
1781
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1107 for (int i = 0; i < cur_devices; i++) |
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1108 { |
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1109 if (device_types[i] == DEV_KEYBOARD) { |
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1110 ioctl(device_fds[i], EVIOCGRAB, 0); |
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1111 } |
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1112 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1113 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1114 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1115 void render_init(int width, int height, char * title, uint8_t fullscreen) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1116 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1117 if (height <= 0) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1118 float aspect = config_aspect() > 0.0f ? config_aspect() : 4.0f/3.0f; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1119 height = ((float)width / aspect) + 0.5f; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1120 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1121 printf("width: %d, height: %d\n", width, height); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1122 windowed_width = width; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1123 windowed_height = height; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1124 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1125 main_width = width; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1126 main_height = height; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1127 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1128 caption = title; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1129 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1130 if (isatty(STDIN_FILENO)) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1131 ioctl(STDIN_FILENO, KDSETMODE, KD_GRAPHICS); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1132 atexit(restore_tty); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1133 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1134 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1135 window_setup(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1136 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1137 init_audio(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1138 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1139 render_set_video_standard(VID_NTSC); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1140 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1141 DIR *d = opendir("/dev/input"); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1142 struct dirent* entry; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1143 int joystick_counter = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1144 while ((entry = readdir(d)) && cur_devices < MAX_DEVICES) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1145 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1146 if (!strncmp("event", entry->d_name, strlen("event"))) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1147 char *filename = alloc_concat("/dev/input/", entry->d_name); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1148 int fd = open(filename, O_RDONLY); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1149 if (fd == -1) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1150 int errnum = errno; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1151 warning("Failed to open evdev device %s for reading: %s\n", filename, strerror(errnum)); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1152 free(filename); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1153 continue; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1154 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1155 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1156 unsigned long bits; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1157 if (-1 == ioctl(fd, EVIOCGBIT(0, sizeof(bits)), &bits)) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1158 int errnum = errno; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1159 warning("Failed get capability bits from evdev device %s: %s\n", filename, strerror(errnum)); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1160 free(filename); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1161 close(fd); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1162 continue; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1163 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1164 if (!(1 & bits >> EV_KEY)) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1165 //if it doesn't support key events we don't care about it |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1166 free(filename); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1167 close(fd); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1168 continue; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1169 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1170 unsigned long button_bits[(BTN_THUMBR+8*sizeof(long))/(8*sizeof(long))]; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1171 int res = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(button_bits)), button_bits); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1172 if (-1 == res) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1173 int errnum = errno; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1174 warning("Failed get capability bits from evdev device %s: %s\n", filename, strerror(errnum)); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1175 free(filename); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1176 close(fd); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1177 continue; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1178 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1179 int to_check[] = {KEY_ENTER, BTN_MOUSE, BTN_GAMEPAD}; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1180 device_type dtype = DEV_NONE; |
1780
fc9bea5ee079
Fix off-by-one error in evdev init code and allow ALSA device to be specified in config
Michael Pavone <pavone@retrodev.com>
parents:
1779
diff
changeset
|
1181 for (int i = 0; i < 3; i++) |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1182 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1183 if (1 & button_bits[to_check[i]/(8*sizeof(button_bits[0]))] >> to_check[i]%(8*sizeof(button_bits[0]))) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1184 dtype = i + 1; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1185 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1186 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1187 if (dtype == DEV_NONE) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1188 close(fd); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1189 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1190 device_fds[cur_devices] = fd; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1191 device_types[cur_devices] = dtype; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1192 char name[1024]; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1193 char *names[] = {"Keyboard", "Mouse", "Gamepad"}; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1194 ioctl(fd, EVIOCGNAME(sizeof(name)), name); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1195 printf("%s is a %s\n%s\n", filename, names[dtype - 1], name); |
1781
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1196 |
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1197 if (dtype == DEV_GAMEPAD) { |
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1198 handle_joy_added(joystick_counter++); |
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1199 } else if (dtype == DEV_KEYBOARD && isatty(STDIN_FILENO)) { |
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1200 ioctl(fd, EVIOCGRAB, 1); |
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1201 } |
2b4d5cfec6d9
Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents:
1780
diff
changeset
|
1202 |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1203 //set FD to non-blocking mode for event polling |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1204 fcntl(fd, F_SETFL, O_NONBLOCK); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1205 cur_devices++; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1206 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1207 free(filename); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1208 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1209 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1210 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1211 atexit(render_quit); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1212 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1213 #include<unistd.h> |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1214 static int in_toggle; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1215 static void update_source(audio_source *src, double rc, uint8_t sync_changed) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1216 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1217 double alpha = src->dt / (src->dt + rc); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1218 int32_t lowpass_alpha = (int32_t)(((double)0x10000) * alpha); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1219 src->lowpass_alpha = lowpass_alpha; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1220 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1221 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1222 void render_config_updated(void) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1223 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1224 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1225 free_surfaces(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1226 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1227 if (render_gl) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1228 /*if (on_context_destroyed) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1229 on_context_destroyed(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1230 }*/ |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1231 gl_teardown(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1232 //FIXME: EGL equivalent |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1233 //SDL_GL_DeleteContext(main_context); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1234 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1235 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1236 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1237 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1238 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1239 //FIXME: EGL equivalent |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1240 //SDL_DestroyWindow(main_window); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1241 drain_events(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1242 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1243 char *config_width = tern_find_path(config, "video\0width\0", TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1244 if (config_width) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1245 windowed_width = atoi(config_width); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1246 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1247 char *config_height = tern_find_path(config, "video\0height\0", TVAL_PTR).ptrval; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1248 if (config_height) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1249 windowed_height = atoi(config_height); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1250 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1251 float aspect = config_aspect() > 0.0f ? config_aspect() : 4.0f/3.0f; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1252 windowed_height = ((float)windowed_width / aspect) + 0.5f; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1253 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1254 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1255 window_setup(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1256 update_aspect(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1257 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1258 //need to check render_gl again after window_setup as render option could have changed |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1259 /*if (render_gl && on_context_created) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1260 on_context_created(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1261 }*/ |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1262 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1263 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1264 render_close_audio(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1265 quitting = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1266 init_audio(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1267 render_set_video_standard(video_standard); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1268 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1269 double lowpass_cutoff = get_lowpass_cutoff(config); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1270 double rc = (1.0 / lowpass_cutoff) / (2.0 * M_PI); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1271 for (uint8_t i = 0; i < num_audio_sources; i++) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1272 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1273 update_source(audio_sources[i], rc, 0); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1274 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1275 for (uint8_t i = 0; i < num_inactive_audio_sources; i++) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1276 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1277 update_source(inactive_audio_sources[i], rc, 0); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1278 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1279 drain_events(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1280 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1281 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1282 void render_set_video_standard(vid_std std) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1283 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1284 video_standard = std; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1285 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1286 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1287 void render_update_caption(char *title) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1288 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1289 caption = title; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1290 free(fps_caption); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1291 fps_caption = NULL; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1292 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1293 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1294 static char *screenshot_path; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1295 void render_save_screenshot(char *path) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1296 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1297 if (screenshot_path) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1298 free(screenshot_path); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1299 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1300 screenshot_path = path; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1301 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1302 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1303 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height, window_close_handler close_handler) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1304 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1305 //not supported under fbdev |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1306 return 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1307 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1308 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1309 void render_destroy_window(uint8_t which) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1310 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1311 //not supported under fbdev |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1312 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1313 |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1314 static uint8_t last_fb; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1315 static uint32_t texture_off; |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1316 uint32_t *render_get_framebuffer(uint8_t which, int *pitch) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1317 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1318 if (max_multiple == 1 && !render_gl) { |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1319 if (last_fb != which) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1320 *pitch = fb_stride * 2; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1321 return framebuffer + (which == FRAMEBUFFER_EVEN ? fb_stride / sizeof(uint32_t) : 0); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1322 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1323 *pitch = fb_stride; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1324 return framebuffer; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1325 } |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1326 if (!render_gl && last_fb != which) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1327 *pitch = LINEBUF_SIZE * sizeof(uint32_t) * 2; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1328 return texture_buf + texture_off + (which == FRAMEBUFFER_EVEN ? LINEBUF_SIZE : 0); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1329 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1330 *pitch = LINEBUF_SIZE * sizeof(uint32_t); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1331 return texture_buf + texture_off; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1332 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1333 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1334 uint8_t events_processed; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1335 #ifdef __ANDROID__ |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1336 #define FPS_INTERVAL 10000 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1337 #else |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1338 #define FPS_INTERVAL 1000 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1339 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1340 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1341 static uint8_t interlaced; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1342 void render_update_display(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1343 void render_framebuffer_updated(uint8_t which, int width) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1344 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1345 uint32_t height = which <= FRAMEBUFFER_EVEN |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1346 ? (video_standard == VID_NTSC ? 243 : 294) - (overscan_top[video_standard] + overscan_bot[video_standard]) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1347 : 240; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1348 width -= overscan_left[video_standard] + overscan_right[video_standard]; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1349 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1350 if (render_gl && which <= FRAMEBUFFER_EVEN) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1351 last_width = width; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1352 glBindTexture(GL_TEXTURE_2D, textures[which]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1353 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, LINEBUF_SIZE, height, SRC_FORMAT, GL_UNSIGNED_BYTE, texture_buf + overscan_left[video_standard] + LINEBUF_SIZE * overscan_top[video_standard]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1354 render_update_display(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1355 last_height = height; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1356 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1357 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1358 if (max_multiple != 1) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1359 if (copy_use_thread) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1360 pthread_mutex_lock(&buffer_lock); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1361 buffer_ready = 1; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1362 last_width = width; |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
1363 last_width_scale = LINEBUF_SIZE - (overscan_left[video_standard] + overscan_right[video_standard]); |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1364 last_height = last_height_scale = height; |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1365 copy_buffer = texture_buf + texture_off + overscan_left[video_standard] + LINEBUF_SIZE * overscan_top[video_standard]; |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1366 if (which != last_fb) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1367 last_height *= 2; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1368 copy_buffer += LINEBUF_SIZE * overscan_top[video_standard]; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1369 uint32_t *src = texture_buf + (texture_off ? 0 : LINEBUF_SIZE * MAX_FB_LINES) + overscan_left[video_standard] + LINEBUF_SIZE * overscan_top[video_standard] + LINEBUF_SIZE * overscan_top[video_standard]; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1370 uint32_t *dst = copy_buffer; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1371 if (which == FRAMEBUFFER_ODD) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1372 src += LINEBUF_SIZE; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1373 dst += LINEBUF_SIZE; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1374 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1375 for (int i = 0; i < height; i++) |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1376 { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1377 memcpy(dst, src, width * sizeof(uint32_t)); |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1378 src += LINEBUF_SIZE * 2; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1379 dst += LINEBUF_SIZE * 2; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1380 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1381 } |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1382 texture_off = texture_off ? 0 : LINEBUF_SIZE * MAX_FB_LINES; |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1383 pthread_cond_signal(&buffer_cond); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1384 pthread_mutex_unlock(&buffer_lock); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1385 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1386 last_width = width; |
1782
b2bffd98063d
Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents:
1781
diff
changeset
|
1387 last_width_scale = LINEBUF_SIZE - (overscan_left[video_standard] + overscan_right[video_standard]); |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1388 last_height = last_height_scale = height; |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1389 copy_buffer = texture_buf + texture_off + overscan_left[video_standard] + LINEBUF_SIZE * overscan_top[video_standard]; |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1390 if (which != last_fb) { |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1391 last_height *= 2; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1392 copy_buffer += LINEBUF_SIZE * overscan_top[video_standard]; |
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1393 } |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1394 do_buffer_copy(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1395 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1396 } |
1785
8f2e78db0872
Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1782
diff
changeset
|
1397 last_fb = which; |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1398 if (!events_processed) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1399 process_events(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1400 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1401 events_processed = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1402 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1403 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1404 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1405 } |
1786
2b661c1e431f
Remove some commented out code in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents:
1785
diff
changeset
|
1406 |
1779
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1407 void render_update_display() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1408 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1409 #ifndef DISABLE_OPENGL |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1410 if (render_gl) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1411 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1412 glClear(GL_COLOR_BUFFER_BIT); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1413 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1414 glUseProgram(program); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1415 glActiveTexture(GL_TEXTURE0); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1416 glBindTexture(GL_TEXTURE_2D, textures[0]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1417 glUniform1i(un_textures[0], 0); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1418 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1419 glActiveTexture(GL_TEXTURE1); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1420 glBindTexture(GL_TEXTURE_2D, textures[interlaced ? 1 : scanlines ? 2 : 0]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1421 glUniform1i(un_textures[1], 1); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1422 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1423 glUniform1f(un_width, render_emulated_width()); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1424 glUniform1f(un_height, last_height); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1425 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1426 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1427 glVertexAttribPointer(at_pos, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat[2]), (void *)0); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1428 glEnableVertexAttribArray(at_pos); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1429 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1430 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1431 glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (void *)0); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1432 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1433 glDisableVertexAttribArray(at_pos); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1434 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1435 /*if (render_ui) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1436 render_ui(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1437 }*/ |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1438 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1439 eglSwapBuffers(egl_display, main_surface); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1440 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1441 #endif |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1442 if (!events_processed) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1443 process_events(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1444 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1445 events_processed = 0; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1446 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1447 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1448 uint32_t render_emulated_width() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1449 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1450 return last_width - overscan_left[video_standard] - overscan_right[video_standard]; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1451 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1452 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1453 uint32_t render_emulated_height() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1454 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1455 return (video_standard == VID_NTSC ? 243 : 294) - overscan_top[video_standard] - overscan_bot[video_standard]; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1456 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1457 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1458 uint32_t render_overscan_left() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1459 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1460 return overscan_left[video_standard]; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1461 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1462 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1463 uint32_t render_overscan_top() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1464 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1465 return overscan_top[video_standard]; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1466 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1467 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1468 void render_wait_quit(vdp_context * context) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1469 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1470 for(;;) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1471 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1472 drain_events(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1473 sleep(1); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1474 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1475 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1476 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1477 int render_lookup_button(char *name) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1478 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1479 static tern_node *button_lookup; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1480 if (!button_lookup) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1481 //xbox/sdl style names |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1482 button_lookup = tern_insert_int(button_lookup, "a", BTN_SOUTH); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1483 button_lookup = tern_insert_int(button_lookup, "b", BTN_EAST); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1484 button_lookup = tern_insert_int(button_lookup, "x", BTN_WEST); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1485 button_lookup = tern_insert_int(button_lookup, "y", BTN_NORTH); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1486 button_lookup = tern_insert_int(button_lookup, "back", BTN_SELECT); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1487 button_lookup = tern_insert_int(button_lookup, "start", BTN_START); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1488 button_lookup = tern_insert_int(button_lookup, "guid", BTN_MODE); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1489 button_lookup = tern_insert_int(button_lookup, "leftshoulder", BTN_TL); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1490 button_lookup = tern_insert_int(button_lookup, "rightshoulder", BTN_TR); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1491 button_lookup = tern_insert_int(button_lookup, "leftstick", BTN_THUMBL); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1492 button_lookup = tern_insert_int(button_lookup, "rightstick", BTN_THUMBR); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1493 //alternative Playstation-style names |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1494 button_lookup = tern_insert_int(button_lookup, "cross", BTN_SOUTH); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1495 button_lookup = tern_insert_int(button_lookup, "circle", BTN_EAST); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1496 button_lookup = tern_insert_int(button_lookup, "square", BTN_WEST); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1497 button_lookup = tern_insert_int(button_lookup, "triangle", BTN_NORTH); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1498 button_lookup = tern_insert_int(button_lookup, "share", BTN_SELECT); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1499 button_lookup = tern_insert_int(button_lookup, "select", BTN_SELECT); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1500 button_lookup = tern_insert_int(button_lookup, "options", BTN_START); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1501 button_lookup = tern_insert_int(button_lookup, "l1", BTN_TL); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1502 button_lookup = tern_insert_int(button_lookup, "r1", BTN_TR); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1503 button_lookup = tern_insert_int(button_lookup, "l3", BTN_THUMBL); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1504 button_lookup = tern_insert_int(button_lookup, "r3", BTN_THUMBR); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1505 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1506 return (int)tern_find_int(button_lookup, name, KEY_CNT); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1507 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1508 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1509 int render_lookup_axis(char *name) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1510 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1511 static tern_node *axis_lookup; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1512 if (!axis_lookup) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1513 //xbox/sdl style names |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1514 axis_lookup = tern_insert_int(axis_lookup, "leftx", ABS_X); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1515 axis_lookup = tern_insert_int(axis_lookup, "lefty", ABS_Y); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1516 axis_lookup = tern_insert_int(axis_lookup, "lefttrigger", ABS_Z); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1517 axis_lookup = tern_insert_int(axis_lookup, "rightx", ABS_RX); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1518 axis_lookup = tern_insert_int(axis_lookup, "righty", ABS_RY); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1519 axis_lookup = tern_insert_int(axis_lookup, "righttrigger", ABS_RZ); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1520 //alternative Playstation-style names |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1521 axis_lookup = tern_insert_int(axis_lookup, "l2", ABS_Z); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1522 axis_lookup = tern_insert_int(axis_lookup, "r2", ABS_RZ); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1523 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1524 return (int)tern_find_int(axis_lookup, name, ABS_CNT); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1525 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1526 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1527 int32_t render_translate_input_name(int32_t controller, char *name, uint8_t is_axis) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1528 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1529 tern_node *button_lookup, *axis_lookup; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1530 if (is_axis) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1531 int axis = render_lookup_axis(name); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1532 if (axis == ABS_CNT) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1533 return RENDER_INVALID_NAME; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1534 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1535 return RENDER_AXIS_BIT | axis; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1536 } else { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1537 int button = render_lookup_button(name); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1538 if (button != KEY_CNT) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1539 return button; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1540 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1541 if (!strcmp("dpup", name)) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1542 return RENDER_DPAD_BIT | 1; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1543 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1544 if (!strcmp("dpdown", name)) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1545 return RENDER_DPAD_BIT | 4; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1546 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1547 if (!strcmp("dpdleft", name)) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1548 return RENDER_DPAD_BIT | 8; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1549 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1550 if (!strcmp("dpright", name)) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1551 return RENDER_DPAD_BIT | 2; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1552 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1553 return RENDER_INVALID_NAME; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1554 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1555 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1556 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1557 int32_t render_dpad_part(int32_t input) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1558 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1559 return input >> 4 & 0xFFFFFF; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1560 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1561 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1562 uint8_t render_direction_part(int32_t input) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1563 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1564 return input & 0xF; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1565 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1566 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1567 int32_t render_axis_part(int32_t input) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1568 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1569 return input & 0xFFFFFFF; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1570 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1571 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1572 void process_events() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1573 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1574 if (events_processed > MAX_EVENT_POLL_PER_FRAME) { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1575 return; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1576 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1577 drain_events(); |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1578 events_processed++; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1579 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1580 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1581 #define TOGGLE_MIN_DELAY 250 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1582 void render_toggle_fullscreen() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1583 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1584 //always fullscreen in fbdev |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1585 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1586 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1587 uint32_t render_audio_buffer() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1588 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1589 return buffer_samples; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1590 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1591 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1592 uint32_t render_sample_rate() |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1593 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1594 return sample_rate; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1595 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1596 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1597 void render_errorbox(char *title, char *message) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1598 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1599 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1600 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1601 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1602 void render_warnbox(char *title, char *message) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1603 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1604 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1605 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1606 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1607 void render_infobox(char *title, char *message) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1608 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1609 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1610 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1611 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1612 uint8_t render_has_gl(void) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1613 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1614 return render_gl; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1615 } |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1616 |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1617 uint8_t render_get_active_framebuffer(void) |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1618 { |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1619 return FRAMEBUFFER_ODD; |
3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1620 } |