Mercurial > repos > blastem
annotate render_sdl.c @ 566:624dd5106060
Add backtrace (bt) command to 68K debugger
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 02 Mar 2014 14:41:43 -0800 |
parents | b7b7a1cab44a |
children | b76d2a628ab9 2e1b3b258523 |
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> |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
8 #include <math.h> |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include "render.h" |
66 | 10 #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
|
11 #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
|
12 #include "util.h" |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
14 #ifndef DISABLE_OPENGL |
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 #endif |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
17 |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 SDL_Surface *screen; |
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; |
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
|
21 uint8_t render_gl = 1; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
23 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
|
24 |
229
d60837a7d18a
Improve color rendering accuracy and optimize SDL renderer a bit
Mike Pavone <pavone@retrodev.com>
parents:
198
diff
changeset
|
25 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
|
26 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
|
27 |
364
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_psg = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
29 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
|
30 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
31 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
|
32 uint32_t missing_count; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
33 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
34 SDL_mutex * audio_mutex; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
35 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
|
36 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
|
37 SDL_cond * ym_cond; |
361 | 38 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
|
39 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
40 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
|
41 { |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
42 //puts("audio_callback"); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
43 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
|
44 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
|
45 int16_t * psg_buf, * ym_buf; |
361 | 46 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
|
47 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
|
48 psg_buf = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
49 ym_buf = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
50 do { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
51 if (!psg_buf) { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
52 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
|
53 current_psg = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
54 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
|
55 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
56 if (!ym_buf) { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
57 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
|
58 current_ym = NULL; |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
59 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
|
60 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
61 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
|
62 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
|
63 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
64 } 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
|
65 |
361 | 66 local_quit = quitting; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
67 SDL_UnlockMutex(audio_mutex); |
361 | 68 if (!local_quit) { |
69 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
|
70 *(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
|
71 *(stream++) = psg_buf[i] + *(ym_buf++); |
361 | 72 } |
354
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 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
75 |
361 | 76 void render_close_audio() |
77 { | |
78 SDL_LockMutex(audio_mutex); | |
79 quitting = 1; | |
80 SDL_CondSignal(audio_ready); | |
81 SDL_UnlockMutex(audio_mutex); | |
82 SDL_CloseAudio(); | |
83 } | |
84 | |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
85 SDL_Joystick * joysticks[MAX_JOYSTICKS]; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
86 int num_joysticks; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
87 |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
88 int render_num_joysticks() |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
89 { |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
90 return num_joysticks; |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
91 } |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
92 |
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
|
93 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
|
94 { |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
95 if (render_gl) { |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
96 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
|
97 } else { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
98 return SDL_MapRGB(screen->format, r, g, b); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
99 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
100 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
101 |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
490
diff
changeset
|
102 #ifndef DISABLE_OPENGL |
505
b7b7a1cab44a
The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
Michael Pavone <pavone@retrodev.com>
parents:
502
diff
changeset
|
103 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
|
104 |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
105 GLfloat vertex_data[] = { |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
106 -1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
107 1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
108 -1.0f, 1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
109 1.0f, 1.0f |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
110 }; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
111 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
112 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
|
113 |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
114 GLuint load_shader(char * fname, GLenum shader_type) |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
115 { |
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
|
116 char * parts[] = {getenv("HOME"), "/.config/blastem/shaders/", 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
|
117 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
|
118 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
|
119 free(shader_path); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 } |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
130 } |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
131 long fsize = file_size(f); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
132 GLchar * text = malloc(fsize); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
133 if (fread(text, 1, fsize, f) != fsize) { |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
134 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
|
135 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
136 return 0; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
137 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
138 GLuint ret = glCreateShader(shader_type); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
139 glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
140 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
141 glCompileShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
142 GLint compile_status, loglen; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
143 glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
144 if (!compile_status) { |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
145 fprintf(stderr, "Shader %s failed to compile\n", fname); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
146 glGetShaderiv(ret, GL_INFO_LOG_LENGTH, &loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
147 text = malloc(loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
148 glGetShaderInfoLog(ret, loglen, NULL, text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
149 fputs(text, stderr); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
150 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
151 glDeleteShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
152 return 0; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
153 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
154 return ret; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
155 } |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
490
diff
changeset
|
156 #endif |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
157 |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
158 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
|
159 { |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
490
diff
changeset
|
160 #ifndef DISABLE_OPENGL |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
161 if (render_gl) { |
502
7fdfcced65b6
Fix allocation and memset size for field buffers when using OpenGL
Mike Pavone <pavone@retrodev.com>
parents:
500
diff
changeset
|
162 context->oddbuf = context->framebuf = malloc(512 * 256 * 4 * 2); |
7fdfcced65b6
Fix allocation and memset size for field buffers when using OpenGL
Mike Pavone <pavone@retrodev.com>
parents:
500
diff
changeset
|
163 memset(context->oddbuf, 0, 512 * 256 * 4 * 2); |
7fdfcced65b6
Fix allocation and memset size for field buffers when using OpenGL
Mike Pavone <pavone@retrodev.com>
parents:
500
diff
changeset
|
164 context->evenbuf = ((char *)context->oddbuf) + 512 * 256 * 4; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
165 glGenTextures(3, textures); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
166 for (int i = 0; i < 3; i++) |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
167 { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
168 glBindTexture(GL_TEXTURE_2D, textures[i]); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
169 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
170 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
171 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
172 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
173 if (i < 2) { |
487
c08a4efeee7f
Update opengl branch from default. Fix build breakage unrelated to merge
Mike Pavone <pavone@retrodev.com>
diff
changeset
|
174 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, i ? context->evenbuf : context->oddbuf); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
175 } else { |
489
e97b80e3bd76
Support interlace mode with OpenGL backend
Mike Pavone <pavone@retrodev.com>
parents:
488
diff
changeset
|
176 uint32_t blank = 255 << 24; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
177 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_BGRA, GL_UNSIGNED_BYTE, &blank); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
178 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
179 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
180 glGenBuffers(2, buffers); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
181 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
182 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
183 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
184 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW); |
498
51bf87f76d15
Pull shader file names from config file.
Mike Pavone <pavone@retrodev.com>
parents:
497
diff
changeset
|
185 vshader = load_shader(tern_find_ptr_default(config, "videovertex_shader", "default.v.glsl"), GL_VERTEX_SHADER); |
51bf87f76d15
Pull shader file names from config file.
Mike Pavone <pavone@retrodev.com>
parents:
497
diff
changeset
|
186 fshader = load_shader(tern_find_ptr_default(config, "videofragment_shader", "default.f.glsl"), GL_FRAGMENT_SHADER); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
187 program = glCreateProgram(); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
188 glAttachShader(program, vshader); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
189 glAttachShader(program, fshader); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
190 glLinkProgram(program); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
191 GLint link_status; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
192 glGetProgramiv(program, GL_LINK_STATUS, &link_status); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
193 if (!link_status) { |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
194 fputs("Failed to link shader program\n", stderr); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
195 exit(1); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
196 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
197 un_textures[0] = glGetUniformLocation(program, "textures[0]"); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
198 un_textures[1] = glGetUniformLocation(program, "textures[1]"); |
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
|
199 un_width = glGetUniformLocation(program, "width"); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
200 at_pos = glGetAttribLocation(program, "pos"); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
201 } else { |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
490
diff
changeset
|
202 #endif |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
203 context->oddbuf = context->framebuf = malloc(320 * 240 * screen->format->BytesPerPixel * 2); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
204 context->evenbuf = ((char *)context->oddbuf) + 320 * 240 * screen->format->BytesPerPixel; |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
490
diff
changeset
|
205 #ifndef DISABLE_OPENGL |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
206 } |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
490
diff
changeset
|
207 #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
|
208 } |
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
|
209 |
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
|
210 uint8_t render_depth() |
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
|
211 { |
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
|
212 return screen->format->BytesPerPixel * 8; |
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
|
213 } |
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
|
214 |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
215 char * caption = NULL; |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
216 |
487
c08a4efeee7f
Update opengl branch from default. Fix build breakage unrelated to merge
Mike Pavone <pavone@retrodev.com>
diff
changeset
|
217 void render_init(int width, int height, char * title, uint32_t fps, uint8_t fullscreen, uint8_t use_gl) |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
218 { |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
219 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) { |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
220 fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
221 exit(1); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
222 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
223 atexit(SDL_Quit); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
224 atexit(render_close_audio); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
225 printf("width: %d, height: %d\n", width, height); |
487
c08a4efeee7f
Update opengl branch from default. Fix build breakage unrelated to merge
Mike Pavone <pavone@retrodev.com>
diff
changeset
|
226 uint32_t flags = SDL_ANYFORMAT; |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
227 |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
228 #ifndef DISABLE_OPENGL |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
229 if (use_gl) |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
230 { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
231 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
232 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
233 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
234 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
235 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
236 flags = SDL_OPENGL; |
490
c8e65962bfed
Enable fullscreen mode in OpenGL renderer
Mike Pavone <pavone@retrodev.com>
parents:
489
diff
changeset
|
237 if (fullscreen) { |
c8e65962bfed
Enable fullscreen mode in OpenGL renderer
Mike Pavone <pavone@retrodev.com>
parents:
489
diff
changeset
|
238 flags |= SDL_FULLSCREEN; |
c8e65962bfed
Enable fullscreen mode in OpenGL renderer
Mike Pavone <pavone@retrodev.com>
parents:
489
diff
changeset
|
239 } |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
240 } else { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
241 #else |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
242 { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
243 #endif |
487
c08a4efeee7f
Update opengl branch from default. Fix build breakage unrelated to merge
Mike Pavone <pavone@retrodev.com>
diff
changeset
|
244 if (fullscreen) { |
c08a4efeee7f
Update opengl branch from default. Fix build breakage unrelated to merge
Mike Pavone <pavone@retrodev.com>
diff
changeset
|
245 flags |= SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF; |
c08a4efeee7f
Update opengl branch from default. Fix build breakage unrelated to merge
Mike Pavone <pavone@retrodev.com>
diff
changeset
|
246 } else { |
c08a4efeee7f
Update opengl branch from default. Fix build breakage unrelated to merge
Mike Pavone <pavone@retrodev.com>
diff
changeset
|
247 flags |= SDL_SWSURFACE; |
c08a4efeee7f
Update opengl branch from default. Fix build breakage unrelated to merge
Mike Pavone <pavone@retrodev.com>
diff
changeset
|
248 } |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
249 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
250 screen = SDL_SetVideoMode(width, height, 32, flags); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
251 if (!screen) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
252 fprintf(stderr, "Unable to get SDL surface: %s\n", SDL_GetError()); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
253 exit(1); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
254 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
255 if (!use_gl && screen->format->BytesPerPixel != 2 && screen->format->BytesPerPixel != 4) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
256 fprintf(stderr, "BlastEm requires a 16-bit or 32-bit surface, SDL returned a %d-bit surface\n", screen->format->BytesPerPixel * 8); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
257 exit(1); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
258 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
259 #ifndef DISABLE_OPENGL |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
260 //TODO: fallback on standard rendering if OpenGL 2.0 is unavailable or if init fails |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
261 if (use_gl) |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
262 { |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
263 GLenum res = glewInit(); |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
264 if (res != GLEW_OK) { |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
265 fprintf(stderr, "Initialization of GLEW failed with code %d\n", res); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
266 exit(1); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
267 } |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
268 if (!GLEW_VERSION_2_0) { |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
269 fputs("OpenGL 2.0 is unable, falling back to standard SDL rendering\n", stderr); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
270 exit(1); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
271 } |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
272 float aspect = (float)width / height; |
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
273 if (fabs(aspect - 4.0/3.0) > 0.01 && strcmp(tern_find_ptr_default(config, "videoaspect", "normal"), "stretch")) { |
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
274 for (int i = 0; i < 4; i++) |
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
275 { |
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
276 if (aspect > 4.0/3.0) { |
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
277 vertex_data[i*2] *= (4.0/3.0)/aspect; |
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
278 } else { |
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
279 vertex_data[i*2+1] *= aspect/(4.0/3.0); |
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
280 } |
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
281 } |
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
282 } |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
283 } |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
284 render_gl = use_gl; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
285 #endif |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
286 SDL_WM_SetCaption(title, title); |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
287 caption = title; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
288 min_delay = 0; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
289 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
|
290 uint32_t start = SDL_GetTicks(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
291 SDL_Delay(1); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
292 uint32_t delay = SDL_GetTicks()-start; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
293 if (delay > min_delay) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
294 min_delay = delay; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
295 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
296 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
297 if (!min_delay) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
298 min_delay = 1; |
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 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
|
301 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
302 frame_delay = 1000/fps; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
303 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
304 audio_mutex = SDL_CreateMutex(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
305 psg_cond = SDL_CreateCond(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
306 ym_cond = SDL_CreateCond(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
307 audio_ready = SDL_CreateCond(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
308 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
309 SDL_AudioSpec desired, actual; |
445
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
310 char * rate_str = tern_find_ptr(config, "audiorate"); |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
311 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
|
312 if (!rate) { |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
313 rate = 48000; |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
314 } |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
315 desired.freq = rate; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
316 desired.format = AUDIO_S16SYS; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
317 desired.channels = 2; |
445
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
318 char * samples_str = tern_find_ptr(config, "audiobuffer"); |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
319 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
|
320 if (!samples) { |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
321 samples = 512; |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
322 } |
80a9527c812c
Add config values for audio sample rate and buffer size
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
323 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
|
324 desired.samples = samples*2; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
325 desired.callback = audio_callback; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
326 desired.userdata = NULL; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
327 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
328 if (SDL_OpenAudio(&desired, &actual) < 0) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
329 fprintf(stderr, "Unable to open SDL audio: %s\n", SDL_GetError()); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
330 exit(1); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
331 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
332 buffer_samples = actual.samples; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
333 sample_rate = actual.freq; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
334 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
|
335 SDL_PauseAudio(0); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
336 num_joysticks = SDL_NumJoysticks(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
337 if (num_joysticks > MAX_JOYSTICKS) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
338 num_joysticks = MAX_JOYSTICKS; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
339 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
340 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
|
341 printf("Joystick %d: %s\n", i, SDL_JoystickName(i)); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
342 SDL_Joystick * joy = joysticks[i] = SDL_JoystickOpen(i); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
343 if (joy) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
344 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
|
345 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
346 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
347 SDL_JoystickEventState(SDL_ENABLE); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
348 } |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
490
diff
changeset
|
349 #ifndef DISABLE_OPENGL |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
350 void render_context_gl(vdp_context * context) |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
351 { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
352 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
|
353 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
|
354 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
355 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
|
356 glClear(GL_COLOR_BUFFER_BIT); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
357 |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
358 glUseProgram(program); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
359 glActiveTexture(GL_TEXTURE0); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
360 glBindTexture(GL_TEXTURE_2D, textures[0]); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
361 glUniform1i(un_textures[0], 0); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
362 |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
363 glActiveTexture(GL_TEXTURE1); |
489
e97b80e3bd76
Support interlace mode with OpenGL backend
Mike Pavone <pavone@retrodev.com>
parents:
488
diff
changeset
|
364 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
|
365 glUniform1i(un_textures[1], 1); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
366 |
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
|
367 glUniform1f(un_width, context->latched_mode & BIT_H40 ? 320.0f : 256.0f); |
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
|
368 |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
369 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
370 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
|
371 glEnableVertexAttribArray(at_pos); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
372 |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
373 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
374 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
|
375 |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
376 glDisableVertexAttribArray(at_pos); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
377 |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
378 SDL_GL_SwapBuffers(); |
489
e97b80e3bd76
Support interlace mode with OpenGL backend
Mike Pavone <pavone@retrodev.com>
parents:
488
diff
changeset
|
379 if (context->regs[REG_MODE_4] & BIT_INTERLACE) |
e97b80e3bd76
Support interlace mode with OpenGL backend
Mike Pavone <pavone@retrodev.com>
parents:
488
diff
changeset
|
380 { |
e97b80e3bd76
Support interlace mode with OpenGL backend
Mike Pavone <pavone@retrodev.com>
parents:
488
diff
changeset
|
381 context->framebuf = context->framebuf == context->oddbuf ? context->evenbuf : context->oddbuf; |
e97b80e3bd76
Support interlace mode with OpenGL backend
Mike Pavone <pavone@retrodev.com>
parents:
488
diff
changeset
|
382 } |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 } |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
490
diff
changeset
|
384 #endif |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 |
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
|
386 uint32_t blankbuf[320*240]; |
413
36fbbced25c2
Initial work on interlace
Mike Pavone <pavone@retrodev.com>
parents:
409
diff
changeset
|
387 |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 void render_context(vdp_context * context) |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 uint16_t *buf_16; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
391 uint32_t *buf_32; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 uint8_t b,g,r; |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
393 last_frame = SDL_GetTicks(); |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
490
diff
changeset
|
394 #ifndef DISABLE_OPENGL |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
395 if (render_gl) |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
396 { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
397 render_context_gl(context); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
398 return; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
399 } |
495
39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
Mike Pavone <pavone@retrodev.com>
parents:
490
diff
changeset
|
400 #endif |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 if (SDL_MUSTLOCK(screen)) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 if (SDL_LockSurface(screen) < 0) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 return; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
404 } |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
405 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
406 uint16_t repeat_x = screen->clip_rect.w / 320; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
407 uint16_t repeat_y = screen->clip_rect.h / 240; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
408 if (repeat_x > repeat_y) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
409 repeat_x = repeat_y; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
410 } else { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
411 repeat_y = repeat_x; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
412 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
413 int othermask = repeat_y >> 1; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
414 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
415 if (screen->format->BytesPerPixel == 2) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
416 uint16_t *otherbuf = (context->regs[REG_MODE_4] & BIT_INTERLACE) ? context->evenbuf : (uint16_t *)blankbuf; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
417 uint16_t * oddbuf = context->oddbuf; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
418 buf_16 = (uint16_t *)screen->pixels; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
419 for (int y = 0; y < 240; y++) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
420 for (int i = 0; i < repeat_y; i++,buf_16 += screen->pitch/2) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
421 uint16_t *line = buf_16; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
422 uint16_t *src_line = (i & othermask ? otherbuf : oddbuf) + y * 320; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
423 for (int x = 0; x < 320; x++) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
424 uint16_t color = *(src_line++); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
425 for (int j = 0; j < repeat_x; j++) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
426 *(line++) = color; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
427 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
428 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
429 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
430 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
431 } else { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
432 uint32_t *otherbuf = (context->regs[REG_MODE_4] & BIT_INTERLACE) ? context->evenbuf : (uint32_t *)blankbuf; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
433 uint32_t * oddbuf = context->oddbuf; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
434 buf_32 = (uint32_t *)screen->pixels; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
435 for (int y = 0; y < 240; y++) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
436 for (int i = 0; i < repeat_y; i++,buf_32 += screen->pitch/4) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
437 uint32_t *line = buf_32; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
438 uint32_t *src_line = (i & othermask ? otherbuf : oddbuf) + y * 320; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
439 for (int x = 0; x < 320; x++) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
440 uint32_t color = *(src_line++); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
441 for (int j = 0; j < repeat_x; j++) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
442 *(line++) = color; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
443 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
444 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
445 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
446 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
447 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
448 if ( SDL_MUSTLOCK(screen) ) { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
449 SDL_UnlockSurface(screen); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
450 } |
444
cc754a309ead
Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents:
432
diff
changeset
|
451 //SDL_UpdateRect(screen, 0, 0, screen->clip_rect.w, screen->clip_rect.h); |
cc754a309ead
Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents:
432
diff
changeset
|
452 SDL_Flip(screen); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
453 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
|
454 { |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
455 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
|
456 } |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
458 |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
459 int render_joystick_num_buttons(int joystick) |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
460 { |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
461 if (joystick >= num_joysticks) { |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
462 return 0; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
463 } |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
464 return SDL_JoystickNumButtons(joysticks[joystick]); |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
465 } |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
466 |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
467 int render_joystick_num_hats(int joystick) |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
468 { |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
469 if (joystick >= num_joysticks) { |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
470 return 0; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
471 } |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
472 return SDL_JoystickNumHats(joysticks[joystick]); |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
473 } |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
474 |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
475 void render_wait_quit(vdp_context * context) |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
476 { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 SDL_Event event; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 while(SDL_WaitEvent(&event)) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 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
|
480 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
|
481 if (event.key.keysym.sym == SDLK_LEFTBRACKET) { |
55
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
482 render_dbg++; |
135 | 483 if (render_dbg == 4) { |
55
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
484 render_dbg = 0; |
8317f174d916
Add palette debug to SDL renderer
Mike Pavone <pavone@retrodev.com>
parents:
54
diff
changeset
|
485 } |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
486 render_context(context); |
135 | 487 } else if(event.key.keysym.sym == SDLK_RIGHTBRACKET) { |
488 debug_pal++; | |
489 if (debug_pal == 4) { | |
490 debug_pal = 0; | |
491 } | |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
492 } |
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
493 break; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 case SDL_QUIT: |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
495 return; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 |
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
|
500 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
|
501 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
502 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
|
503 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
|
504 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
505 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
506 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
507 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
|
508 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
509 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
|
510 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
|
511 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
512 } |
66 | 513 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
514 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
|
515 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
516 switch (event->type) { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
517 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
|
518 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
|
519 break; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
520 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
|
521 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
|
522 break; |
418
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
523 case SDL_JOYBUTTONDOWN: |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
524 handle_joydown(event->jbutton.which, event->jbutton.button); |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
525 break; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
526 case SDL_JOYBUTTONUP: |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
527 handle_joyup(event->jbutton.which, event->jbutton.button); |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
528 break; |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
529 case SDL_JOYHATMOTION: |
dbf4e1c86f3c
Implement basic joystick support
Mike Pavone <pavone@retrodev.com>
parents:
416
diff
changeset
|
530 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
|
531 break; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
532 case SDL_QUIT: |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
533 puts(""); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
534 exit(0); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
535 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
536 return 0; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
537 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
538 |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
539 char * fps_caption = NULL; |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
540 |
63
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
541 uint32_t frame_counter = 0; |
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
542 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
|
543 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
|
544 { |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
545 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
|
546 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
|
547 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
|
548 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
|
549 } |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
550 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
|
551 //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
|
552 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
|
553 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
|
554 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
|
555 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
|
556 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
|
557 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
|
558 } |
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
559 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
|
560 } |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
561 } |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
322
diff
changeset
|
562 } |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
563 render_context(context); |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
564 |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
565 |
64
2b1a65f4b85d
Cleanup 68K timing code. Temporarily omment out fFPS counter as it was causing segfaults
Mike Pavone <pavone@retrodev.com>
parents:
63
diff
changeset
|
566 //TODO: Figure out why this causes segfaults |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
567 frame_counter++; |
63
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
568 if ((last_frame - start) > 1000) { |
272 | 569 if (start && (last_frame-start)) { |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
570 if (!fps_caption) { |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
571 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
|
572 } |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
573 sprintf(fps_caption, "%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); |
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
574 SDL_WM_SetCaption(fps_caption, caption); |
63
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
575 fflush(stdout); |
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
576 } |
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
577 start = last_frame; |
a6dd5b7a971b
Add FPS counter to console output
Mike Pavone <pavone@retrodev.com>
parents:
55
diff
changeset
|
578 frame_counter = 0; |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
579 } |
198
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
135
diff
changeset
|
580 return ret; |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
581 } |
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
582 |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
583 void process_events() |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
584 { |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
585 SDL_Event event; |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
586 while(SDL_PollEvent(&event)) { |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
587 handle_event(&event); |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
588 } |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
589 } |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
590 |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
591 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
|
592 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
593 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
|
594 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
|
595 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
|
596 } |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
597 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
|
598 SDL_CondSignal(audio_ready); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
599 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
600 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
|
601 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
|
602 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
|
603 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
|
604 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
605 |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
606 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
|
607 { |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
608 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
|
609 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
|
610 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
|
611 } |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
612 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
|
613 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
|
614 |
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
615 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
|
616 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
|
617 SDL_UnlockMutex(audio_mutex); |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
618 context->buffer_pos = 0; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
619 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
620 |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
621 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
|
622 { |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
623 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
|
624 } |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
625 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
626 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
|
627 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
628 return buffer_samples; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
629 } |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
630 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
631 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
|
632 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
633 return sample_rate; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
634 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
635 |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
636 |