Mercurial > repos > blastem
annotate render_sdl.c @ 1532:b505083dcd87
Added png screenshot support
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 24 Mar 2018 19:40:51 -0700 |
parents | 8a3d3bb2cd08 |
children | c59adc305e46 |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
2 Copyright 2013 Michael Pavone |
487
c08a4efeee7f
Update opengl branch from default. Fix build breakage unrelated to merge
Mike Pavone <pavone@retrodev.com>
diff
changeset
|
3 This file is part of BlastEm. |
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
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. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
5 */ |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include <stdlib.h> |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include <stdio.h> |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
744
diff
changeset
|
8 #include <string.h> |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
9 #include <math.h> |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include "render.h" |
66 | 11 #include "blastem.h" |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
12 #include "genesis.h" |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
418
diff
changeset
|
13 #include "io.h" |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
14 #include "util.h" |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
15 #include "ppm.h" |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
16 #include "png.h" |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
18 #ifndef DISABLE_OPENGL |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
19 #include <GL/glew.h> |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
20 #endif |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
21 |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
22 #define MAX_EVENT_POLL_PER_FRAME 2 |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
23 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
24 static SDL_Window *main_window; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
25 static SDL_Renderer *main_renderer; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
26 static SDL_Texture **sdl_textures; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
27 static uint8_t num_textures; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
28 static SDL_Rect main_clip; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
29 static SDL_GLContext *main_context; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
30 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
31 static int main_width, main_height, windowed_width, windowed_height, is_fullscreen; |
914
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
32 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
33 static uint8_t render_gl = 1; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
34 static uint8_t scanlines = 0; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
36 static uint32_t last_frame = 0; |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
37 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
38 static int16_t * current_psg = NULL; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
39 static int16_t * current_ym = NULL; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
40 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
41 static uint32_t buffer_samples, sample_rate; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
42 static uint32_t missing_count; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
43 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
44 static SDL_mutex * audio_mutex; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
45 static SDL_cond * audio_ready; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
46 static SDL_cond * psg_cond; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
47 static SDL_cond * ym_cond; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
48 static uint8_t quitting = 0; |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
49 static uint8_t ym_enabled = 1; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
50 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
51 static void audio_callback(void * userdata, uint8_t *byte_stream, int len) |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 { |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
53 //puts("audio_callback"); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
54 int16_t * stream = (int16_t *)byte_stream; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
55 int samples = len/(sizeof(int16_t)*2); |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
56 int16_t * psg_buf, * ym_buf; |
361 | 57 uint8_t local_quit; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
58 SDL_LockMutex(audio_mutex); |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
59 psg_buf = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
60 ym_buf = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
61 do { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
62 if (!psg_buf) { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
63 psg_buf = current_psg; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
64 current_psg = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
65 SDL_CondSignal(psg_cond); |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
66 } |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
67 if (ym_enabled && !ym_buf) { |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
68 ym_buf = current_ym; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
69 current_ym = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
70 SDL_CondSignal(ym_cond); |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
71 } |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
72 if (!quitting && (!psg_buf || (ym_enabled && !ym_buf))) { |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
73 SDL_CondWait(audio_ready, audio_mutex); |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
74 } |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
75 } while(!quitting && (!psg_buf || (ym_enabled && !ym_buf))); |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
76 |
361 | 77 local_quit = quitting; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
78 SDL_UnlockMutex(audio_mutex); |
361 | 79 if (!local_quit) { |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
80 if (ym_enabled) { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
81 for (int i = 0; i < samples; i++) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
82 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
83 *(stream++) = psg_buf[i] + *(ym_buf++); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
84 *(stream++) = psg_buf[i] + *(ym_buf++); |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
85 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
86 } else { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
87 for (int i = 0; i < samples; i++) |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
88 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
89 *(stream++) = psg_buf[i]; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
90 *(stream++) = psg_buf[i]; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
91 } |
361 | 92 } |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
93 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
94 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
95 |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
96 void render_disable_ym() |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
97 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
98 ym_enabled = 0; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
99 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
100 |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
101 void render_enable_ym() |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
102 { |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
103 ym_enabled = 1; |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
104 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
105 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
106 static void render_close_audio() |
361 | 107 { |
108 SDL_LockMutex(audio_mutex); | |
109 quitting = 1; | |
110 SDL_CondSignal(audio_ready); | |
111 SDL_UnlockMutex(audio_mutex); | |
112 SDL_CloseAudio(); | |
113 } | |
114 | |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
115 static SDL_Joystick * joysticks[MAX_JOYSTICKS]; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
116 static int joystick_sdl_index[MAX_JOYSTICKS]; |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
117 |
914
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
118 int render_width() |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
119 { |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
120 return main_width; |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
121 } |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
122 |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
123 int render_height() |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
124 { |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
125 return main_height; |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
126 } |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
127 |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
128 int render_fullscreen() |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
129 { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
130 return is_fullscreen; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
131 } |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
132 |
426
add9e2f5c0e3
Make VDP render in native pixel format of the renderer for a modest performance gain and to make it easier to use OpenGL for rendering
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
133 uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b) |
add9e2f5c0e3
Make VDP render in native pixel format of the renderer for a modest performance gain and to make it easier to use OpenGL for rendering
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
134 { |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
135 return 255 << 24 | r << 16 | g << 8 | b; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
136 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
137 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
138 #ifndef DISABLE_OPENGL |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
139 static GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], un_width, un_height, at_pos; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
140 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
141 static GLfloat vertex_data_default[] = { |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
142 -1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
143 1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
144 -1.0f, 1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
145 1.0f, 1.0f |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
146 }; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
147 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
148 static GLfloat vertex_data[8]; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
149 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
150 static const GLushort element_data[] = {0, 1, 2, 3}; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
151 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
152 static GLuint load_shader(char * fname, GLenum shader_type) |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
153 { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
154 char const * parts[] = {get_home_dir(), "/.config/blastem/shaders/", fname}; |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
155 char * shader_path = alloc_concat_m(3, parts); |
816
7ed55a361e79
Use binary mode for reading shaders and config files so we actually get the number of bytes we expect
Michael Pavone <pavone@retrodev.com>
parents:
800
diff
changeset
|
156 FILE * f = fopen(shader_path, "rb"); |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
157 free(shader_path); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
158 if (!f) { |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
159 parts[0] = get_exe_dir(); |
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
160 parts[1] = "/shaders/"; |
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
161 shader_path = alloc_concat_m(3, parts); |
816
7ed55a361e79
Use binary mode for reading shaders and config files so we actually get the number of bytes we expect
Michael Pavone <pavone@retrodev.com>
parents:
800
diff
changeset
|
162 f = fopen(shader_path, "rb"); |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
163 free(shader_path); |
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
164 if (!f) { |
800 | 165 warning("Failed to open shader file %s for reading\n", fname); |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
166 return 0; |
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
167 } |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
168 } |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
169 long fsize = file_size(f); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
170 GLchar * text = malloc(fsize); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
171 if (fread(text, 1, fsize, f) != fsize) { |
800 | 172 warning("Error reading from shader file %s\n", fname); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
173 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
174 return 0; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
175 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
176 GLuint ret = glCreateShader(shader_type); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
177 glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
178 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
179 glCompileShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
180 GLint compile_status, loglen; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
181 glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
182 if (!compile_status) { |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
183 glGetShaderiv(ret, GL_INFO_LOG_LENGTH, &loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
184 text = malloc(loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
185 glGetShaderInfoLog(ret, loglen, NULL, text); |
800 | 186 warning("Shader %s failed to compile:\n%s\n", fname, text); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
187 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
188 glDeleteShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
189 return 0; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
190 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
191 return ret; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
192 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
193 #endif |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
194 |
1167
e758ddbf0624
Initial work on emulating top and bottom border area
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
195 static uint32_t texture_buf[512 * 513]; |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
196 #ifndef DISABLE_OPENGL |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
197 static void gl_setup() |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
198 { |
1403
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
199 tern_val def = {.ptrval = "linear"}; |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
200 char *scaling = tern_find_path_default(config, "video\0scaling\0", def, TVAL_PTR).ptrval; |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
201 GLint filter = strcmp(scaling, "linear") ? GL_NEAREST : GL_LINEAR; |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
202 glGenTextures(3, textures); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
203 for (int i = 0; i < 3; i++) |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
204 { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
205 glBindTexture(GL_TEXTURE_2D, textures[i]); |
1403
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
206 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
207 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
208 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
209 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
210 if (i < 2) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
211 //TODO: Fixme for PAL + invalid display mode |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
212 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 512, 0, GL_BGRA, GL_UNSIGNED_BYTE, texture_buf); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
213 } else { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
214 uint32_t blank = 255 << 24; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
215 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_BGRA, GL_UNSIGNED_BYTE, &blank); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
216 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
217 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
218 glGenBuffers(2, buffers); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
219 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
220 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
221 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
222 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW); |
1403
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
223 def.ptrval = "default.v.glsl"; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
224 vshader = load_shader(tern_find_path_default(config, "video\0vertex_shader\0", def, TVAL_PTR).ptrval, GL_VERTEX_SHADER); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
225 def.ptrval = "default.f.glsl"; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
226 fshader = load_shader(tern_find_path_default(config, "video\0fragment_shader\0", def, TVAL_PTR).ptrval, GL_FRAGMENT_SHADER); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
227 program = glCreateProgram(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
228 glAttachShader(program, vshader); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
229 glAttachShader(program, fshader); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
230 glLinkProgram(program); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
231 GLint link_status; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
232 glGetProgramiv(program, GL_LINK_STATUS, &link_status); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
233 if (!link_status) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
234 fputs("Failed to link shader program\n", stderr); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
235 exit(1); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
236 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
237 un_textures[0] = glGetUniformLocation(program, "textures[0]"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
238 un_textures[1] = glGetUniformLocation(program, "textures[1]"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
239 un_width = glGetUniformLocation(program, "width"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
240 un_height = glGetUniformLocation(program, "height"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
241 at_pos = glGetAttribLocation(program, "pos"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
242 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
243 #endif |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
244 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
245 static void render_alloc_surfaces() |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
246 { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
247 static uint8_t texture_init; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
248 |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
249 if (texture_init) { |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
250 return; |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
251 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
252 sdl_textures= malloc(sizeof(SDL_Texture *) * 2); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
253 num_textures = 2; |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
254 texture_init = 1; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
255 #ifndef DISABLE_OPENGL |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
256 if (render_gl) { |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
257 sdl_textures[0] = sdl_textures[1] = NULL; |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
258 gl_setup(); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
259 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
260 #endif |
1403
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
261 tern_val def = {.ptrval = "linear"}; |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
262 char *scaling = tern_find_path_default(config, "video\0scaling\0", def, TVAL_PTR).ptrval; |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
263 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scaling); |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
264 //TODO: Fixme for invalid display mode |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
265 sdl_textures[0] = sdl_textures[1] = SDL_CreateTexture(main_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, LINEBUF_SIZE, 588); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
266 #ifndef DISABLE_OPENGL |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
267 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
268 #endif |
426
add9e2f5c0e3
Make VDP render in native pixel format of the renderer for a modest performance gain and to make it easier to use OpenGL for rendering
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
269 } |
add9e2f5c0e3
Make VDP render in native pixel format of the renderer for a modest performance gain and to make it easier to use OpenGL for rendering
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
270 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
271 static char * caption = NULL; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
272 static char * fps_caption = NULL; |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
273 |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
274 static void render_quit() |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
275 { |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
276 render_close_audio(); |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
277 for (int i = 0; i < num_textures; i++) |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
278 { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
279 if (sdl_textures[i]) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
280 SDL_DestroyTexture(sdl_textures[i]); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
281 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
282 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
283 } |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
284 |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
285 static float config_aspect() |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
286 { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
287 static float aspect = 0.0f; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
288 if (aspect == 0.0f) { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
289 char *config_aspect = tern_find_path_default(config, "video\0aspect\0", (tern_val){.ptrval = "4:3"}, TVAL_PTR).ptrval; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
290 if (strcmp("stretch", config_aspect)) { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
291 aspect = 4.0f/3.0f; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
292 char *end; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
293 float aspect_numerator = strtof(config_aspect, &end); |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
294 if (aspect_numerator > 0.0f && *end == ':') { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
295 float aspect_denominator = strtof(end+1, &end); |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
296 if (aspect_denominator > 0.0f && !*end) { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
297 aspect = aspect_numerator / aspect_denominator; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
298 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
299 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
300 } else { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
301 aspect = -1.0f; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
302 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
303 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
304 return aspect; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
305 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
306 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
307 static void update_aspect() |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
308 { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
309 //reset default values |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
310 memcpy(vertex_data, vertex_data_default, sizeof(vertex_data)); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
311 main_clip.w = main_width; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
312 main_clip.h = main_height; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
313 main_clip.x = main_clip.y = 0; |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
314 if (config_aspect() > 0.0f) { |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
315 float aspect = (float)main_width / main_height; |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
316 if (fabs(aspect - config_aspect()) < 0.01f) { |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
317 //close enough for government work |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
318 return; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
319 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
320 #ifndef DISABLE_OPENGL |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
321 if (render_gl) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
322 for (int i = 0; i < 4; i++) |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
323 { |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
324 if (aspect > config_aspect()) { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
325 vertex_data[i*2] *= config_aspect()/aspect; |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
326 } else { |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
327 vertex_data[i*2+1] *= aspect/config_aspect(); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
328 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
329 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
330 } else { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
331 #endif |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
332 main_clip.w = aspect > config_aspect() ? config_aspect() * (float)main_height : main_width; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
333 main_clip.h = aspect > config_aspect() ? main_height : main_width / config_aspect(); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
334 main_clip.x = (main_width - main_clip.w) / 2; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
335 main_clip.y = (main_height - main_clip.h) / 2; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
336 #ifndef DISABLE_OPENGL |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
337 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
338 #endif |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
339 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
340 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
341 |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
342 static uint32_t overscan_top[NUM_VID_STD] = {2, 21}; |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
343 static uint32_t overscan_bot[NUM_VID_STD] = {1, 17}; |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
344 static uint32_t overscan_left[NUM_VID_STD] = {13, 13}; |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
345 static uint32_t overscan_right[NUM_VID_STD] = {14, 14}; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
346 static vid_std video_standard = VID_NTSC; |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
347 static char *vid_std_names[NUM_VID_STD] = {"ntsc", "pal"}; |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
348 void render_init(int width, int height, char * title, uint8_t fullscreen) |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
349 { |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
350 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) { |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
351 fatal_error("Unable to init SDL: %s\n", SDL_GetError()); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
352 } |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
353 atexit(SDL_Quit); |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
354 if (height <= 0) { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
355 float aspect = config_aspect() > 0.0f ? config_aspect() : 4.0f/3.0f; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
356 height = ((float)width / aspect) + 0.5f; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
357 } |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
358 printf("width: %d, height: %d\n", width, height); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
359 windowed_width = width; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
360 windowed_height = height; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
361 |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
362 uint32_t flags = SDL_WINDOW_RESIZABLE; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
363 |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
364 if (fullscreen) { |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
365 flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
366 SDL_DisplayMode mode; |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
367 //TODO: Multiple monitor support |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
368 SDL_GetCurrentDisplayMode(0, &mode); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
369 //the SDL2 migration guide suggests setting width and height to 0 when using SDL_WINDOW_FULLSCREEN_DESKTOP |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
370 //but that doesn't seem to work right when using OpenGL, at least on Linux anyway |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
371 width = mode.w; |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
372 height = mode.h; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
373 } |
914
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
374 main_width = width; |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
375 main_height = height; |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
376 is_fullscreen = fullscreen; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
377 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
378 render_gl = 0; |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
379 tern_val def = {.ptrval = "off"}; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
380 char *vsync = tern_find_path_default(config, "video\0vsync\0", def, TVAL_PTR).ptrval; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
381 |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
382 tern_node *video = tern_find_node(config, "video"); |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
383 if (video) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
384 { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
385 for (int i = 0; i < NUM_VID_STD; i++) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
386 { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
387 tern_node *std_settings = tern_find_node(video, vid_std_names[i]); |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
388 if (std_settings) { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
389 char *val = tern_find_path_default(std_settings, "overscan\0top\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
390 if (val) { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
391 overscan_top[i] = atoi(val); |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
392 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
393 val = tern_find_path_default(std_settings, "overscan\0bottom\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
394 if (val) { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
395 overscan_bot[i] = atoi(val); |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
396 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
397 val = tern_find_path_default(std_settings, "overscan\0left\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
398 if (val) { |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
399 overscan_left[i] = atoi(val); |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
400 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
401 val = tern_find_path_default(std_settings, "overscan\0right\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
402 if (val) { |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
403 overscan_right[i] = atoi(val); |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
404 } |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
405 } |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
406 } |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
407 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
408 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
409 #ifndef DISABLE_OPENGL |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
410 char *gl_enabled_str = tern_find_path_default(config, "video\0gl\0", def, TVAL_PTR).ptrval; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
411 uint8_t gl_enabled = strcmp(gl_enabled_str, "off") != 0; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
412 if (gl_enabled) |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
413 { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
414 flags |= SDL_WINDOW_OPENGL; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
415 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
416 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
417 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
418 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
419 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
420 } |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
421 #endif |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
422 main_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
423 if (!main_window) { |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
424 fatal_error("Unable to create SDL window: %s\n", SDL_GetError()); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
425 } |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
426 #ifndef DISABLE_OPENGL |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
427 if (gl_enabled) |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
428 { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
429 main_context = SDL_GL_CreateContext(main_window); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
430 GLenum res = glewInit(); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
431 if (res != GLEW_OK) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
432 warning("Initialization of GLEW failed with code %d\n", res); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
433 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
434 |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
435 if (res == GLEW_OK && GLEW_VERSION_2_0) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
436 render_gl = 1; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
437 if (!strcmp("tear", vsync)) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
438 if (SDL_GL_SetSwapInterval(-1) < 0) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
439 warning("late tear is not available (%s), using normal vsync\n", SDL_GetError()); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
440 vsync = "on"; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
441 } else { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
442 vsync = NULL; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
443 } |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
444 } |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
445 if (vsync) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
446 if (SDL_GL_SetSwapInterval(!strcmp("on", vsync)) < 0) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
447 warning("Failed to set vsync to %s: %s\n", vsync, SDL_GetError()); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
448 } |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
449 } |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
450 } else { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
451 warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n"); |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
452 } |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
453 } |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
454 if (!render_gl) { |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
455 #endif |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
456 flags = SDL_RENDERER_ACCELERATED; |
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
457 if (!strcmp("on", vsync) || !strcmp("tear", vsync)) { |
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
458 flags |= SDL_RENDERER_PRESENTVSYNC; |
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
459 } |
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
460 main_renderer = SDL_CreateRenderer(main_window, -1, flags); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
461 |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
462 if (!main_renderer) { |
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
463 fatal_error("unable to create SDL renderer: %s\n", SDL_GetError()); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
464 } |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
465 main_clip.x = main_clip.y = 0; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
466 main_clip.w = width; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
467 main_clip.h = height; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
468 #ifndef DISABLE_OPENGL |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
469 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
470 #endif |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
471 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
472 SDL_GetWindowSize(main_window, &main_width, &main_height); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
473 printf("Window created with size: %d x %d\n", main_width, main_height); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
474 update_aspect(); |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
475 render_alloc_surfaces(); |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
476 def.ptrval = "off"; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
477 scanlines = !strcmp(tern_find_path_default(config, "video\0scanlines\0", def, TVAL_PTR).ptrval, "on"); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
478 |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
479 caption = title; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
480 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
481 audio_mutex = SDL_CreateMutex(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
482 psg_cond = SDL_CreateCond(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
483 ym_cond = SDL_CreateCond(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
484 audio_ready = SDL_CreateCond(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
485 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
486 SDL_AudioSpec desired, actual; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
487 char * rate_str = tern_find_path(config, "audio\0rate\0", TVAL_PTR).ptrval; |
445
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
488 int rate = rate_str ? atoi(rate_str) : 0; |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
489 if (!rate) { |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
490 rate = 48000; |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
491 } |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
492 desired.freq = rate; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
493 desired.format = AUDIO_S16SYS; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
494 desired.channels = 2; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
495 char * samples_str = tern_find_path(config, "audio\0buffer\0", TVAL_PTR).ptrval; |
445
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
496 int samples = samples_str ? atoi(samples_str) : 0; |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
497 if (!samples) { |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
498 samples = 512; |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
499 } |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
500 printf("config says: %d\n", samples); |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
501 desired.samples = samples*2; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
502 desired.callback = audio_callback; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
503 desired.userdata = NULL; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
504 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
505 if (SDL_OpenAudio(&desired, &actual) < 0) { |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
506 fatal_error("Unable to open SDL audio: %s\n", SDL_GetError()); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
507 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
508 buffer_samples = actual.samples; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
509 sample_rate = actual.freq; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
510 printf("Initialized audio at frequency %d with a %d sample buffer\n", actual.freq, actual.samples); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
511 SDL_PauseAudio(0); |
1355
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
512 |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
513 uint32_t db_size; |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
514 char *db_data = read_bundled_file("gamecontrollerdb.txt", &db_size); |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
515 if (db_data) { |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
516 int added = SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(db_data, db_size), 1); |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
517 free(db_data); |
1359
8c6d2ed3b959
Use printf rather than info_message for message about game controller mappings so it does not pop up a modal when not run from a terminal
Michael Pavone <pavone@retrodev.com>
parents:
1355
diff
changeset
|
518 printf("Added %d game controller mappings from gamecontrollerdb.txt\n", added); |
1355
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
519 } |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
520 |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
521 SDL_JoystickEventState(SDL_ENABLE); |
874
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
522 |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
523 atexit(render_quit); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
524 } |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
525 |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
526 void render_set_video_standard(vid_std std) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
527 { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
528 video_standard = std; |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
529 } |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
530 |
874
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
531 void render_update_caption(char *title) |
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
532 { |
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
533 caption = title; |
1068
624696318b5b
Fix a memory corruption bug from failing to grow the buffer for the window caption when switching games
Michael Pavone <pavone@retrodev.com>
parents:
1033
diff
changeset
|
534 free(fps_caption); |
624696318b5b
Fix a memory corruption bug from failing to grow the buffer for the window caption when switching games
Michael Pavone <pavone@retrodev.com>
parents:
1033
diff
changeset
|
535 fps_caption = NULL; |
874
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
536 } |
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
537 |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
538 static char *screenshot_path; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
539 void render_save_screenshot(char *path) |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
540 { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
541 if (screenshot_path) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
542 free(screenshot_path); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
543 } |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
544 screenshot_path = path; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
545 } |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
546 |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
547 uint32_t *locked_pixels; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
548 uint32_t locked_pitch; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
549 uint32_t *render_get_framebuffer(uint8_t which, int *pitch) |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
550 { |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
551 #ifndef DISABLE_OPENGL |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
552 if (render_gl && which <= FRAMEBUFFER_EVEN) { |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
553 *pitch = LINEBUF_SIZE * sizeof(uint32_t); |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
554 return texture_buf; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
555 } else { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
556 #endif |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
557 if (which >= num_textures) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
558 warning("Request for invalid framebuffer number %d\n", which); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
559 return NULL; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
560 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
561 void *pixels; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
562 if (SDL_LockTexture(sdl_textures[which], NULL, &pixels, pitch) < 0) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
563 warning("Failed to lock texture: %s\n", SDL_GetError()); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
564 return NULL; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
565 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
566 static uint8_t last; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
567 if (which <= FRAMEBUFFER_EVEN) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
568 locked_pixels = pixels; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
569 if (which == FRAMEBUFFER_EVEN) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
570 pixels += *pitch; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
571 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
572 locked_pitch = *pitch; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
573 if (which != last) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
574 *pitch *= 2; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
575 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
576 last = which; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
577 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
578 return pixels; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
579 #ifndef DISABLE_OPENGL |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
580 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
581 #endif |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
582 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
583 |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
584 uint8_t events_processed; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
585 #ifdef __ANDROID__ |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
586 #define FPS_INTERVAL 10000 |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
587 #else |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
588 #define FPS_INTERVAL 1000 |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
589 #endif |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
590 |
1398
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
591 static uint32_t last_width; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
592 void render_framebuffer_updated(uint8_t which, int width) |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
593 { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
594 static uint8_t last; |
1398
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
595 last_width = width; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
596 uint32_t height = which <= FRAMEBUFFER_EVEN |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
597 ? (video_standard == VID_NTSC ? 243 : 294) - (overscan_top[video_standard] + overscan_bot[video_standard]) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
598 : 240; |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
599 FILE *screenshot_file = NULL; |
1336
baaf05fd64c4
Make internal screenshot functionality completely ignore overscan settings rather than only doing it for the height
Michael Pavone <pavone@retrodev.com>
parents:
1328
diff
changeset
|
600 uint32_t shot_height, shot_width; |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
601 char *ext; |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
602 if (screenshot_path && which == FRAMEBUFFER_ODD) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
603 screenshot_file = fopen(screenshot_path, "wb"); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
604 if (screenshot_file) { |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
605 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
606 ext = path_extension(screenshot_path); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
607 #endif |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
608 info_message("Saving screenshot to %s\n", screenshot_path); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
609 } else { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
610 warning("Failed to open screenshot file %s for writing\n", screenshot_path); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
611 } |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
612 free(screenshot_path); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
613 screenshot_path = NULL; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
614 shot_height = video_standard == VID_NTSC ? 243 : 294; |
1336
baaf05fd64c4
Make internal screenshot functionality completely ignore overscan settings rather than only doing it for the height
Michael Pavone <pavone@retrodev.com>
parents:
1328
diff
changeset
|
615 shot_width = width; |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
616 } |
1336
baaf05fd64c4
Make internal screenshot functionality completely ignore overscan settings rather than only doing it for the height
Michael Pavone <pavone@retrodev.com>
parents:
1328
diff
changeset
|
617 width -= overscan_left[video_standard] + overscan_right[video_standard]; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
618 #ifndef DISABLE_OPENGL |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
619 if (render_gl && which <= FRAMEBUFFER_EVEN) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
620 glBindTexture(GL_TEXTURE_2D, textures[which]); |
1268
eca01056a915
Width on glTexSubImage2D call in render_framebuffer_updated needs to match the buffer pitch
Michael Pavone <pavone@retrodev.com>
parents:
1267
diff
changeset
|
621 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, LINEBUF_SIZE, height, GL_BGRA, GL_UNSIGNED_BYTE, texture_buf + overscan_left[video_standard] + LINEBUF_SIZE * overscan_top[video_standard]); |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
622 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
623 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
624 glClear(GL_COLOR_BUFFER_BIT); |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
625 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
626 glUseProgram(program); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
627 glActiveTexture(GL_TEXTURE0); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
628 glBindTexture(GL_TEXTURE_2D, textures[0]); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
629 glUniform1i(un_textures[0], 0); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
630 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
631 glActiveTexture(GL_TEXTURE1); |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
632 glBindTexture(GL_TEXTURE_2D, textures[last != which ? 1 : scanlines ? 2 : 0]); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
633 glUniform1i(un_textures[1], 1); |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
634 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
635 glUniform1f(un_width, width); |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
636 glUniform1f(un_height, height); |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
637 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
638 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
639 glVertexAttribPointer(at_pos, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat[2]), (void *)0); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
640 glEnableVertexAttribArray(at_pos); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
641 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
642 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
643 glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (void *)0); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
644 |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
645 glDisableVertexAttribArray(at_pos); |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
646 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
647 SDL_GL_SwapWindow(main_window); |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
648 |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
649 if (screenshot_file) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
650 //properly supporting interlaced modes here is non-trivial, so only save the odd field for now |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
651 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
652 if (!strcasecmp(ext, "png")) { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
653 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
654 save_png(screenshot_file, texture_buf, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
655 } else { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
656 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
657 #endif |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
658 save_ppm(screenshot_file, texture_buf, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
659 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
660 } |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
661 #endif |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
662 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
663 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
664 #endif |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
665 if (which <= FRAMEBUFFER_EVEN && last != which) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
666 uint8_t *cur_dst = (uint8_t *)locked_pixels; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
667 uint8_t *cur_saved = (uint8_t *)texture_buf; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
668 uint32_t dst_off = which == FRAMEBUFFER_EVEN ? 0 : locked_pitch; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
669 uint32_t src_off = which == FRAMEBUFFER_EVEN ? locked_pitch : 0; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
670 for (int i = 0; i < height; ++i) |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
671 { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
672 //copy saved line from other field |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
673 memcpy(cur_dst + dst_off, cur_saved, locked_pitch); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
674 //save line from this field to buffer for next frame |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
675 memcpy(cur_saved, cur_dst + src_off, locked_pitch); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
676 cur_dst += locked_pitch * 2; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
677 cur_saved += locked_pitch; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
678 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
679 height = 480; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
680 } |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
681 if (screenshot_file) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
682 uint32_t shot_pitch = locked_pitch; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
683 if (which == FRAMEBUFFER_EVEN) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
684 shot_height *= 2; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
685 } else { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
686 shot_pitch *= 2; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
687 } |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
688 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
689 if (!strcasecmp(ext, "png")) { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
690 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
691 save_png(screenshot_file, locked_pixels, shot_width, shot_height, shot_pitch); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
692 } else { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
693 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
694 #endif |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
695 save_ppm(screenshot_file, locked_pixels, shot_width, shot_height, shot_pitch); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
696 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
697 } |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
698 #endif |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
699 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
700 SDL_UnlockTexture(sdl_textures[which]); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
701 SDL_Rect src_clip = { |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
702 .x = overscan_left[video_standard], |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
703 .y = overscan_top[video_standard], |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
704 .w = width, |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
705 .h = height |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
706 }; |
1441
8a3d3bb2cd08
Clear display in SDL2 renderer before doing the texture copy. This gets rid of the artifacts noted in ticket:29
Michael Pavone <pavone@retrodev.com>
parents:
1403
diff
changeset
|
707 SDL_SetRenderDrawColor(main_renderer, 0, 0, 0, 255); |
8a3d3bb2cd08
Clear display in SDL2 renderer before doing the texture copy. This gets rid of the artifacts noted in ticket:29
Michael Pavone <pavone@retrodev.com>
parents:
1403
diff
changeset
|
708 SDL_RenderClear(main_renderer); |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
709 SDL_RenderCopy(main_renderer, sdl_textures[which], &src_clip, &main_clip); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
710 SDL_RenderPresent(main_renderer); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
711 #ifndef DISABLE_OPENGL |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
712 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
713 #endif |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
714 if (screenshot_file) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
715 fclose(screenshot_file); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
716 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
717 if (which <= FRAMEBUFFER_EVEN) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
718 last = which; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
719 static uint32_t frame_counter, start; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
720 frame_counter++; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
721 last_frame= SDL_GetTicks(); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
722 if ((last_frame - start) > FPS_INTERVAL) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
723 if (start && (last_frame-start)) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
724 #ifdef __ANDROID__ |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
725 info_message("%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
726 #else |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
727 if (!fps_caption) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
728 fps_caption = malloc(strlen(caption) + strlen(" - 100000000.1 fps") + 1); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
729 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
730 sprintf(fps_caption, "%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
731 SDL_SetWindowTitle(main_window, fps_caption); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
732 #endif |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
733 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
734 start = last_frame; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
735 frame_counter = 0; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
736 } |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
737 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
738 if (!events_processed) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
739 process_events(); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
740 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
741 events_processed = 0; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
742 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
743 |
1398
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
744 uint32_t render_emulated_width() |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
745 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
746 return last_width - overscan_left[video_standard] - overscan_right[video_standard]; |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
747 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
748 |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
749 uint32_t render_emulated_height() |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
750 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
751 return (video_standard == VID_NTSC ? 243 : 294) - overscan_top[video_standard] - overscan_bot[video_standard]; |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
752 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
753 |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
754 uint32_t render_overscan_left() |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
755 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
756 return overscan_left[video_standard]; |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
757 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
758 |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
759 uint32_t render_overscan_top() |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
760 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
761 return overscan_top[video_standard]; |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
762 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
763 |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
764 void render_wait_quit(vdp_context * context) |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
765 { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
766 SDL_Event event; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
767 while(SDL_WaitEvent(&event)) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
768 switch (event.type) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
769 case SDL_QUIT: |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
770 return; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
771 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
772 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
773 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
774 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
775 static int find_joystick_index(SDL_JoystickID instanceID) |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
776 { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
777 for (int i = 0; i < MAX_JOYSTICKS; i++) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
778 if (joysticks[i] && SDL_JoystickInstanceID(joysticks[i]) == instanceID) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
779 return i; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
780 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
781 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
782 return -1; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
783 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
784 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
785 static int lowest_unused_joystick_index() |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
786 { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
787 for (int i = 0; i < MAX_JOYSTICKS; i++) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
788 if (!joysticks[i]) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
789 return i; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
790 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
791 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
792 return -1; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
793 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
794 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
795 int32_t render_translate_input_name(int32_t controller, char *name, uint8_t is_axis) |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
796 { |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
797 static tern_node *button_lookup, *axis_lookup; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
798 if (controller > MAX_JOYSTICKS || !joysticks[controller]) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
799 return RENDER_NOT_PLUGGED_IN; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
800 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
801 |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
802 if (!SDL_IsGameController(joystick_sdl_index[controller])) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
803 return RENDER_NOT_MAPPED; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
804 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
805 SDL_GameController *control = SDL_GameControllerOpen(joystick_sdl_index[controller]); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
806 if (!control) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
807 warning("Failed to open game controller %d: %s\n", controller, SDL_GetError()); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
808 return RENDER_NOT_PLUGGED_IN; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
809 } |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
810 |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
811 SDL_GameControllerButtonBind cbind; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
812 if (is_axis) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
813 if (!axis_lookup) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
814 for (int i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
815 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
816 axis_lookup = tern_insert_int(axis_lookup, SDL_GameControllerGetStringForAxis(i), i); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
817 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
818 //alternative Playstation-style names |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
819 axis_lookup = tern_insert_int(axis_lookup, "l2", SDL_CONTROLLER_AXIS_TRIGGERLEFT); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
820 axis_lookup = tern_insert_int(axis_lookup, "r2", SDL_CONTROLLER_AXIS_TRIGGERRIGHT); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
821 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
822 intptr_t sdl_axis = tern_find_int(axis_lookup, name, SDL_CONTROLLER_AXIS_INVALID); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
823 if (sdl_axis == SDL_CONTROLLER_AXIS_INVALID) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
824 SDL_GameControllerClose(control); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
825 return RENDER_INVALID_NAME; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
826 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
827 cbind = SDL_GameControllerGetBindForAxis(control, sdl_axis); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
828 } else { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
829 if (!button_lookup) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
830 for (int i = SDL_CONTROLLER_BUTTON_A; i < SDL_CONTROLLER_BUTTON_MAX; i++) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
831 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
832 button_lookup = tern_insert_int(button_lookup, SDL_GameControllerGetStringForButton(i), i); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
833 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
834 //alternative Playstation-style names |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
835 button_lookup = tern_insert_int(button_lookup, "cross", SDL_CONTROLLER_BUTTON_A); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
836 button_lookup = tern_insert_int(button_lookup, "circle", SDL_CONTROLLER_BUTTON_B); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
837 button_lookup = tern_insert_int(button_lookup, "square", SDL_CONTROLLER_BUTTON_X); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
838 button_lookup = tern_insert_int(button_lookup, "triangle", SDL_CONTROLLER_BUTTON_Y); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
839 button_lookup = tern_insert_int(button_lookup, "share", SDL_CONTROLLER_BUTTON_BACK); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
840 button_lookup = tern_insert_int(button_lookup, "select", SDL_CONTROLLER_BUTTON_BACK); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
841 button_lookup = tern_insert_int(button_lookup, "options", SDL_CONTROLLER_BUTTON_START); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
842 button_lookup = tern_insert_int(button_lookup, "l1", SDL_CONTROLLER_BUTTON_LEFTSHOULDER); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
843 button_lookup = tern_insert_int(button_lookup, "r1", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
844 button_lookup = tern_insert_int(button_lookup, "l3", SDL_CONTROLLER_BUTTON_LEFTSTICK); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
845 button_lookup = tern_insert_int(button_lookup, "r3", SDL_CONTROLLER_BUTTON_RIGHTSTICK); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
846 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
847 intptr_t sdl_button = tern_find_int(button_lookup, name, SDL_CONTROLLER_BUTTON_INVALID); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
848 if (sdl_button == SDL_CONTROLLER_BUTTON_INVALID) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
849 SDL_GameControllerClose(control); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
850 return RENDER_INVALID_NAME; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
851 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
852 cbind = SDL_GameControllerGetBindForButton(control, sdl_button); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
853 } |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
854 SDL_GameControllerClose(control); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
855 switch (cbind.bindType) |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
856 { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
857 case SDL_CONTROLLER_BINDTYPE_BUTTON: |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
858 return cbind.value.button; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
859 case SDL_CONTROLLER_BINDTYPE_AXIS: |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
860 return RENDER_AXIS_BIT | cbind.value.axis; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
861 case SDL_CONTROLLER_BINDTYPE_HAT: |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
862 return RENDER_DPAD_BIT | (cbind.value.hat.hat << 4) | cbind.value.hat.hat_mask; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
863 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
864 return RENDER_NOT_MAPPED; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
865 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
866 |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
867 int32_t render_dpad_part(int32_t input) |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
868 { |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
869 return input >> 4 & 0xFFFFFF; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
870 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
871 |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
872 uint8_t render_direction_part(int32_t input) |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
873 { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
874 return input & 0xF; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
875 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
876 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
877 int32_t render_axis_part(int32_t input) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
878 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
879 return input & 0xFFFFFFF; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
880 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
881 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
882 static uint8_t scancode_map[SDL_NUM_SCANCODES] = { |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
883 [SDL_SCANCODE_A] = 0x1C, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
884 [SDL_SCANCODE_B] = 0x32, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
885 [SDL_SCANCODE_C] = 0x21, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
886 [SDL_SCANCODE_D] = 0x23, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
887 [SDL_SCANCODE_E] = 0x24, |
1258
1148567ab355
Fix scancode for F key
Michael Pavone <pavone@retrodev.com>
parents:
1207
diff
changeset
|
888 [SDL_SCANCODE_F] = 0x2B, |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
889 [SDL_SCANCODE_G] = 0x34, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
890 [SDL_SCANCODE_H] = 0x33, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
891 [SDL_SCANCODE_I] = 0x43, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
892 [SDL_SCANCODE_J] = 0x3B, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
893 [SDL_SCANCODE_K] = 0x42, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
894 [SDL_SCANCODE_L] = 0x4B, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
895 [SDL_SCANCODE_M] = 0x3A, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
896 [SDL_SCANCODE_N] = 0x31, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
897 [SDL_SCANCODE_O] = 0x44, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
898 [SDL_SCANCODE_P] = 0x4D, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
899 [SDL_SCANCODE_Q] = 0x15, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
900 [SDL_SCANCODE_R] = 0x2D, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
901 [SDL_SCANCODE_S] = 0x1B, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
902 [SDL_SCANCODE_T] = 0x2C, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
903 [SDL_SCANCODE_U] = 0x3C, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
904 [SDL_SCANCODE_V] = 0x2A, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
905 [SDL_SCANCODE_W] = 0x1D, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
906 [SDL_SCANCODE_X] = 0x22, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
907 [SDL_SCANCODE_Y] = 0x35, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
908 [SDL_SCANCODE_Z] = 0x1A, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
909 [SDL_SCANCODE_1] = 0x16, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
910 [SDL_SCANCODE_2] = 0x1E, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
911 [SDL_SCANCODE_3] = 0x26, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
912 [SDL_SCANCODE_4] = 0x25, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
913 [SDL_SCANCODE_5] = 0x2E, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
914 [SDL_SCANCODE_6] = 0x36, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
915 [SDL_SCANCODE_7] = 0x3D, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
916 [SDL_SCANCODE_8] = 0x3E, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
917 [SDL_SCANCODE_9] = 0x46, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
918 [SDL_SCANCODE_0] = 0x45, |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
919 [SDL_SCANCODE_RETURN] = 0x5A, |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
920 [SDL_SCANCODE_ESCAPE] = 0x76, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
921 [SDL_SCANCODE_SPACE] = 0x29, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
922 [SDL_SCANCODE_TAB] = 0x0D, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
923 [SDL_SCANCODE_BACKSPACE] = 0x66, |
1033
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
924 [SDL_SCANCODE_MINUS] = 0x4E, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
925 [SDL_SCANCODE_EQUALS] = 0x55, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
926 [SDL_SCANCODE_LEFTBRACKET] = 0x54, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
927 [SDL_SCANCODE_RIGHTBRACKET] = 0x5B, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
928 [SDL_SCANCODE_BACKSLASH] = 0x5D, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
929 [SDL_SCANCODE_SEMICOLON] = 0x4C, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
930 [SDL_SCANCODE_APOSTROPHE] = 0x52, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
931 [SDL_SCANCODE_GRAVE] = 0x0E, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
932 [SDL_SCANCODE_COMMA] = 0x41, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
933 [SDL_SCANCODE_PERIOD] = 0x49, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
934 [SDL_SCANCODE_SLASH] = 0x4A, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
935 [SDL_SCANCODE_CAPSLOCK] = 0x58, |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
936 [SDL_SCANCODE_F1] = 0x05, |
1033
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
937 [SDL_SCANCODE_F2] = 0x06, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
938 [SDL_SCANCODE_F3] = 0x04, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
939 [SDL_SCANCODE_F4] = 0x0C, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
940 [SDL_SCANCODE_F5] = 0x03, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
941 [SDL_SCANCODE_F6] = 0x0B, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
942 [SDL_SCANCODE_F7] = 0x83, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
943 [SDL_SCANCODE_F8] = 0x0A, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
944 [SDL_SCANCODE_F9] = 0x01, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
945 [SDL_SCANCODE_F10] = 0x09, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
946 [SDL_SCANCODE_F11] = 0x78, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
947 [SDL_SCANCODE_F12] = 0x07, |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
948 [SDL_SCANCODE_LCTRL] = 0x14, |
1033
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
949 [SDL_SCANCODE_LSHIFT] = 0x12, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
950 [SDL_SCANCODE_LALT] = 0x11, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
951 [SDL_SCANCODE_RCTRL] = 0x18, |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
952 [SDL_SCANCODE_RSHIFT] = 0x59, |
1033
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
953 [SDL_SCANCODE_RALT] = 0x17, |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
954 [SDL_SCANCODE_INSERT] = 0x81, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
955 [SDL_SCANCODE_PAUSE] = 0x82, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
956 [SDL_SCANCODE_PRINTSCREEN] = 0x84, |
1033
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
957 [SDL_SCANCODE_SCROLLLOCK] = 0x7E, |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
958 [SDL_SCANCODE_DELETE] = 0x85, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
959 [SDL_SCANCODE_LEFT] = 0x86, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
960 [SDL_SCANCODE_HOME] = 0x87, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
961 [SDL_SCANCODE_END] = 0x88, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
962 [SDL_SCANCODE_UP] = 0x89, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
963 [SDL_SCANCODE_DOWN] = 0x8A, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
964 [SDL_SCANCODE_PAGEUP] = 0x8B, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
965 [SDL_SCANCODE_PAGEDOWN] = 0x8C, |
1033
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
966 [SDL_SCANCODE_RIGHT] = 0x8D, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
967 [SDL_SCANCODE_NUMLOCKCLEAR] = 0x77, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
968 [SDL_SCANCODE_KP_DIVIDE] = 0x80, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
969 [SDL_SCANCODE_KP_MULTIPLY] = 0x7C, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
970 [SDL_SCANCODE_KP_MINUS] = 0x7B, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
971 [SDL_SCANCODE_KP_PLUS] = 0x79, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
972 [SDL_SCANCODE_KP_ENTER] = 0x19, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
973 [SDL_SCANCODE_KP_1] = 0x69, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
974 [SDL_SCANCODE_KP_2] = 0x72, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
975 [SDL_SCANCODE_KP_3] = 0x7A, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
976 [SDL_SCANCODE_KP_4] = 0x6B, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
977 [SDL_SCANCODE_KP_5] = 0x73, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
978 [SDL_SCANCODE_KP_6] = 0x74, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
979 [SDL_SCANCODE_KP_7] = 0x6C, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
980 [SDL_SCANCODE_KP_8] = 0x75, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
981 [SDL_SCANCODE_KP_9] = 0x7D, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
982 [SDL_SCANCODE_KP_0] = 0x70, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
983 [SDL_SCANCODE_KP_PERIOD] = 0x71, |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
984 }; |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
985 |
1397
89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents:
1359
diff
changeset
|
986 static drop_handler drag_drop_handler; |
89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents:
1359
diff
changeset
|
987 void render_set_drag_drop_handler(drop_handler handler) |
89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents:
1359
diff
changeset
|
988 { |
89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents:
1359
diff
changeset
|
989 drag_drop_handler = handler; |
89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents:
1359
diff
changeset
|
990 } |
89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents:
1359
diff
changeset
|
991 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
992 static int32_t handle_event(SDL_Event *event) |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
993 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
994 switch (event->type) { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
995 case SDL_KEYDOWN: |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
996 handle_keydown(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]); |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
997 break; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
998 case SDL_KEYUP: |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1004
diff
changeset
|
999 handle_keyup(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]); |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1000 break; |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
1001 case SDL_JOYBUTTONDOWN: |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1002 handle_joydown(find_joystick_index(event->jbutton.which), event->jbutton.button); |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
1003 break; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
1004 case SDL_JOYBUTTONUP: |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1005 handle_joyup(find_joystick_index(event->jbutton.which), event->jbutton.button); |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
1006 break; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
1007 case SDL_JOYHATMOTION: |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1008 handle_joy_dpad(find_joystick_index(event->jbutton.which), event->jhat.hat, event->jhat.value); |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
1009 break; |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1010 case SDL_JOYAXISMOTION: |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1011 handle_joy_axis(find_joystick_index(event->jaxis.which), event->jaxis.axis, event->jaxis.value); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1012 break; |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1013 case SDL_JOYDEVICEADDED: |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1014 if (event->jdevice.which < MAX_JOYSTICKS) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1015 int index = lowest_unused_joystick_index(); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1016 if (index >= 0) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1017 SDL_Joystick * joy = joysticks[index] = SDL_JoystickOpen(event->jdevice.which); |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1018 joystick_sdl_index[index] = event->jdevice.which; |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1019 if (joy) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1020 printf("Joystick %d added: %s\n", index, SDL_JoystickName(joy)); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1021 printf("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1022 handle_joy_added(index); |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1023 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1024 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1025 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1026 break; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1027 case SDL_JOYDEVICEREMOVED: { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1028 int index = find_joystick_index(event->jdevice.which); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1029 if (index >= 0) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1030 SDL_JoystickClose(joysticks[index]); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1031 joysticks[index] = NULL; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1032 printf("Joystick %d removed\n", index); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1033 } else { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1034 printf("Failed to find removed joystick with instance ID: %d\n", index); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1035 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1036 break; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
1037 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1038 case SDL_MOUSEMOTION: |
1198
8715174e9366
Adjust mouse cursor in absolute mode/menu to account for presence of top border
Michael Pavone <pavone@retrodev.com>
parents:
1194
diff
changeset
|
1039 handle_mouse_moved(event->motion.which, event->motion.x, event->motion.y + overscan_top[video_standard], event->motion.xrel, event->motion.yrel); |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
1040 break; |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
906
diff
changeset
|
1041 case SDL_MOUSEBUTTONDOWN: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
906
diff
changeset
|
1042 handle_mousedown(event->button.which, event->button.button); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
906
diff
changeset
|
1043 break; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
906
diff
changeset
|
1044 case SDL_MOUSEBUTTONUP: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
906
diff
changeset
|
1045 handle_mouseup(event->button.which, event->button.button); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
906
diff
changeset
|
1046 break; |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1047 case SDL_WINDOWEVENT: |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1048 switch (event->window.event) |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1049 { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1050 case SDL_WINDOWEVENT_SIZE_CHANGED: |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1051 main_width = event->window.data1; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1052 main_height = event->window.data2; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1053 update_aspect(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1054 #ifndef DISABLE_OPENGL |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1055 if (render_gl) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1056 SDL_GL_DeleteContext(main_context); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1057 main_context = SDL_GL_CreateContext(main_window); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1058 gl_setup(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1059 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1060 #endif |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1061 break; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1062 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1063 break; |
1397
89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents:
1359
diff
changeset
|
1064 case SDL_DROPFILE: |
89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents:
1359
diff
changeset
|
1065 if (drag_drop_handler) { |
89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents:
1359
diff
changeset
|
1066 drag_drop_handler(event->drop.file); |
89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents:
1359
diff
changeset
|
1067 } |
89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents:
1359
diff
changeset
|
1068 SDL_free(event->drop.file); |
89eb967fed72
Initial support for drag and drop. Some work needed for proper menu integration.
Michael Pavone <pavone@retrodev.com>
parents:
1359
diff
changeset
|
1069 break; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1070 case SDL_QUIT: |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1071 puts(""); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1072 exit(0); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1073 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1074 return 0; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1075 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1076 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1077 static void drain_events() |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1078 { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1079 SDL_Event event; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1080 while(SDL_PollEvent(&event)) |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1081 { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1082 handle_event(&event); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1083 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1084 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1085 |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
1086 void process_events() |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
1087 { |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1088 if (events_processed > MAX_EVENT_POLL_PER_FRAME) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1089 return; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1090 } |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1091 drain_events(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1092 events_processed++; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1093 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1094 |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1095 #define TOGGLE_MIN_DELAY 250 |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1096 void render_toggle_fullscreen() |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1097 { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1098 static int in_toggle; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1099 //protect against event processing causing us to attempt to toggle while still toggling |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1100 if (in_toggle) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1101 return; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1102 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1103 in_toggle = 1; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1104 |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1105 //toggling too fast seems to cause a deadlock |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1106 static uint32_t last_toggle; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1107 uint32_t cur = SDL_GetTicks(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1108 if (last_toggle && cur - last_toggle < TOGGLE_MIN_DELAY) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1109 in_toggle = 0; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1110 return; |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
1111 } |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1112 last_toggle = cur; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1113 |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1114 drain_events(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1115 is_fullscreen = !is_fullscreen; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1116 if (is_fullscreen) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1117 SDL_DisplayMode mode; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1118 //TODO: Multiple monitor support |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1119 SDL_GetCurrentDisplayMode(0, &mode); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1120 //In theory, the SDL2 docs suggest this is unnecessary |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1121 //but without it the OpenGL context remains the original size |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1122 //This needs to happen before the fullscreen transition to have any effect |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1123 //because SDL does not apply window size changes in fullscreen |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1124 SDL_SetWindowSize(main_window, mode.w, mode.h); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1125 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1126 SDL_SetWindowFullscreen(main_window, is_fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1127 //Since we change the window size on transition to full screen |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1128 //we need to set it back to normal so we can also go back to windowed mode |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1129 //normally you would think that this should only be done when actually transitioning |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1130 //but something is screwy in the guts of SDL (at least on Linux) and setting it each time |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1131 //is the only thing that seems to work reliably |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1132 //when we've just switched to fullscreen mode this should be harmless though |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1133 SDL_SetWindowSize(main_window, windowed_width, windowed_height); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1134 drain_events(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1135 in_toggle = 0; |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
1136 } |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
1137 |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1138 void render_wait_psg(psg_context * context) |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1139 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1140 SDL_LockMutex(audio_mutex); |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1141 while (current_psg != NULL) { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1142 SDL_CondWait(psg_cond, audio_mutex); |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1143 } |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1144 current_psg = context->audio_buffer; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1145 SDL_CondSignal(audio_ready); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1146 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1147 context->audio_buffer = context->back_buffer; |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1148 context->back_buffer = current_psg; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1149 SDL_UnlockMutex(audio_mutex); |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1150 context->buffer_pos = 0; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1151 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1152 |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1153 void render_wait_ym(ym2612_context * context) |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1154 { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1155 SDL_LockMutex(audio_mutex); |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1156 while (current_ym != NULL) { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1157 SDL_CondWait(ym_cond, audio_mutex); |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1158 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1159 current_ym = context->audio_buffer; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1160 SDL_CondSignal(audio_ready); |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1161 |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1162 context->audio_buffer = context->back_buffer; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
1163 context->back_buffer = current_ym; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1164 SDL_UnlockMutex(audio_mutex); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1165 context->buffer_pos = 0; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1166 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1167 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1168 uint32_t render_audio_buffer() |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1169 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1170 return buffer_samples; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1171 } |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1172 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1173 uint32_t render_sample_rate() |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1174 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1175 return sample_rate; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1176 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1177 |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1178 void render_errorbox(char *title, char *message) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1179 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1180 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, NULL); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1181 } |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1182 |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1183 void render_warnbox(char *title, char *message) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1184 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1185 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, title, message, NULL); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1186 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1187 |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1188 void render_infobox(char *title, char *message) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1189 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1190 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, title, message, NULL); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1191 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1192 |