Mercurial > repos > blastem
annotate render_sdl.c @ 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).
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 25 Jul 2015 18:22:07 -0700 |
parents | 1b2f8280ba81 |
children | 0b692b5d154b |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
2 Copyright 2013 Michael Pavone |
487
c08a4efeee7f
Update opengl branch from default. Fix build breakage unrelated to merge
Mike Pavone <pavone@retrodev.com>
diff
changeset
|
3 This file is part of BlastEm. |
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
5 */ |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include <stdlib.h> |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include <stdio.h> |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
744
diff
changeset
|
8 #include <string.h> |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
9 #include <math.h> |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include "render.h" |
66 | 11 #include "blastem.h" |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
418
diff
changeset
|
12 #include "io.h" |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
13 #include "util.h" |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
15 #include <GL/glew.h> |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
16 |
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
|
17 SDL_Window *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
|
18 SDL_GLContext *main_context; |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
19 uint8_t render_dbg = 0; |
135 | 20 uint8_t debug_pal = 0; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
22 uint32_t last_frame = 0; |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
23 |
229
d60837a7d18a
Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents:
198
diff
changeset
|
24 uint32_t min_delay; |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
25 uint32_t frame_delay = 1000/60; |
229
d60837a7d18a
Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents:
198
diff
changeset
|
26 |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
27 int16_t * current_psg = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
28 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
|
29 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
30 uint32_t buffer_samples, sample_rate; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
31 uint32_t missing_count; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
32 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
33 SDL_mutex * audio_mutex; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
34 SDL_cond * audio_ready; |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
35 SDL_cond * psg_cond; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
36 SDL_cond * ym_cond; |
361 | 37 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
|
38 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
39 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
|
40 { |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
41 //puts("audio_callback"); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
42 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
|
43 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
|
44 int16_t * psg_buf, * ym_buf; |
361 | 45 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
|
46 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
|
47 psg_buf = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
48 ym_buf = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
49 do { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
50 if (!psg_buf) { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
51 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
|
52 current_psg = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
53 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
|
54 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
55 if (!ym_buf) { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
56 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
|
57 current_ym = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
58 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
|
59 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
60 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
|
61 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
|
62 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
63 } 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
|
64 |
361 | 65 local_quit = quitting; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
66 SDL_UnlockMutex(audio_mutex); |
361 | 67 if (!local_quit) { |
68 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
|
69 *(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
|
70 *(stream++) = psg_buf[i] + *(ym_buf++); |
361 | 71 } |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
72 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
73 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
74 |
361 | 75 void render_close_audio() |
76 { | |
77 SDL_LockMutex(audio_mutex); | |
78 quitting = 1; | |
79 SDL_CondSignal(audio_ready); | |
80 SDL_UnlockMutex(audio_mutex); | |
81 SDL_CloseAudio(); | |
82 } | |
83 | |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
84 SDL_Joystick * joysticks[MAX_JOYSTICKS]; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
85 int num_joysticks; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
86 |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
87 int render_num_joysticks() |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
88 { |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
89 return num_joysticks; |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
90 } |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
91 |
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
|
92 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
|
93 { |
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
|
94 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
|
95 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
96 |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
502
diff
changeset
|
97 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
|
98 |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
99 GLfloat vertex_data[] = { |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
100 -1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
101 1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
102 -1.0f, 1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
103 1.0f, 1.0f |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
104 }; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
105 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
106 const GLushort element_data[] = {0, 1, 2, 3}; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
107 |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
108 GLuint load_shader(char * fname, GLenum shader_type) |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
109 { |
746
9d4d40f833d0
Fix crash bug in windows build
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
110 char * 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
|
111 char * shader_path = alloc_concat_m(3, parts); |
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
|
112 FILE * f = fopen(shader_path, "r"); |
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
|
113 free(shader_path); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 shader_path = alloc_concat_m(3, parts); |
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
|
118 f = fopen(shader_path, "r"); |
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
|
119 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
|
120 if (!f) { |
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
|
121 fprintf(stderr, "Failed to open shader file %s for reading\n", fname); |
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
|
122 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
|
123 } |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
124 } |
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
|
125 long fsize = file_size(f); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
126 GLchar * text = malloc(fsize); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
127 if (fread(text, 1, fsize, f) != fsize) { |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
128 fprintf(stderr, "Error reading from shader file %s\n", fname); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
129 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
130 return 0; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
131 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
132 GLuint ret = glCreateShader(shader_type); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
133 glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
134 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
135 glCompileShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
136 GLint compile_status, loglen; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
137 glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
138 if (!compile_status) { |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
139 fprintf(stderr, "Shader %s failed to compile\n", fname); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
140 glGetShaderiv(ret, GL_INFO_LOG_LENGTH, &loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
141 text = malloc(loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
142 glGetShaderInfoLog(ret, loglen, NULL, text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
143 fputs(text, stderr); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
144 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
145 glDeleteShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
146 return 0; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
147 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
148 return ret; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
149 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
150 |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
151 void render_alloc_surfaces(vdp_context * context) |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
152 { |
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
|
153 context->oddbuf = context->framebuf = malloc(512 * 256 * 4 * 2); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
154 memset(context->oddbuf, 0, 512 * 256 * 4 * 2); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
155 context->evenbuf = ((char *)context->oddbuf) + 512 * 256 * 4; |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
156 glGenTextures(3, textures); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
157 for (int i = 0; i < 3; i++) |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
158 { |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
159 glBindTexture(GL_TEXTURE_2D, textures[i]); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
160 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
161 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
162 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
163 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
164 if (i < 2) { |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
165 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, i ? context->evenbuf : context->oddbuf); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
166 } else { |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
167 uint32_t blank = 255 << 24; |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
168 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_BGRA, GL_UNSIGNED_BYTE, &blank); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
169 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
170 } |
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
|
171 glGenBuffers(2, buffers); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
172 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
173 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
174 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
175 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW); |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
746
diff
changeset
|
176 tern_val def = {.ptrval = "default.v.glsl"}; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
746
diff
changeset
|
177 vshader = load_shader(tern_find_path_default(config, "video\0vertex_shader\0", def).ptrval, GL_VERTEX_SHADER); |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
746
diff
changeset
|
178 def.ptrval = "default.f.glsl"; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
746
diff
changeset
|
179 fshader = load_shader(tern_find_path_default(config, "video\0fragment_shader\0", def).ptrval, GL_FRAGMENT_SHADER); |
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
|
180 program = glCreateProgram(); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
181 glAttachShader(program, vshader); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
182 glAttachShader(program, fshader); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
183 glLinkProgram(program); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
184 GLint link_status; |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
185 glGetProgramiv(program, GL_LINK_STATUS, &link_status); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
186 if (!link_status) { |
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
|
187 fatal_error("Failed to link shader program\n"); |
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
|
188 } |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
189 un_textures[0] = glGetUniformLocation(program, "textures[0]"); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
190 un_textures[1] = glGetUniformLocation(program, "textures[1]"); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
191 un_width = glGetUniformLocation(program, "width"); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
192 at_pos = glGetAttribLocation(program, "pos"); |
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
|
193 } |
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
|
194 |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
195 char * caption = NULL; |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
196 |
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
|
197 void render_init(int width, int height, char * title, uint32_t fps, uint8_t fullscreen) |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
198 { |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
199 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
|
200 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
|
201 } |
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
|
202 atexit(SDL_Quit); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
203 printf("width: %d, height: %d\n", width, height); |
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
|
204 uint32_t flags = SDL_WINDOW_OPENGL; |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
205 |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
206 |
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
|
207 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
208 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
209 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
210 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
211 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
212 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
|
213 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
|
214 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
|
215 //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
|
216 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
|
217 //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
|
218 //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
|
219 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
|
220 height = mode.h; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
221 } |
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
|
222 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
|
223 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
|
224 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
|
225 } |
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
|
226 SDL_GetWindowSize(main_window, &width, &height); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
227 printf("Window created with size: %d x %d\n", width, height); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
228 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
|
229 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
|
230 if (res != GLEW_OK) { |
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
|
231 fatal_error("Initialization of GLEW failed with code %d\n", res); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
232 } |
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
|
233 if (!GLEW_VERSION_2_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
|
234 fatal_error("BlastEm requires at least OpenGL 2.0, but it is unavailable\n"); |
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
|
235 } |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
236 float aspect = (float)width / height; |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
746
diff
changeset
|
237 tern_val def = {.ptrval = "normal"}; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
746
diff
changeset
|
238 if (fabs(aspect - 4.0/3.0) > 0.01 && strcmp(tern_find_path_default(config, "video\0aspect\0", def).ptrval, "stretch")) { |
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
|
239 for (int i = 0; i < 4; i++) |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
240 { |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
241 if (aspect > 4.0/3.0) { |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
242 vertex_data[i*2] *= (4.0/3.0)/aspect; |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
243 } else { |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
244 vertex_data[i*2+1] *= aspect/(4.0/3.0); |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
245 } |
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
246 } |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
247 } |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
248 caption = title; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
249 min_delay = 0; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
250 for (int i = 0; i < 100; i++) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
251 uint32_t start = SDL_GetTicks(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
252 SDL_Delay(1); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
253 uint32_t delay = SDL_GetTicks()-start; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
254 if (delay > min_delay) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
255 min_delay = delay; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
256 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
257 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
258 if (!min_delay) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
259 min_delay = 1; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
260 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
261 printf("minimum delay: %d\n", min_delay); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
262 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
263 frame_delay = 1000/fps; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
264 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
265 audio_mutex = SDL_CreateMutex(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
266 psg_cond = SDL_CreateCond(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
267 ym_cond = SDL_CreateCond(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
268 audio_ready = SDL_CreateCond(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
269 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 if (!rate) { |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
274 rate = 48000; |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
275 } |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
276 desired.freq = rate; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
277 desired.format = AUDIO_S16SYS; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
278 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
|
279 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
|
280 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
|
281 if (!samples) { |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
282 samples = 512; |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
283 } |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
284 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
|
285 desired.samples = samples*2; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
286 desired.callback = audio_callback; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
287 desired.userdata = NULL; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
288 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
289 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
|
290 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
|
291 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
292 buffer_samples = actual.samples; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
293 sample_rate = actual.freq; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
294 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
|
295 SDL_PauseAudio(0); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
296 num_joysticks = SDL_NumJoysticks(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
297 if (num_joysticks > MAX_JOYSTICKS) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
298 num_joysticks = MAX_JOYSTICKS; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
299 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
300 for (int i = 0; i < num_joysticks; i++) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
301 SDL_Joystick * joy = joysticks[i] = SDL_JoystickOpen(i); |
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
|
302 printf("Joystick %d: %s\n", i, SDL_JoystickName(joy)); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
303 if (joy) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
304 printf("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
305 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
306 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
307 SDL_JoystickEventState(SDL_ENABLE); |
655
38006d43f5a3
Avoid calling atexit(SDL_Quit) until after OpenGL initialization to avoid a segfault on exit when using fglrx
Michael Pavone <pavone@retrodev.com>
parents:
622
diff
changeset
|
308 |
38006d43f5a3
Avoid calling atexit(SDL_Quit) until after OpenGL initialization to avoid a segfault on exit when using fglrx
Michael Pavone <pavone@retrodev.com>
parents:
622
diff
changeset
|
309 atexit(render_close_audio); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
310 } |
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
|
311 |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
312 void render_context(vdp_context * context) |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
313 { |
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
|
314 last_frame = SDL_GetTicks(); |
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
315 |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
316 glBindTexture(GL_TEXTURE_2D, textures[context->framebuf == context->oddbuf ? 0 : 1]); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
317 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 320, 240, GL_BGRA, GL_UNSIGNED_BYTE, context->framebuf);; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
318 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
319 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
320 glClear(GL_COLOR_BUFFER_BIT); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
321 |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
322 glUseProgram(program); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
323 glActiveTexture(GL_TEXTURE0); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
324 glBindTexture(GL_TEXTURE_2D, textures[0]); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
325 glUniform1i(un_textures[0], 0); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
326 |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
327 glActiveTexture(GL_TEXTURE1); |
489
e97b80e3bd76
Support interlace mode with OpenGL backend
Mike Pavone <pavone@retrodev.com>
parents:
488
diff
changeset
|
328 glBindTexture(GL_TEXTURE_2D, (context->regs[REG_MODE_4] & BIT_INTERLACE) ? textures[1] : textures[2]); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
329 glUniform1i(un_textures[1], 1); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
330 |
622
b76d2a628ab9
Partially working switch to having a vcounter and hslot counter in the context rather than trying to derive them from the cycle count. This should allow for more accurate handling of mid screen mode switches. Interrupt timing is broken currently though
Michael Pavone <pavone@retrodev.com>
parents:
505
diff
changeset
|
331 glUniform1f(un_width, context->regs[REG_MODE_4] & BIT_H40 ? 320.0f : 256.0f); |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
502
diff
changeset
|
332 |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
333 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
334 glVertexAttribPointer(at_pos, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat[2]), (void *)0); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
335 glEnableVertexAttribArray(at_pos); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
336 |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
337 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
338 glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (void *)0); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
339 |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
340 glDisableVertexAttribArray(at_pos); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
341 |
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
|
342 SDL_GL_SwapWindow(main_window); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
343 if (context->regs[REG_MODE_4] & BIT_INTERLACE) |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
344 { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
345 context->framebuf = context->framebuf == context->oddbuf ? context->evenbuf : context->oddbuf; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
346 } |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
347 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
349 int render_joystick_num_buttons(int joystick) |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
350 { |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
351 if (joystick >= num_joysticks) { |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
352 return 0; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
353 } |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
354 return SDL_JoystickNumButtons(joysticks[joystick]); |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
355 } |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
356 |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
357 int render_joystick_num_hats(int joystick) |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
358 { |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
359 if (joystick >= num_joysticks) { |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
360 return 0; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
361 } |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
362 return SDL_JoystickNumHats(joysticks[joystick]); |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
363 } |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
364 |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
365 void render_wait_quit(vdp_context * context) |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
366 { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
367 SDL_Event event; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
368 while(SDL_WaitEvent(&event)) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
369 switch (event.type) { |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
370 case SDL_KEYDOWN: |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
371 if (event.key.keysym.sym == SDLK_LEFTBRACKET) { |
55
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
372 render_dbg++; |
135 | 373 if (render_dbg == 4) { |
55
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
374 render_dbg = 0; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
375 } |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
376 render_context(context); |
135 | 377 } else if(event.key.keysym.sym == SDLK_RIGHTBRACKET) { |
378 debug_pal++; | |
379 if (debug_pal == 4) { | |
380 debug_pal = 0; | |
381 } | |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
382 } |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
383 break; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
384 case SDL_QUIT: |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 return; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
386 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
387 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 |
398
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
390 void render_debug_mode(uint8_t mode) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
391 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
392 if (mode < 4) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
393 render_dbg = mode; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
394 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
395 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
396 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
397 void render_debug_pal(uint8_t pal) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
398 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
399 if (pal < 4) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
400 debug_pal = pal; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
401 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
402 } |
66 | 403 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
404 int32_t handle_event(SDL_Event *event) |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
405 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
406 switch (event->type) { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
407 case SDL_KEYDOWN: |
398
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
408 handle_keydown(event->key.keysym.sym); |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
409 break; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
410 case SDL_KEYUP: |
398
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
411 handle_keyup(event->key.keysym.sym); |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
412 break; |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
413 case SDL_JOYBUTTONDOWN: |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
414 handle_joydown(event->jbutton.which, event->jbutton.button); |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
415 break; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
416 case SDL_JOYBUTTONUP: |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
417 handle_joyup(event->jbutton.which, event->jbutton.button); |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
418 break; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
419 case SDL_JOYHATMOTION: |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
420 handle_joy_dpad(event->jbutton.which, event->jhat.hat, event->jhat.value); |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
421 break; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
422 case SDL_QUIT: |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
423 puts(""); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
424 exit(0); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
425 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
426 return 0; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
427 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
428 |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
429 char * fps_caption = NULL; |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
430 |
63
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
431 uint32_t frame_counter = 0; |
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
432 uint32_t start = 0; |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
433 int wait_render_frame(vdp_context * context, int frame_limit) |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
434 { |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
435 SDL_Event event; |
198
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
436 int ret = 0; |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
437 while(SDL_PollEvent(&event)) { |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
438 ret = handle_event(&event); |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
439 } |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
440 if (frame_limit) { |
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
441 //TODO: Adjust frame delay so we actually get 60 FPS rather than 62.5 FPS |
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
442 uint32_t current = SDL_GetTicks(); |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
443 uint32_t desired = last_frame + frame_delay; |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
444 if (current < desired) { |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
445 uint32_t delay = last_frame + frame_delay - current; |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
446 if (delay > min_delay) { |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
447 SDL_Delay((delay/min_delay)*min_delay); |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
448 } |
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
449 while ((desired) >= SDL_GetTicks()) { |
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
450 } |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
451 } |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
452 } |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
453 render_context(context); |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
454 |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
455 frame_counter++; |
63
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
456 if ((last_frame - start) > 1000) { |
272 | 457 if (start && (last_frame-start)) { |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
458 if (!fps_caption) { |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
459 fps_caption = malloc(strlen(caption) + strlen(" - 1000.1 fps") + 1); |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
460 } |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
461 sprintf(fps_caption, "%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
462 SDL_SetWindowTitle(main_window, fps_caption); |
63
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
463 } |
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
464 start = last_frame; |
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
465 frame_counter = 0; |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
466 } |
198
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
467 return ret; |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
468 } |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
469 |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
470 void process_events() |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
471 { |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
472 SDL_Event event; |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
473 while(SDL_PollEvent(&event)) { |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
474 handle_event(&event); |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
475 } |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
476 } |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
477 |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
478 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
|
479 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
480 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
|
481 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
|
482 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
|
483 } |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
484 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
|
485 SDL_CondSignal(audio_ready); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
486 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
487 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
|
488 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
|
489 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
|
490 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
|
491 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
492 |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
493 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
|
494 { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
495 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
|
496 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
|
497 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
|
498 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
499 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
|
500 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
|
501 |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
502 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
|
503 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
|
504 SDL_UnlockMutex(audio_mutex); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
505 context->buffer_pos = 0; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
506 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
507 |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
508 void render_fps(uint32_t fps) |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
509 { |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
510 frame_delay = 1000/fps; |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
511 } |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
512 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
513 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
|
514 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
515 return buffer_samples; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
516 } |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
517 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
518 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
|
519 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
520 return sample_rate; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
521 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
522 |
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
|
523 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
|
524 { |
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
|
525 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
|
526 } |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
527 |
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
|
528 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
|
529 { |
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
|
530 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
|
531 } |
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
|
532 |
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
|
533 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
|
534 { |
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
|
535 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
|
536 } |
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
|
537 |