Mercurial > repos > blastem
annotate render_sdl.c @ 1076:fa6fe03f218a
Removed obsolete TOOD
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 12 Aug 2016 09:39:39 -0700 |
parents | 3a0f684891ae |
children | 1a66d5165ea7 |
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" |
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
|
12 #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
|
13 #include "util.h" |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
15 #ifndef DISABLE_OPENGL |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
16 #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
|
17 #endif |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
18 |
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
|
19 SDL_Window *main_window; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
20 SDL_Renderer *main_renderer; |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
21 SDL_Texture *main_texture; |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
22 SDL_Rect main_clip; |
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
|
23 SDL_GLContext *main_context; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
24 |
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
|
25 int main_width, main_height, is_fullscreen; |
914
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
26 |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
27 uint8_t render_dbg = 0; |
135 | 28 uint8_t debug_pal = 0; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
29 uint8_t render_gl = 1; |
1003
534f522a1162
Added a config option that allows turning scanlines on and off
Michael Pavone <pavone@retrodev.com>
parents:
937
diff
changeset
|
30 uint8_t scanlines = 0; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
32 uint32_t last_frame = 0; |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
33 |
229
d60837a7d18a
Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents:
198
diff
changeset
|
34 uint32_t min_delay; |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
35 uint32_t frame_delay = 1000/60; |
229
d60837a7d18a
Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents:
198
diff
changeset
|
36 |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
37 int16_t * current_psg = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
38 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
|
39 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
40 uint32_t buffer_samples, sample_rate; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
41 uint32_t missing_count; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
42 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
43 SDL_mutex * audio_mutex; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
44 SDL_cond * audio_ready; |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
45 SDL_cond * psg_cond; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
46 SDL_cond * ym_cond; |
361 | 47 uint8_t quitting = 0; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
48 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
49 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
|
50 { |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
51 //puts("audio_callback"); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
52 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
|
53 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
|
54 int16_t * psg_buf, * ym_buf; |
361 | 55 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
|
56 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
|
57 psg_buf = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
58 ym_buf = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
59 do { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
60 if (!psg_buf) { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
61 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
|
62 current_psg = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
63 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
|
64 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
65 if (!ym_buf) { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
66 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
|
67 current_ym = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
68 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
|
69 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
70 if (!quitting && (!psg_buf || !ym_buf)) { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
71 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
|
72 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
73 } while(!quitting && (!psg_buf || !ym_buf)); |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
74 |
361 | 75 local_quit = quitting; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
76 SDL_UnlockMutex(audio_mutex); |
361 | 77 if (!local_quit) { |
78 for (int i = 0; i < samples; i++) { | |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
79 *(stream++) = psg_buf[i] + *(ym_buf++); |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
80 *(stream++) = psg_buf[i] + *(ym_buf++); |
361 | 81 } |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
82 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
83 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
84 |
361 | 85 void render_close_audio() |
86 { | |
87 SDL_LockMutex(audio_mutex); | |
88 quitting = 1; | |
89 SDL_CondSignal(audio_ready); | |
90 SDL_UnlockMutex(audio_mutex); | |
91 SDL_CloseAudio(); | |
92 } | |
93 | |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
94 static SDL_Joystick * joysticks[MAX_JOYSTICKS]; |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
95 |
914
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
96 int render_width() |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
97 { |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
98 return main_width; |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
99 } |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
100 |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
101 int render_height() |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
102 { |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
103 return main_height; |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
104 } |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
105 |
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
|
106 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
|
107 { |
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
|
108 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
|
109 } |
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
|
110 |
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
|
111 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
|
112 { |
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
|
113 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
|
114 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
115 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
116 #ifndef DISABLE_OPENGL |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
502
diff
changeset
|
117 GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], un_width, at_pos; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
118 |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
119 GLfloat vertex_data[] = { |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
120 -1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
121 1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
122 -1.0f, 1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
123 1.0f, 1.0f |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
124 }; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
125 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
126 const GLushort element_data[] = {0, 1, 2, 3}; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
127 |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
128 GLuint load_shader(char * fname, GLenum shader_type) |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
129 { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
130 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
|
131 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
|
132 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
|
133 free(shader_path); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
134 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 if (!f) { |
800 | 141 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
|
142 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
|
143 } |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
144 } |
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
|
145 long fsize = file_size(f); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
146 GLchar * text = malloc(fsize); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
147 if (fread(text, 1, fsize, f) != fsize) { |
800 | 148 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
|
149 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
150 return 0; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
151 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
152 GLuint ret = glCreateShader(shader_type); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
153 glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
154 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
155 glCompileShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
156 GLint compile_status, loglen; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
157 glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
158 if (!compile_status) { |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
159 glGetShaderiv(ret, GL_INFO_LOG_LENGTH, &loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
160 text = malloc(loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
161 glGetShaderInfoLog(ret, loglen, NULL, text); |
800 | 162 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
|
163 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
164 glDeleteShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
165 return 0; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
166 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
167 return ret; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
168 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
169 #endif |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
170 |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
171 void render_alloc_surfaces(vdp_context * context) |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
172 { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
173 static uint8_t texture_init; |
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
|
174 context->oddbuf = context->framebuf = malloc(512 * 256 * 4 * 2); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
175 memset(context->oddbuf, 0, 512 * 256 * 4 * 2); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
176 context->evenbuf = ((char *)context->oddbuf) + 512 * 256 * 4; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
177 |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
178 if (texture_init) { |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
179 return; |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
180 } |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
181 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
|
182 #ifndef DISABLE_OPENGL |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
183 if (render_gl) { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
184 glGenTextures(3, textures); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
185 for (int i = 0; i < 3; i++) |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
186 { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
187 glBindTexture(GL_TEXTURE_2D, textures[i]); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
188 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
189 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
190 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
191 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
192 if (i < 2) { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
193 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, i ? context->evenbuf : context->oddbuf); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
194 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
195 uint32_t blank = 255 << 24; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
196 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_BGRA, GL_UNSIGNED_BYTE, &blank); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
197 } |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
198 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
199 glGenBuffers(2, buffers); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
200 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
|
201 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
202 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
|
203 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
204 tern_val def = {.ptrval = "default.v.glsl"}; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
205 vshader = load_shader(tern_find_path_default(config, "video\0vertex_shader\0", def).ptrval, GL_VERTEX_SHADER); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
206 def.ptrval = "default.f.glsl"; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
207 fshader = load_shader(tern_find_path_default(config, "video\0fragment_shader\0", def).ptrval, GL_FRAGMENT_SHADER); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
208 program = glCreateProgram(); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
209 glAttachShader(program, vshader); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
210 glAttachShader(program, fshader); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
211 glLinkProgram(program); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
212 GLint link_status; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
213 glGetProgramiv(program, GL_LINK_STATUS, &link_status); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
214 if (!link_status) { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
215 fputs("Failed to link shader program\n", stderr); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
216 exit(1); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
217 } |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
218 un_textures[0] = glGetUniformLocation(program, "textures[0]"); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
219 un_textures[1] = glGetUniformLocation(program, "textures[1]"); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
220 un_width = glGetUniformLocation(program, "width"); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
221 at_pos = glGetAttribLocation(program, "pos"); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
222 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
223 #endif |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
224 /* height=480 to fit interlaced output */ |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
225 main_texture = SDL_CreateTexture(main_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 480); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
226 #ifndef DISABLE_OPENGL |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
227 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
228 #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
|
229 } |
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
|
230 |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
231 void render_free_surfaces(vdp_context *context) |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
232 { |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
233 free(context->framebuf); |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
234 } |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
235 |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
236 char * caption = NULL; |
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
|
237 char * fps_caption = NULL; |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
238 |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
239 static void render_quit() |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
240 { |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
241 render_close_audio(); |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
242 #ifdef DISABLE_OPENGL |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
243 SDL_DestroyTexture(main_texture); |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
244 #endif |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
245 } |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
246 |
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
|
247 void render_init(int width, int height, char * title, uint32_t fps, uint8_t fullscreen) |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
248 { |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
249 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 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
|
250 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
|
251 } |
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
|
252 atexit(SDL_Quit); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
253 printf("width: %d, height: %d\n", width, height); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
254 |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
255 uint32_t flags = 0; |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
256 |
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
|
257 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
|
258 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
|
259 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
|
260 //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
|
261 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
|
262 //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
|
263 //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
|
264 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
|
265 height = mode.h; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
266 } |
914
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
267 main_width = width; |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
268 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
|
269 is_fullscreen = fullscreen; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
270 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
271 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
|
272 tern_val def = {.ptrval = "off"}; |
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
|
273 char *vsync = tern_find_path_default(config, "video\0vsync\0", def).ptrval; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
274 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
275 #ifndef DISABLE_OPENGL |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
276 flags |= SDL_WINDOW_OPENGL; |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
277 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
278 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
279 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
280 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
281 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
282 #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
|
283 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
|
284 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
|
285 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
|
286 } |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
287 #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
|
288 main_context = SDL_GL_CreateContext(main_window); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
289 GLenum res = glewInit(); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
290 if (res != GLEW_OK) { |
800 | 291 warning("Initialization of GLEW failed with code %d\n", res); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
292 } |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
293 |
800 | 294 if (res == GLEW_OK && GLEW_VERSION_2_0) { |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
295 render_gl = 1; |
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
|
296 if (!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
|
297 if (SDL_GL_SetSwapInterval(-1) < 0) { |
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
|
298 warning("late tear is not available (%s), using normal vsync\n", SDL_GetError()); |
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
|
299 vsync = "on"; |
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
|
300 } else { |
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
|
301 vsync = NULL; |
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
|
302 } |
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
|
303 } |
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
|
304 if (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
|
305 if (SDL_GL_SetSwapInterval(!strcmp("on", vsync)) < 0) { |
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
|
306 warning("Failed to set vsync to %s: %s\n", vsync, SDL_GetError()); |
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
|
307 } |
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
|
308 } |
800 | 309 } else { |
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
|
310 warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n"); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
311 #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
|
312 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
|
313 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
|
314 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
|
315 } |
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
|
316 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
|
317 |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
318 if (!main_renderer) { |
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
319 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
|
320 } |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
321 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
|
322 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
|
323 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
|
324 #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
|
325 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
326 #endif |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
327 |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
328 SDL_GetWindowSize(main_window, &width, &height); |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
329 printf("Window created with size: %d x %d\n", width, height); |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
330 float src_aspect = 4.0/3.0; |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
331 float aspect = (float)width / height; |
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
|
332 def.ptrval = "normal"; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
333 int stretch = fabs(aspect - src_aspect) > 0.01 && !strcmp(tern_find_path_default(config, "video\0aspect\0", def).ptrval, "stretch"); |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
334 |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
335 if (!stretch) { |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
336 #ifndef DISABLE_OPENGL |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
337 if (render_gl) { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
338 for (int i = 0; i < 4; i++) |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
339 { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
340 if (aspect > src_aspect) { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
341 vertex_data[i*2] *= src_aspect/aspect; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
342 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
343 vertex_data[i*2+1] *= aspect/src_aspect; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
344 } |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
345 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
346 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
347 #endif |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
348 float scale_x = (float)width / 320.0; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
349 float scale_y = (float)height / 240.0; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
350 float scale = scale_x > scale_y ? scale_y : scale_x; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
351 main_clip.w = 320.0 * scale; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
352 main_clip.h = 240.0 * scale; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
353 main_clip.x = (width - main_clip.w) / 2; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
354 main_clip.y = (height - main_clip.h) / 2; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
355 #ifndef DISABLE_OPENGL |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
356 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
357 #endif |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
358 } |
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
|
359 def.ptrval = "off"; |
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
|
360 scanlines = !strcmp(tern_find_path_default(config, "video\0scanlines\0", def).ptrval, "on"); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
361 |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
362 caption = title; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
363 min_delay = 0; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
364 for (int i = 0; i < 100; i++) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
365 uint32_t start = SDL_GetTicks(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
366 SDL_Delay(1); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
367 uint32_t delay = SDL_GetTicks()-start; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
368 if (delay > min_delay) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
369 min_delay = delay; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
370 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
371 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
372 if (!min_delay) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
373 min_delay = 1; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
374 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
375 printf("minimum delay: %d\n", min_delay); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
376 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
377 frame_delay = 1000/fps; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
378 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
379 audio_mutex = SDL_CreateMutex(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
380 psg_cond = SDL_CreateCond(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
381 ym_cond = SDL_CreateCond(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
382 audio_ready = SDL_CreateCond(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
383 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
384 SDL_AudioSpec desired, actual; |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
746
diff
changeset
|
385 char * rate_str = tern_find_path(config, "audio\0rate\0").ptrval; |
445
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
386 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
|
387 if (!rate) { |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
388 rate = 48000; |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
389 } |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
390 desired.freq = rate; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
391 desired.format = AUDIO_S16SYS; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
392 desired.channels = 2; |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
746
diff
changeset
|
393 char * samples_str = tern_find_path(config, "audio\0buffer\0").ptrval; |
445
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
394 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
|
395 if (!samples) { |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
396 samples = 512; |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
397 } |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
398 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
|
399 desired.samples = samples*2; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
400 desired.callback = audio_callback; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
401 desired.userdata = NULL; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
402 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
403 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
|
404 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
|
405 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
406 buffer_samples = actual.samples; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
407 sample_rate = actual.freq; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
408 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
|
409 SDL_PauseAudio(0); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
410 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
|
411 |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
412 atexit(render_quit); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
413 } |
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
|
414 |
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
|
415 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
|
416 { |
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
|
417 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
|
418 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
|
419 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
|
420 } |
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
|
421 |
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 void render_context(vdp_context * context) |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
423 { |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
424 int width = context->regs[REG_MODE_4] & BIT_H40 ? 320.0f : 256.0f; |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
425 int height = 240; |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
426 |
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
|
427 last_frame = SDL_GetTicks(); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
428 #ifndef DISABLE_OPENGL |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
429 if (render_gl) { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
430 glBindTexture(GL_TEXTURE_2D, textures[context->framebuf == context->oddbuf ? 0 : 1]); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
431 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 320, 240, GL_BGRA, GL_UNSIGNED_BYTE, context->framebuf);; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
432 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
433 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
|
434 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
|
435 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
436 glUseProgram(program); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
437 glActiveTexture(GL_TEXTURE0); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
438 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
|
439 glUniform1i(un_textures[0], 0); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
440 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
441 glActiveTexture(GL_TEXTURE1); |
1003
534f522a1162
Added a config option that allows turning scanlines on and off
Michael Pavone <pavone@retrodev.com>
parents:
937
diff
changeset
|
442 glBindTexture(GL_TEXTURE_2D, textures[(context->regs[REG_MODE_4] & BIT_INTERLACE) ? 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
|
443 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
|
444 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
445 glUniform1f(un_width, width); |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
446 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
447 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
|
448 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
|
449 glEnableVertexAttribArray(at_pos); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
450 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
451 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
|
452 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
|
453 |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
454 glDisableVertexAttribArray(at_pos); |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
455 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
456 SDL_GL_SwapWindow(main_window); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
457 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
458 #endif |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
459 SDL_Rect area; |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
460 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
461 area.x = area.y = 0; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
462 area.w = width; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
463 area.h = height; |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
464 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
465 if (context->regs[REG_MODE_4] & BIT_INTERLACE) { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
466 unsigned skip; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
467 uint32_t *src = (uint32_t*)context->framebuf; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
468 uint8_t *dst; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
469 int i; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
470 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
471 area.h *= 2; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
472 |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
473 SDL_LockTexture(main_texture, &area, (void**)&dst, &skip); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
474 |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
475 if (context->framebuf == context->evenbuf) |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
476 dst += skip; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
477 |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
478 skip *= 2; |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
502
diff
changeset
|
479 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
480 for (i = 0; i < 240; ++i) { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
481 memcpy(dst, src, width*sizeof(uint32_t)); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
482 src += 320; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
483 dst += skip; |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
484 } |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
485 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
486 SDL_UnlockTexture(main_texture); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
487 } |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
488 else /* possibly faster path for non-interlaced output */ |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
489 SDL_UpdateTexture(main_texture, &area, context->framebuf, 320*sizeof(uint32_t)); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
490 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
491 SDL_RenderClear(main_renderer); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
492 SDL_RenderCopy(main_renderer, main_texture, &area, &main_clip); |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
493 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
|
494 #ifndef DISABLE_OPENGL |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
495 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
496 #endif |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
497 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
498 if (context->regs[REG_MODE_4] & BIT_INTERLACE) { |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
499 context->framebuf = context->framebuf == context->oddbuf ? context->evenbuf : context->oddbuf; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
500 } |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
503 void render_wait_quit(vdp_context * context) |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
504 { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
505 SDL_Event event; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
506 while(SDL_WaitEvent(&event)) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
507 switch (event.type) { |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
508 case SDL_KEYDOWN: |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
509 if (event.key.keysym.sym == SDLK_LEFTBRACKET) { |
55
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
510 render_dbg++; |
135 | 511 if (render_dbg == 4) { |
55
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
512 render_dbg = 0; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
513 } |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
514 render_context(context); |
135 | 515 } else if(event.key.keysym.sym == SDLK_RIGHTBRACKET) { |
516 debug_pal++; | |
517 if (debug_pal == 4) { | |
518 debug_pal = 0; | |
519 } | |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
520 } |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
521 break; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
522 case SDL_QUIT: |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
523 return; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
524 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
525 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
526 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
527 |
398
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
528 void render_debug_mode(uint8_t mode) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
529 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
530 if (mode < 4) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
531 render_dbg = mode; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
532 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
533 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
534 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
535 void render_debug_pal(uint8_t pal) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
536 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
537 if (pal < 4) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
538 debug_pal = pal; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
539 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
540 } |
66 | 541 |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
542 int find_joystick_index(SDL_JoystickID instanceID) |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
543 { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
544 for (int i = 0; i < MAX_JOYSTICKS; i++) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
545 if (joysticks[i] && SDL_JoystickInstanceID(joysticks[i]) == instanceID) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
546 return i; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
547 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
548 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
549 return -1; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
550 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
551 |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
552 int lowest_unused_joystick_index() |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
553 { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
554 for (int i = 0; i < MAX_JOYSTICKS; i++) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
555 if (!joysticks[i]) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
556 return i; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
557 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
558 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
559 return -1; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
560 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
561 |
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
|
562 uint8_t scancode_map[SDL_NUM_SCANCODES] = { |
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
|
563 [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
|
564 [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
|
565 [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
|
566 [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
|
567 [SDL_SCANCODE_E] = 0x24, |
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
|
568 [SDL_SCANCODE_F] = 0x28, |
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
|
569 [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
|
570 [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
|
571 [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
|
572 [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
|
573 [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
|
574 [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
|
575 [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
|
576 [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
|
577 [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
|
578 [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
|
579 [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
|
580 [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
|
581 [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
|
582 [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
|
583 [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
|
584 [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
|
585 [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
|
586 [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
|
587 [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
|
588 [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
|
589 [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
|
590 [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
|
591 [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
|
592 [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
|
593 [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
|
594 [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
|
595 [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
|
596 [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
|
597 [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
|
598 [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
|
599 [SDL_SCANCODE_RETURN] = 0x5A, |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
600 [SDL_SCANCODE_ESCAPE] = 0x76, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
601 [SDL_SCANCODE_SPACE] = 0x29, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
602 [SDL_SCANCODE_TAB] = 0x0D, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
603 [SDL_SCANCODE_BACKSPACE] = 0x66, |
1033
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
604 [SDL_SCANCODE_MINUS] = 0x4E, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
605 [SDL_SCANCODE_EQUALS] = 0x55, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
606 [SDL_SCANCODE_LEFTBRACKET] = 0x54, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
607 [SDL_SCANCODE_RIGHTBRACKET] = 0x5B, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
608 [SDL_SCANCODE_BACKSLASH] = 0x5D, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
609 [SDL_SCANCODE_SEMICOLON] = 0x4C, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
610 [SDL_SCANCODE_APOSTROPHE] = 0x52, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
611 [SDL_SCANCODE_GRAVE] = 0x0E, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
612 [SDL_SCANCODE_COMMA] = 0x41, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
613 [SDL_SCANCODE_PERIOD] = 0x49, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
614 [SDL_SCANCODE_SLASH] = 0x4A, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
615 [SDL_SCANCODE_CAPSLOCK] = 0x58, |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
616 [SDL_SCANCODE_F1] = 0x05, |
1033
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
617 [SDL_SCANCODE_F2] = 0x06, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
618 [SDL_SCANCODE_F3] = 0x04, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
619 [SDL_SCANCODE_F4] = 0x0C, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
620 [SDL_SCANCODE_F5] = 0x03, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
621 [SDL_SCANCODE_F6] = 0x0B, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
622 [SDL_SCANCODE_F7] = 0x83, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
623 [SDL_SCANCODE_F8] = 0x0A, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
624 [SDL_SCANCODE_F9] = 0x01, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
625 [SDL_SCANCODE_F10] = 0x09, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
626 [SDL_SCANCODE_F11] = 0x78, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
627 [SDL_SCANCODE_F12] = 0x07, |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
628 [SDL_SCANCODE_LCTRL] = 0x14, |
1033
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
629 [SDL_SCANCODE_LSHIFT] = 0x12, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
630 [SDL_SCANCODE_LALT] = 0x11, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
631 [SDL_SCANCODE_RCTRL] = 0x18, |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
632 [SDL_SCANCODE_RSHIFT] = 0x59, |
1033
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
633 [SDL_SCANCODE_RALT] = 0x17, |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
634 [SDL_SCANCODE_INSERT] = 0x81, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
635 [SDL_SCANCODE_PAUSE] = 0x82, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
636 [SDL_SCANCODE_PRINTSCREEN] = 0x84, |
1033
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
637 [SDL_SCANCODE_SCROLLLOCK] = 0x7E, |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
638 [SDL_SCANCODE_DELETE] = 0x85, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
639 [SDL_SCANCODE_LEFT] = 0x86, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
640 [SDL_SCANCODE_HOME] = 0x87, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
641 [SDL_SCANCODE_END] = 0x88, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
642 [SDL_SCANCODE_UP] = 0x89, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
643 [SDL_SCANCODE_DOWN] = 0x8A, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
644 [SDL_SCANCODE_PAGEUP] = 0x8B, |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
645 [SDL_SCANCODE_PAGEDOWN] = 0x8C, |
1033
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
646 [SDL_SCANCODE_RIGHT] = 0x8D, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
647 [SDL_SCANCODE_NUMLOCKCLEAR] = 0x77, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
648 [SDL_SCANCODE_KP_DIVIDE] = 0x80, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
649 [SDL_SCANCODE_KP_MULTIPLY] = 0x7C, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
650 [SDL_SCANCODE_KP_MINUS] = 0x7B, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
651 [SDL_SCANCODE_KP_PLUS] = 0x79, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
652 [SDL_SCANCODE_KP_ENTER] = 0x19, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
653 [SDL_SCANCODE_KP_1] = 0x69, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
654 [SDL_SCANCODE_KP_2] = 0x72, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
655 [SDL_SCANCODE_KP_3] = 0x7A, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
656 [SDL_SCANCODE_KP_4] = 0x6B, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
657 [SDL_SCANCODE_KP_5] = 0x73, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
658 [SDL_SCANCODE_KP_6] = 0x74, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
659 [SDL_SCANCODE_KP_7] = 0x6C, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
660 [SDL_SCANCODE_KP_8] = 0x75, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
661 [SDL_SCANCODE_KP_9] = 0x7D, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
662 [SDL_SCANCODE_KP_0] = 0x70, |
4db1a2e5d8e6
Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
663 [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
|
664 }; |
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
|
665 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
666 int32_t handle_event(SDL_Event *event) |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
667 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
668 switch (event->type) { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
669 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
|
670 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
|
671 break; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
672 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
|
673 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
|
674 break; |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
675 case SDL_JOYBUTTONDOWN: |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
676 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
|
677 break; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
678 case SDL_JOYBUTTONUP: |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
679 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
|
680 break; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
681 case SDL_JOYHATMOTION: |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
682 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
|
683 break; |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
684 case SDL_JOYDEVICEADDED: |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
685 if (event->jdevice.which < MAX_JOYSTICKS) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
686 int index = lowest_unused_joystick_index(); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
687 if (index >= 0) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
688 SDL_Joystick * joy = joysticks[index] = SDL_JoystickOpen(event->jdevice.which); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
689 if (joy) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
690 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
|
691 printf("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
692 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
693 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
694 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
695 break; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
696 case SDL_JOYDEVICEREMOVED: { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
697 int index = find_joystick_index(event->jdevice.which); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
698 if (index >= 0) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
699 SDL_JoystickClose(joysticks[index]); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
700 joysticks[index] = NULL; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
701 printf("Joystick %d removed\n", index); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
702 } else { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
703 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
|
704 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
705 break; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
706 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
707 case SDL_MOUSEMOTION: |
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
|
708 handle_mouse_moved(event->motion.which, event->motion.x, event->motion.y, event->motion.xrel, event->motion.yrel); |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
709 break; |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
906
diff
changeset
|
710 case SDL_MOUSEBUTTONDOWN: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
906
diff
changeset
|
711 handle_mousedown(event->button.which, event->button.button); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
906
diff
changeset
|
712 break; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
906
diff
changeset
|
713 case SDL_MOUSEBUTTONUP: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
906
diff
changeset
|
714 handle_mouseup(event->button.which, event->button.button); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
906
diff
changeset
|
715 break; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
716 case SDL_QUIT: |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
717 puts(""); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
718 exit(0); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
719 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
720 return 0; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
721 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
722 |
63
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
723 uint32_t frame_counter = 0; |
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
724 uint32_t start = 0; |
905
b3b399665356
Don't try setting the window title on Android
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
725 #ifdef __ANDROID__ |
b3b399665356
Don't try setting the window title on Android
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
726 #define FPS_INTERVAL 10000 |
b3b399665356
Don't try setting the window title on Android
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
727 #else |
b3b399665356
Don't try setting the window title on Android
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
728 #define FPS_INTERVAL 1000 |
b3b399665356
Don't try setting the window title on Android
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
729 #endif |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
730 int wait_render_frame(vdp_context * context, int frame_limit) |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
731 { |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
732 SDL_Event event; |
198
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
733 int ret = 0; |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
734 while(SDL_PollEvent(&event)) { |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
735 ret = handle_event(&event); |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
736 } |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
737 if (frame_limit) { |
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
738 //TODO: Adjust frame delay so we actually get 60 FPS rather than 62.5 FPS |
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
739 uint32_t current = SDL_GetTicks(); |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
740 uint32_t desired = last_frame + frame_delay; |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
741 if (current < desired) { |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
742 uint32_t delay = last_frame + frame_delay - current; |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
743 if (delay > min_delay) { |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
744 SDL_Delay((delay/min_delay)*min_delay); |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
745 } |
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
746 while ((desired) >= SDL_GetTicks()) { |
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
747 } |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
748 } |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
749 } |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
750 render_context(context); |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
751 |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
752 frame_counter++; |
905
b3b399665356
Don't try setting the window title on Android
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
753 if ((last_frame - start) > FPS_INTERVAL) { |
272 | 754 if (start && (last_frame-start)) { |
906
8cf57c6558ed
Dividing by FPS_INTERVAL does not make senese as the division was to convert milliseconds to seconds
Michael Pavone <pavone@retrodev.com>
parents:
905
diff
changeset
|
755 #ifdef __ANDROID__ |
8cf57c6558ed
Dividing by FPS_INTERVAL does not make senese as the division was to convert milliseconds to seconds
Michael Pavone <pavone@retrodev.com>
parents:
905
diff
changeset
|
756 info_message("%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); |
8cf57c6558ed
Dividing by FPS_INTERVAL does not make senese as the division was to convert milliseconds to seconds
Michael Pavone <pavone@retrodev.com>
parents:
905
diff
changeset
|
757 #else |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
758 if (!fps_caption) { |
905
b3b399665356
Don't try setting the window title on Android
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
759 fps_caption = malloc(strlen(caption) + strlen(" - 100000000.1 fps") + 1); |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
760 } |
906
8cf57c6558ed
Dividing by FPS_INTERVAL does not make senese as the division was to convert milliseconds to seconds
Michael Pavone <pavone@retrodev.com>
parents:
905
diff
changeset
|
761 sprintf(fps_caption, "%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); |
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
|
762 SDL_SetWindowTitle(main_window, fps_caption); |
905
b3b399665356
Don't try setting the window title on Android
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
763 #endif |
63
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
764 } |
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
765 start = last_frame; |
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
766 frame_counter = 0; |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
767 } |
198
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
768 return ret; |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
769 } |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
770 |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
771 void process_events() |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
772 { |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
773 SDL_Event event; |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
774 while(SDL_PollEvent(&event)) { |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
775 handle_event(&event); |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
776 } |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
777 } |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
778 |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
779 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
|
780 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
781 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
|
782 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
|
783 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
|
784 } |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
785 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
|
786 SDL_CondSignal(audio_ready); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
787 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
788 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
|
789 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
|
790 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
|
791 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
|
792 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
793 |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
794 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
|
795 { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
796 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
|
797 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
|
798 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
|
799 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
800 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
|
801 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
|
802 |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
803 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
|
804 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
|
805 SDL_UnlockMutex(audio_mutex); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
806 context->buffer_pos = 0; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
807 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
808 |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
809 void render_fps(uint32_t fps) |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
810 { |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
811 frame_delay = 1000/fps; |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
812 } |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
813 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
814 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
|
815 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
816 return buffer_samples; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
817 } |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
818 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
819 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
|
820 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
821 return sample_rate; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
822 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
823 |
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
|
824 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
|
825 { |
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
|
826 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
|
827 } |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
828 |
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
|
829 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
|
830 { |
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
|
831 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
|
832 } |
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
|
833 |
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
|
834 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
|
835 { |
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
|
836 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
|
837 } |
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
|
838 |