annotate render_sdl.c @ 1116:fe8c79f82c22

More cleanup in preparation for SMS/Mark III support
author Michael Pavone <pavone@retrodev.com>
date Thu, 22 Dec 2016 10:51:33 -0800
parents 22e87b739ad6
children 928a65750345
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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>
parents: 449 486
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
7a22a0e6c004 Gamepad support
Mike Pavone <pavone@retrodev.com>
parents: 64
diff changeset
11 #include "blastem.h"
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1102
diff changeset
12 #include "genesis.h"
421
d0cacb4ade0b Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents: 418
diff changeset
13 #include "io.h"
497
0820a71b80f3 Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents: 495
diff changeset
14 #include "util.h"
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
15
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
16 #ifndef DISABLE_OPENGL
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
17 #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
18 #endif
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
19
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
20 #define MAX_EVENT_POLL_PER_FRAME 2
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
21
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
22 static SDL_Window *main_window;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
23 static SDL_Renderer *main_renderer;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
24 static SDL_Texture **sdl_textures;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
25 static uint8_t num_textures;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
26 static SDL_Rect main_clip;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
27 static SDL_GLContext *main_context;
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
28
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
29 static 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
30
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
31 static uint8_t render_gl = 1;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
32 static uint8_t scanlines = 0;
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
33
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
34 static uint32_t last_frame = 0;
54
3b79cbcf6846 Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents: 43
diff changeset
35
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
36 static int16_t * current_psg = NULL;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
37 static int16_t * current_ym = NULL;
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
38
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
39 static uint32_t buffer_samples, sample_rate;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
40 static uint32_t missing_count;
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
41
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
42 static SDL_mutex * audio_mutex;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
43 static SDL_cond * audio_ready;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
44 static SDL_cond * psg_cond;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
45 static SDL_cond * ym_cond;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
46 static 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
47
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
48 static void audio_callback(void * userdata, uint8_t *byte_stream, int len)
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
49 {
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
50 //puts("audio_callback");
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
51 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
52 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
53 int16_t * psg_buf, * ym_buf;
361
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
54 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
55 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
56 psg_buf = NULL;
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
57 ym_buf = NULL;
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
58 do {
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
59 if (!psg_buf) {
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
60 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
61 current_psg = NULL;
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
62 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
63 }
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
64 if (!ym_buf) {
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
65 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
66 current_ym = NULL;
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
67 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
68 }
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
69 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
70 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
71 }
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
72 } 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
73
361
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
74 local_quit = quitting;
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
75 SDL_UnlockMutex(audio_mutex);
361
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
76 if (!local_quit) {
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
77 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
78 *(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
79 *(stream++) = psg_buf[i] + *(ym_buf++);
361
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
80 }
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
81 }
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
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
84 static void render_close_audio()
361
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
85 {
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
86 SDL_LockMutex(audio_mutex);
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
87 quitting = 1;
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
88 SDL_CondSignal(audio_ready);
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
89 SDL_UnlockMutex(audio_mutex);
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
90 SDL_CloseAudio();
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
91 }
946ae3749260 Fix deadlock on quit
Mike Pavone <pavone@retrodev.com>
parents: 356
diff changeset
92
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
93 static SDL_Joystick * joysticks[MAX_JOYSTICKS];
432
18cde14e8c10 Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
94
914
28ec32e720b2 Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
95 int render_width()
28ec32e720b2 Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
96 {
28ec32e720b2 Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
97 return main_width;
28ec32e720b2 Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
98 }
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 int render_height()
28ec32e720b2 Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
101 {
28ec32e720b2 Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
102 return main_height;
28ec32e720b2 Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
103 }
28ec32e720b2 Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
104
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
105 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
106 {
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 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
108 }
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
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
110 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
111 {
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
112 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
113 }
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
114
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
115 #ifndef DISABLE_OPENGL
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
116 static 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
117
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
118 static GLfloat vertex_data[] = {
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
119 -1.0f, -1.0f,
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 };
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
124
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
125 static const GLushort element_data[] = {0, 1, 2, 3};
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
126
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
127 static GLuint load_shader(char * fname, GLenum shader_type)
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
128 {
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
129 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
130 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
131 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
132 free(shader_path);
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
133 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
134 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
135 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
136 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
137 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
138 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
139 if (!f) {
800
ec23202df6a6 Minor cleanup
Michael Pavone <pavone@retrodev.com>
parents: 799
diff changeset
140 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
141 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
142 }
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
143 }
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
144 long fsize = file_size(f);
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
145 GLchar * text = malloc(fsize);
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
146 if (fread(text, 1, fsize, f) != fsize) {
800
ec23202df6a6 Minor cleanup
Michael Pavone <pavone@retrodev.com>
parents: 799
diff changeset
147 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
148 free(text);
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
149 return 0;
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
150 }
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
151 GLuint ret = glCreateShader(shader_type);
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
152 glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize);
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
153 free(text);
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
154 glCompileShader(ret);
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
155 GLint compile_status, loglen;
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
156 glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status);
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
157 if (!compile_status) {
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
158 glGetShaderiv(ret, GL_INFO_LOG_LENGTH, &loglen);
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
159 text = malloc(loglen);
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
160 glGetShaderInfoLog(ret, loglen, NULL, text);
800
ec23202df6a6 Minor cleanup
Michael Pavone <pavone@retrodev.com>
parents: 799
diff changeset
161 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
162 free(text);
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
163 glDeleteShader(ret);
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
164 return 0;
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
165 }
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
166 return ret;
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
167 }
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
168 #endif
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
169
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
170 static uint32_t texture_buf[512 * 256];
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
171 static void render_alloc_surfaces()
449
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;
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
174
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
175 if (texture_init) {
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
176 return;
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
177 }
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
178 sdl_textures= malloc(sizeof(SDL_Texture *) * 2);
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
179 num_textures = 2;
884
252dfd29831d Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents: 874
diff changeset
180 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
181 #ifndef DISABLE_OPENGL
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
182 if (render_gl) {
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
183 sdl_textures[0] = sdl_textures[1] = NULL;
798
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) {
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
193 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, texture_buf);
798
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
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
224
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
225 //height=480 to fit interlaced output
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
226 sdl_textures[0] = sdl_textures[1] = SDL_CreateTexture(main_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 480);
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
227 #ifndef DISABLE_OPENGL
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
228 }
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
229 #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
230 }
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
231
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
232 static char * caption = NULL;
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
233 static char * fps_caption = NULL;
486
db5880d8ea03 Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents: 467
diff changeset
234
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
235 static void render_quit()
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
236 {
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
237 render_close_audio();
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
238 for (int i = 0; i < num_textures; i++)
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
239 {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
240 if (sdl_textures[i]) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
241 SDL_DestroyTexture(sdl_textures[i]);
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
242 }
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
243 }
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
244 }
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
245
1103
22e87b739ad6 WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents: 1102
diff changeset
246 void render_init(int width, int height, char * title, uint8_t fullscreen)
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
247 {
418
dbf4e1c86f3c Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents: 416
diff changeset
248 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
249 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
250 }
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
251 atexit(SDL_Quit);
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
252 printf("width: %d, height: %d\n", width, height);
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
253
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
254 uint32_t flags = 0;
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
255
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
256 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
257 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
258 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
259 //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
260 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
261 //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
262 //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
263 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
264 height = mode.h;
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
265 }
914
28ec32e720b2 Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
266 main_width = width;
28ec32e720b2 Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents: 907
diff changeset
267 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
268 is_fullscreen = fullscreen;
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
269
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
270 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
271 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
272 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
273
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
274 #ifndef DISABLE_OPENGL
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
275 flags |= SDL_WINDOW_OPENGL;
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
276 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
277 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
278 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
279 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
280 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
1074
3a0f684891ae Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents: 1068
diff changeset
281 #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
282 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
283 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
284 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
285 }
1074
3a0f684891ae Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents: 1068
diff changeset
286 #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
287 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
288 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
289 if (res != GLEW_OK) {
800
ec23202df6a6 Minor cleanup
Michael Pavone <pavone@retrodev.com>
parents: 799
diff changeset
290 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
291 }
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
292
800
ec23202df6a6 Minor cleanup
Michael Pavone <pavone@retrodev.com>
parents: 799
diff changeset
293 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
294 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
295 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
296 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
297 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
298 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
299 } 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
300 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
301 }
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 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
304 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
305 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
306 }
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 }
800
ec23202df6a6 Minor cleanup
Michael Pavone <pavone@retrodev.com>
parents: 799
diff changeset
308 } 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
309 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
310 #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
311 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
312 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
313 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
314 }
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 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
316
1074
3a0f684891ae Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents: 1068
diff changeset
317 if (!main_renderer) {
3a0f684891ae Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents: 1068
diff changeset
318 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
319 }
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
320 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
321 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
322 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
323 #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
324 }
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
325 #endif
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
326
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
327 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
328 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
329 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
330 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
331 def.ptrval = "normal";
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
332 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
333
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
334 if (!stretch) {
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
335 #ifndef DISABLE_OPENGL
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
336 if (render_gl) {
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
337 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
338 {
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
339 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
340 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
341 } else {
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
342 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
343 }
500
251fe7a75a14 Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents: 498
diff changeset
344 }
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
345 } else {
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
346 #endif
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
347 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
348 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
349 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
350 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
351 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
352 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
353 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
354 #ifndef DISABLE_OPENGL
500
251fe7a75a14 Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents: 498
diff changeset
355 }
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
356 #endif
488
32f053ad9b02 Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents: 487
diff changeset
357 }
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
358 render_alloc_surfaces();
1004
fc000f245cc8 Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents: 1003
diff changeset
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
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
364 audio_mutex = SDL_CreateMutex();
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
365 psg_cond = SDL_CreateCond();
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
366 ym_cond = SDL_CreateCond();
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
367 audio_ready = SDL_CreateCond();
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
368
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
369 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
370 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
371 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
372 if (!rate) {
80a9527c812c Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
373 rate = 48000;
80a9527c812c Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
374 }
80a9527c812c Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
375 desired.freq = rate;
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
376 desired.format = AUDIO_S16SYS;
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
377 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
378 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
379 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
380 if (!samples) {
80a9527c812c Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
381 samples = 512;
80a9527c812c Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
382 }
80a9527c812c Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents: 444
diff changeset
383 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
384 desired.samples = samples*2;
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
385 desired.callback = audio_callback;
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
386 desired.userdata = NULL;
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
387
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
388 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
389 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
390 }
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
391 buffer_samples = actual.samples;
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
392 sample_rate = actual.freq;
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
393 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
394 SDL_PauseAudio(0);
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
395 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
396
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
397 atexit(render_quit);
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
398 }
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
399
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
400 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
401 {
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
402 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
403 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
404 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
405 }
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
406
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
407 uint32_t *locked_pixels;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
408 uint32_t locked_pitch;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
409 uint32_t *render_get_framebuffer(uint8_t which, int *pitch)
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
410 {
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
411 #ifndef DISABLE_OPENGL
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
412 if (render_gl && which <= FRAMEBUFFER_EVEN) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
413 *pitch = 320 * sizeof(uint32_t); //TODO: change this to LINEBUF_SIZE once border rendering is added
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
414 return texture_buf;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
415 } else {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
416 #endif
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
417 if (which >= num_textures) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
418 warning("Request for invalid framebuffer number %d\n", which);
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
419 return NULL;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
420 }
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
421 void *pixels;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
422 if (SDL_LockTexture(sdl_textures[which], NULL, &pixels, pitch) < 0) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
423 warning("Failed to lock texture: %s\n", SDL_GetError());
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
424 return NULL;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
425 }
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
426 static uint8_t last;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
427 if (which <= FRAMEBUFFER_EVEN) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
428 locked_pixels = pixels;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
429 if (which == FRAMEBUFFER_EVEN) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
430 pixels += *pitch;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
431 }
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
432 locked_pitch = *pitch;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
433 if (which != last) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
434 *pitch *= 2;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
435 }
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
436 last = which;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
437 }
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
438 return pixels;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
439 #ifndef DISABLE_OPENGL
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
440 }
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
441 #endif
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
442 }
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
443
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
444 uint8_t events_processed;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
445 #ifdef __ANDROID__
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
446 #define FPS_INTERVAL 10000
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
447 #else
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
448 #define FPS_INTERVAL 1000
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
449 #endif
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
450
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
451 void render_framebuffer_updated(uint8_t which, int width)
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
452 {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
453 static uint8_t last;
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
454 #ifndef DISABLE_OPENGL
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
455 if (render_gl && which <= FRAMEBUFFER_EVEN) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
456 glBindTexture(GL_TEXTURE_2D, textures[which]);
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
457 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 320, 240, GL_BGRA, GL_UNSIGNED_BYTE, texture_buf);
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
458
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
459 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
460 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
461
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
462 glUseProgram(program);
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
463 glActiveTexture(GL_TEXTURE0);
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
464 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
465 glUniform1i(un_textures[0], 0);
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
466
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
467 glActiveTexture(GL_TEXTURE1);
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
468 glBindTexture(GL_TEXTURE_2D, textures[last != which ? 1 : scanlines ? 2 : 0]);
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
469 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
470
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
471 glUniform1f(un_width, width);
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
472
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
473 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
474 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
475 glEnableVertexAttribArray(at_pos);
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
476
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
477 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
478 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
479
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
480 glDisableVertexAttribArray(at_pos);
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
481
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
482 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
483 } else {
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
484 #endif
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
485 uint32_t height = 240;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
486 if (which <= FRAMEBUFFER_EVEN && last != which) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
487 uint8_t *cur_dst = (uint8_t *)locked_pixels;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
488 uint8_t *cur_saved = (uint8_t *)texture_buf;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
489 uint32_t dst_off = which == FRAMEBUFFER_EVEN ? 0 : locked_pitch;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
490 uint32_t src_off = which == FRAMEBUFFER_EVEN ? locked_pitch : 0;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
491 for (int i = 0; i < 240; ++i)
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
492 {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
493 //copy saved line from other field
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
494 memcpy(cur_dst + dst_off, cur_saved, locked_pitch);
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
495 //save line from this field to buffer for next frame
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
496 memcpy(cur_saved, cur_dst + src_off, locked_pitch);
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
497 cur_dst += locked_pitch * 2;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
498 cur_saved += locked_pitch;
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
499 }
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
500 height = 480;
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
501 }
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
502 SDL_UnlockTexture(sdl_textures[which]);
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
503 SDL_Rect src_clip = {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
504 .x = 0,
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
505 .y = 0,
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
506 .w = width,
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
507 .h = height
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
508 };
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
509 SDL_RenderCopy(main_renderer, sdl_textures[which], &src_clip, &main_clip);
798
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
510 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
511 #ifndef DISABLE_OPENGL
062a2199daf6 Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 797
diff changeset
512 }
797
65181c3ee560 Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents: 766
diff changeset
513 #endif
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
514 if (which <= FRAMEBUFFER_EVEN) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
515 last = which;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
516 static uint32_t frame_counter, start;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
517 frame_counter++;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
518 last_frame= SDL_GetTicks();
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
519 if ((last_frame - start) > FPS_INTERVAL) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
520 if (start && (last_frame-start)) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
521 #ifdef __ANDROID__
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
522 info_message("%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0));
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
523 #else
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
524 if (!fps_caption) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
525 fps_caption = malloc(strlen(caption) + strlen(" - 100000000.1 fps") + 1);
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
526 }
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
527 sprintf(fps_caption, "%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0));
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
528 SDL_SetWindowTitle(main_window, fps_caption);
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
529 #endif
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
530 }
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
531 start = last_frame;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
532 frame_counter = 0;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
533 }
449
7696d824489d Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents: 426
diff changeset
534 }
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
535 if (!events_processed) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
536 process_events();
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
537 }
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
538 events_processed = 0;
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
539 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
540
43
3fc57e1a2c56 Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents: 33
diff changeset
541 void render_wait_quit(vdp_context * context)
20
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
542 {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
543 SDL_Event event;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
544 while(SDL_WaitEvent(&event)) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
545 switch (event.type) {
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
546 case SDL_QUIT:
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
547 return;
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
548 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
549 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
550 }
f664eeb55cb4 Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff changeset
551
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
552 static int find_joystick_index(SDL_JoystickID instanceID)
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
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] && SDL_JoystickInstanceID(joysticks[i]) == instanceID) {
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
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
562 static int lowest_unused_joystick_index()
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
563 {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
564 for (int i = 0; i < MAX_JOYSTICKS; i++) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
565 if (!joysticks[i]) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
566 return i;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
567 }
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
568 }
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
569 return -1;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
570 }
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
571
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
572 static uint8_t scancode_map[SDL_NUM_SCANCODES] = {
1026
7267bc1ab547 Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents: 1004
diff changeset
573 [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
574 [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
575 [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
576 [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
577 [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
578 [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
579 [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
580 [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
581 [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
582 [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
583 [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
584 [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
585 [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
586 [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
587 [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
588 [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
589 [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
590 [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
591 [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
592 [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
593 [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
594 [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
595 [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
596 [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
597 [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
598 [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
599 [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
600 [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
601 [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
602 [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
603 [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
604 [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
605 [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
606 [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
607 [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
608 [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
609 [SDL_SCANCODE_RETURN] = 0x5A,
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
610 [SDL_SCANCODE_ESCAPE] = 0x76,
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
611 [SDL_SCANCODE_SPACE] = 0x29,
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
612 [SDL_SCANCODE_TAB] = 0x0D,
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
613 [SDL_SCANCODE_BACKSPACE] = 0x66,
1033
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
614 [SDL_SCANCODE_MINUS] = 0x4E,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
615 [SDL_SCANCODE_EQUALS] = 0x55,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
616 [SDL_SCANCODE_LEFTBRACKET] = 0x54,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
617 [SDL_SCANCODE_RIGHTBRACKET] = 0x5B,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
618 [SDL_SCANCODE_BACKSLASH] = 0x5D,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
619 [SDL_SCANCODE_SEMICOLON] = 0x4C,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
620 [SDL_SCANCODE_APOSTROPHE] = 0x52,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
621 [SDL_SCANCODE_GRAVE] = 0x0E,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
622 [SDL_SCANCODE_COMMA] = 0x41,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
623 [SDL_SCANCODE_PERIOD] = 0x49,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
624 [SDL_SCANCODE_SLASH] = 0x4A,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
625 [SDL_SCANCODE_CAPSLOCK] = 0x58,
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
626 [SDL_SCANCODE_F1] = 0x05,
1033
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
627 [SDL_SCANCODE_F2] = 0x06,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
628 [SDL_SCANCODE_F3] = 0x04,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
629 [SDL_SCANCODE_F4] = 0x0C,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
630 [SDL_SCANCODE_F5] = 0x03,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
631 [SDL_SCANCODE_F6] = 0x0B,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
632 [SDL_SCANCODE_F7] = 0x83,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
633 [SDL_SCANCODE_F8] = 0x0A,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
634 [SDL_SCANCODE_F9] = 0x01,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
635 [SDL_SCANCODE_F10] = 0x09,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
636 [SDL_SCANCODE_F11] = 0x78,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
637 [SDL_SCANCODE_F12] = 0x07,
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
638 [SDL_SCANCODE_LCTRL] = 0x14,
1033
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
639 [SDL_SCANCODE_LSHIFT] = 0x12,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
640 [SDL_SCANCODE_LALT] = 0x11,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
641 [SDL_SCANCODE_RCTRL] = 0x18,
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
642 [SDL_SCANCODE_RSHIFT] = 0x59,
1033
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
643 [SDL_SCANCODE_RALT] = 0x17,
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
644 [SDL_SCANCODE_INSERT] = 0x81,
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
645 [SDL_SCANCODE_PAUSE] = 0x82,
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
646 [SDL_SCANCODE_PRINTSCREEN] = 0x84,
1033
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
647 [SDL_SCANCODE_SCROLLLOCK] = 0x7E,
1028
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
648 [SDL_SCANCODE_DELETE] = 0x85,
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
649 [SDL_SCANCODE_LEFT] = 0x86,
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
650 [SDL_SCANCODE_HOME] = 0x87,
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
651 [SDL_SCANCODE_END] = 0x88,
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
652 [SDL_SCANCODE_UP] = 0x89,
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
653 [SDL_SCANCODE_DOWN] = 0x8A,
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
654 [SDL_SCANCODE_PAGEUP] = 0x8B,
56b1748a8473 Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents: 1026
diff changeset
655 [SDL_SCANCODE_PAGEDOWN] = 0x8C,
1033
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
656 [SDL_SCANCODE_RIGHT] = 0x8D,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
657 [SDL_SCANCODE_NUMLOCKCLEAR] = 0x77,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
658 [SDL_SCANCODE_KP_DIVIDE] = 0x80,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
659 [SDL_SCANCODE_KP_MULTIPLY] = 0x7C,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
660 [SDL_SCANCODE_KP_MINUS] = 0x7B,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
661 [SDL_SCANCODE_KP_PLUS] = 0x79,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
662 [SDL_SCANCODE_KP_ENTER] = 0x19,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
663 [SDL_SCANCODE_KP_1] = 0x69,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
664 [SDL_SCANCODE_KP_2] = 0x72,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
665 [SDL_SCANCODE_KP_3] = 0x7A,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
666 [SDL_SCANCODE_KP_4] = 0x6B,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
667 [SDL_SCANCODE_KP_5] = 0x73,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
668 [SDL_SCANCODE_KP_6] = 0x74,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
669 [SDL_SCANCODE_KP_7] = 0x6C,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
670 [SDL_SCANCODE_KP_8] = 0x75,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
671 [SDL_SCANCODE_KP_9] = 0x7D,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
672 [SDL_SCANCODE_KP_0] = 0x70,
4db1a2e5d8e6 Complete SDL to Saturn scan code mapping
Michael Pavone <pavone@retrodev.com>
parents: 1028
diff changeset
673 [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
674 };
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
675
1102
c15896605bf2 Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents: 1077
diff changeset
676 static int32_t handle_event(SDL_Event *event)
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
677 {
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
678 switch (event->type) {
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
679 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
680 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
681 break;
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
682 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
683 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
684 break;
418
dbf4e1c86f3c Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents: 416
diff changeset
685 case SDL_JOYBUTTONDOWN:
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
686 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
687 break;
dbf4e1c86f3c Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents: 416
diff changeset
688 case SDL_JOYBUTTONUP:
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
689 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
690 break;
dbf4e1c86f3c Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents: 416
diff changeset
691 case SDL_JOYHATMOTION:
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
692 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
693 break;
937
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
694 case SDL_JOYDEVICEADDED:
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
695 if (event->jdevice.which < MAX_JOYSTICKS) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
696 int index = lowest_unused_joystick_index();
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
697 if (index >= 0) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
698 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
699 if (joy) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
700 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
701 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
702 }
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
703 }
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 case SDL_JOYDEVICEREMOVED: {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
707 int index = find_joystick_index(event->jdevice.which);
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
708 if (index >= 0) {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
709 SDL_JoystickClose(joysticks[index]);
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
710 joysticks[index] = NULL;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
711 printf("Joystick %d removed\n", index);
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
712 } else {
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
713 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
714 }
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
715 break;
9364dad5561a Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents: 915
diff changeset
716 }
897
b9564fb88a5a WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents: 884
diff changeset
717 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
718 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
719 break;
907
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 906
diff changeset
720 case SDL_MOUSEBUTTONDOWN:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 906
diff changeset
721 handle_mousedown(event->button.which, event->button.button);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 906
diff changeset
722 break;
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 906
diff changeset
723 case SDL_MOUSEBUTTONUP:
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 906
diff changeset
724 handle_mouseup(event->button.which, event->button.button);
b5d35222047e Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents: 906
diff changeset
725 break;
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
726 case SDL_QUIT:
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
727 puts("");
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
728 exit(0);
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
729 }
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
730 return 0;
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
731 }
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
732
409
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 398
diff changeset
733 void process_events()
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 398
diff changeset
734 {
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
735 if (events_processed > MAX_EVENT_POLL_PER_FRAME) {
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
736 return;
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
737 }
409
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 398
diff changeset
738 SDL_Event event;
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 398
diff changeset
739 while(SDL_PollEvent(&event)) {
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 398
diff changeset
740 handle_event(&event);
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 398
diff changeset
741 }
1077
1a66d5165ea7 Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents: 1074
diff changeset
742 events_processed++;
409
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 398
diff changeset
743 }
c1bddeadc566 Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents: 398
diff changeset
744
364
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
745 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
746 {
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
747 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
748 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
749 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
750 }
364
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
751 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
752 SDL_CondSignal(audio_ready);
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
753
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
754 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
755 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
756 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
757 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
758 }
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
759
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
760 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
761 {
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
762 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
763 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
764 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
765 }
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
766 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
767 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
768
62177cc39049 Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents: 361
diff changeset
769 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
770 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
771 SDL_UnlockMutex(audio_mutex);
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
772 context->buffer_pos = 0;
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
773 }
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
774
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
775 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
776 {
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
777 return buffer_samples;
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
778 }
342
13f994c88c34 Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents: 340
diff changeset
779
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
780 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
781 {
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
782 return sample_rate;
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
783 }
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
784
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
785 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
786 {
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
787 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
788 }
354
15dd6418fe67 Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents: 342
diff changeset
789
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
790 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
791 {
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
792 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
793 }
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
794
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
795 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
796 {
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
797 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
798 }
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
799