annotate render_fbdev.c @ 1918:6fdac0108e47

Fix bug in in (c) instruction in Z80 dynarec
author Michael Pavone <pavone@retrodev.com>
date Fri, 03 Apr 2020 23:47:57 -0700
parents 2b661c1e431f
children 2fd0a8cb1c80
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 static unsigned int output_channels, sample_rate;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 static uint32_t missing_count;
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 struct audio_source {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 int16_t *front;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 int16_t *back;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 double dt;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 uint64_t buffer_fraction;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 uint64_t buffer_inc;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 uint32_t buffer_pos;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 uint32_t read_start;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 uint32_t read_end;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 uint32_t lowpass_alpha;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 uint32_t mask;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 int16_t last_left;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 int16_t last_right;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 uint8_t num_channels;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
73 uint8_t front_populated;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 };
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
76 static audio_source *audio_sources[8];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 static audio_source *inactive_audio_sources[8];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 static uint8_t num_audio_sources;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 static uint8_t num_inactive_audio_sources;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 static uint32_t min_buffered;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 typedef int32_t (*mix_func)(audio_source *audio, void *vstream, int len);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 static int32_t mix_s16(audio_source *audio, void *vstream, int len)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 int samples = len/(sizeof(int16_t)*output_channels);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 int16_t *stream = vstream;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 int16_t *end = stream + output_channels*samples;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 int16_t *src = audio->front;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 uint32_t i = audio->read_start;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 uint32_t i_end = audio->read_end;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 int16_t *cur = stream;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 size_t first_add = output_channels > 1 ? 1 : 0, second_add = output_channels > 1 ? output_channels - 1 : 1;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 if (audio->num_channels == 1) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
95 while (cur < end && i != i_end)
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 *cur += src[i];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
98 cur += first_add;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
99 *cur += src[i++];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 cur += second_add;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
101 i &= audio->mask;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
102 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
103 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
104 while (cur < end && i != i_end)
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 *cur += src[i++];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
107 cur += first_add;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
108 *cur += src[i++];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
109 cur += second_add;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
110 i &= audio->mask;
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
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
114 if (cur != end) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
115 printf("Underflow of %d samples, read_start: %d, read_end: %d, mask: %X\n", (int)(end-cur)/2, audio->read_start, audio->read_end, audio->mask);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
116 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
117 if (cur != end) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
118 //printf("Underflow of %d samples, read_start: %d, read_end: %d, mask: %X\n", (int)(end-cur)/2, audio->read_start, audio->read_end, audio->mask);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 return (cur-end)/2;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
120 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
121 return ((i_end - i) & audio->mask) / audio->num_channels;
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 }
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 int32_t mix_f32(audio_source *audio, void *vstream, int len)
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 int samples = len/(sizeof(float)*output_channels);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 float *stream = vstream;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
129 float *end = stream + output_channels*samples;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
130 int16_t *src = audio->front;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 uint32_t i = audio->read_start;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132 uint32_t i_end = audio->read_end;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
133 float *cur = stream;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
134 size_t first_add = output_channels > 1 ? 1 : 0, second_add = output_channels > 1 ? output_channels - 1 : 1;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
135 if (audio->num_channels == 1) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
136 while (cur < end && i != i_end)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
137 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138 *cur += ((float)src[i]) / 0x7FFF;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
139 cur += first_add;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
140 *cur += ((float)src[i++]) / 0x7FFF;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 cur += second_add;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
142 i &= audio->mask;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
143 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
144 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
145 while(cur < end && i != i_end)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
146 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 *cur += ((float)src[i++]) / 0x7FFF;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 cur += first_add;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
149 *cur += ((float)src[i++]) / 0x7FFF;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 cur += second_add;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151 i &= audio->mask;
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 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 if (cur != end) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155 printf("Underflow of %d samples, read_start: %d, read_end: %d, mask: %X\n", (int)(end-cur)/2, audio->read_start, audio->read_end, audio->mask);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156 return (cur-end)/2;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
158 return ((i_end - i) & audio->mask) / audio->num_channels;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
159 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
160 }
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 static int32_t mix_null(audio_source *audio, void *vstream, int len)
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 return 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 static mix_func mix;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
169 static void render_close_audio()
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
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 #define BUFFER_INC_RES 0x40000000UL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
176 void render_audio_adjust_clock(audio_source *src, uint64_t master_clock, uint64_t sample_divider)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
177 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
178 src->buffer_inc = ((BUFFER_INC_RES * (uint64_t)sample_rate) / master_clock) * sample_divider;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
179 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
180
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
181 audio_source *render_audio_source(uint64_t master_clock, uint64_t sample_divider, uint8_t channels)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
182 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
183 audio_source *ret = NULL;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
184 uint32_t alloc_size = channels * buffer_samples;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
185 if (num_audio_sources < 8) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
186 ret = malloc(sizeof(audio_source));
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
187 ret->back = malloc(alloc_size * sizeof(int16_t));
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
188 ret->front = malloc(alloc_size * sizeof(int16_t));
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
189 ret->front_populated = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
190 ret->num_channels = channels;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
191 audio_sources[num_audio_sources++] = ret;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
192 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
193 if (!ret) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
194 fatal_error("Too many audio sources!");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
195 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
196 render_audio_adjust_clock(ret, master_clock, sample_divider);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
197 double lowpass_cutoff = get_lowpass_cutoff(config);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
198 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
199 ret->dt = 1.0 / ((double)master_clock / (double)(sample_divider));
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
200 double alpha = ret->dt / (ret->dt + rc);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
201 ret->lowpass_alpha = (int32_t)(((double)0x10000) * alpha);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
202 ret->buffer_pos = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
203 ret->buffer_fraction = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
204 ret->last_left = ret->last_right = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
205 ret->read_start = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
206 ret->read_end = buffer_samples * channels;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
207 ret->mask = 0xFFFFFFFF;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
208 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
209 return ret;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
210 }
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 void render_pause_source(audio_source *src)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
213 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
214 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
215 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
216 if (audio_sources[i] == src) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
217 audio_sources[i] = audio_sources[--num_audio_sources];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
218 break;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
219 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
220 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
221 inactive_audio_sources[num_inactive_audio_sources++] = src;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
222 }
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 void render_resume_source(audio_source *src)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
225 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
226 if (num_audio_sources < 8) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
227 audio_sources[num_audio_sources++] = src;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
228 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
229 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
230 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
231 if (inactive_audio_sources[i] == src) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
232 inactive_audio_sources[i] = inactive_audio_sources[--num_inactive_audio_sources];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
233 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
234 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
235 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
236
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
237 void render_free_source(audio_source *src)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
238 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
239 render_pause_source(src);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
240
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
241 free(src->front);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
242 free(src->back);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
243 free(src);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
244 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
245 snd_pcm_t *audio_handle;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
246 static void do_audio_ready(audio_source *src)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
247 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
248 if (src->front_populated) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
249 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
250 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
251 int16_t *tmp = src->front;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
252 src->front = src->back;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
253 src->back = tmp;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
254 src->front_populated = 1;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
255 src->buffer_pos = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
256
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
257 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
258 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
259 if (!audio_sources[i]->front_populated) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
260 //at least one audio source is not ready yet.
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
261 return;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
262 }
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
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
265 size_t bytes = (mix == mix_s16 ? sizeof(int16_t) : sizeof(float)) * output_channels * buffer_samples;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
266 void *buffer = malloc(bytes);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
267 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
268 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
269 mix(audio_sources[i], buffer, bytes);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
270 audio_sources[i]->front_populated = 0;
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 int frames = snd_pcm_writei(audio_handle, buffer, buffer_samples);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
273 if (frames < 0) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
274 frames = snd_pcm_recover(audio_handle, frames, 0);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
275 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
276 if (frames < 0) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
277 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
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
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
281 static int16_t lowpass_sample(audio_source *src, int16_t last, int16_t current)
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 int32_t tmp = current * src->lowpass_alpha + last * (0x10000 - src->lowpass_alpha);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
284 current = tmp >> 16;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
285 return current;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
286 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
287
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
288 static void interp_sample(audio_source *src, int16_t last, int16_t current)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
289 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
290 int64_t tmp = last * ((src->buffer_fraction << 16) / src->buffer_inc);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
291 tmp += current * (0x10000 - ((src->buffer_fraction << 16) / src->buffer_inc));
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
292 src->back[src->buffer_pos++] = tmp >> 16;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
293 }
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 void render_put_mono_sample(audio_source *src, int16_t value)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
296 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
297 value = lowpass_sample(src, src->last_left, value);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
298 src->buffer_fraction += src->buffer_inc;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
299 uint32_t base = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
300 while (src->buffer_fraction > BUFFER_INC_RES)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
301 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
302 src->buffer_fraction -= BUFFER_INC_RES;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
303 interp_sample(src, src->last_left, value);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
304
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
305 if (((src->buffer_pos - base) & src->mask) >= buffer_samples) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
306 do_audio_ready(src);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
307 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
308 src->buffer_pos &= src->mask;
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 src->last_left = value;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
311 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
312
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
313 void render_put_stereo_sample(audio_source *src, int16_t left, int16_t right)
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 left = lowpass_sample(src, src->last_left, left);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
316 right = lowpass_sample(src, src->last_right, right);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
317 src->buffer_fraction += src->buffer_inc;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
318 uint32_t base = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
319 while (src->buffer_fraction > BUFFER_INC_RES)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
320 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
321 src->buffer_fraction -= BUFFER_INC_RES;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
322
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
323 interp_sample(src, src->last_left, left);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
324 interp_sample(src, src->last_right, right);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
325
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
326 if (((src->buffer_pos - base) & src->mask)/2 >= buffer_samples) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
327 do_audio_ready(src);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
328 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
329 src->buffer_pos &= src->mask;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
330 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
331 src->last_left = left;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
332 src->last_right = right;
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
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
335 int render_width()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
336 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
337 return main_width;
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 int render_height()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
341 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
342 return main_height;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
343 }
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 int render_fullscreen()
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 return 1;
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
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
350 uint32_t red_shift, blue_shift, green_shift;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
351 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
352 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
353 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
354 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
355
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
356 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
357 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
358
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
359 static GLfloat vertex_data_default[] = {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
360 -1.0f, -1.0f,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
361 1.0f, -1.0f,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
362 -1.0f, 1.0f,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
363 1.0f, 1.0f
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
364 };
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
365
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
366 static GLfloat vertex_data[8];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
367
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
368 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
369
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
370 static const GLchar shader_prefix[] =
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
371 #ifdef USE_GLES
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
372 "#version 100\n";
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
373 #else
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
374 "#version 110\n"
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
375 "#define lowp\n"
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
376 "#define mediump\n"
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
377 "#define highp\n";
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
378 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
379
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
380 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
381 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
382 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
383 char * shader_path = alloc_concat_m(3, parts);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
384 FILE * f = fopen(shader_path, "rb");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
385 free(shader_path);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
386 GLchar * text;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
387 long fsize;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
388 if (f) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
389 fsize = file_size(f);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
390 text = malloc(fsize);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
391 if (fread(text, 1, fsize, f) != fsize) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
392 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
393 free(text);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
394 return 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
395 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
396 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
397 shader_path = path_append("shaders", fname);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
398 uint32_t fsize32;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
399 text = read_bundled_file(shader_path, &fsize32);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
400 free(shader_path);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
401 if (!text) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
402 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
403 return 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
404 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
405 fsize = fsize32;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
406 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
407
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
408 if (strncmp(text, "#version", strlen("#version"))) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
409 GLchar *tmp = text;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
410 text = alloc_concat(shader_prefix, tmp);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
411 free(tmp);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
412 fsize += strlen(shader_prefix);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
413 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
414 GLuint ret = glCreateShader(shader_type);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
415 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
416 free(text);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
417 glCompileShader(ret);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
418 GLint compile_status, loglen;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
419 glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
420 if (!compile_status) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
421 glGetShaderiv(ret, GL_INFO_LOG_LENGTH, &loglen);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
422 text = malloc(loglen);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
423 glGetShaderInfoLog(ret, loglen, NULL, text);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
424 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
425 free(text);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
426 glDeleteShader(ret);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
427 return 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
428 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
429 return ret;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
430 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
431 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
432
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
433 #define MAX_FB_LINES 590
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
434 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
435 #ifdef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
436 #define RENDER_FORMAT SDL_PIXELFORMAT_ARGB8888
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
437 #else
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
438 #ifdef USE_GLES
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
439 #define INTERNAL_FORMAT GL_RGBA
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
440 #define SRC_FORMAT GL_RGBA
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
441 #define RENDER_FORMAT SDL_PIXELFORMAT_ABGR8888
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
442 #else
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
443 #define INTERNAL_FORMAT GL_RGBA8
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
444 #define SRC_FORMAT GL_BGRA
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
445 #define RENDER_FORMAT SDL_PIXELFORMAT_ARGB8888
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
446 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
447 static void gl_setup()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
448 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
449 tern_val def = {.ptrval = "linear"};
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
450 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
451 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
452 glGenTextures(3, textures);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
453 for (int i = 0; i < 3; i++)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
454 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
455 glBindTexture(GL_TEXTURE_2D, textures[i]);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
456 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
457 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
458 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
459 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
460 if (i < 2) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
461 //TODO: Fixme for PAL + invalid display mode
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
462 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
463 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
464 uint32_t blank = 255 << 24;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
465 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
466 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
467 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
468 glGenBuffers(2, buffers);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
469 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
470 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
471 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
472 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
473 def.ptrval = "default.v.glsl";
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
474 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
475 def.ptrval = "default.f.glsl";
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
476 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
477 program = glCreateProgram();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
478 glAttachShader(program, vshader);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
479 glAttachShader(program, fshader);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
480 glLinkProgram(program);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
481 GLint link_status;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
482 glGetProgramiv(program, GL_LINK_STATUS, &link_status);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
483 if (!link_status) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
484 fputs("Failed to link shader program\n", stderr);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
485 exit(1);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
486 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
487 un_textures[0] = glGetUniformLocation(program, "textures[0]");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
488 un_textures[1] = glGetUniformLocation(program, "textures[1]");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
489 un_width = glGetUniformLocation(program, "width");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
490 un_height = glGetUniformLocation(program, "height");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
491 at_pos = glGetAttribLocation(program, "pos");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
492 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
493
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
494 static void gl_teardown()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
495 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
496 glDeleteProgram(program);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
497 glDeleteShader(vshader);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
498 glDeleteShader(fshader);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
499 glDeleteBuffers(2, buffers);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
500 glDeleteTextures(3, textures);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
501 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
502 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
503
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
504 static uint8_t texture_init;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
505 static void render_alloc_surfaces()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
506 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
507 if (texture_init) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
508 return;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
509 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
510 texture_init = 1;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
511 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
512 if (render_gl) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
513 gl_setup();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
514 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
515 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
516 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
517
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
518 static void free_surfaces(void)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
519 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
520 texture_init = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
521 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
522
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
523 static char * caption = NULL;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
524 static char * fps_caption = NULL;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
525
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
526 static void render_quit()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
527 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
528 render_close_audio();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
529 free_surfaces();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
530 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
531 if (render_gl) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
532 gl_teardown();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
533 //FIXME: replace with EGL equivalent
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
534 //SDL_GL_DeleteContext(main_context);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
535 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
536 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
537 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
538
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
539 static float config_aspect()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
540 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
541 static float aspect = 0.0f;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
542 if (aspect == 0.0f) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
543 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
544 if (strcmp("stretch", config_aspect)) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
545 aspect = 4.0f/3.0f;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
546 char *end;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
547 float aspect_numerator = strtof(config_aspect, &end);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
548 if (aspect_numerator > 0.0f && *end == ':') {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
549 float aspect_denominator = strtof(end+1, &end);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
550 if (aspect_denominator > 0.0f && !*end) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
551 aspect = aspect_numerator / aspect_denominator;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
552 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
553 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
554 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
555 aspect = -1.0f;
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 return aspect;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
559 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
560
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
561 static void update_aspect()
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 //reset default values
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
564 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
565 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
566 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
567 if (config_aspect() > 0.0f) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
568 float aspect = (float)main_width / main_height;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
569 if (fabs(aspect - config_aspect()) < 0.01f) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
570 //close enough for government work
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
571 return;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
572 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
573 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
574 if (render_gl) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
575 for (int i = 0; i < 4; i++)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
576 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
577 if (aspect > config_aspect()) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
578 vertex_data[i*2] *= config_aspect()/aspect;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
579 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
580 vertex_data[i*2+1] *= aspect/config_aspect();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
581 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
582 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
583 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
584 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
585 //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
586 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
587 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
588 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
589 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
590 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
591
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
592 static uint8_t scancode_map[128] = {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
593 [KEY_A] = 0x1C,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
594 [KEY_B] = 0x32,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
595 [KEY_C] = 0x21,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
596 [KEY_D] = 0x23,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
597 [KEY_E] = 0x24,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
598 [KEY_F] = 0x2B,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
599 [KEY_G] = 0x34,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
600 [KEY_H] = 0x33,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
601 [KEY_I] = 0x43,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
602 [KEY_J] = 0x3B,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
603 [KEY_K] = 0x42,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
604 [KEY_L] = 0x4B,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
605 [KEY_M] = 0x3A,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
606 [KEY_N] = 0x31,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
607 [KEY_O] = 0x44,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
608 [KEY_P] = 0x4D,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
609 [KEY_Q] = 0x15,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
610 [KEY_R] = 0x2D,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
611 [KEY_S] = 0x1B,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
612 [KEY_T] = 0x2C,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
613 [KEY_U] = 0x3C,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
614 [KEY_V] = 0x2A,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
615 [KEY_W] = 0x1D,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
616 [KEY_X] = 0x22,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
617 [KEY_Y] = 0x35,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
618 [KEY_Z] = 0x1A,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
619 [KEY_1] = 0x16,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
620 [KEY_2] = 0x1E,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
621 [KEY_3] = 0x26,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
622 [KEY_4] = 0x25,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
623 [KEY_5] = 0x2E,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
624 [KEY_6] = 0x36,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
625 [KEY_7] = 0x3D,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
626 [KEY_8] = 0x3E,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
627 [KEY_9] = 0x46,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
628 [KEY_0] = 0x45,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
629 [KEY_ENTER] = 0x5A,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
630 [KEY_ESC] = 0x76,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
631 [KEY_SPACE] = 0x29,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
632 [KEY_TAB] = 0x0D,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
633 [KEY_BACKSPACE] = 0x66,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
634 [KEY_MINUS] = 0x4E,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
635 [KEY_EQUAL] = 0x55,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
636 [KEY_LEFTBRACE] = 0x54,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
637 [KEY_RIGHTBRACE] = 0x5B,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
638 [KEY_BACKSLASH] = 0x5D,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
639 [KEY_SEMICOLON] = 0x4C,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
640 [KEY_APOSTROPHE] = 0x52,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
641 [KEY_GRAVE] = 0x0E,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
642 [KEY_COMMA] = 0x41,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
643 [KEY_DOT] = 0x49,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
644 [KEY_SLASH] = 0x4A,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
645 [KEY_CAPSLOCK] = 0x58,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
646 [KEY_F1] = 0x05,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
647 [KEY_F2] = 0x06,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
648 [KEY_F3] = 0x04,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
649 [KEY_F4] = 0x0C,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
650 [KEY_F5] = 0x03,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
651 [KEY_F6] = 0x0B,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
652 [KEY_F7] = 0x83,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
653 [KEY_F8] = 0x0A,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
654 [KEY_F9] = 0x01,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
655 [KEY_F10] = 0x09,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
656 [KEY_F11] = 0x78,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
657 [KEY_F12] = 0x07,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
658 [KEY_LEFTCTRL] = 0x14,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
659 [KEY_LEFTSHIFT] = 0x12,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
660 [KEY_LEFTALT] = 0x11,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
661 [KEY_RIGHTCTRL] = 0x18,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
662 [KEY_RIGHTSHIFT] = 0x59,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
663 [KEY_RIGHTALT] = 0x17,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
664 [KEY_INSERT] = 0x81,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
665 [KEY_PAUSE] = 0x82,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
666 [KEY_SYSRQ] = 0x84,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
667 [KEY_SCROLLLOCK] = 0x7E,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
668 [KEY_DELETE] = 0x85,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
669 [KEY_LEFT] = 0x86,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
670 [KEY_HOME] = 0x87,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
671 [KEY_END] = 0x88,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
672 [KEY_UP] = 0x89,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
673 [KEY_DOWN] = 0x8A,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
674 [KEY_PAGEUP] = 0x8B,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
675 [KEY_PAGEDOWN] = 0x8C,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
676 [KEY_RIGHT] = 0x8D,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
677 [KEY_NUMLOCK] = 0x77,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
678 [KEY_KPSLASH] = 0x80,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
679 [KEY_KPASTERISK] = 0x7C,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
680 [KEY_KPMINUS] = 0x7B,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
681 [KEY_KPPLUS] = 0x79,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
682 [KEY_KPENTER] = 0x19,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
683 [KEY_KP1] = 0x69,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
684 [KEY_KP2] = 0x72,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
685 [KEY_KP3] = 0x7A,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
686 [KEY_KP4] = 0x6B,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
687 [KEY_KP5] = 0x73,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
688 [KEY_KP6] = 0x74,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
689 [KEY_KP7] = 0x6C,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
690 [KEY_KP8] = 0x75,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
691 [KEY_KP9] = 0x7D,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
692 [KEY_KP0] = 0x70,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
693 [KEY_KPDOT] = 0x71,
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
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
696 #include "special_keys_evdev.h"
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
697 static uint8_t sym_map[128] = {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
698 [KEY_A] = 'a',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
699 [KEY_B] = 'b',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
700 [KEY_C] = 'c',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
701 [KEY_D] = 'd',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
702 [KEY_E] = 'e',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
703 [KEY_F] = 'f',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
704 [KEY_G] = 'g',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
705 [KEY_H] = 'h',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
706 [KEY_I] = 'i',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
707 [KEY_J] = 'j',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
708 [KEY_K] = 'k',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
709 [KEY_L] = 'l',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
710 [KEY_M] = 'm',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
711 [KEY_N] = 'n',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
712 [KEY_O] = 'o',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
713 [KEY_P] = 'p',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
714 [KEY_Q] = 'q',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
715 [KEY_R] = 'r',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
716 [KEY_S] = 's',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
717 [KEY_T] = 't',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
718 [KEY_U] = 'u',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
719 [KEY_V] = 'v',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
720 [KEY_W] = 'w',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
721 [KEY_X] = 'x',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
722 [KEY_Y] = 'y',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
723 [KEY_Z] = 'z',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
724 [KEY_1] = '1',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
725 [KEY_2] = '2',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
726 [KEY_3] = '3',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
727 [KEY_4] = '4',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
728 [KEY_5] = '5',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
729 [KEY_6] = '6',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
730 [KEY_7] = '7',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
731 [KEY_8] = '8',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
732 [KEY_9] = '9',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
733 [KEY_0] = '0',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
734 [KEY_ENTER] = '\r',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
735 [KEY_SPACE] = ' ',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
736 [KEY_TAB] = '\t',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
737 [KEY_BACKSPACE] = '\b',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
738 [KEY_MINUS] = '-',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
739 [KEY_EQUAL] = '=',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
740 [KEY_LEFTBRACE] = '[',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
741 [KEY_RIGHTBRACE] = ']',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
742 [KEY_BACKSLASH] = '\\',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
743 [KEY_SEMICOLON] = ';',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
744 [KEY_APOSTROPHE] = '\'',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
745 [KEY_GRAVE] = '`',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
746 [KEY_COMMA] = ',',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
747 [KEY_DOT] = '.',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
748 [KEY_SLASH] = '/',
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
749 [KEY_ESC] = RENDERKEY_ESC,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
750 [KEY_F1] = RENDERKEY_F1,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
751 [KEY_F2] = RENDERKEY_F2,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
752 [KEY_F3] = RENDERKEY_F3,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
753 [KEY_F4] = RENDERKEY_F4,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
754 [KEY_F5] = RENDERKEY_F5,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
755 [KEY_F6] = RENDERKEY_F6,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
756 [KEY_F7] = RENDERKEY_F7,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
757 [KEY_F8] = RENDERKEY_F8,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
758 [KEY_F9] = RENDERKEY_F9,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
759 [KEY_F10] = RENDERKEY_F10,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
760 [KEY_F11] = RENDERKEY_F11,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
761 [KEY_F12] = RENDERKEY_F12,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
762 [KEY_LEFTCTRL] = RENDERKEY_LCTRL,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
763 [KEY_LEFTSHIFT] = RENDERKEY_LSHIFT,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
764 [KEY_LEFTALT] = RENDERKEY_LALT,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
765 [KEY_RIGHTCTRL] = RENDERKEY_RCTRL,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
766 [KEY_RIGHTSHIFT] = RENDERKEY_RSHIFT,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
767 [KEY_RIGHTALT] = RENDERKEY_RALT,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
768 [KEY_DELETE] = RENDERKEY_DEL,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
769 [KEY_LEFT] = RENDERKEY_LEFT,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
770 [KEY_HOME] = RENDERKEY_HOME,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
771 [KEY_END] = RENDERKEY_END,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
772 [KEY_UP] = RENDERKEY_UP,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
773 [KEY_DOWN] = RENDERKEY_DOWN,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
774 [KEY_PAGEUP] = RENDERKEY_PAGEUP,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
775 [KEY_PAGEDOWN] = RENDERKEY_PAGEDOWN,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
776 [KEY_RIGHT] = RENDERKEY_RIGHT,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
777 [KEY_KPSLASH] = 0x80,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
778 [KEY_KPASTERISK] = 0x7C,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
779 [KEY_KPMINUS] = 0x7B,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
780 [KEY_KPPLUS] = 0x79,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
781 [KEY_KPENTER] = 0x19,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
782 [KEY_KP1] = 0x69,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
783 [KEY_KP2] = 0x72,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
784 [KEY_KP3] = 0x7A,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
785 [KEY_KP4] = 0x6B,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
786 [KEY_KP5] = 0x73,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
787 [KEY_KP6] = 0x74,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
788 [KEY_KP7] = 0x6C,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
789 [KEY_KP8] = 0x75,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
790 [KEY_KP9] = 0x7D,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
791 [KEY_KP0] = 0x70,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
792 [KEY_KPDOT] = 0x71,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
793 };
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
794
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
795 static drop_handler drag_drop_handler;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
796 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
797 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
798 drag_drop_handler = handler;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
799 }
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 char* render_joystick_type_id(int index)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
802 {
1786
2b661c1e431f Remove some commented out code in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1785
diff changeset
803 return strdup("");
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
804 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
805
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
806 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
807 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
808 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
809 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
810 static vid_std video_standard = VID_NTSC;
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 typedef enum {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
813 DEV_NONE,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
814 DEV_KEYBOARD,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
815 DEV_MOUSE,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
816 DEV_GAMEPAD
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
817 } device_type;
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 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
820 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
821 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
822 switch (event->type) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
823 case EV_KEY:
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
824 //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
825 if (dtype == DEV_KEYBOARD && event->code < 128) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
826 //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
827 if (event->value) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
828 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
829 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
830 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
831 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
832 } 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
833 //mosue button
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
834 if (event->value) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
835 handle_mousedown(device_index, event->code - BTN_LEFT);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
836 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
837 handle_mouseup(device_index, event->code - BTN_LEFT);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
838 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
839 } 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
840 //gamepad button
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
841 if (event->value) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
842 handle_joydown(device_index, event->code - BTN_SOUTH);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
843 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
844 handle_joyup(device_index, event->code - BTN_SOUTH);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
845 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
846 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
847 break;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
848 case EV_REL:
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
849 if (dtype == DEV_MOUSE) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
850 switch(event->code)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
851 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
852 case REL_X:
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
853 mouse_accum_x += event->value;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
854 break;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
855 case REL_Y:
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
856 mouse_accum_y += event->value;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
857 break;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
858 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
859 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
860 break;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
861 case EV_ABS:
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
862 //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
863 break;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
864 case EV_SYN:
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
865 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
866 mouse_x += mouse_accum_x;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
867 mouse_y += mouse_accum_y;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
868 if (mouse_x < 0) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
869 mouse_x = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
870 } else if (mouse_x >= main_width) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
871 mouse_x = main_width - 1;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
872 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
873 if (mouse_y < 0) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
874 mouse_y = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
875 } else if (mouse_y >= main_height) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
876 mouse_y = main_height - 1;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
877 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
878 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
879 mouse_accum_x = mouse_accum_y = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
880 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
881 break;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
882 /*
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
883 case SDL_JOYHATMOTION:
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
884 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
885 break;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
886 case SDL_JOYAXISMOTION:
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
887 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
888 break;*/
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
889 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
890 return 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
891 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
892
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
893 #define MAX_DEVICES 16
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
894 static int device_fds[MAX_DEVICES];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
895 static device_type device_types[MAX_DEVICES];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
896 static int cur_devices;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
897
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
898 static void drain_events()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
899 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
900 struct input_event events[64];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
901 int index_by_type[3] = {0,0,0};
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
902 for (int i = 0; i < cur_devices; i++)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
903 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
904 int bytes = sizeof(events);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
905 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
906 while (bytes == sizeof(events))
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
907 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
908 bytes = read(device_fds[i], events, sizeof(events));
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
909 if (bytes > 0) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
910 int num_events = bytes / sizeof(events[0]);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
911 for (int j = 0; j < num_events; j++)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
912 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
913 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
914 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
915 } else if (bytes < 0 && errno != EAGAIN && errno != EWOULDBLOCK) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
916 perror("Failed to read evdev events");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
917 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
918 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
919 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
920 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
921
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
922 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
923
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
924 static void init_audio()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
925 {
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
926 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
927 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
928 if (res < 0) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
929 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
930 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
931
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
932 snd_pcm_hw_params_t *params;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
933 snd_pcm_hw_params_alloca(&params);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
934 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
935 if (res < 0) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
936 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
937 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
938 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
939 if (res < 0) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
940 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
941 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
942 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
943 if (res < 0) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
944 //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
945 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
946 if (res < 0) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
947 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
948 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
949 mix = mix_f32;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
950 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
951 mix = mix_s16;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
952 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
953
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
954 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
955 sample_rate = rate_str ? atoi(rate_str) : 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
956 if (!sample_rate) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
957 sample_rate = 48000;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
958 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
959 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
960 output_channels = 2;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
961 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
962
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
963 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
964 buffer_samples = samples_str ? atoi(samples_str) : 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
965 if (!buffer_samples) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
966 buffer_samples = 512;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
967 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
968 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
969
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
970 int dir = 1;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
971 unsigned int periods = 2;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
972 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
973
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
974 res = snd_pcm_hw_params(audio_handle, params);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
975 if (res < 0) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
976 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
977 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
978
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
979 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
980 if (mix == mix_s16) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
981 puts("signed 16-bit int format");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
982 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
983 puts("32-bit float format");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
984 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
985 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
986
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
987 int fbfd;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
988 uint32_t *framebuffer;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
989 uint32_t fb_stride;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
990 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
991 EGLDisplay egl_display;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
992 EGLSurface main_surface;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
993 uint8_t egl_setup(void)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
994 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
995 //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
996 egl_display = eglGetDisplay((EGLNativeDisplayType)fbfd);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
997 if (egl_display == EGL_NO_DISPLAY) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
998 //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
999 egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1000 if (egl_display == EGL_NO_DISPLAY) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1001 warning("eglGetDisplay failed with error %X\n", eglGetError());
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1002 return 0;
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 EGLint major, minor;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1006 if (!eglInitialize(egl_display, &major, &minor)) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1007 warning("eglInitialize failed with error %X\n", eglGetError());
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1008 return 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1009 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1010 printf("EGL version %d.%d\n", major, minor);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1011 EGLint num_configs;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1012 EGLConfig config;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1013 EGLint const config_attribs[] = {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1014 EGL_RED_SIZE, 5,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1015 EGL_GREEN_SIZE, 5,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1016 EGL_BLUE_SIZE, 5,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1017 EGL_CONFORMANT, EGL_OPENGL_ES2_BIT,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1018 EGL_NONE
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1019 };
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1020 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
1021 num_configs = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1022 warning("eglChooseConfig failed with error %X\n", eglGetError());
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1023 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1024 if (!num_configs) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1025 warning("Failed to choose an EGL config\n");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1026 goto error;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1027 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1028 EGLint const context_attribs[] = {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1029 #ifdef EGL_CONTEXT_MAJOR_VERSION
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1030 EGL_CONTEXT_MAJOR_VERSION, 2,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1031 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1032 EGL_NONE
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1033 };
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1034 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
1035 if (main_context == EGL_NO_CONTEXT) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1036 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
1037 goto error;
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 #ifdef USE_MALI
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1040 struct mali_native_window native_window = {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1041 .width = main_width,
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1042 .height = main_height
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 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
1045 #else
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1046 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
1047 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1048 if (main_surface == EGL_NO_SURFACE) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1049 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
1050 goto post_context_error;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1051 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1052 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
1053 return 1;
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 eglDestroySurface(egl_display, main_surface);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1056 post_context_error:
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1057 eglDestroyContext(egl_display, main_context);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1058 error:
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1059 eglTerminate(egl_display);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1060 return 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1061 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1062 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1063 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
1064 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
1065 static uint8_t buffer_ready;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1066 static uint32_t *copy_buffer;
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1067 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
1068 static uint32_t max_multiple;
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1069
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1070 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
1071 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1072 float a,b,c,d;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1073 a = (last & 255) * ratio;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1074 b = (last >> 8 & 255) * ratio;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1075 c = (last >> 16 & 255) * ratio;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1076 d = (last >> 24 & 255) * ratio;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1077 ratio = 1.0f - ratio;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1078 a += (cur & 255) * ratio;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1079 b += (cur >> 8 & 255) * ratio;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1080 c += (cur >> 16 & 255) * ratio;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1081 d += (cur >> 24 & 255) * ratio;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1082 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
1083 }
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1084 static void do_buffer_copy(void)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1085 {
1782
b2bffd98063d Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents: 1781
diff changeset
1086 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
1087 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
1088 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
1089 if (max_multiple && multiple > max_multiple) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1090 multiple = max_multiple;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1091 }
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1092 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
1093 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
1094 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
1095 uint32_t *src_line = copy_buffer;
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1096 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
1097 if (last_width == last_width_scale) {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1098 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
1099 {
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1100 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
1101 {
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1102 uint32_t *cur = cur_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1103 uint32_t *src = src_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1104 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
1105 {
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1106 uint32_t pixel = *(src++);
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1107 for (uint32_t j = 0; j < multiple; j++)
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1108 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1109 *(cur++) = pixel;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1110 }
1782
b2bffd98063d Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents: 1781
diff changeset
1111 }
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1112
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1113 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
1114 }
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1115 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
1116 }
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1117 } else {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1118 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
1119 float remaining = 0.0f;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1120 uint32_t last_pixel = 0;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1121 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
1122 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1123 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
1124 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1125 uint32_t *cur = cur_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1126 uint32_t *src = src_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1127 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
1128 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1129 uint32_t pixel = *(src++);
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1130 float count = scale_multiple;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1131 if (remaining > 0.0f) {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1132 *(cur++) = mix_pixel(last_pixel, pixel, remaining);
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1133 count -= 1.0f - remaining;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1134 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1135 for (; count >= 1; count -= 1.0f)
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1136 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1137 *(cur++) = pixel;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1138 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1139 remaining = count;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1140 last_pixel = pixel;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1141 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1142
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1143 cur_line += fb_stride / sizeof(uint32_t);
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1144 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1145 src_line += LINEBUF_SIZE;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1146 }
1782
b2bffd98063d Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents: 1781
diff changeset
1147 }
b2bffd98063d Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents: 1781
diff changeset
1148 } else {
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1149 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
1150 float height_remaining = 0.0f;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1151 uint32_t *last_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1152 if (last_width == last_width_scale) {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1153 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
1154 {
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1155 float hcount = height_scale;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1156 if (height_remaining > 0.0f) {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1157 uint32_t *cur = cur_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1158 uint32_t *src = src_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1159 uint32_t *last = last_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1160 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
1161 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1162 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
1163 for (uint32_t j = 0; j < multiple; j++)
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1164 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1165 *(cur++) = mixed;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1166 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1167 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1168 hcount -= 1.0f - height_remaining;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1169 cur_line += fb_stride / sizeof(uint32_t);
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1170 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1171 for(; hcount >= 1; hcount -= 1.0f)
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1172 {
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1173 uint32_t *cur = cur_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1174 uint32_t *src = src_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1175 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
1176 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1177 uint32_t pixel = *(src++);
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1178 for (uint32_t j = 0; j < multiple; j++)
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1179 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1180 *(cur++) = pixel;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1181 }
1782
b2bffd98063d Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents: 1781
diff changeset
1182 }
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1183
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1184 cur_line += fb_stride / sizeof(uint32_t);
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1185 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1186 height_remaining = hcount;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1187 last_line = src_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1188 src_line += LINEBUF_SIZE;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1189 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1190 } else {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1191 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
1192 float remaining = 0.0f;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1193 uint32_t last_pixel = 0;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1194 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
1195 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1196 float hcount = height_scale;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1197 if (height_remaining > 0.0f) {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1198 uint32_t *cur = cur_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1199 uint32_t *src = src_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1200 uint32_t *last = last_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1201
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1202 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
1203 {
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1204 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
1205 float count = scale_multiple;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1206 if (remaining > 0.0f) {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1207 *(cur++) = mix_pixel(last_pixel, pixel, remaining);
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1208 count -= 1.0f - remaining;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1209 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1210 for (; count >= 1.0f; count -= 1.0f)
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1211 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1212 *(cur++) = pixel;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1213 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1214 remaining = count;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1215 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
1216 }
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1217 hcount -= 1.0f - height_remaining;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1218 cur_line += fb_stride / sizeof(uint32_t);
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1219 }
1782
b2bffd98063d Scale H32 horizontally in fbdev backend so it has the correct aspect ratio
Michael Pavone <pavone@retrodev.com>
parents: 1781
diff changeset
1220
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1221 for (; hcount >= 1.0f; hcount -= 1.0f)
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1222 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1223 uint32_t *cur = cur_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1224 uint32_t *src = src_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1225 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
1226 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1227 uint32_t pixel = *(src++);
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1228 float count = scale_multiple;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1229 if (remaining > 0.0f) {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1230 *(cur++) = mix_pixel(last_pixel, pixel, remaining);
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1231 count -= 1.0f - remaining;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1232 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1233 for (; count >= 1; count -= 1.0f)
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1234 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1235 *(cur++) = pixel;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1236 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1237 remaining = count;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1238 last_pixel = pixel;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1239 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1240
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1241 cur_line += fb_stride / sizeof(uint32_t);
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1242 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1243 height_remaining = hcount;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1244 last_line = src_line;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1245 src_line += LINEBUF_SIZE;
1779
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 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1248 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1249 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1250 static void *buffer_copy(void *data)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1251 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1252 pthread_mutex_lock(&buffer_lock);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1253 for(;;)
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 while (!buffer_ready)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1256 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1257 pthread_cond_wait(&buffer_cond, &buffer_lock);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1258 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1259 buffer_ready = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1260 do_buffer_copy();
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 return 0;
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
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1265 static pthread_t buffer_copy_handle;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1266 static uint8_t copy_use_thread;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1267 void window_setup(void)
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 fbfd = open("/dev/fb0", O_RDWR);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1270 struct fb_fix_screeninfo fixInfo;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1271 struct fb_var_screeninfo varInfo;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1272 ioctl(fbfd, FBIOGET_FSCREENINFO, &fixInfo);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1273 ioctl(fbfd, FBIOGET_VSCREENINFO, &varInfo);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1274 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
1275 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
1276 main_width = varInfo.xres;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1277 main_height = varInfo.yres;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1278 fb_stride = fixInfo.line_length;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1279 tern_val def = {.ptrval = "audio"};
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1280 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
1281
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1282 const char *vsync;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1283 def.ptrval = "off";
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1284 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
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 tern_node *video = tern_find_node(config, "video");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1288 if (video)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1289 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1290 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
1291 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1292 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
1293 if (std_settings) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1294 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
1295 if (val) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1296 overscan_top[i] = atoi(val);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1297 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1298 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
1299 if (val) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1300 overscan_bot[i] = atoi(val);
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 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
1303 if (val) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1304 overscan_left[i] = atoi(val);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1305 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1306 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
1307 if (val) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1308 overscan_right[i] = atoi(val);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1309 }
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 }
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 render_gl = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1314 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1315 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
1316 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
1317 if (gl_enabled)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1318 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1319 render_gl = egl_setup();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1320 blue_shift = 16;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1321 green_shift = 8;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1322 red_shift = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1323 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1324 if (!render_gl) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1325 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1326 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
1327 red_shift = varInfo.red.offset;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1328 green_shift = varInfo.green.offset;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1329 blue_shift = varInfo.blue.offset;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1330 def.ptrval = "0";
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1331 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
1332 def.ptrval = "true";
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1333 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
1334 if (copy_use_thread) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1335 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
1336 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1337 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1338 }
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 update_aspect();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1342 render_alloc_surfaces();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1343 def.ptrval = "off";
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1344 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
1345 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1346
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1347 void restore_tty(void)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1348 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1349 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
1350 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
1351 {
2b4d5cfec6d9 Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents: 1780
diff changeset
1352 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
1353 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
1354 }
2b4d5cfec6d9 Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents: 1780
diff changeset
1355 }
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1356 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1357
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1358 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
1359 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1360 if (height <= 0) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1361 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
1362 height = ((float)width / aspect) + 0.5f;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1363 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1364 printf("width: %d, height: %d\n", width, height);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1365 windowed_width = width;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1366 windowed_height = height;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1367
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1368 main_width = width;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1369 main_height = height;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1370
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1371 caption = title;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1372
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1373 if (isatty(STDIN_FILENO)) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1374 ioctl(STDIN_FILENO, KDSETMODE, KD_GRAPHICS);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1375 atexit(restore_tty);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1376 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1377
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1378 window_setup();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1379
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1380 init_audio();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1381
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1382 render_set_video_standard(VID_NTSC);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1383
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1384 DIR *d = opendir("/dev/input");
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1385 struct dirent* entry;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1386 int joystick_counter = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1387 while ((entry = readdir(d)) && cur_devices < MAX_DEVICES)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1388 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1389 if (!strncmp("event", entry->d_name, strlen("event"))) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1390 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
1391 int fd = open(filename, O_RDONLY);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1392 if (fd == -1) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1393 int errnum = errno;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1394 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
1395 free(filename);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1396 continue;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1397 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1398
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1399 unsigned long bits;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1400 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
1401 int errnum = errno;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1402 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
1403 free(filename);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1404 close(fd);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1405 continue;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1406 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1407 if (!(1 & bits >> EV_KEY)) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1408 //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
1409 free(filename);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1410 close(fd);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1411 continue;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1412 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1413 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
1414 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
1415 if (-1 == res) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1416 int errnum = errno;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1417 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
1418 free(filename);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1419 close(fd);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1420 continue;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1421 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1422 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
1423 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
1424 for (int i = 0; i < 3; i++)
1779
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 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
1427 dtype = i + 1;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1428 }
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 if (dtype == DEV_NONE) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1431 close(fd);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1432 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1433 device_fds[cur_devices] = fd;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1434 device_types[cur_devices] = dtype;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1435 char name[1024];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1436 char *names[] = {"Keyboard", "Mouse", "Gamepad"};
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1437 ioctl(fd, EVIOCGNAME(sizeof(name)), name);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1438 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
1439
2b4d5cfec6d9 Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents: 1780
diff changeset
1440 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
1441 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
1442 } 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
1443 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
1444 }
2b4d5cfec6d9 Grab keyboard devices at startup so keyboard input stops going to terminal while running
Michael Pavone <pavone@retrodev.com>
parents: 1780
diff changeset
1445
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1446 //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
1447 fcntl(fd, F_SETFL, O_NONBLOCK);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1448 cur_devices++;
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 free(filename);
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
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1454 atexit(render_quit);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1455 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1456 #include<unistd.h>
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1457 static int in_toggle;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1458 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
1459 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1460 double alpha = src->dt / (src->dt + rc);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1461 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
1462 src->lowpass_alpha = lowpass_alpha;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1463 }
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 void render_config_updated(void)
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 free_surfaces();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1469 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1470 if (render_gl) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1471 /*if (on_context_destroyed) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1472 on_context_destroyed();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1473 }*/
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1474 gl_teardown();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1475 //FIXME: EGL equivalent
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1476 //SDL_GL_DeleteContext(main_context);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1477 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1478 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1479 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1480 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1481 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1482 //FIXME: EGL equivalent
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1483 //SDL_DestroyWindow(main_window);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1484 drain_events();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1485
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1486 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
1487 if (config_width) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1488 windowed_width = atoi(config_width);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1489 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1490 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
1491 if (config_height) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1492 windowed_height = atoi(config_height);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1493 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1494 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
1495 windowed_height = ((float)windowed_width / aspect) + 0.5f;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1496 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1497
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1498 window_setup();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1499 update_aspect();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1500 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1501 //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
1502 /*if (render_gl && on_context_created) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1503 on_context_created();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1504 }*/
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1505 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1506
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1507 render_close_audio();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1508 quitting = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1509 init_audio();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1510 render_set_video_standard(video_standard);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1511
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1512 double lowpass_cutoff = get_lowpass_cutoff(config);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1513 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
1514 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
1515 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1516 update_source(audio_sources[i], rc, 0);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1517 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1518 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
1519 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1520 update_source(inactive_audio_sources[i], rc, 0);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1521 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1522 drain_events();
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
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1525 void render_set_video_standard(vid_std std)
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 video_standard = std;
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
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1530 void render_update_caption(char *title)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1531 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1532 caption = title;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1533 free(fps_caption);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1534 fps_caption = NULL;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1535 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1536
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1537 static char *screenshot_path;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1538 void render_save_screenshot(char *path)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1539 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1540 if (screenshot_path) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1541 free(screenshot_path);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1542 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1543 screenshot_path = path;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1544 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1545
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1546 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
1547 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1548 //not supported under fbdev
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1549 return 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1550 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1551
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1552 void render_destroy_window(uint8_t which)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1553 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1554 //not supported under fbdev
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
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1557 static uint8_t last_fb;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1558 static uint32_t texture_off;
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1559 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
1560 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1561 if (max_multiple == 1 && !render_gl) {
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1562 if (last_fb != which) {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1563 *pitch = fb_stride * 2;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1564 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
1565 }
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1566 *pitch = fb_stride;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1567 return framebuffer;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1568 }
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1569 if (!render_gl && last_fb != which) {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1570 *pitch = LINEBUF_SIZE * sizeof(uint32_t) * 2;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1571 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
1572 }
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1573 *pitch = LINEBUF_SIZE * sizeof(uint32_t);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1574 return texture_buf + texture_off;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1575 }
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 uint8_t events_processed;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1578 #ifdef __ANDROID__
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1579 #define FPS_INTERVAL 10000
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1580 #else
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1581 #define FPS_INTERVAL 1000
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1582 #endif
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 static uint8_t interlaced;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1585 void render_update_display();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1586 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
1587 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1588 uint32_t height = which <= FRAMEBUFFER_EVEN
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1589 ? (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
1590 : 240;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1591 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
1592 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1593 if (render_gl && which <= FRAMEBUFFER_EVEN) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1594 last_width = width;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1595 glBindTexture(GL_TEXTURE_2D, textures[which]);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1596 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
1597 render_update_display();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1598 last_height = height;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1599 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1600 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1601 if (max_multiple != 1) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1602 if (copy_use_thread) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1603 pthread_mutex_lock(&buffer_lock);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1604 buffer_ready = 1;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1605 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
1606 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
1607 last_height = last_height_scale = height;
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1608 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
1609 if (which != last_fb) {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1610 last_height *= 2;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1611 copy_buffer += LINEBUF_SIZE * overscan_top[video_standard];
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1612 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
1613 uint32_t *dst = copy_buffer;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1614 if (which == FRAMEBUFFER_ODD) {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1615 src += LINEBUF_SIZE;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1616 dst += LINEBUF_SIZE;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1617 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1618 for (int i = 0; i < height; i++)
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1619 {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1620 memcpy(dst, src, width * sizeof(uint32_t));
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1621 src += LINEBUF_SIZE * 2;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1622 dst += LINEBUF_SIZE * 2;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1623 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1624 }
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1625 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
1626 pthread_cond_signal(&buffer_cond);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1627 pthread_mutex_unlock(&buffer_lock);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1628 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1629 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
1630 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
1631 last_height = last_height_scale = height;
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1632 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
1633 if (which != last_fb) {
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1634 last_height *= 2;
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1635 copy_buffer += LINEBUF_SIZE * overscan_top[video_standard];
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1636 }
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1637 do_buffer_copy();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1638 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1639 }
1785
8f2e78db0872 Handle interlaced mode in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1782
diff changeset
1640 last_fb = which;
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1641 if (!events_processed) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1642 process_events();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1643 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1644 events_processed = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1645 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1646 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1647 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1648 }
1786
2b661c1e431f Remove some commented out code in fbdev backend
Michael Pavone <pavone@retrodev.com>
parents: 1785
diff changeset
1649
1779
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1650 void render_update_display()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1651 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1652 #ifndef DISABLE_OPENGL
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1653 if (render_gl) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1654 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
1655 glClear(GL_COLOR_BUFFER_BIT);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1656
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1657 glUseProgram(program);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1658 glActiveTexture(GL_TEXTURE0);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1659 glBindTexture(GL_TEXTURE_2D, textures[0]);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1660 glUniform1i(un_textures[0], 0);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1661
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1662 glActiveTexture(GL_TEXTURE1);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1663 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
1664 glUniform1i(un_textures[1], 1);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1665
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1666 glUniform1f(un_width, render_emulated_width());
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1667 glUniform1f(un_height, last_height);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1668
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1669 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1670 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
1671 glEnableVertexAttribArray(at_pos);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1672
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1673 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1674 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
1675
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1676 glDisableVertexAttribArray(at_pos);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1677
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1678 /*if (render_ui) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1679 render_ui();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1680 }*/
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1681
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1682 eglSwapBuffers(egl_display, main_surface);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1683 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1684 #endif
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1685 if (!events_processed) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1686 process_events();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1687 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1688 events_processed = 0;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1689 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1690
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1691 uint32_t render_emulated_width()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1692 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1693 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
1694 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1695
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1696 uint32_t render_emulated_height()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1697 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1698 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
1699 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1700
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1701 uint32_t render_overscan_left()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1702 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1703 return overscan_left[video_standard];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1704 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1705
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1706 uint32_t render_overscan_top()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1707 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1708 return overscan_top[video_standard];
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1709 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1710
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1711 void render_wait_quit(vdp_context * context)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1712 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1713 for(;;)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1714 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1715 drain_events();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1716 sleep(1);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1717 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1718 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1719
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1720 int render_lookup_button(char *name)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1721 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1722 static tern_node *button_lookup;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1723 if (!button_lookup) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1724 //xbox/sdl style names
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1725 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
1726 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
1727 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
1728 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
1729 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
1730 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
1731 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
1732 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
1733 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
1734 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
1735 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
1736 //alternative Playstation-style names
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1737 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
1738 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
1739 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
1740 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
1741 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
1742 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
1743 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
1744 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
1745 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
1746 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
1747 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
1748 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1749 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
1750 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1751
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1752 int render_lookup_axis(char *name)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1753 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1754 static tern_node *axis_lookup;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1755 if (!axis_lookup) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1756 //xbox/sdl style names
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1757 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
1758 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
1759 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
1760 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
1761 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
1762 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
1763 //alternative Playstation-style names
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1764 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
1765 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
1766 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1767 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
1768 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1769
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1770 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
1771 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1772 tern_node *button_lookup, *axis_lookup;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1773 if (is_axis) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1774 int axis = render_lookup_axis(name);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1775 if (axis == ABS_CNT) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1776 return RENDER_INVALID_NAME;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1777 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1778 return RENDER_AXIS_BIT | axis;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1779 } else {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1780 int button = render_lookup_button(name);
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1781 if (button != KEY_CNT) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1782 return button;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1783 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1784 if (!strcmp("dpup", name)) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1785 return RENDER_DPAD_BIT | 1;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1786 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1787 if (!strcmp("dpdown", name)) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1788 return RENDER_DPAD_BIT | 4;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1789 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1790 if (!strcmp("dpdleft", name)) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1791 return RENDER_DPAD_BIT | 8;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1792 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1793 if (!strcmp("dpright", name)) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1794 return RENDER_DPAD_BIT | 2;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1795 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1796 return RENDER_INVALID_NAME;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1797 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1798 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1799
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1800 int32_t render_dpad_part(int32_t input)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1801 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1802 return input >> 4 & 0xFFFFFF;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1803 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1804
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1805 uint8_t render_direction_part(int32_t input)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1806 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1807 return input & 0xF;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1808 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1809
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1810 int32_t render_axis_part(int32_t input)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1811 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1812 return input & 0xFFFFFFF;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1813 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1814
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1815 void process_events()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1816 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1817 if (events_processed > MAX_EVENT_POLL_PER_FRAME) {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1818 return;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1819 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1820 drain_events();
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1821 events_processed++;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1822 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1823
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1824 #define TOGGLE_MIN_DELAY 250
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1825 void render_toggle_fullscreen()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1826 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1827 //always fullscreen in fbdev
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1828 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1829
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1830 uint32_t render_audio_buffer()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1831 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1832 return buffer_samples;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1833 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1834
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1835 uint32_t render_sample_rate()
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1836 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1837 return sample_rate;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1838 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1839
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1840 void render_errorbox(char *title, char *message)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1841 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1842
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1843 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1844
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1845 void render_warnbox(char *title, char *message)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1846 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1847
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1848 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1849
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1850 void render_infobox(char *title, char *message)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1851 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1852
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1853 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1854
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1855 uint8_t render_has_gl(void)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1856 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1857 return render_gl;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1858 }
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1859
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1860 uint8_t render_get_active_framebuffer(void)
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1861 {
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1862 return FRAMEBUFFER_ODD;
3a8c4ee68568 Added raw fbdev/evdev/ALSA render backend
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1863 }