Mercurial > repos > blastem
annotate render_sdl.c @ 1573:a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 27 Apr 2018 20:08:47 -0700 |
parents | 66387b1645e4 |
children | ade5b8148caa |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
2 Copyright 2013 Michael Pavone |
487
c08a4efeee7f
Update opengl branch from default. Fix build breakage unrelated to merge
Mike Pavone <pavone@retrodev.com>
diff
changeset
|
3 This file is part of BlastEm. |
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
445
diff
changeset
|
5 */ |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include <stdlib.h> |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include <stdio.h> |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
744
diff
changeset
|
8 #include <string.h> |
500
251fe7a75a14
Preserve aspect ratio unless config file says otherwise
Mike Pavone <pavone@retrodev.com>
parents:
498
diff
changeset
|
9 #include <math.h> |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include "render.h" |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
11 #include "render_sdl.h" |
66 | 12 #include "blastem.h" |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1102
diff
changeset
|
13 #include "genesis.h" |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
418
diff
changeset
|
14 #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
|
15 #include "util.h" |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
16 #include "ppm.h" |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
17 #include "png.h" |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
18 #include "config.h" |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
20 #ifndef DISABLE_OPENGL |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
21 #include <GL/glew.h> |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
22 #endif |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
23 |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
24 #define MAX_EVENT_POLL_PER_FRAME 2 |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
25 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
26 static SDL_Window *main_window; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
27 static SDL_Renderer *main_renderer; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
28 static SDL_Texture **sdl_textures; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
29 static uint8_t num_textures; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
30 static SDL_Rect main_clip; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
31 static SDL_GLContext *main_context; |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
32 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
33 static int main_width, main_height, windowed_width, windowed_height, is_fullscreen; |
914
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
34 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
35 static uint8_t render_gl = 1; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
36 static uint8_t scanlines = 0; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
38 static uint32_t last_frame = 0; |
54
3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
Mike Pavone <pavone@retrodev.com>
parents:
43
diff
changeset
|
39 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
40 static uint32_t buffer_samples, sample_rate; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
41 static uint32_t missing_count; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
42 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
43 static SDL_mutex * audio_mutex; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
44 static SDL_cond * audio_ready; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
45 static uint8_t quitting = 0; |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
46 |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
47 struct audio_source { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
48 SDL_cond *cond; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
49 int16_t *front; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
50 int16_t *back; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
51 double dt; |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
52 uint64_t buffer_fraction; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
53 uint64_t buffer_inc; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
54 uint32_t buffer_pos; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
55 uint32_t read_start; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
56 uint32_t read_end; |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
57 uint32_t lowpass_alpha; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
58 uint32_t mask; |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
59 int16_t last_left; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
60 int16_t last_right; |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
61 uint8_t num_channels; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
62 uint8_t front_populated; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
63 }; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
64 |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
65 static audio_source *audio_sources[8]; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
66 static uint8_t num_audio_sources; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
67 static uint8_t sync_to_audio; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
68 static uint32_t min_buffered; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
69 |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
70 typedef int32_t (*mix_func)(audio_source *audio, void *vstream, int len); |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
71 |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
72 static int32_t mix_s16(audio_source *audio, void *vstream, int len) |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
73 { |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
74 int samples = len/(sizeof(int16_t)*2); |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
75 int16_t *stream = vstream; |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
76 int16_t *end = stream + 2*samples; |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
77 int16_t *src = audio->front; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
78 uint32_t i = audio->read_start; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
79 uint32_t i_end = audio->read_end; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
80 int16_t *cur = stream; |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
81 if (audio->num_channels == 1) { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
82 while (cur < end && i != i_end) |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
83 { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
84 *(cur++) += src[i]; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
85 *(cur++) += src[i++]; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
86 i &= audio->mask; |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
87 } |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
88 } else { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
89 while (cur < end && i != i_end) |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
90 { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
91 *(cur++) += src[i++]; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
92 *(cur++) += src[i++]; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
93 i &= audio->mask; |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
94 } |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
95 } |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
96 |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
97 if (cur != end) { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
98 printf("Underflow of %d samples, read_start: %d, read_end: %d, mask: %X\n", (int)(end-cur)/2, audio->read_start, audio->read_end, audio->mask); |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
99 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
100 if (!sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
101 audio->read_start = i; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
102 } |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
103 if (cur != end) { |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
104 //printf("Underflow of %d samples, read_start: %d, read_end: %d, mask: %X\n", (int)(end-cur)/2, audio->read_start, audio->read_end, audio->mask); |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
105 return (cur-end)/2; |
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
106 } else { |
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
107 return ((i_end - i) & audio->mask) / audio->num_channels; |
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
108 } |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
109 } |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
110 |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
111 static int32_t mix_f32(audio_source *audio, void *vstream, int len) |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
112 { |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
113 int samples = len/(sizeof(float)*2); |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
114 float *stream = vstream; |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
115 float *end = stream + 2*samples; |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
116 int16_t *src = audio->front; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
117 uint32_t i = audio->read_start; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
118 uint32_t i_end = audio->read_end; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
119 float *cur = stream; |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
120 if (audio->num_channels == 1) { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
121 while (cur < end && i != i_end) |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
122 { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
123 *(cur++) += ((float)src[i]) / 0x7FFF; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
124 *(cur++) += ((float)src[i++]) / 0x7FFF; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
125 i &= audio->mask; |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
126 } |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
127 } else { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
128 while(cur < end && i != i_end) |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
129 { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
130 *(cur++) += ((float)src[i++]) / 0x7FFF; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
131 *(cur++) += ((float)src[i++]) / 0x7FFF; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
132 i &= audio->mask; |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
133 } |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
134 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
135 if (!sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
136 audio->read_start = i; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
137 } |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
138 if (cur != end) { |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
139 printf("Underflow of %d samples, read_start: %d, read_end: %d, mask: %X\n", (int)(end-cur)/2, audio->read_start, audio->read_end, audio->mask); |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
140 return (cur-end)/2; |
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
141 } else { |
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
142 return ((i_end - i) & audio->mask) / audio->num_channels; |
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
143 } |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
144 } |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
145 |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
146 static int32_t mix_null(audio_source *audio, void *vstream, int len) |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
147 { |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
148 return 0; |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
149 } |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
150 |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
151 static mix_func mix; |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
152 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
153 static void audio_callback(void * userdata, uint8_t *byte_stream, int len) |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 { |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
155 //int16_t * stream = (int16_t *)byte_stream; |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
156 //int samples = len/(sizeof(int16_t)*2); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
157 uint8_t num_populated; |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
158 memset(byte_stream, 0, len); |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
159 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
|
160 do { |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
161 num_populated = 0; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
162 for (uint8_t i = 0; i < num_audio_sources; i++) |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
163 { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
164 if (audio_sources[i]->front_populated) { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
165 num_populated++; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
166 } |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
167 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
168 if (!quitting && num_populated < num_audio_sources) { |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
169 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
|
170 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
171 } while(!quitting && num_populated < num_audio_sources); |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
172 if (!quitting) { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
173 for (uint8_t i = 0; i < num_audio_sources; i++) |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
174 { |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
175 mix(audio_sources[i], byte_stream, len); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
176 audio_sources[i]->front_populated = 0; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
177 SDL_CondSignal(audio_sources[i]->cond); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
178 } |
361 | 179 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
180 SDL_UnlockMutex(audio_mutex); |
1117
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
181 } |
928a65750345
Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
182 |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
183 #define NO_LAST_BUFFERED -2000000000 |
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
184 static int32_t last_buffered = NO_LAST_BUFFERED; |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
185 static float average_change; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
186 #define BUFFER_FRAMES_THRESHOLD 6 |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
187 #define BASE_MAX_ADJUST 0.0125 |
1565
61fafcbc2c38
Audio DRC now sounds good in both NTSC and PAL, just need to adjust constants to minimize latency without leading to dropouts
Michael Pavone <pavone@retrodev.com>
parents:
1564
diff
changeset
|
188 static float max_adjust; |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
189 static int32_t cur_min_buffered; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
190 static uint32_t min_remaining_buffer; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
191 static void audio_callback_drc(void *userData, uint8_t *byte_stream, int len) |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
192 { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
193 memset(byte_stream, 0, len); |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
194 cur_min_buffered = 0x7FFFFFFF; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
195 min_remaining_buffer = 0xFFFFFFFF; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
196 for (uint8_t i = 0; i < num_audio_sources; i++) |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
197 { |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
198 |
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
199 int32_t buffered = mix(audio_sources[i], byte_stream, len); |
1565
61fafcbc2c38
Audio DRC now sounds good in both NTSC and PAL, just need to adjust constants to minimize latency without leading to dropouts
Michael Pavone <pavone@retrodev.com>
parents:
1564
diff
changeset
|
200 cur_min_buffered = buffered < cur_min_buffered ? buffered : cur_min_buffered; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
201 uint32_t remaining = (audio_sources[i]->mask + 1)/audio_sources[i]->num_channels - buffered; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
202 min_remaining_buffer = remaining < min_remaining_buffer ? remaining : min_remaining_buffer; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
203 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
204 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
205 |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
206 static void lock_audio() |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
207 { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
208 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
209 SDL_LockMutex(audio_mutex); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
210 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
211 SDL_LockAudio(); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
212 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
213 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
214 |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
215 static void unlock_audio() |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
216 { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
217 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
218 SDL_UnlockMutex(audio_mutex); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
219 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
220 SDL_UnlockAudio(); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
221 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
222 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
223 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
224 static void render_close_audio() |
361 | 225 { |
226 SDL_LockMutex(audio_mutex); | |
227 quitting = 1; | |
228 SDL_CondSignal(audio_ready); | |
229 SDL_UnlockMutex(audio_mutex); | |
230 SDL_CloseAudio(); | |
231 } | |
232 | |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
233 #define BUFFER_INC_RES 0x40000000UL |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
234 |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
235 void render_audio_adjust_clock(audio_source *src, uint64_t master_clock, uint64_t sample_divider) |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
236 { |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
237 src->buffer_inc = ((BUFFER_INC_RES * (uint64_t)sample_rate) / master_clock) * sample_divider; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
238 } |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
239 |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
240 audio_source *render_audio_source(uint64_t master_clock, uint64_t sample_divider, uint8_t channels) |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
241 { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
242 audio_source *ret = NULL; |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
243 uint32_t alloc_size = sync_to_audio ? channels * buffer_samples : nearest_pow2(min_buffered * 4 * channels); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
244 lock_audio(); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
245 if (num_audio_sources < 8) { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
246 ret = malloc(sizeof(audio_source)); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
247 ret->back = malloc(alloc_size * sizeof(int16_t)); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
248 ret->front = sync_to_audio ? malloc(alloc_size * sizeof(int16_t)) : ret->back; |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
249 ret->front_populated = 0; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
250 ret->cond = SDL_CreateCond(); |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
251 ret->num_channels = channels; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
252 audio_sources[num_audio_sources++] = ret; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
253 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
254 unlock_audio(); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
255 if (!ret) { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
256 fatal_error("Too many audio sources!"); |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
257 } else { |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
258 render_audio_adjust_clock(ret, master_clock, sample_divider); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
259 double lowpass_cutoff = get_lowpass_cutoff(config); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
260 double rc = (1.0 / lowpass_cutoff) / (2.0 * M_PI); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
261 ret->dt = 1.0 / ((double)master_clock / (double)(sample_divider)); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
262 double alpha = ret->dt / (ret->dt + rc); |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
263 ret->lowpass_alpha = (int32_t)(((double)0x10000) * alpha); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
264 ret->buffer_pos = 0; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
265 ret->buffer_fraction = 0; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
266 ret->last_left = ret->last_right = 0; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
267 ret->read_start = ret->read_end = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
268 ret->mask = alloc_size-1; |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
269 } |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
270 return ret; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
271 } |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
272 |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
273 void render_pause_source(audio_source *src) |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
274 { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
275 uint8_t need_pause = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
276 lock_audio(); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
277 for (uint8_t i = 0; i < num_audio_sources; i++) |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
278 { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
279 if (audio_sources[i] == src) { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
280 audio_sources[i] = audio_sources[--num_audio_sources]; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
281 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
282 SDL_CondSignal(audio_ready); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
283 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
284 break; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
285 } |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
286 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
287 if (!num_audio_sources) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
288 need_pause = 1; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
289 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
290 unlock_audio(); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
291 if (need_pause) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
292 SDL_PauseAudio(1); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
293 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
294 } |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
295 |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
296 void render_resume_source(audio_source *src) |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
297 { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
298 lock_audio(); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
299 if (num_audio_sources < 8) { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
300 audio_sources[num_audio_sources++] = src; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
301 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
302 unlock_audio(); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
303 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
304 SDL_PauseAudio(0); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
305 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
306 } |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
307 |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
308 void render_free_source(audio_source *src) |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
309 { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
310 render_pause_source(src); |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
311 |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
312 free(src->front); |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
313 free(src->back); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
314 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
315 SDL_DestroyCond(src->cond); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
316 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
317 free(src); |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
318 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
319 static uint32_t sync_samples; |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
320 static void do_audio_ready(audio_source *src) |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
321 { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
322 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
323 SDL_LockMutex(audio_mutex); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
324 while (src->front_populated) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
325 SDL_CondWait(src->cond, audio_mutex); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
326 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
327 int16_t *tmp = src->front; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
328 src->front = src->back; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
329 src->back = tmp; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
330 src->front_populated = 1; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
331 src->buffer_pos = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
332 SDL_CondSignal(audio_ready); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
333 SDL_UnlockMutex(audio_mutex); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
334 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
335 uint32_t num_buffered; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
336 SDL_LockAudio(); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
337 src->read_end = src->buffer_pos; |
1565
61fafcbc2c38
Audio DRC now sounds good in both NTSC and PAL, just need to adjust constants to minimize latency without leading to dropouts
Michael Pavone <pavone@retrodev.com>
parents:
1564
diff
changeset
|
338 num_buffered = ((src->read_end - src->read_start) & src->mask) / src->num_channels; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
339 SDL_UnlockAudio(); |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
340 if (num_buffered >= min_buffered && SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
341 SDL_PauseAudio(0); |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
342 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
343 } |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
344 } |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
345 |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
346 static int16_t lowpass_sample(audio_source *src, int16_t last, int16_t current) |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
347 { |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
348 int32_t tmp = current * src->lowpass_alpha + last * (0x10000 - src->lowpass_alpha); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
349 current = tmp >> 16; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
350 return current; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
351 } |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
352 |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
353 static void interp_sample(audio_source *src, int16_t last, int16_t current) |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
354 { |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
355 int64_t tmp = last * ((src->buffer_fraction << 16) / src->buffer_inc); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
356 tmp += current * (0x10000 - ((src->buffer_fraction << 16) / src->buffer_inc)); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
357 src->back[src->buffer_pos++] = tmp >> 16; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
358 } |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
359 |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
360 void render_put_mono_sample(audio_source *src, int16_t value) |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
361 { |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
362 value = lowpass_sample(src, src->last_left, value); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
363 src->buffer_fraction += src->buffer_inc; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
364 while (src->buffer_fraction > BUFFER_INC_RES) |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
365 { |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
366 src->buffer_fraction -= BUFFER_INC_RES; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
367 interp_sample(src, src->last_left, value); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
368 |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
369 if (((src->buffer_pos - src->read_end) & src->mask) >= sync_samples) { |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
370 do_audio_ready(src); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
371 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
372 src->buffer_pos &= src->mask; |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
373 } |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
374 src->last_left = value; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
375 } |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
376 |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
377 void render_put_stereo_sample(audio_source *src, int16_t left, int16_t right) |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
378 { |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
379 left = lowpass_sample(src, src->last_left, left); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
380 right = lowpass_sample(src, src->last_right, right); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
381 src->buffer_fraction += src->buffer_inc; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
382 while (src->buffer_fraction > BUFFER_INC_RES) |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
383 { |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
384 src->buffer_fraction -= BUFFER_INC_RES; |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
385 |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
386 interp_sample(src, src->last_left, left); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
387 interp_sample(src, src->last_right, right); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
388 |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
389 if (((src->buffer_pos - src->read_end) & src->mask)/2 >= sync_samples) { |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
390 do_audio_ready(src); |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
391 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
392 src->buffer_pos &= src->mask; |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
393 } |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
394 src->last_left = left; |
1562
d7b0d0ce8ed1
Fix regression in right audio channel
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
395 src->last_right = right; |
1555
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
396 } |
6ce36c3f250b
More audio refactoring in preparation for allowing proper sync to video with dynamic audio rate control
Michael Pavone <pavone@retrodev.com>
parents:
1552
diff
changeset
|
397 |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
398 static SDL_Joystick * joysticks[MAX_JOYSTICKS]; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
399 static int joystick_sdl_index[MAX_JOYSTICKS]; |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
400 |
914
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
401 int render_width() |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
402 { |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
403 return main_width; |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
404 } |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
405 |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
406 int render_height() |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
407 { |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
408 return main_height; |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
409 } |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
410 |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
411 int render_fullscreen() |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
412 { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
413 return is_fullscreen; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
414 } |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
415 |
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
|
416 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
|
417 { |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
418 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
|
419 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
420 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
421 #ifndef DISABLE_OPENGL |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
422 static GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], un_width, un_height, at_pos; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
423 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
424 static GLfloat vertex_data_default[] = { |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
425 -1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
426 1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
427 -1.0f, 1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
428 1.0f, 1.0f |
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 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
431 static GLfloat vertex_data[8]; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
432 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
433 static const GLushort element_data[] = {0, 1, 2, 3}; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
434 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
435 static GLuint load_shader(char * fname, GLenum shader_type) |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
436 { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
437 char const * parts[] = {get_home_dir(), "/.config/blastem/shaders/", fname}; |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
438 char * shader_path = alloc_concat_m(3, parts); |
816
7ed55a361e79
Use binary mode for reading shaders and config files so we actually get the number of bytes we expect
Michael Pavone <pavone@retrodev.com>
parents:
800
diff
changeset
|
439 FILE * f = fopen(shader_path, "rb"); |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
440 free(shader_path); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
441 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
|
442 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
|
443 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
|
444 shader_path = alloc_concat_m(3, parts); |
816
7ed55a361e79
Use binary mode for reading shaders and config files so we actually get the number of bytes we expect
Michael Pavone <pavone@retrodev.com>
parents:
800
diff
changeset
|
445 f = fopen(shader_path, "rb"); |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
446 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
|
447 if (!f) { |
800 | 448 warning("Failed to open shader file %s for reading\n", fname); |
497
0820a71b80f3
Move shader files to their own directory. Read shaders from /.config/blastem/shaders or from path_to_exe/shaders instead of the current working directory.
Mike Pavone <pavone@retrodev.com>
parents:
495
diff
changeset
|
449 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
|
450 } |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
451 } |
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
|
452 long fsize = file_size(f); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
453 GLchar * text = malloc(fsize); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
454 if (fread(text, 1, fsize, f) != fsize) { |
800 | 455 warning("Error reading from shader file %s\n", fname); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
456 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
457 return 0; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
458 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
459 GLuint ret = glCreateShader(shader_type); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
460 glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
461 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
462 glCompileShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
463 GLint compile_status, loglen; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
464 glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
465 if (!compile_status) { |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
466 glGetShaderiv(ret, GL_INFO_LOG_LENGTH, &loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
467 text = malloc(loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
468 glGetShaderInfoLog(ret, loglen, NULL, text); |
800 | 469 warning("Shader %s failed to compile:\n%s\n", fname, text); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
470 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
471 glDeleteShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
472 return 0; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
473 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
474 return ret; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
475 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
476 #endif |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
477 |
1167
e758ddbf0624
Initial work on emulating top and bottom border area
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
478 static uint32_t texture_buf[512 * 513]; |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
479 #ifndef DISABLE_OPENGL |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
480 static void gl_setup() |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
481 { |
1403
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
482 tern_val def = {.ptrval = "linear"}; |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
483 char *scaling = tern_find_path_default(config, "video\0scaling\0", def, TVAL_PTR).ptrval; |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
484 GLint filter = strcmp(scaling, "linear") ? GL_NEAREST : GL_LINEAR; |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
485 glGenTextures(3, textures); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
486 for (int i = 0; i < 3; i++) |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
487 { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
488 glBindTexture(GL_TEXTURE_2D, textures[i]); |
1403
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
489 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
490 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
491 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
492 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
493 if (i < 2) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
494 //TODO: Fixme for PAL + invalid display mode |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
495 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 512, 512, 0, GL_BGRA, GL_UNSIGNED_BYTE, texture_buf); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
496 } else { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
497 uint32_t blank = 255 << 24; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
498 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_BGRA, GL_UNSIGNED_BYTE, &blank); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
499 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
500 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
501 glGenBuffers(2, buffers); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
502 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
503 glBufferData(GL_ARRAY_BUFFER, sizeof(vertex_data), vertex_data, GL_STATIC_DRAW); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
504 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
505 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(element_data), element_data, GL_STATIC_DRAW); |
1403
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
506 def.ptrval = "default.v.glsl"; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
507 vshader = load_shader(tern_find_path_default(config, "video\0vertex_shader\0", def, TVAL_PTR).ptrval, GL_VERTEX_SHADER); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
508 def.ptrval = "default.f.glsl"; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
509 fshader = load_shader(tern_find_path_default(config, "video\0fragment_shader\0", def, TVAL_PTR).ptrval, GL_FRAGMENT_SHADER); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
510 program = glCreateProgram(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
511 glAttachShader(program, vshader); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
512 glAttachShader(program, fshader); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
513 glLinkProgram(program); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
514 GLint link_status; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
515 glGetProgramiv(program, GL_LINK_STATUS, &link_status); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
516 if (!link_status) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
517 fputs("Failed to link shader program\n", stderr); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
518 exit(1); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
519 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
520 un_textures[0] = glGetUniformLocation(program, "textures[0]"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
521 un_textures[1] = glGetUniformLocation(program, "textures[1]"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
522 un_width = glGetUniformLocation(program, "width"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
523 un_height = glGetUniformLocation(program, "height"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
524 at_pos = glGetAttribLocation(program, "pos"); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
525 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
526 #endif |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
527 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
528 static uint8_t texture_init; |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
529 static void render_alloc_surfaces() |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
530 { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
531 if (texture_init) { |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
532 return; |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
533 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
534 sdl_textures= malloc(sizeof(SDL_Texture *) * 2); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
535 num_textures = 2; |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
536 texture_init = 1; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
537 #ifndef DISABLE_OPENGL |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
538 if (render_gl) { |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
539 sdl_textures[0] = sdl_textures[1] = NULL; |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
540 gl_setup(); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
541 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
542 #endif |
1403
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
543 tern_val def = {.ptrval = "linear"}; |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
544 char *scaling = tern_find_path_default(config, "video\0scaling\0", def, TVAL_PTR).ptrval; |
87493f585c7f
Allow selecting linear or nearet neighbor scaling for both the Open GL and SDL 2 renderers
Michael Pavone <pavone@retrodev.com>
parents:
1402
diff
changeset
|
545 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scaling); |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
546 //TODO: Fixme for invalid display mode |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
547 sdl_textures[0] = sdl_textures[1] = SDL_CreateTexture(main_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, LINEBUF_SIZE, 588); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
548 #ifndef DISABLE_OPENGL |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
549 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
550 #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
|
551 } |
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
|
552 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
553 static void free_surfaces(void) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
554 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
555 for (int i = 0; i < num_textures; i++) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
556 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
557 if (sdl_textures[i]) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
558 SDL_DestroyTexture(sdl_textures[i]); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
559 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
560 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
561 free(sdl_textures); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
562 sdl_textures = NULL; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
563 texture_init = 0; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
564 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
565 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
566 static char * caption = NULL; |
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
567 static char * fps_caption = NULL; |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
568 |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
569 static void render_quit() |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
570 { |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
571 render_close_audio(); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
572 free_surfaces(); |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
573 } |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
574 |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
575 static float config_aspect() |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
576 { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
577 static float aspect = 0.0f; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
578 if (aspect == 0.0f) { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
579 char *config_aspect = tern_find_path_default(config, "video\0aspect\0", (tern_val){.ptrval = "4:3"}, TVAL_PTR).ptrval; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
580 if (strcmp("stretch", config_aspect)) { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
581 aspect = 4.0f/3.0f; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
582 char *end; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
583 float aspect_numerator = strtof(config_aspect, &end); |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
584 if (aspect_numerator > 0.0f && *end == ':') { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
585 float aspect_denominator = strtof(end+1, &end); |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
586 if (aspect_denominator > 0.0f && !*end) { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
587 aspect = aspect_numerator / aspect_denominator; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
588 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
589 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
590 } else { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
591 aspect = -1.0f; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
592 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
593 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
594 return aspect; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
595 } |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
596 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
597 static void update_aspect() |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
598 { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
599 //reset default values |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
600 memcpy(vertex_data, vertex_data_default, sizeof(vertex_data)); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
601 main_clip.w = main_width; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
602 main_clip.h = main_height; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
603 main_clip.x = main_clip.y = 0; |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
604 if (config_aspect() > 0.0f) { |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
605 float aspect = (float)main_width / main_height; |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
606 if (fabs(aspect - config_aspect()) < 0.01f) { |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
607 //close enough for government work |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
608 return; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
609 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
610 #ifndef DISABLE_OPENGL |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
611 if (render_gl) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
612 for (int i = 0; i < 4; i++) |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
613 { |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
614 if (aspect > config_aspect()) { |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
615 vertex_data[i*2] *= config_aspect()/aspect; |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
616 } else { |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
617 vertex_data[i*2+1] *= aspect/config_aspect(); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
618 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
619 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
620 } else { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
621 #endif |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
622 main_clip.w = aspect > config_aspect() ? config_aspect() * (float)main_height : main_width; |
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
623 main_clip.h = aspect > config_aspect() ? main_height : main_width / config_aspect(); |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
624 main_clip.x = (main_width - main_clip.w) / 2; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
625 main_clip.y = (main_height - main_clip.h) / 2; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
626 #ifndef DISABLE_OPENGL |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
627 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
628 #endif |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
629 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
630 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
631 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
632 static ui_render_fun on_context_destroyed, on_context_created; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
633 void render_set_gl_context_handlers(ui_render_fun destroy, ui_render_fun create) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
634 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
635 on_context_destroyed = destroy; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
636 on_context_created = create; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
637 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
638 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
639 static uint8_t scancode_map[SDL_NUM_SCANCODES] = { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
640 [SDL_SCANCODE_A] = 0x1C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
641 [SDL_SCANCODE_B] = 0x32, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
642 [SDL_SCANCODE_C] = 0x21, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
643 [SDL_SCANCODE_D] = 0x23, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
644 [SDL_SCANCODE_E] = 0x24, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
645 [SDL_SCANCODE_F] = 0x2B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
646 [SDL_SCANCODE_G] = 0x34, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
647 [SDL_SCANCODE_H] = 0x33, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
648 [SDL_SCANCODE_I] = 0x43, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
649 [SDL_SCANCODE_J] = 0x3B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
650 [SDL_SCANCODE_K] = 0x42, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
651 [SDL_SCANCODE_L] = 0x4B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
652 [SDL_SCANCODE_M] = 0x3A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
653 [SDL_SCANCODE_N] = 0x31, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
654 [SDL_SCANCODE_O] = 0x44, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
655 [SDL_SCANCODE_P] = 0x4D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
656 [SDL_SCANCODE_Q] = 0x15, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
657 [SDL_SCANCODE_R] = 0x2D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
658 [SDL_SCANCODE_S] = 0x1B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
659 [SDL_SCANCODE_T] = 0x2C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
660 [SDL_SCANCODE_U] = 0x3C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
661 [SDL_SCANCODE_V] = 0x2A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
662 [SDL_SCANCODE_W] = 0x1D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
663 [SDL_SCANCODE_X] = 0x22, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
664 [SDL_SCANCODE_Y] = 0x35, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
665 [SDL_SCANCODE_Z] = 0x1A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
666 [SDL_SCANCODE_1] = 0x16, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
667 [SDL_SCANCODE_2] = 0x1E, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
668 [SDL_SCANCODE_3] = 0x26, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
669 [SDL_SCANCODE_4] = 0x25, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
670 [SDL_SCANCODE_5] = 0x2E, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
671 [SDL_SCANCODE_6] = 0x36, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
672 [SDL_SCANCODE_7] = 0x3D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
673 [SDL_SCANCODE_8] = 0x3E, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
674 [SDL_SCANCODE_9] = 0x46, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
675 [SDL_SCANCODE_0] = 0x45, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
676 [SDL_SCANCODE_RETURN] = 0x5A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
677 [SDL_SCANCODE_ESCAPE] = 0x76, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
678 [SDL_SCANCODE_SPACE] = 0x29, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
679 [SDL_SCANCODE_TAB] = 0x0D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
680 [SDL_SCANCODE_BACKSPACE] = 0x66, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
681 [SDL_SCANCODE_MINUS] = 0x4E, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
682 [SDL_SCANCODE_EQUALS] = 0x55, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
683 [SDL_SCANCODE_LEFTBRACKET] = 0x54, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
684 [SDL_SCANCODE_RIGHTBRACKET] = 0x5B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
685 [SDL_SCANCODE_BACKSLASH] = 0x5D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
686 [SDL_SCANCODE_SEMICOLON] = 0x4C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
687 [SDL_SCANCODE_APOSTROPHE] = 0x52, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
688 [SDL_SCANCODE_GRAVE] = 0x0E, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
689 [SDL_SCANCODE_COMMA] = 0x41, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
690 [SDL_SCANCODE_PERIOD] = 0x49, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
691 [SDL_SCANCODE_SLASH] = 0x4A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
692 [SDL_SCANCODE_CAPSLOCK] = 0x58, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
693 [SDL_SCANCODE_F1] = 0x05, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
694 [SDL_SCANCODE_F2] = 0x06, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
695 [SDL_SCANCODE_F3] = 0x04, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
696 [SDL_SCANCODE_F4] = 0x0C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
697 [SDL_SCANCODE_F5] = 0x03, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
698 [SDL_SCANCODE_F6] = 0x0B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
699 [SDL_SCANCODE_F7] = 0x83, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
700 [SDL_SCANCODE_F8] = 0x0A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
701 [SDL_SCANCODE_F9] = 0x01, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
702 [SDL_SCANCODE_F10] = 0x09, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
703 [SDL_SCANCODE_F11] = 0x78, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
704 [SDL_SCANCODE_F12] = 0x07, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
705 [SDL_SCANCODE_LCTRL] = 0x14, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
706 [SDL_SCANCODE_LSHIFT] = 0x12, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
707 [SDL_SCANCODE_LALT] = 0x11, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
708 [SDL_SCANCODE_RCTRL] = 0x18, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
709 [SDL_SCANCODE_RSHIFT] = 0x59, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
710 [SDL_SCANCODE_RALT] = 0x17, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
711 [SDL_SCANCODE_INSERT] = 0x81, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
712 [SDL_SCANCODE_PAUSE] = 0x82, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
713 [SDL_SCANCODE_PRINTSCREEN] = 0x84, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
714 [SDL_SCANCODE_SCROLLLOCK] = 0x7E, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
715 [SDL_SCANCODE_DELETE] = 0x85, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
716 [SDL_SCANCODE_LEFT] = 0x86, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
717 [SDL_SCANCODE_HOME] = 0x87, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
718 [SDL_SCANCODE_END] = 0x88, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
719 [SDL_SCANCODE_UP] = 0x89, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
720 [SDL_SCANCODE_DOWN] = 0x8A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
721 [SDL_SCANCODE_PAGEUP] = 0x8B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
722 [SDL_SCANCODE_PAGEDOWN] = 0x8C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
723 [SDL_SCANCODE_RIGHT] = 0x8D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
724 [SDL_SCANCODE_NUMLOCKCLEAR] = 0x77, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
725 [SDL_SCANCODE_KP_DIVIDE] = 0x80, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
726 [SDL_SCANCODE_KP_MULTIPLY] = 0x7C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
727 [SDL_SCANCODE_KP_MINUS] = 0x7B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
728 [SDL_SCANCODE_KP_PLUS] = 0x79, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
729 [SDL_SCANCODE_KP_ENTER] = 0x19, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
730 [SDL_SCANCODE_KP_1] = 0x69, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
731 [SDL_SCANCODE_KP_2] = 0x72, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
732 [SDL_SCANCODE_KP_3] = 0x7A, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
733 [SDL_SCANCODE_KP_4] = 0x6B, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
734 [SDL_SCANCODE_KP_5] = 0x73, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
735 [SDL_SCANCODE_KP_6] = 0x74, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
736 [SDL_SCANCODE_KP_7] = 0x6C, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
737 [SDL_SCANCODE_KP_8] = 0x75, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
738 [SDL_SCANCODE_KP_9] = 0x7D, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
739 [SDL_SCANCODE_KP_0] = 0x70, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
740 [SDL_SCANCODE_KP_PERIOD] = 0x71, |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
741 }; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
742 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
743 static drop_handler drag_drop_handler; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
744 void render_set_drag_drop_handler(drop_handler handler) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
745 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
746 drag_drop_handler = handler; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
747 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
748 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
749 static event_handler custom_event_handler; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
750 void render_set_event_handler(event_handler handler) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
751 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
752 custom_event_handler = handler; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
753 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
754 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
755 static int find_joystick_index(SDL_JoystickID instanceID) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
756 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
757 for (int i = 0; i < MAX_JOYSTICKS; i++) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
758 if (joysticks[i] && SDL_JoystickInstanceID(joysticks[i]) == instanceID) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
759 return i; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
760 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
761 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
762 return -1; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
763 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
764 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
765 static int lowest_unused_joystick_index() |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
766 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
767 for (int i = 0; i < MAX_JOYSTICKS; i++) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
768 if (!joysticks[i]) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
769 return i; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
770 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
771 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
772 return -1; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
773 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
774 |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
775 static uint32_t overscan_top[NUM_VID_STD] = {2, 21}; |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
776 static uint32_t overscan_bot[NUM_VID_STD] = {1, 17}; |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
777 static uint32_t overscan_left[NUM_VID_STD] = {13, 13}; |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
778 static uint32_t overscan_right[NUM_VID_STD] = {14, 14}; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
779 static vid_std video_standard = VID_NTSC; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
780 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
781 static int32_t handle_event(SDL_Event *event) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
782 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
783 if (custom_event_handler) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
784 custom_event_handler(event); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
785 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
786 switch (event->type) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
787 case SDL_KEYDOWN: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
788 handle_keydown(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
789 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
790 case SDL_KEYUP: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
791 handle_keyup(event->key.keysym.sym, scancode_map[event->key.keysym.scancode]); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
792 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
793 case SDL_JOYBUTTONDOWN: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
794 handle_joydown(find_joystick_index(event->jbutton.which), event->jbutton.button); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
795 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
796 case SDL_JOYBUTTONUP: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
797 handle_joyup(find_joystick_index(event->jbutton.which), event->jbutton.button); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
798 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
799 case SDL_JOYHATMOTION: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
800 handle_joy_dpad(find_joystick_index(event->jbutton.which), event->jhat.hat, event->jhat.value); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
801 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
802 case SDL_JOYAXISMOTION: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
803 handle_joy_axis(find_joystick_index(event->jaxis.which), event->jaxis.axis, event->jaxis.value); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
804 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
805 case SDL_JOYDEVICEADDED: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
806 if (event->jdevice.which < MAX_JOYSTICKS) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
807 int index = lowest_unused_joystick_index(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
808 if (index >= 0) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
809 SDL_Joystick * joy = joysticks[index] = SDL_JoystickOpen(event->jdevice.which); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
810 joystick_sdl_index[index] = event->jdevice.which; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
811 if (joy) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
812 printf("Joystick %d added: %s\n", index, SDL_JoystickName(joy)); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
813 printf("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
814 handle_joy_added(index); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
815 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
816 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
817 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
818 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
819 case SDL_JOYDEVICEREMOVED: { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
820 int index = find_joystick_index(event->jdevice.which); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
821 if (index >= 0) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
822 SDL_JoystickClose(joysticks[index]); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
823 joysticks[index] = NULL; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
824 printf("Joystick %d removed\n", index); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
825 } else { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
826 printf("Failed to find removed joystick with instance ID: %d\n", index); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
827 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
828 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
829 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
830 case SDL_MOUSEMOTION: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
831 handle_mouse_moved(event->motion.which, event->motion.x, event->motion.y + overscan_top[video_standard], event->motion.xrel, event->motion.yrel); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
832 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
833 case SDL_MOUSEBUTTONDOWN: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
834 handle_mousedown(event->button.which, event->button.button); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
835 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
836 case SDL_MOUSEBUTTONUP: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
837 handle_mouseup(event->button.which, event->button.button); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
838 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
839 case SDL_WINDOWEVENT: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
840 switch (event->window.event) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
841 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
842 case SDL_WINDOWEVENT_SIZE_CHANGED: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
843 main_width = event->window.data1; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
844 main_height = event->window.data2; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
845 update_aspect(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
846 #ifndef DISABLE_OPENGL |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
847 if (render_gl) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
848 if (on_context_destroyed) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
849 on_context_destroyed(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
850 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
851 SDL_GL_DeleteContext(main_context); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
852 main_context = SDL_GL_CreateContext(main_window); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
853 gl_setup(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
854 if (on_context_created) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
855 on_context_created(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
856 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
857 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
858 #endif |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
859 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
860 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
861 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
862 case SDL_DROPFILE: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
863 if (drag_drop_handler) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
864 drag_drop_handler(event->drop.file); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
865 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
866 SDL_free(event->drop.file); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
867 break; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
868 case SDL_QUIT: |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
869 puts(""); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
870 exit(0); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
871 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
872 return 0; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
873 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
874 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
875 static void drain_events() |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
876 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
877 SDL_Event event; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
878 while(SDL_PollEvent(&event)) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
879 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
880 handle_event(&event); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
881 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
882 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
883 |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
884 static char *vid_std_names[NUM_VID_STD] = {"ntsc", "pal"}; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
885 static int display_hz; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
886 static int source_hz; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
887 static int source_frame; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
888 static int source_frame_count; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
889 static int frame_repeat[60]; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
890 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
891 static void init_audio() |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
892 { |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
893 SDL_AudioSpec desired, actual; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
894 char * rate_str = tern_find_path(config, "audio\0rate\0", TVAL_PTR).ptrval; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
895 int rate = rate_str ? atoi(rate_str) : 0; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
896 if (!rate) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
897 rate = 48000; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
898 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
899 desired.freq = rate; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
900 desired.format = AUDIO_S16SYS; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
901 desired.channels = 2; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
902 char * samples_str = tern_find_path(config, "audio\0buffer\0", TVAL_PTR).ptrval; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
903 int samples = samples_str ? atoi(samples_str) : 0; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
904 if (!samples) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
905 samples = 512; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
906 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
907 printf("config says: %d\n", samples); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
908 desired.samples = samples*2; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
909 desired.callback = sync_to_audio ? audio_callback : audio_callback_drc; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
910 desired.userdata = NULL; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
911 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
912 if (SDL_OpenAudio(&desired, &actual) < 0) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
913 fatal_error("Unable to open SDL audio: %s\n", SDL_GetError()); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
914 } |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
915 buffer_samples = actual.samples; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
916 sample_rate = actual.freq; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
917 printf("Initialized audio at frequency %d with a %d sample buffer, ", actual.freq, actual.samples); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
918 if (actual.format == AUDIO_S16SYS) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
919 puts("signed 16-bit int format"); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
920 mix = mix_s16; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
921 } else if (actual.format == AUDIO_F32SYS) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
922 puts("32-bit float format"); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
923 mix = mix_f32; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
924 } else { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
925 printf("unsupported format %X\n", actual.format); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
926 warning("Unsupported audio sample format: %X\n", actual.format); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
927 mix = mix_null; |
1402
458df351af06
Allow height to be specified in the config file and properly calculate from the aspect setting if it is not specified
Michael Pavone <pavone@retrodev.com>
parents:
1398
diff
changeset
|
928 } |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
929 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
930 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
931 void window_setup(void) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
932 { |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
933 uint32_t flags = SDL_WINDOW_RESIZABLE; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
934 if (is_fullscreen) { |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
935 flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
936 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
937 |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
938 tern_val def = {.ptrval = "video"}; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
939 char *sync_src = tern_find_path_default(config, "system\0sync_source\0", def, TVAL_PTR).ptrval; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
940 sync_to_audio = !strcmp(sync_src, "audio"); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
941 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
942 const char *vsync; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
943 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
944 def.ptrval = "off"; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
945 vsync = tern_find_path_default(config, "video\0vsync\0", def, TVAL_PTR).ptrval; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
946 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
947 vsync = "on"; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
948 } |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
949 |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
950 tern_node *video = tern_find_node(config, "video"); |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
951 if (video) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
952 { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
953 for (int i = 0; i < NUM_VID_STD; i++) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
954 { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
955 tern_node *std_settings = tern_find_node(video, vid_std_names[i]); |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
956 if (std_settings) { |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
957 char *val = tern_find_path_default(std_settings, "overscan\0top\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
958 if (val) { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
959 overscan_top[i] = atoi(val); |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
960 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
961 val = tern_find_path_default(std_settings, "overscan\0bottom\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
962 if (val) { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
963 overscan_bot[i] = atoi(val); |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
964 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
965 val = tern_find_path_default(std_settings, "overscan\0left\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
966 if (val) { |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
967 overscan_left[i] = atoi(val); |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
968 } |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
969 val = tern_find_path_default(std_settings, "overscan\0right\0", (tern_val){.ptrval = NULL}, TVAL_PTR).ptrval; |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
970 if (val) { |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
971 overscan_right[i] = atoi(val); |
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
972 } |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
973 } |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
974 } |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
975 } |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
976 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
977 #ifndef DISABLE_OPENGL |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
978 char *gl_enabled_str = tern_find_path_default(config, "video\0gl\0", def, TVAL_PTR).ptrval; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
979 uint8_t gl_enabled = strcmp(gl_enabled_str, "off") != 0; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
980 if (gl_enabled) |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
981 { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
982 flags |= SDL_WINDOW_OPENGL; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
983 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
984 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
985 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
986 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
987 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
988 } |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
989 #endif |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
990 main_window = SDL_CreateWindow(caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, main_width, main_height, flags); |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
991 if (!main_window) { |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
992 fatal_error("Unable to create SDL window: %s\n", SDL_GetError()); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
993 } |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
994 #ifndef DISABLE_OPENGL |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
995 if (gl_enabled) |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
996 { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
997 main_context = SDL_GL_CreateContext(main_window); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
998 GLenum res = glewInit(); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
999 if (res != GLEW_OK) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1000 warning("Initialization of GLEW failed with code %d\n", res); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1001 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1002 |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1003 if (res == GLEW_OK && GLEW_VERSION_2_0) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1004 render_gl = 1; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1005 if (!strcmp("tear", vsync)) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1006 if (SDL_GL_SetSwapInterval(-1) < 0) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1007 warning("late tear is not available (%s), using normal vsync\n", SDL_GetError()); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1008 vsync = "on"; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1009 } else { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1010 vsync = NULL; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1011 } |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1012 } |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1013 if (vsync) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1014 if (SDL_GL_SetSwapInterval(!strcmp("on", vsync)) < 0) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1015 warning("Failed to set vsync to %s: %s\n", vsync, SDL_GetError()); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1016 } |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1017 } |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1018 } else { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1019 warning("OpenGL 2.0 is unavailable, falling back to SDL2 renderer\n"); |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1020 } |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1021 } |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1022 if (!render_gl) { |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1023 #endif |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1024 flags = SDL_RENDERER_ACCELERATED; |
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1025 if (!strcmp("on", vsync) || !strcmp("tear", vsync)) { |
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1026 flags |= SDL_RENDERER_PRESENTVSYNC; |
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1027 } |
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1028 main_renderer = SDL_CreateRenderer(main_window, -1, flags); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1029 |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
1030 if (!main_renderer) { |
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
1031 fatal_error("unable to create SDL renderer: %s\n", SDL_GetError()); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1032 } |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1033 main_clip.x = main_clip.y = 0; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1034 main_clip.w = main_width; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1035 main_clip.h = main_height; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1036 #ifndef DISABLE_OPENGL |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
1037 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
1038 #endif |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1039 |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1040 SDL_GetWindowSize(main_window, &main_width, &main_height); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1041 printf("Window created with size: %d x %d\n", main_width, main_height); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1042 update_aspect(); |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1043 render_alloc_surfaces(); |
1004
fc000f245cc8
Set vsync state based on config file rather than just using whatever the system decides for us.
Michael Pavone <pavone@retrodev.com>
parents:
1003
diff
changeset
|
1044 def.ptrval = "off"; |
1326
071e761bcdcf
Fix a deficiency in the way types were handled in my ternary tree. Fixes in which some paths that were constructed from a template with variables would sometimes get an extra garbage character thrown in
Michael Pavone <pavone@retrodev.com>
parents:
1268
diff
changeset
|
1045 scanlines = !strcmp(tern_find_path_default(config, "video\0scanlines\0", def, TVAL_PTR).ptrval, "on"); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1046 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1047 |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1048 void render_init(int width, int height, char * title, uint8_t fullscreen) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1049 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1050 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1051 fatal_error("Unable to init SDL: %s\n", SDL_GetError()); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1052 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1053 atexit(SDL_Quit); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1054 if (height <= 0) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1055 float aspect = config_aspect() > 0.0f ? config_aspect() : 4.0f/3.0f; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1056 height = ((float)width / aspect) + 0.5f; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1057 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1058 printf("width: %d, height: %d\n", width, height); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1059 windowed_width = width; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1060 windowed_height = height; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1061 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1062 SDL_DisplayMode mode; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1063 //TODO: Explicit multiple monitor support |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1064 SDL_GetCurrentDisplayMode(0, &mode); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1065 display_hz = mode.refresh_rate; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1066 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1067 if (fullscreen) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1068 //the SDL2 migration guide suggests setting width and height to 0 when using SDL_WINDOW_FULLSCREEN_DESKTOP |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1069 //but that doesn't seem to work right when using OpenGL, at least on Linux anyway |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1070 width = mode.w; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1071 height = mode.h; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1072 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1073 main_width = width; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1074 main_height = height; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1075 is_fullscreen = fullscreen; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1076 |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
1077 caption = title; |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1078 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1079 window_setup(); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1080 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1081 audio_mutex = SDL_CreateMutex(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1082 audio_ready = SDL_CreateCond(); |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1083 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1084 init_audio(); |
1355
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1085 |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1086 uint32_t db_size; |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1087 char *db_data = read_bundled_file("gamecontrollerdb.txt", &db_size); |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1088 if (db_data) { |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1089 int added = SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(db_data, db_size), 1); |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1090 free(db_data); |
1359
8c6d2ed3b959
Use printf rather than info_message for message about game controller mappings so it does not pop up a modal when not run from a terminal
Michael Pavone <pavone@retrodev.com>
parents:
1355
diff
changeset
|
1091 printf("Added %d game controller mappings from gamecontrollerdb.txt\n", added); |
1355
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1092 } |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1093 |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1094 SDL_JoystickEventState(SDL_ENABLE); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1095 |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1096 render_set_video_standard(VID_NTSC); |
874
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
1097 |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
1098 atexit(render_quit); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1099 } |
1573
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1100 #include<unistd.h> |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1101 static int in_toggle; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1102 void render_config_updated(void) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1103 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1104 uint8_t old_sync_to_audio = sync_to_audio; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1105 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1106 free_surfaces(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1107 #ifndef DISABLE_OPENGL |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1108 if (render_gl) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1109 if (on_context_destroyed) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1110 on_context_destroyed(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1111 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1112 SDL_GL_DeleteContext(main_context); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1113 } else { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1114 #endif |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1115 SDL_DestroyRenderer(main_renderer); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1116 #ifndef DISABLE_OPENGL |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1117 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1118 #endif |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1119 in_toggle = 1; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1120 SDL_DestroyWindow(main_window); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1121 drain_events(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1122 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1123 char *config_width = tern_find_path(config, "video\0width\0", TVAL_PTR).ptrval; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1124 if (config_width) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1125 windowed_width = atoi(config_width); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1126 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1127 char *config_height = tern_find_path(config, "video\0height\0", TVAL_PTR).ptrval; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1128 if (config_height) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1129 windowed_height = atoi(config_height); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1130 } else { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1131 float aspect = config_aspect() > 0.0f ? config_aspect() : 4.0f/3.0f; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1132 windowed_height = ((float)windowed_width / aspect) + 0.5f; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1133 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1134 char *config_fullscreen = tern_find_path(config, "video\0fullscreen\0", TVAL_PTR).ptrval; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1135 is_fullscreen = config_fullscreen && !strcmp("on", config_fullscreen); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1136 if (is_fullscreen) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1137 SDL_DisplayMode mode; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1138 //TODO: Multiple monitor support |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1139 SDL_GetCurrentDisplayMode(0, &mode); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1140 main_width = mode.w; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1141 main_height = mode.h; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1142 } else { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1143 main_width = windowed_width; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1144 main_height = windowed_height; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1145 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1146 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1147 window_setup(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1148 update_aspect(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1149 #ifndef DISABLE_OPENGL |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1150 //need to check render_gl again after window_setup as render option could have changed |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1151 if (render_gl && on_context_created) { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1152 on_context_created(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1153 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1154 #endif |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1155 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1156 SDL_CloseAudio(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1157 init_audio(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1158 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1159 double lowpass_cutoff = get_lowpass_cutoff(config); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1160 double rc = (1.0 / lowpass_cutoff) / (2.0 * M_PI); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1161 lock_audio(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1162 for (uint8_t i = 0; i < num_audio_sources; i++) |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1163 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1164 double alpha = audio_sources[i]->dt / (audio_sources[i]->dt + rc); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1165 int32_t lowpass_alpha = (int32_t)(((double)0x10000) * alpha); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1166 audio_sources[i]->lowpass_alpha = lowpass_alpha; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1167 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1168 unlock_audio(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1169 drain_events(); |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1170 in_toggle = 0; |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1171 } |
719
019d27995e32
Upgrade to SDL 2.0 and drop support for the non-OpenGL render path
Michael Pavone <pavone@retrodev.com>
parents:
655
diff
changeset
|
1172 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1173 SDL_Window *render_get_window(void) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1174 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1175 return main_window; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1176 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1177 |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1178 void render_set_video_standard(vid_std std) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1179 { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1180 video_standard = std; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1181 source_hz = std == VID_PAL ? 50 : 60; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1182 uint32_t max_repeat = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1183 if (abs(source_hz - display_hz) < 2) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1184 memset(frame_repeat, 0, sizeof(int)*display_hz); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1185 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1186 int inc = display_hz * 100000 / source_hz; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1187 int accum = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1188 int dst_frames = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1189 for (int src_frame = 0; src_frame < source_hz; src_frame++) |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1190 { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1191 frame_repeat[src_frame] = -1; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1192 accum += inc; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1193 while (accum > 100000) |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1194 { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1195 accum -= 100000; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1196 frame_repeat[src_frame]++; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1197 max_repeat = frame_repeat[src_frame] > max_repeat ? frame_repeat[src_frame] : max_repeat; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1198 dst_frames++; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1199 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1200 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1201 if (dst_frames != display_hz) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1202 frame_repeat[source_hz-1] += display_hz - dst_frames; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1203 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1204 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1205 source_frame = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1206 source_frame_count = frame_repeat[0]; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1207 //sync samples with audio thread approximately every 8 lines |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1208 sync_samples = 8 * sample_rate / (source_hz * (VID_PAL ? 313 : 262)); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1209 max_repeat++; |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1210 min_buffered = (((float)max_repeat * (float)sample_rate/(float)source_hz)/* / (float)buffer_samples*/);// + 0.9999; |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1211 //min_buffered *= buffer_samples; |
1565
61fafcbc2c38
Audio DRC now sounds good in both NTSC and PAL, just need to adjust constants to minimize latency without leading to dropouts
Michael Pavone <pavone@retrodev.com>
parents:
1564
diff
changeset
|
1212 printf("Min samples buffered before audio start: %d\n", min_buffered); |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1213 max_adjust = BASE_MAX_ADJUST / source_hz; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1214 } |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1215 |
874
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
1216 void render_update_caption(char *title) |
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
1217 { |
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
1218 caption = title; |
1068
624696318b5b
Fix a memory corruption bug from failing to grow the buffer for the window caption when switching games
Michael Pavone <pavone@retrodev.com>
parents:
1033
diff
changeset
|
1219 free(fps_caption); |
624696318b5b
Fix a memory corruption bug from failing to grow the buffer for the window caption when switching games
Michael Pavone <pavone@retrodev.com>
parents:
1033
diff
changeset
|
1220 fps_caption = NULL; |
874
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
1221 } |
b6842dfb8edf
ROM is now run after being selected in menu. Initial path for menu is read from config file.
Michael Pavone <pavone@retrodev.com>
parents:
816
diff
changeset
|
1222 |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1223 static char *screenshot_path; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1224 void render_save_screenshot(char *path) |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1225 { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1226 if (screenshot_path) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1227 free(screenshot_path); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1228 } |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1229 screenshot_path = path; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1230 } |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1231 |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1232 uint32_t *locked_pixels; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1233 uint32_t locked_pitch; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1234 uint32_t *render_get_framebuffer(uint8_t which, int *pitch) |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1235 { |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1236 #ifndef DISABLE_OPENGL |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1237 if (render_gl && which <= FRAMEBUFFER_EVEN) { |
1267
3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
Michael Pavone <pavone@retrodev.com>
parents:
1263
diff
changeset
|
1238 *pitch = LINEBUF_SIZE * sizeof(uint32_t); |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1239 return texture_buf; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1240 } else { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1241 #endif |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1242 if (which >= num_textures) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1243 warning("Request for invalid framebuffer number %d\n", which); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1244 return NULL; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1245 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1246 void *pixels; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1247 if (SDL_LockTexture(sdl_textures[which], NULL, &pixels, pitch) < 0) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1248 warning("Failed to lock texture: %s\n", SDL_GetError()); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1249 return NULL; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1250 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1251 static uint8_t last; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1252 if (which <= FRAMEBUFFER_EVEN) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1253 locked_pixels = pixels; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1254 if (which == FRAMEBUFFER_EVEN) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1255 pixels += *pitch; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1256 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1257 locked_pitch = *pitch; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1258 if (which != last) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1259 *pitch *= 2; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1260 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1261 last = which; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1262 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1263 return pixels; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1264 #ifndef DISABLE_OPENGL |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1265 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1266 #endif |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1267 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
1268 |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1269 uint8_t events_processed; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1270 #ifdef __ANDROID__ |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1271 #define FPS_INTERVAL 10000 |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1272 #else |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1273 #define FPS_INTERVAL 1000 |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1274 #endif |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1275 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1276 static uint32_t last_width, last_height; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1277 static uint8_t interlaced; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1278 void render_framebuffer_updated(uint8_t which, int width) |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1279 { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1280 static uint8_t last; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1281 if (!sync_to_audio && which <= FRAMEBUFFER_EVEN && source_frame_count < 0) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1282 source_frame++; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1283 if (source_frame >= source_hz) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1284 source_frame = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1285 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1286 source_frame_count = frame_repeat[source_frame]; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1287 //TODO: Figure out what to do about SDL Render API texture locking |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1288 return; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1289 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1290 |
1398
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1291 last_width = width; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1292 uint32_t height = which <= FRAMEBUFFER_EVEN |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1293 ? (video_standard == VID_NTSC ? 243 : 294) - (overscan_top[video_standard] + overscan_bot[video_standard]) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1294 : 240; |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1295 FILE *screenshot_file = NULL; |
1336
baaf05fd64c4
Make internal screenshot functionality completely ignore overscan settings rather than only doing it for the height
Michael Pavone <pavone@retrodev.com>
parents:
1328
diff
changeset
|
1296 uint32_t shot_height, shot_width; |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1297 char *ext; |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1298 if (screenshot_path && which == FRAMEBUFFER_ODD) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1299 screenshot_file = fopen(screenshot_path, "wb"); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1300 if (screenshot_file) { |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1301 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1302 ext = path_extension(screenshot_path); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1303 #endif |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1304 info_message("Saving screenshot to %s\n", screenshot_path); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1305 } else { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1306 warning("Failed to open screenshot file %s for writing\n", screenshot_path); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1307 } |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1308 free(screenshot_path); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1309 screenshot_path = NULL; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1310 shot_height = video_standard == VID_NTSC ? 243 : 294; |
1336
baaf05fd64c4
Make internal screenshot functionality completely ignore overscan settings rather than only doing it for the height
Michael Pavone <pavone@retrodev.com>
parents:
1328
diff
changeset
|
1311 shot_width = width; |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1312 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1313 interlaced = last != which; |
1336
baaf05fd64c4
Make internal screenshot functionality completely ignore overscan settings rather than only doing it for the height
Michael Pavone <pavone@retrodev.com>
parents:
1328
diff
changeset
|
1314 width -= overscan_left[video_standard] + overscan_right[video_standard]; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1315 #ifndef DISABLE_OPENGL |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1316 if (render_gl && which <= FRAMEBUFFER_EVEN) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1317 glBindTexture(GL_TEXTURE_2D, textures[which]); |
1268
eca01056a915
Width on glTexSubImage2D call in render_framebuffer_updated needs to match the buffer pitch
Michael Pavone <pavone@retrodev.com>
parents:
1267
diff
changeset
|
1318 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, LINEBUF_SIZE, height, GL_BGRA, GL_UNSIGNED_BYTE, texture_buf + overscan_left[video_standard] + LINEBUF_SIZE * overscan_top[video_standard]); |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1319 |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1320 if (screenshot_file) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1321 //properly supporting interlaced modes here is non-trivial, so only save the odd field for now |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1322 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1323 if (!strcasecmp(ext, "png")) { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1324 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1325 save_png(screenshot_file, texture_buf, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1326 } else { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1327 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1328 #endif |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1329 save_ppm(screenshot_file, texture_buf, shot_width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1330 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1331 } |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1332 #endif |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1333 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1334 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1335 #endif |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1336 if (which <= FRAMEBUFFER_EVEN && last != which) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1337 uint8_t *cur_dst = (uint8_t *)locked_pixels; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1338 uint8_t *cur_saved = (uint8_t *)texture_buf; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1339 uint32_t dst_off = which == FRAMEBUFFER_EVEN ? 0 : locked_pitch; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1340 uint32_t src_off = which == FRAMEBUFFER_EVEN ? locked_pitch : 0; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1341 for (int i = 0; i < height; ++i) |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1342 { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1343 //copy saved line from other field |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1344 memcpy(cur_dst + dst_off, cur_saved, locked_pitch); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1345 //save line from this field to buffer for next frame |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1346 memcpy(cur_saved, cur_dst + src_off, locked_pitch); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1347 cur_dst += locked_pitch * 2; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1348 cur_saved += locked_pitch; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1349 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1350 height = 480; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1351 } |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1352 if (screenshot_file) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1353 uint32_t shot_pitch = locked_pitch; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1354 if (which == FRAMEBUFFER_EVEN) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1355 shot_height *= 2; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1356 } else { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1357 shot_pitch *= 2; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1358 } |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1359 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1360 if (!strcasecmp(ext, "png")) { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1361 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1362 save_png(screenshot_file, locked_pixels, shot_width, shot_height, shot_pitch); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1363 } else { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1364 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1365 #endif |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1366 save_ppm(screenshot_file, locked_pixels, shot_width, shot_height, shot_pitch); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1367 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1368 } |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1369 #endif |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1370 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1371 SDL_UnlockTexture(sdl_textures[which]); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1372 #ifndef DISABLE_OPENGL |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1373 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
1374 #endif |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1375 last_height = height; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1376 render_update_display(); |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1377 if (screenshot_file) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1378 fclose(screenshot_file); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1379 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1380 if (which <= FRAMEBUFFER_EVEN) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1381 last = which; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1382 static uint32_t frame_counter, start; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1383 frame_counter++; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1384 last_frame= SDL_GetTicks(); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1385 if ((last_frame - start) > FPS_INTERVAL) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1386 if (start && (last_frame-start)) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1387 #ifdef __ANDROID__ |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1388 info_message("%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1389 #else |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1390 if (!fps_caption) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1391 fps_caption = malloc(strlen(caption) + strlen(" - 100000000.1 fps") + 1); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1392 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1393 sprintf(fps_caption, "%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1394 SDL_SetWindowTitle(main_window, fps_caption); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1395 #endif |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1396 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1397 start = last_frame; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1398 frame_counter = 0; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1399 } |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1400 } |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1401 if (!sync_to_audio) { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1402 int32_t local_cur_min, local_min_remaining; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1403 SDL_LockAudio(); |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1404 if (last_buffered > NO_LAST_BUFFERED) { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1405 average_change *= 0.9f; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1406 average_change += (cur_min_buffered - last_buffered) * 0.1f; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1407 } |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1408 local_cur_min = cur_min_buffered; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1409 local_min_remaining = min_remaining_buffer; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1410 last_buffered = cur_min_buffered; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1411 SDL_UnlockAudio(); |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1412 float frames_to_problem; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1413 if (average_change < 0) { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1414 frames_to_problem = (float)local_cur_min / -average_change; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1415 } else { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1416 frames_to_problem = (float)local_min_remaining / average_change; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1417 } |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1418 float adjust_ratio = 0.0f; |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1419 if ( |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1420 frames_to_problem < BUFFER_FRAMES_THRESHOLD |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1421 || (average_change < 0 && local_cur_min < 3*min_buffered / 4) |
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1422 || (average_change >0 && local_cur_min > 5 * min_buffered / 4) |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1423 ) { |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1424 |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1425 if (cur_min_buffered < 0) { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1426 adjust_ratio = max_adjust; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1427 SDL_PauseAudio(1); |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1428 last_buffered = NO_LAST_BUFFERED; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1429 } else { |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1430 adjust_ratio = -1.0 * average_change / ((float)sample_rate / (float)source_hz); |
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1431 adjust_ratio /= 2.5 * source_hz; |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1432 if (fabsf(adjust_ratio) > max_adjust) { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1433 adjust_ratio = adjust_ratio > 0 ? max_adjust : -max_adjust; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1434 } |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1435 } |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1436 } else if (local_cur_min < min_buffered / 2) { |
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1437 adjust_ratio = max_adjust; |
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1438 } |
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1439 if (adjust_ratio != 0.0f) { |
1566
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1440 average_change = 0; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1441 for (uint8_t i = 0; i < num_audio_sources; i++) |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1442 { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1443 audio_sources[i]->buffer_inc = ((double)audio_sources[i]->buffer_inc) + ((double)audio_sources[i]->buffer_inc) * adjust_ratio + 0.5; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1444 } |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1445 } |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1446 while (source_frame_count > 0) |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1447 { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1448 render_update_display(); |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1449 source_frame_count--; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1450 } |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1451 source_frame++; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1452 if (source_frame >= source_hz) { |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1453 source_frame = 0; |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1454 } |
cbb40af77a94
Moved resample rate adjustment to after frame flip rather than in audio callback as it makes more sense there. Needs adjustment to avoid audible pitch changes
Michael Pavone <pavone@retrodev.com>
parents:
1565
diff
changeset
|
1455 source_frame_count = frame_repeat[source_frame]; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1456 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1457 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1458 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1459 static ui_render_fun render_ui; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1460 void render_set_ui_render_fun(ui_render_fun fun) |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1461 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1462 render_ui = fun; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1463 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1464 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1465 void render_update_display() |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1466 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1467 #ifndef DISABLE_OPENGL |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1468 if (render_gl) { |
1528
855210dca5b9
Set glClearColor back to black
Michael Pavone <pavone@retrodev.com>
parents:
1483
diff
changeset
|
1469 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1470 glClear(GL_COLOR_BUFFER_BIT); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1471 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1472 glUseProgram(program); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1473 glActiveTexture(GL_TEXTURE0); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1474 glBindTexture(GL_TEXTURE_2D, textures[0]); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1475 glUniform1i(un_textures[0], 0); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1476 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1477 glActiveTexture(GL_TEXTURE1); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1478 glBindTexture(GL_TEXTURE_2D, textures[interlaced ? 1 : scanlines ? 2 : 0]); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1479 glUniform1i(un_textures[1], 1); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1480 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1481 glUniform1f(un_width, render_emulated_width()); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1482 glUniform1f(un_height, last_height); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1483 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1484 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1485 glVertexAttribPointer(at_pos, 2, GL_FLOAT, GL_FALSE, sizeof(GLfloat[2]), (void *)0); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1486 glEnableVertexAttribArray(at_pos); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1487 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1488 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1489 glDrawElements(GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_SHORT, (void *)0); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1490 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1491 glDisableVertexAttribArray(at_pos); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1492 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1493 if (render_ui) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1494 render_ui(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1495 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1496 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1497 SDL_GL_SwapWindow(main_window); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1498 } else { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1499 #endif |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1500 SDL_Rect src_clip = { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1501 .x = overscan_left[video_standard], |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1502 .y = overscan_top[video_standard], |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1503 .w = render_emulated_width(), |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1504 .h = last_height |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1505 }; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1506 SDL_SetRenderDrawColor(main_renderer, 0, 0, 0, 255); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1507 SDL_RenderClear(main_renderer); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1508 SDL_RenderCopy(main_renderer, sdl_textures[FRAMEBUFFER_ODD], &src_clip, &main_clip); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1509 if (render_ui) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1510 render_ui(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1511 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1512 SDL_RenderPresent(main_renderer); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1513 #ifndef DISABLE_OPENGL |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1514 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1515 #endif |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1516 if (!events_processed) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1517 process_events(); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1518 } |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1519 events_processed = 0; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1520 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1521 |
1398
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1522 uint32_t render_emulated_width() |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1523 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1524 return last_width - overscan_left[video_standard] - overscan_right[video_standard]; |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1525 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1526 |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1527 uint32_t render_emulated_height() |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1528 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1529 return (video_standard == VID_NTSC ? 243 : 294) - overscan_top[video_standard] - overscan_bot[video_standard]; |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1530 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1531 |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1532 uint32_t render_overscan_left() |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1533 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1534 return overscan_left[video_standard]; |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1535 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1536 |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1537 uint32_t render_overscan_top() |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1538 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1539 return overscan_top[video_standard]; |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1540 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1541 |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
1542 void render_wait_quit(vdp_context * context) |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1543 { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1544 SDL_Event event; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1545 while(SDL_WaitEvent(&event)) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1546 switch (event.type) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1547 case SDL_QUIT: |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1548 return; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1549 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1550 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1551 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1552 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1553 int32_t render_translate_input_name(int32_t controller, char *name, uint8_t is_axis) |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1554 { |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1555 static tern_node *button_lookup, *axis_lookup; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1556 if (controller > MAX_JOYSTICKS || !joysticks[controller]) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1557 return RENDER_NOT_PLUGGED_IN; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1558 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1559 |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1560 if (!SDL_IsGameController(joystick_sdl_index[controller])) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1561 return RENDER_NOT_MAPPED; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1562 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1563 SDL_GameController *control = SDL_GameControllerOpen(joystick_sdl_index[controller]); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1564 if (!control) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1565 warning("Failed to open game controller %d: %s\n", controller, SDL_GetError()); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1566 return RENDER_NOT_PLUGGED_IN; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1567 } |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1568 |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1569 SDL_GameControllerButtonBind cbind; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1570 if (is_axis) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1571 if (!axis_lookup) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1572 for (int i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1573 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1574 axis_lookup = tern_insert_int(axis_lookup, SDL_GameControllerGetStringForAxis(i), i); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1575 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1576 //alternative Playstation-style names |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1577 axis_lookup = tern_insert_int(axis_lookup, "l2", SDL_CONTROLLER_AXIS_TRIGGERLEFT); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1578 axis_lookup = tern_insert_int(axis_lookup, "r2", SDL_CONTROLLER_AXIS_TRIGGERRIGHT); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1579 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1580 intptr_t sdl_axis = tern_find_int(axis_lookup, name, SDL_CONTROLLER_AXIS_INVALID); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1581 if (sdl_axis == SDL_CONTROLLER_AXIS_INVALID) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1582 SDL_GameControllerClose(control); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1583 return RENDER_INVALID_NAME; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1584 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1585 cbind = SDL_GameControllerGetBindForAxis(control, sdl_axis); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1586 } else { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1587 if (!button_lookup) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1588 for (int i = SDL_CONTROLLER_BUTTON_A; i < SDL_CONTROLLER_BUTTON_MAX; i++) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1589 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1590 button_lookup = tern_insert_int(button_lookup, SDL_GameControllerGetStringForButton(i), i); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1591 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1592 //alternative Playstation-style names |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1593 button_lookup = tern_insert_int(button_lookup, "cross", SDL_CONTROLLER_BUTTON_A); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1594 button_lookup = tern_insert_int(button_lookup, "circle", SDL_CONTROLLER_BUTTON_B); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1595 button_lookup = tern_insert_int(button_lookup, "square", SDL_CONTROLLER_BUTTON_X); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1596 button_lookup = tern_insert_int(button_lookup, "triangle", SDL_CONTROLLER_BUTTON_Y); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1597 button_lookup = tern_insert_int(button_lookup, "share", SDL_CONTROLLER_BUTTON_BACK); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1598 button_lookup = tern_insert_int(button_lookup, "select", SDL_CONTROLLER_BUTTON_BACK); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1599 button_lookup = tern_insert_int(button_lookup, "options", SDL_CONTROLLER_BUTTON_START); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1600 button_lookup = tern_insert_int(button_lookup, "l1", SDL_CONTROLLER_BUTTON_LEFTSHOULDER); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1601 button_lookup = tern_insert_int(button_lookup, "r1", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1602 button_lookup = tern_insert_int(button_lookup, "l3", SDL_CONTROLLER_BUTTON_LEFTSTICK); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1603 button_lookup = tern_insert_int(button_lookup, "r3", SDL_CONTROLLER_BUTTON_RIGHTSTICK); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1604 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1605 intptr_t sdl_button = tern_find_int(button_lookup, name, SDL_CONTROLLER_BUTTON_INVALID); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1606 if (sdl_button == SDL_CONTROLLER_BUTTON_INVALID) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1607 SDL_GameControllerClose(control); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1608 return RENDER_INVALID_NAME; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1609 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1610 cbind = SDL_GameControllerGetBindForButton(control, sdl_button); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1611 } |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1612 SDL_GameControllerClose(control); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1613 switch (cbind.bindType) |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1614 { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1615 case SDL_CONTROLLER_BINDTYPE_BUTTON: |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1616 return cbind.value.button; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1617 case SDL_CONTROLLER_BINDTYPE_AXIS: |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1618 return RENDER_AXIS_BIT | cbind.value.axis; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1619 case SDL_CONTROLLER_BINDTYPE_HAT: |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1620 return RENDER_DPAD_BIT | (cbind.value.hat.hat << 4) | cbind.value.hat.hat_mask; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1621 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1622 return RENDER_NOT_MAPPED; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1623 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1624 |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1625 int32_t render_dpad_part(int32_t input) |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1626 { |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1627 return input >> 4 & 0xFFFFFF; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1628 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1629 |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1630 uint8_t render_direction_part(int32_t input) |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1631 { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1632 return input & 0xF; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1633 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1634 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1635 int32_t render_axis_part(int32_t input) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1636 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1637 return input & 0xFFFFFFF; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1638 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1639 |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
1640 void process_events() |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
1641 { |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1642 if (events_processed > MAX_EVENT_POLL_PER_FRAME) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1643 return; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1074
diff
changeset
|
1644 } |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1645 drain_events(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1646 events_processed++; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1647 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1648 |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1649 #define TOGGLE_MIN_DELAY 250 |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1650 void render_toggle_fullscreen() |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1651 { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1652 //protect against event processing causing us to attempt to toggle while still toggling |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1653 if (in_toggle) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1654 return; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1655 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1656 in_toggle = 1; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1657 |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1658 //toggling too fast seems to cause a deadlock |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1659 static uint32_t last_toggle; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1660 uint32_t cur = SDL_GetTicks(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1661 if (last_toggle && cur - last_toggle < TOGGLE_MIN_DELAY) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1662 in_toggle = 0; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1663 return; |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
1664 } |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1665 last_toggle = cur; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1666 |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1667 drain_events(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1668 is_fullscreen = !is_fullscreen; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1669 if (is_fullscreen) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1670 SDL_DisplayMode mode; |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1671 //TODO: Multiple monitor support |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1672 SDL_GetCurrentDisplayMode(0, &mode); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1673 //In theory, the SDL2 docs suggest this is unnecessary |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1674 //but without it the OpenGL context remains the original size |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1675 //This needs to happen before the fullscreen transition to have any effect |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1676 //because SDL does not apply window size changes in fullscreen |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1677 SDL_SetWindowSize(main_window, mode.w, mode.h); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1678 } |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1679 SDL_SetWindowFullscreen(main_window, is_fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1680 //Since we change the window size on transition to full screen |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1681 //we need to set it back to normal so we can also go back to windowed mode |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1682 //normally you would think that this should only be done when actually transitioning |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1683 //but something is screwy in the guts of SDL (at least on Linux) and setting it each time |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1684 //is the only thing that seems to work reliably |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1685 //when we've just switched to fullscreen mode this should be harmless though |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1686 SDL_SetWindowSize(main_window, windowed_width, windowed_height); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1687 drain_events(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1198
diff
changeset
|
1688 in_toggle = 0; |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
1689 } |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
1690 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1691 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
|
1692 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1693 return buffer_samples; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1694 } |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1695 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1696 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
|
1697 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1698 return sample_rate; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1699 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1700 |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1701 void render_errorbox(char *title, char *message) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1702 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1703 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, NULL); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1704 } |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1705 |
792
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1706 void render_warnbox(char *title, char *message) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1707 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1708 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, title, message, NULL); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1709 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1710 |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1711 void render_infobox(char *title, char *message) |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1712 { |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1713 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, title, message, NULL); |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1714 } |
724bbec47f86
Use a new fatal_error function instead of calling fprintf and exit for fatal errors. This new function more gracefully handles the case in which BlastEm was not started from a terminal or disconnected from ther terminal (Windows).
Michael Pavone <pavone@retrodev.com>
parents:
766
diff
changeset
|
1715 |
1482
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1716 uint32_t render_elapsed_ms(void) |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1717 { |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1718 return SDL_GetTicks(); |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1719 } |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1720 |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1721 void render_sleep_ms(uint32_t delay) |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1722 { |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1723 return SDL_Delay(delay); |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1724 } |
2d203bf73dbd
Avoid burning a huge amount of CPU in the menu when emulation is not running and vsync is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1476
diff
changeset
|
1725 |
1483
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1726 uint8_t render_has_gl(void) |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1727 { |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1728 return render_gl; |
001120e91fed
Skip loading menu ROM if Nuklear UI is enabled. Allow disabling Nuklear UI in favor of old menu ROM both at compile time and in config. Fall back to ROM UI if GL is unavailable
Michael Pavone <pavone@retrodev.com>
parents:
1482
diff
changeset
|
1729 } |