Mercurial > repos > blastem
annotate render_sdl.c @ 1864:96323d73b8ab
add input descriptors
for remapping from the 'controls' menu
author | hizzlekizzle <hizzlekizzle@users.noreply.github.com> |
---|---|
date | Sun, 02 Jun 2019 23:16:15 -0700 |
parents | e07fc3d473b2 |
children | 4c322abd9fa5 |
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" |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
1580
diff
changeset
|
14 #include "bindings.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" |
1693
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
16 #include "paths.h" |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
17 #include "ppm.h" |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
18 #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
|
19 #include "config.h" |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
20 #include "controller_info.h" |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
22 #ifndef DISABLE_OPENGL |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
23 #ifdef USE_GLES |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
24 #include <SDL_opengles2.h> |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
25 #else |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
26 #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
|
27 #endif |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
28 #endif |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
29 |
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
|
30 #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
|
31 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
32 static SDL_Window *main_window; |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
33 static SDL_Window **extra_windows; |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
34 static SDL_Renderer *main_renderer; |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
35 static SDL_Renderer **extra_renderers; |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
36 static SDL_Texture **sdl_textures; |
1649
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
37 static window_close_handler *close_handlers; |
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 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
|
39 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
|
40 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
|
41 |
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
|
42 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
|
43 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
44 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
|
45 static uint8_t scanlines = 0; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
47 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
|
48 |
1684
b1d063466d03
Modified audio code to support an arbitrary number of output channels so that things aren't weird if SDL2 picks a number of channels other than what we ask for
Michael Pavone <pavone@retrodev.com>
parents:
1659
diff
changeset
|
49 static uint8_t output_channels; |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
50 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
|
51 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
|
52 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
57 struct audio_source { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
58 SDL_cond *cond; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
59 int16_t *front; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 uint64_t buffer_inc; |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
64 float gain_mult; |
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
|
65 uint32_t buffer_pos; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
66 uint32_t read_start; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
67 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
|
68 uint32_t lowpass_alpha; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 }; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
75 |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
76 static audio_source *audio_sources[8]; |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
77 static audio_source *inactive_audio_sources[8]; |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
78 static uint8_t num_audio_sources; |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
79 static uint8_t num_inactive_audio_sources; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
80 static uint8_t sync_to_audio; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
81 static uint32_t min_buffered; |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
82 static float overall_gain_mult, *mix_buf; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
83 static int sample_size; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
84 |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
85 typedef void (*conv_func)(float *samples, void *vstream, int sample_count); |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
86 |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
87 static void convert_null(float *samples, void *vstream, int sample_count) |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
88 { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
89 memset(vstream, 0, sample_count * sample_size); |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
90 } |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
91 |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
92 static void convert_s16(float *samples, void *vstream, int sample_count) |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
93 { |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
94 int16_t *stream = vstream; |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
95 for (int16_t *end = stream + sample_count; stream < end; stream++, samples++) |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
96 { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
97 float sample = *samples; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
98 int16_t out_sample; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
99 if (sample >= 1.0f) { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
100 out_sample = 0x7FFF; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
101 } else if (sample <= -1.0f) { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
102 out_sample = -0x8000; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
103 } else { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
104 out_sample = sample * 0x7FFF; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
105 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
106 *stream = out_sample; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
107 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
108 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
109 |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
110 static void clamp_f32(float *samples, void *vstream, int sample_count) |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
111 { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
112 for (; sample_count > 0; sample_count--, samples++) |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
113 { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
114 float sample = *samples; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
115 if (sample > 1.0f) { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
116 sample = 1.0f; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
117 } else if (sample < -1.0f) { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
118 sample = -1.0f; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
119 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
120 *samples = sample; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
121 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
122 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
123 |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
124 static int32_t mix_f32(audio_source *audio, float *stream, int samples) |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
125 { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
126 float *end = stream + samples; |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
127 int16_t *src = audio->front; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
128 uint32_t i = audio->read_start; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
129 uint32_t i_end = audio->read_end; |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
130 float *cur = stream; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
131 float gain_mult = audio->gain_mult * overall_gain_mult; |
1684
b1d063466d03
Modified audio code to support an arbitrary number of output channels so that things aren't weird if SDL2 picks a number of channels other than what we ask for
Michael Pavone <pavone@retrodev.com>
parents:
1659
diff
changeset
|
132 size_t first_add = output_channels > 1 ? 1 : 0, second_add = output_channels > 1 ? output_channels - 1 : 1; |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
133 if (audio->num_channels == 1) { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
134 while (cur < end && i != i_end) |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
135 { |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
136 *cur += gain_mult * ((float)src[i]) / 0x7FFF; |
1684
b1d063466d03
Modified audio code to support an arbitrary number of output channels so that things aren't weird if SDL2 picks a number of channels other than what we ask for
Michael Pavone <pavone@retrodev.com>
parents:
1659
diff
changeset
|
137 cur += first_add; |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
138 *cur += gain_mult * ((float)src[i++]) / 0x7FFF; |
1684
b1d063466d03
Modified audio code to support an arbitrary number of output channels so that things aren't weird if SDL2 picks a number of channels other than what we ask for
Michael Pavone <pavone@retrodev.com>
parents:
1659
diff
changeset
|
139 cur += second_add; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
140 i &= audio->mask; |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
141 } |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
142 } else { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
143 while(cur < end && i != i_end) |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
144 { |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
145 *cur += gain_mult * ((float)src[i++]) / 0x7FFF; |
1684
b1d063466d03
Modified audio code to support an arbitrary number of output channels so that things aren't weird if SDL2 picks a number of channels other than what we ask for
Michael Pavone <pavone@retrodev.com>
parents:
1659
diff
changeset
|
146 cur += first_add; |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
147 *cur += gain_mult * ((float)src[i++]) / 0x7FFF; |
1684
b1d063466d03
Modified audio code to support an arbitrary number of output channels so that things aren't weird if SDL2 picks a number of channels other than what we ask for
Michael Pavone <pavone@retrodev.com>
parents:
1659
diff
changeset
|
148 cur += second_add; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
149 i &= audio->mask; |
1552
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 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
152 if (!sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
153 audio->read_start = i; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
154 } |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
155 if (cur != end) { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
156 debug_message("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
|
157 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
|
158 } else { |
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
159 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
|
160 } |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
161 } |
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
162 |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
163 static conv_func convert; |
1552
13a82adb185b
Add support for float32 format audio samples
Michael Pavone <pavone@retrodev.com>
parents:
1551
diff
changeset
|
164 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
165 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
|
166 { |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
167 uint8_t num_populated; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
168 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
|
169 do { |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
170 num_populated = 0; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
171 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
|
172 { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
173 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
|
174 num_populated++; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
175 } |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
176 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
177 if (!quitting && num_populated < num_audio_sources) { |
1574
ade5b8148caa
Fix sync to audio option
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
178 fflush(stdout); |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
361
diff
changeset
|
179 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
|
180 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
181 } while(!quitting && num_populated < num_audio_sources); |
1797
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
182 int samples = len / sample_size; |
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
183 float *mix_dest = mix_buf ? mix_buf : (float *)byte_stream; |
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
184 memset(mix_dest, 0, samples * sizeof(float)); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
185 if (!quitting) { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
186 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
|
187 { |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
188 mix_f32(audio_sources[i], mix_dest, samples); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
189 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
|
190 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
|
191 } |
361 | 192 } |
1797
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
193 convert(mix_dest, byte_stream, samples); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
194 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
|
195 } |
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
|
196 |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
197 #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
|
198 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
|
199 static float average_change; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
200 #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
|
201 #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
|
202 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
|
203 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
|
204 static uint32_t min_remaining_buffer; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
205 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
|
206 { |
1589
780604a036e4
Limit underflow warning spam
Michael Pavone <pavone@retrodev.com>
parents:
1588
diff
changeset
|
207 if (cur_min_buffered < 0) { |
780604a036e4
Limit underflow warning spam
Michael Pavone <pavone@retrodev.com>
parents:
1588
diff
changeset
|
208 //underflow last frame, but main thread hasn't gotten a chance to call SDL_PauseAudio yet |
780604a036e4
Limit underflow warning spam
Michael Pavone <pavone@retrodev.com>
parents:
1588
diff
changeset
|
209 return; |
780604a036e4
Limit underflow warning spam
Michael Pavone <pavone@retrodev.com>
parents:
1588
diff
changeset
|
210 } |
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
|
211 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
|
212 min_remaining_buffer = 0xFFFFFFFF; |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
213 float *mix_dest = mix_buf ? mix_buf : (float *)byte_stream; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
214 int samples = len / sample_size; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
215 memset(mix_dest, 0, samples * sizeof(float)); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
216 for (uint8_t i = 0; i < num_audio_sources; i++) |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
217 { |
1564
48b08986bf8f
Mostly working dynamic rate control. Needs some tweaking, especially for PAL
Michael Pavone <pavone@retrodev.com>
parents:
1563
diff
changeset
|
218 |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
219 int32_t buffered = mix_f32(audio_sources[i], mix_dest, 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
|
220 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
|
221 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
|
222 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
|
223 } |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
224 convert(mix_dest, byte_stream, samples); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
225 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
226 |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
227 static void lock_audio() |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
228 { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
229 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
230 SDL_LockMutex(audio_mutex); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
231 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
232 SDL_LockAudio(); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
233 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
234 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
235 |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
236 static void unlock_audio() |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
237 { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
238 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
239 SDL_UnlockMutex(audio_mutex); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
240 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
241 SDL_UnlockAudio(); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
242 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
243 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
244 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
245 static void render_close_audio() |
361 | 246 { |
247 SDL_LockMutex(audio_mutex); | |
248 quitting = 1; | |
249 SDL_CondSignal(audio_ready); | |
250 SDL_UnlockMutex(audio_mutex); | |
251 SDL_CloseAudio(); | |
1797
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
252 if (mix_buf) { |
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
253 free(mix_buf); |
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
254 mix_buf = NULL; |
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
255 } |
361 | 256 } |
257 | |
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
|
258 #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
|
259 |
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 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
|
261 { |
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
|
262 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
|
263 } |
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 |
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 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
|
266 { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
267 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
|
268 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
|
269 lock_audio(); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
270 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
|
271 ret = malloc(sizeof(audio_source)); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
272 ret->back = malloc(alloc_size * sizeof(int16_t)); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
279 unlock_audio(); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
280 if (!ret) { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
281 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
|
282 } 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 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
|
290 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
|
291 ret->last_left = ret->last_right = 0; |
1574
ade5b8148caa
Fix sync to audio option
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
292 ret->read_start = 0; |
ade5b8148caa
Fix sync to audio option
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
293 ret->read_end = sync_to_audio ? buffer_samples * channels : 0; |
ade5b8148caa
Fix sync to audio option
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
294 ret->mask = sync_to_audio ? 0xFFFFFFFF : alloc_size-1; |
1799
ed6c38cd288c
Initialize gain_mult when creating an audio source so things work okay for clients that don't explicitly set the gain
Michael Pavone <pavone@retrodev.com>
parents:
1797
diff
changeset
|
295 ret->gain_mult = 1.0f; |
1574
ade5b8148caa
Fix sync to audio option
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
296 } |
ade5b8148caa
Fix sync to audio option
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
297 if (sync_to_audio && SDL_GetAudioStatus() == SDL_AUDIO_PAUSED) { |
ade5b8148caa
Fix sync to audio option
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
298 SDL_PauseAudio(0); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
299 } |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
300 return ret; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
301 } |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
302 |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
303 static float db_to_mult(float gain) |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
304 { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
305 return powf(10.0f, gain/20.0f); |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
306 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
307 |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
308 void render_audio_source_gaindb(audio_source *src, float gain) |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
309 { |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
310 src->gain_mult = db_to_mult(gain); |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
311 } |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
312 |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
313 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
|
314 { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
315 uint8_t need_pause = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
316 lock_audio(); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
317 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
|
318 { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
319 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
|
320 audio_sources[i] = audio_sources[--num_audio_sources]; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
321 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
322 SDL_CondSignal(audio_ready); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
323 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
324 break; |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
325 } |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
326 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
327 if (!num_audio_sources) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
328 need_pause = 1; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
329 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
330 unlock_audio(); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
331 if (need_pause) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
332 SDL_PauseAudio(1); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
333 } |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
334 inactive_audio_sources[num_inactive_audio_sources++] = src; |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
335 } |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
336 |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
337 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
|
338 { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
339 lock_audio(); |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
340 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
|
341 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
|
342 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
343 unlock_audio(); |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
344 for (uint8_t i = 0; i < num_inactive_audio_sources; i++) |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
345 { |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
346 if (inactive_audio_sources[i] == src) { |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
347 inactive_audio_sources[i] = inactive_audio_sources[--num_inactive_audio_sources]; |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
348 } |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
349 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
350 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
351 SDL_PauseAudio(0); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
352 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
353 } |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
354 |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
355 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
|
356 { |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
357 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
|
358 |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
359 free(src->front); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
360 if (sync_to_audio) { |
1588
348814d5b73f
Fix double free in sync to video mode
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
361 free(src->back); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
362 SDL_DestroyCond(src->cond); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
363 } |
1551
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
364 free(src); |
ce1f93be0104
Small cleanup to audio interface between emulation code and renderer backend
Michael Pavone <pavone@retrodev.com>
parents:
1534
diff
changeset
|
365 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
366 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
|
367 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
|
368 { |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
369 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
370 SDL_LockMutex(audio_mutex); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
371 while (src->front_populated) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
372 SDL_CondWait(src->cond, audio_mutex); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
373 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
374 int16_t *tmp = src->front; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
375 src->front = src->back; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
376 src->back = tmp; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
377 src->front_populated = 1; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
378 src->buffer_pos = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
379 SDL_CondSignal(audio_ready); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
380 SDL_UnlockMutex(audio_mutex); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
381 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
382 uint32_t num_buffered; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
383 SDL_LockAudio(); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
384 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
|
385 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
|
386 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
|
387 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
|
388 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
|
389 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
390 } |
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
|
391 } |
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
|
392 |
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 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
|
394 { |
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
|
395 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
|
396 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
|
397 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
|
398 } |
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
|
399 |
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
|
400 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
|
401 { |
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
|
402 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
|
403 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
|
404 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
|
405 } |
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
|
406 |
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
|
407 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
|
408 { |
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
|
409 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
|
410 src->buffer_fraction += src->buffer_inc; |
1574
ade5b8148caa
Fix sync to audio option
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
411 uint32_t base = sync_to_audio ? 0 : src->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
|
412 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
|
413 { |
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
|
414 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
|
415 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
|
416 |
1574
ade5b8148caa
Fix sync to audio option
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
417 if (((src->buffer_pos - base) & 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
|
418 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
|
419 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
420 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
|
421 } |
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
|
422 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
|
423 } |
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
|
424 |
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
|
425 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
|
426 { |
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
|
427 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
|
428 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
|
429 src->buffer_fraction += src->buffer_inc; |
1574
ade5b8148caa
Fix sync to audio option
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
430 uint32_t base = sync_to_audio ? 0 : src->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
|
431 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
|
432 { |
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
|
433 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
|
434 |
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
|
435 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
|
436 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
|
437 |
1574
ade5b8148caa
Fix sync to audio option
Michael Pavone <pavone@retrodev.com>
parents:
1573
diff
changeset
|
438 if (((src->buffer_pos - base) & 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
|
439 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
|
440 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
441 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
|
442 } |
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
|
443 src->last_left = left; |
1562
d7b0d0ce8ed1
Fix regression in right audio channel
Michael Pavone <pavone@retrodev.com>
parents:
1555
diff
changeset
|
444 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
|
445 } |
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
|
446 |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
447 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
|
448 static int joystick_sdl_index[MAX_JOYSTICKS]; |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
449 static uint8_t joystick_index_locked[MAX_JOYSTICKS]; |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
450 |
914
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
451 int render_width() |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
452 { |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
453 return main_width; |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
454 } |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
455 |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
456 int render_height() |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
457 { |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
458 return main_height; |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
459 } |
28ec32e720b2
Scale mouse data based on window size
Michael Pavone <pavone@retrodev.com>
parents:
907
diff
changeset
|
460 |
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
|
461 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
|
462 { |
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
|
463 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
|
464 } |
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
|
465 |
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
|
466 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
|
467 { |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
468 #ifdef USE_GLES |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
469 return 255 << 24 | b << 16 | g << 8 | r; |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
470 #else |
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
|
471 return 255 << 24 | r << 16 | g << 8 | b; |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
472 #endif |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
473 } |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
474 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
475 #ifndef DISABLE_OPENGL |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
476 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
|
477 |
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
|
478 static GLfloat vertex_data_default[] = { |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
479 -1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
480 1.0f, -1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
481 -1.0f, 1.0f, |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
482 1.0f, 1.0f |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
483 }; |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
484 |
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 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
|
486 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
487 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
|
488 |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
489 static const GLchar shader_prefix[] = |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
490 #ifdef USE_GLES |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
491 "#version 100\n"; |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
492 #else |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
493 "#version 110\n" |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
494 "#define lowp\n" |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
495 "#define mediump\n" |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
496 "#define highp\n"; |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
497 #endif |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
498 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
499 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
|
500 { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
501 char * shader_path; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
502 FILE *f; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
503 GLchar *text; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
504 long fsize; |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
505 #ifndef __ANDROID__ |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
506 char const * parts[] = {get_home_dir(), "/.config/blastem/shaders/", fname}; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
507 shader_path = alloc_concat_m(3, parts); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
508 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
|
509 free(shader_path); |
1693
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
510 if (f) { |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
511 fsize = file_size(f); |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
512 text = malloc(fsize); |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
513 if (fread(text, 1, fsize, f) != fsize) { |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
514 warning("Error reading from shader file %s\n", fname); |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
515 free(text); |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
516 return 0; |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
517 } |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
518 } else { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
519 #endif |
1693
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
520 shader_path = path_append("shaders", fname); |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
521 uint32_t fsize32; |
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
522 text = read_bundled_file(shader_path, &fsize32); |
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
|
523 free(shader_path); |
1693
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
524 if (!text) { |
800 | 525 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
|
526 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
|
527 } |
1693
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
528 fsize = fsize32; |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
529 #ifndef __ANDROID__ |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
530 } |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
531 #endif |
1797
5ff8f0d28188
Make sure there are no races between main thread and audio thread around mix_buf. Fix lack of proper termination in shader loading code
Mike Pavone <pavone@retrodev.com>
parents:
1796
diff
changeset
|
532 text[fsize] = 0; |
1693
ba3fb7a3be6b
Added some Makefile options to build a packaging friendly executable
Michael Pavone <pavone@retrodev.com>
parents:
1686
diff
changeset
|
533 |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
534 if (strncmp(text, "#version", strlen("#version"))) { |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
535 GLchar *tmp = text; |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
536 text = alloc_concat(shader_prefix, tmp); |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
537 free(tmp); |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
538 fsize += strlen(shader_prefix); |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
539 } |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
540 GLuint ret = glCreateShader(shader_type); |
1820
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
541 if (!ret) { |
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
542 warning("glCreateShader failed with error %d\n", glGetError()); |
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
543 return 0; |
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
544 } |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
545 glShaderSource(ret, 1, (const GLchar **)&text, (const GLint *)&fsize); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
546 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
547 glCompileShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
548 GLint compile_status, loglen; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
549 glGetShaderiv(ret, GL_COMPILE_STATUS, &compile_status); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
550 if (!compile_status) { |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
551 glGetShaderiv(ret, GL_INFO_LOG_LENGTH, &loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
552 text = malloc(loglen); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
553 glGetShaderInfoLog(ret, loglen, NULL, text); |
800 | 554 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
|
555 free(text); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
556 glDeleteShader(ret); |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
557 return 0; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
558 } |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
559 return ret; |
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
560 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
561 #endif |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
562 |
1167
e758ddbf0624
Initial work on emulating top and bottom border area
Michael Pavone <pavone@retrodev.com>
parents:
1117
diff
changeset
|
563 static uint32_t texture_buf[512 * 513]; |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
564 #ifdef DISABLE_OPENGL |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
565 #define RENDER_FORMAT SDL_PIXELFORMAT_ARGB8888 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
566 #else |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
567 #ifdef USE_GLES |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
568 #define INTERNAL_FORMAT GL_RGBA |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
569 #define SRC_FORMAT GL_RGBA |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
570 #define RENDER_FORMAT SDL_PIXELFORMAT_ABGR8888 |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
571 #else |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
572 #define INTERNAL_FORMAT GL_RGBA8 |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
573 #define SRC_FORMAT GL_BGRA |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
574 #define RENDER_FORMAT SDL_PIXELFORMAT_ARGB8888 |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
575 #endif |
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
|
576 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
|
577 { |
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
|
578 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
|
579 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
|
580 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
|
581 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
|
582 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
|
583 { |
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
|
584 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
|
585 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
|
586 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
|
587 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
|
588 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
|
589 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
|
590 //TODO: Fixme for PAL + invalid display mode |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
591 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, 512, 512, 0, SRC_FORMAT, GL_UNSIGNED_BYTE, texture_buf); |
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
|
592 } 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
|
593 uint32_t blank = 255 << 24; |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
594 glTexImage2D(GL_TEXTURE_2D, 0, INTERNAL_FORMAT, 1, 1, 0, SRC_FORMAT, GL_UNSIGNED_BYTE, &blank); |
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
|
595 } |
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
|
596 } |
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 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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 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
|
603 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
|
604 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
|
605 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
|
606 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
|
607 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
|
608 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
|
609 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
|
610 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
|
611 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
|
612 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
|
613 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
|
614 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
|
615 } |
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 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
|
617 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
|
618 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
|
619 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
|
620 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
|
621 } |
1593
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
622 |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
623 static void gl_teardown() |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
624 { |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
625 glDeleteProgram(program); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
626 glDeleteShader(vshader); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
627 glDeleteShader(fshader); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
628 glDeleteBuffers(2, buffers); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
629 glDeleteTextures(3, textures); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
630 } |
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
|
631 #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
|
632 |
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
|
633 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
|
634 static void render_alloc_surfaces() |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
635 { |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
636 if (texture_init) { |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
637 return; |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
638 } |
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
|
639 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
|
640 num_textures = 2; |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
874
diff
changeset
|
641 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
|
642 #ifndef DISABLE_OPENGL |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
643 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
|
644 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
|
645 gl_setup(); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
646 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
647 #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
|
648 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
|
649 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
|
650 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, scaling); |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
651 //TODO: Fixme for invalid display mode |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
652 sdl_textures[0] = sdl_textures[1] = SDL_CreateTexture(main_renderer, RENDER_FORMAT, 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
|
653 #ifndef DISABLE_OPENGL |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
654 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
655 #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
|
656 } |
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
|
657 |
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
|
658 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
|
659 { |
a051d8ee4528
Only save config file if 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 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
|
661 { |
a051d8ee4528
Only save config file if 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 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
|
663 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
|
664 } |
a051d8ee4528
Only save config file if 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 } |
a051d8ee4528
Only save config file if 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 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
|
667 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
|
668 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
|
669 } |
a051d8ee4528
Only save config file if 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 |
1102
c15896605bf2
Clean up symbol visiblity and delete a ltitle bit of dead code
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
671 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
|
672 static char * fps_caption = NULL; |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
673 |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
674 static void render_quit() |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
675 { |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
676 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
|
677 free_surfaces(); |
1593
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
678 #ifndef DISABLE_OPENGL |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
679 if (render_gl) { |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
680 gl_teardown(); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
681 SDL_GL_DeleteContext(main_context); |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
682 } |
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
683 #endif |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
684 } |
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
685 |
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
|
686 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
|
687 { |
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
|
688 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
|
689 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
|
690 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
|
691 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
|
692 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
|
693 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
|
694 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
|
695 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
|
696 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
|
697 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
|
698 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
|
699 } |
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
|
700 } |
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
|
701 } 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
|
702 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
|
703 } |
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
|
704 } |
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
|
705 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
|
706 } |
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
|
707 |
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
|
708 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
|
709 { |
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
|
710 //reset default values |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
711 #ifndef DISABLE_OPENGL |
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
|
712 memcpy(vertex_data, vertex_data_default, sizeof(vertex_data)); |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
713 #endif |
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
|
714 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
|
715 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
|
716 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
|
717 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
|
718 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
|
719 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
|
720 //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
|
721 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
|
722 } |
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
|
723 #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
|
724 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
|
725 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
|
726 { |
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
|
727 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
|
728 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
|
729 } 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
|
730 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
|
731 } |
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
|
732 } |
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
|
733 } 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
|
734 #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
|
735 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
|
736 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
|
737 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
|
738 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
|
739 #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
|
740 } |
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
|
741 #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
|
742 } |
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
|
743 } |
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
|
744 |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
745 static ui_render_fun on_context_destroyed, on_context_created, on_ui_fb_resized; |
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
|
746 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
|
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 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
|
749 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
|
750 } |
a051d8ee4528
Only save config file if 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 |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
752 void render_set_ui_fb_resize_handler(ui_render_fun resize) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
753 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
754 on_ui_fb_resized = resize; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
755 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
756 |
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
|
757 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
|
758 [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
|
759 [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
|
760 [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
|
761 [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
|
762 [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
|
763 [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
|
764 [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
|
765 [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
|
766 [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
|
767 [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
|
768 [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
|
769 [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
|
770 [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
|
771 [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
|
772 [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
|
773 [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
|
774 [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
|
775 [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
|
776 [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
|
777 [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
|
778 [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
|
779 [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
|
780 [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
|
781 [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
|
782 [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
|
783 [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
|
784 [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
|
785 [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
|
786 [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
|
787 [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
|
788 [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
|
789 [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
|
790 [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
|
791 [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
|
792 [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
|
793 [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
|
794 [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
|
795 [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
|
796 [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
|
797 [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
|
798 [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
|
799 [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
|
800 [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
|
801 [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
|
802 [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
|
803 [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
|
804 [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
|
805 [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
|
806 [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
|
807 [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
|
808 [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
|
809 [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
|
810 [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
|
811 [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
|
812 [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
|
813 [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
|
814 [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
|
815 [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
|
816 [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
|
817 [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
|
818 [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
|
819 [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
|
820 [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
|
821 [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
|
822 [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
|
823 [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
|
824 [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
|
825 [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
|
826 [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
|
827 [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
|
828 [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
|
829 [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
|
830 [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
|
831 [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
|
832 [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
|
833 [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
|
834 [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
|
835 [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
|
836 [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
|
837 [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
|
838 [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
|
839 [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
|
840 [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
|
841 [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
|
842 [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
|
843 [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
|
844 [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
|
845 [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
|
846 [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
|
847 [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
|
848 [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
|
849 [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
|
850 [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
|
851 [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
|
852 [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
|
853 [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
|
854 [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
|
855 [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
|
856 [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
|
857 [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
|
858 [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
|
859 }; |
a051d8ee4528
Only save config file if 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 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
|
862 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
|
863 { |
a051d8ee4528
Only save config file if 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 = 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
|
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 |
a051d8ee4528
Only save config file if 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 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
|
868 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
|
869 { |
a051d8ee4528
Only save config file if 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 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
|
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 |
a051d8ee4528
Only save config file if 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 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
|
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 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
|
876 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
|
877 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
|
878 } |
a051d8ee4528
Only save config file if 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 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
|
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 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
|
884 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
885 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
|
886 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
|
887 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
|
888 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
889 } |
a051d8ee4528
Only save config file if 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 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
|
891 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
892 |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
893 static int lowest_unlocked_joystick_index(void) |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
894 { |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
895 for (int i = 0; i < MAX_JOYSTICKS; i++) { |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
896 if (!joystick_index_locked[i]) { |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
897 return i; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
898 } |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
899 } |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
900 return -1; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
901 } |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
902 |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
903 SDL_Joystick *render_get_joystick(int index) |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
904 { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
905 if (index >= MAX_JOYSTICKS) { |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
906 return NULL; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
907 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
908 return joysticks[index]; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
909 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
910 |
1608
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
911 char* render_joystick_type_id(int index) |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
912 { |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
913 SDL_Joystick *stick = render_get_joystick(index); |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
914 if (!stick) { |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
915 return NULL; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
916 } |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
917 char *guid_string = malloc(33); |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
918 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(stick), guid_string, 33); |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
919 return guid_string; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
920 } |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1603
diff
changeset
|
921 |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
922 SDL_GameController *render_get_controller(int index) |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
923 { |
1862
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
924 if (index >= MAX_JOYSTICKS || !joysticks[index]) { |
1596
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
925 return NULL; |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
926 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
927 return SDL_GameControllerOpen(joystick_sdl_index[index]); |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
928 } |
437e80a700aa
Initial heuristics for detecting controller types and showing different labels in UI. Modified controller settings view to first display a list of controllers, only showing mapping after selecting controller
Michael Pavone <pavone@retrodev.com>
parents:
1593
diff
changeset
|
929 |
1862
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
930 static uint8_t gc_events_enabled; |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
931 static SDL_GameController *controllers[MAX_JOYSTICKS]; |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
932 void render_enable_gamepad_events(uint8_t enabled) |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
933 { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
934 if (enabled != gc_events_enabled) { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
935 gc_events_enabled = enabled; |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
936 for (int i = 0; i < MAX_JOYSTICKS; i++) { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
937 if (enabled) { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
938 controllers[i] = render_get_controller(i); |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
939 } else if (controllers[i]) { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
940 SDL_GameControllerClose(controllers[i]); |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
941 controllers[i] = NULL; |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
942 } |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
943 } |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
944 } |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
945 } |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
946 |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
947 static uint32_t overscan_top[NUM_VID_STD] = {2, 21}; |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
948 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
|
949 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
|
950 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
|
951 static vid_std video_standard = VID_NTSC; |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
952 static uint8_t need_ui_fb_resize; |
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
|
953 |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
954 int lock_joystick_index(int joystick, int desired_index) |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
955 { |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
956 if (desired_index < 0) { |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
957 desired_index = lowest_unlocked_joystick_index(); |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
958 if (desired_index < 0 || desired_index >= joystick) { |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
959 return joystick; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
960 } |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
961 } |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
962 SDL_Joystick *tmp_joy = joysticks[joystick]; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
963 int tmp_index = joystick_sdl_index[joystick]; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
964 joysticks[joystick] = joysticks[desired_index]; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
965 joystick_sdl_index[joystick] = joystick_sdl_index[desired_index]; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
966 joystick_index_locked[joystick] = joystick_sdl_index[desired_index]; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
967 joysticks[desired_index] = tmp_joy; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
968 joystick_sdl_index[desired_index] = tmp_index; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
969 joystick_index_locked[desired_index] = 1; |
1861
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1860
diff
changeset
|
970 //update bindings as the controllers being swapped may have different mappings |
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1860
diff
changeset
|
971 handle_joy_added(desired_index); |
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1860
diff
changeset
|
972 if (joysticks[joystick]) { |
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1860
diff
changeset
|
973 handle_joy_added(joystick); |
fc05f49075c2
Reprocess bindings when SDL2 mappings, controller types or controller order change
Michael Pavone <pavone@retrodev.com>
parents:
1860
diff
changeset
|
974 } |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
975 return desired_index; |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
976 } |
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
977 |
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
|
978 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
|
979 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
980 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
|
981 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
|
982 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
983 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
|
984 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
|
985 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
|
986 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
|
987 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
|
988 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
|
989 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
|
990 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
|
991 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
|
992 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
|
993 case SDL_JOYBUTTONUP: |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
994 handle_joyup(lock_joystick_index(find_joystick_index(event->jbutton.which), -1), event->jbutton.button); |
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
|
995 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
|
996 case SDL_JOYHATMOTION: |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
997 handle_joy_dpad(lock_joystick_index(find_joystick_index(event->jhat.which), -1), event->jhat.hat, event->jhat.value); |
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
|
998 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
|
999 case SDL_JOYAXISMOTION: |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
1000 handle_joy_axis(lock_joystick_index(find_joystick_index(event->jaxis.which), -1), event->jaxis.axis, event->jaxis.value); |
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
|
1001 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
|
1002 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
|
1003 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
|
1004 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
|
1005 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
|
1006 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
|
1007 joystick_sdl_index[index] = event->jdevice.which; |
1860
bdca98187c9f
Reorder controllers based on which one receives player input first
Michael Pavone <pavone@retrodev.com>
parents:
1851
diff
changeset
|
1008 joystick_index_locked[index] = 0; |
1862
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
1009 if (gc_events_enabled) { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
1010 controllers[index] = SDL_GameControllerOpen(event->jdevice.which); |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
1011 } |
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
|
1012 if (joy) { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1013 debug_message("Joystick %d added: %s\n", index, SDL_JoystickName(joy)); |
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1014 debug_message("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); |
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
|
1015 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
|
1016 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1017 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1018 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1019 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
|
1020 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
|
1021 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
|
1022 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
|
1023 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
|
1024 joysticks[index] = NULL; |
1862
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
1025 if (controllers[index]) { |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
1026 SDL_GameControllerClose(controllers[index]); |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
1027 controllers[index] = NULL; |
e07fc3d473b2
Basic UI navigation with controller
Michael Pavone <pavone@retrodev.com>
parents:
1861
diff
changeset
|
1028 } |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1029 debug_message("Joystick %d removed\n", index); |
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
|
1030 } else { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1031 debug_message("Failed to find removed joystick with instance ID: %d\n", index); |
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
|
1032 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1033 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
|
1034 } |
a051d8ee4528
Only save config file if 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 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
|
1036 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
|
1037 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
|
1038 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
|
1039 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
|
1040 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
|
1041 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
|
1042 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
|
1043 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
|
1044 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
|
1045 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
|
1046 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1047 case SDL_WINDOWEVENT_SIZE_CHANGED: |
1820
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
1048 if (!main_window) { |
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
1049 break; |
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
1050 } |
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
|
1051 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
|
1052 main_height = event->window.data2; |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1053 need_ui_fb_resize = 1; |
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
|
1054 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
|
1055 #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
|
1056 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
|
1057 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
|
1058 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
|
1059 } |
1593
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
1060 gl_teardown(); |
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
|
1061 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
|
1062 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
|
1063 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
|
1064 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
|
1065 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
|
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 } |
a051d8ee4528
Only save config file if 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 #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
|
1069 break; |
1649
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1070 case SDL_WINDOWEVENT_CLOSE: |
1820
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
1071 if (main_window && SDL_GetWindowID(main_window) == event->window.windowID) { |
1649
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1072 exit(0); |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1073 } else { |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1074 for (int i = 0; i < num_textures - FRAMEBUFFER_USER_START; i++) |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1075 { |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1076 if (SDL_GetWindowID(extra_windows[i]) == event->window.windowID) { |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1077 if (close_handlers[i]) { |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1078 close_handlers[i](i + FRAMEBUFFER_USER_START); |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1079 } |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1080 break; |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1081 } |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1082 } |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1083 } |
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1084 break; |
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
|
1085 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1086 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
|
1087 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
|
1088 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
|
1089 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
|
1090 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1091 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
|
1092 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
|
1093 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
|
1094 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
|
1095 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
|
1096 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1097 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
|
1098 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1099 |
a051d8ee4528
Only save config file if 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 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
|
1101 { |
a051d8ee4528
Only save config file if 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 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
|
1103 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
|
1104 { |
a051d8ee4528
Only save config file if 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 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
|
1106 } |
a051d8ee4528
Only save config file if 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 } |
a051d8ee4528
Only save config file if 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 |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1109 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
|
1110 static int display_hz; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1111 static int source_hz; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1112 static int source_frame; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1113 static int source_frame_count; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1114 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
|
1115 |
a051d8ee4528
Only save config file if 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 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
|
1117 { |
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
|
1118 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
|
1119 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
|
1120 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
|
1121 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
|
1122 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
|
1123 } |
a051d8ee4528
Only save config file if 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 desired.freq = rate; |
1809
c2057d79998c
Request float 32 sample format since it saves us a conversion now that the gain code has been added
Michael Pavone <pavone@retrodev.com>
parents:
1804
diff
changeset
|
1125 desired.format = AUDIO_F32SYS; |
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
|
1126 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
|
1127 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
|
1128 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
|
1129 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
|
1130 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
|
1131 } |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1132 debug_message("config says: %d\n", samples); |
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
|
1133 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
|
1134 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
|
1135 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
|
1136 |
a051d8ee4528
Only save config file if 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 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
|
1138 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
|
1139 } |
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
|
1140 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
|
1141 sample_rate = actual.freq; |
1684
b1d063466d03
Modified audio code to support an arbitrary number of output channels so that things aren't weird if SDL2 picks a number of channels other than what we ask for
Michael Pavone <pavone@retrodev.com>
parents:
1659
diff
changeset
|
1142 output_channels = actual.channels; |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1143 debug_message("Initialized audio at frequency %d with a %d sample buffer, ", actual.freq, actual.samples); |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1144 sample_size = SDL_AUDIO_BITSIZE(actual.format) / 8; |
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
|
1145 if (actual.format == AUDIO_S16SYS) { |
1810
73a9d06413bc
Restore some newlines in debug output that got lost when fixing GDB remote debugging issue
Michael Pavone <pavone@retrodev.com>
parents:
1809
diff
changeset
|
1146 debug_message("signed 16-bit int format\n"); |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1147 convert = convert_s16; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1148 mix_buf = calloc(output_channels * buffer_samples, sizeof(float)); |
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
|
1149 } else if (actual.format == AUDIO_F32SYS) { |
1810
73a9d06413bc
Restore some newlines in debug output that got lost when fixing GDB remote debugging issue
Michael Pavone <pavone@retrodev.com>
parents:
1809
diff
changeset
|
1150 debug_message("32-bit float format\n"); |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1151 convert = clamp_f32; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1152 mix_buf = NULL; |
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
|
1153 } else { |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1154 debug_message("unsupported format %X\n", actual.format); |
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
|
1155 warning("Unsupported audio sample format: %X\n", actual.format); |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1156 convert = convert_null; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1157 mix_buf = calloc(output_channels * buffer_samples, sizeof(float)); |
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
|
1158 } |
1796
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1159 char * gain_str = tern_find_path(config, "audio\0gain\0", TVAL_PTR).ptrval; |
51417bb557b6
Configurable gain for overall output and individual components
Michael Pavone <pavone@retrodev.com>
parents:
1792
diff
changeset
|
1160 overall_gain_mult = db_to_mult(gain_str ? atof(gain_str) : 0.0f); |
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
|
1161 } |
a051d8ee4528
Only save config file if 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 |
a051d8ee4528
Only save config file if 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 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
|
1164 { |
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
|
1165 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
|
1166 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
|
1167 flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1168 } |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1169 |
1659
19331a21da3a
Switched default sync source back to audio as the video option is not ready for prime timeop
Mike Pavone <pavone@retrodev.com>
parents:
1658
diff
changeset
|
1170 tern_val def = {.ptrval = "audio"}; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1171 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
|
1172 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
|
1173 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1174 const char *vsync; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1175 if (sync_to_audio) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1176 def.ptrval = "off"; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1177 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
|
1178 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1179 vsync = "on"; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1180 } |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1181 |
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
|
1182 tern_node *video = tern_find_node(config, "video"); |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1183 if (video) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1184 { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1185 for (int i = 0; i < NUM_VID_STD; i++) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1186 { |
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
|
1187 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
|
1188 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
|
1189 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
|
1190 if (val) { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1191 overscan_top[i] = atoi(val); |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1192 } |
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
|
1193 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
|
1194 if (val) { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1195 overscan_bot[i] = atoi(val); |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1196 } |
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
|
1197 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
|
1198 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
|
1199 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
|
1200 } |
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
|
1201 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
|
1202 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
|
1203 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
|
1204 } |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1205 } |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1206 } |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1207 } |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1208 render_gl = 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
|
1209 |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1210 #ifndef DISABLE_OPENGL |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1211 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
|
1212 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
|
1213 if (gl_enabled) |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1214 { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1215 flags |= SDL_WINDOW_OPENGL; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1216 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
|
1217 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
|
1218 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
|
1219 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
|
1220 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1221 #ifdef USE_GLES |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1222 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1223 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1224 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1225 #endif |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1226 } |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
1227 #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
|
1228 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
|
1229 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
|
1230 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
|
1231 } |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
1232 #ifndef DISABLE_OPENGL |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1233 if (gl_enabled) |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1234 { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1235 main_context = SDL_GL_CreateContext(main_window); |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1236 #ifdef USE_GLES |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1237 int major_version; |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1238 if (SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &major_version) == 0 && major_version >= 2) { |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1239 #else |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1240 GLenum res = glewInit(); |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1241 if (res != GLEW_OK) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1242 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
|
1243 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1244 |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1245 if (res == GLEW_OK && GLEW_VERSION_2_0) { |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1246 #endif |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1247 render_gl = 1; |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1248 SDL_GL_MakeCurrent(main_window, main_context); |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1249 if (!strcmp("tear", vsync)) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1250 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
|
1251 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
|
1252 vsync = "on"; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1253 } else { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1254 vsync = NULL; |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1255 } |
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
|
1256 } |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1257 if (vsync) { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1258 if (SDL_GL_SetSwapInterval(!strcmp("on", vsync)) < 0) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
1259 #ifdef __ANDROID__ |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
1260 debug_message("Failed to set vsync to %s: %s\n", vsync, SDL_GetError()); |
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
1261 #else |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1262 warning("Failed to set vsync to %s: %s\n", vsync, SDL_GetError()); |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
1263 #endif |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1264 } |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1265 } |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1266 } else { |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1267 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
|
1268 } |
1328
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1269 } |
70faad89d491
Add config file option to disable Open GL rendering
Michael Pavone <pavone@retrodev.com>
parents:
1326
diff
changeset
|
1270 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
|
1271 #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
|
1272 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
|
1273 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
|
1274 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
|
1275 } |
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
|
1276 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
|
1277 |
1074
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
1278 if (!main_renderer) { |
3a0f684891ae
Fix NOGL compile option
Michael Pavone <pavone@retrodev.com>
parents:
1068
diff
changeset
|
1279 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
|
1280 } |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1281 SDL_RendererInfo rinfo; |
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1282 SDL_GetRendererInfo(main_renderer, &rinfo); |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1283 debug_message("SDL2 Render Driver: %s\n", rinfo.name); |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1284 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
|
1285 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
|
1286 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
|
1287 #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
|
1288 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
1289 #endif |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1290 |
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
|
1291 SDL_GetWindowSize(main_window, &main_width, &main_height); |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1292 debug_message("Window created with size: %d x %d\n", main_width, main_height); |
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
|
1293 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
|
1294 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
|
1295 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
|
1296 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
|
1297 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1298 |
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
|
1299 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
|
1300 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1301 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
|
1302 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
|
1303 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1304 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
|
1305 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
|
1306 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
|
1307 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
|
1308 } |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1309 debug_message("width: %d, height: %d\n", width, height); |
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
|
1310 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
|
1311 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
|
1312 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1313 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
|
1314 //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
|
1315 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
|
1316 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
|
1317 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1318 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
|
1319 //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
|
1320 //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
|
1321 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
|
1322 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
|
1323 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1324 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
|
1325 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
|
1326 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
|
1327 |
486
db5880d8ea03
Add an FPS counter to the title bar
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
1328 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
|
1329 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1330 window_setup(); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1331 |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1332 audio_mutex = SDL_CreateMutex(); |
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1333 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
|
1334 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1335 init_audio(); |
1355
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1336 |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1337 uint32_t db_size; |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1338 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
|
1339 if (db_data) { |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1340 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
|
1341 free(db_data); |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1342 debug_message("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
|
1343 } |
03cb4dd2499f
Load extra controller mappings from gamecontrollerdb.txt
Michael Pavone <pavone@retrodev.com>
parents:
1336
diff
changeset
|
1344 |
1603
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
1345 controller_add_mappings(); |
c0727712d529
Read extral SDL2 mappings on startup from controller_types.cfg
Michael Pavone <pavone@retrodev.com>
parents:
1600
diff
changeset
|
1346 |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1347 SDL_JoystickEventState(SDL_ENABLE); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1348 |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1349 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
|
1350 |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
1351 atexit(render_quit); |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1352 } |
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
|
1353 #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
|
1354 static int in_toggle; |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1355 static void update_source(audio_source *src, double rc, uint8_t sync_changed) |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1356 { |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1357 double alpha = src->dt / (src->dt + rc); |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1358 int32_t lowpass_alpha = (int32_t)(((double)0x10000) * alpha); |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1359 src->lowpass_alpha = lowpass_alpha; |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1360 if (sync_changed) { |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1361 uint32_t alloc_size = sync_to_audio ? src->num_channels * buffer_samples : nearest_pow2(min_buffered * 4 * src->num_channels); |
1591
5cfc7e4a207e
Fix code for handling switch between sync styles at runtime
Michael Pavone <pavone@retrodev.com>
parents:
1590
diff
changeset
|
1362 src->back = realloc(src->back, alloc_size * sizeof(int16_t)); |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1363 if (sync_to_audio) { |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1364 src->front = malloc(alloc_size * sizeof(int16_t)); |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1365 } else { |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1366 free(src->front); |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1367 src->front = src->back; |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1368 } |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1369 src->mask = sync_to_audio ? 0xFFFFFFFF : alloc_size-1; |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1370 src->read_start = 0; |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1371 src->read_end = sync_to_audio ? buffer_samples * src->num_channels : 0; |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1372 src->buffer_pos = 0; |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1373 } |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1374 } |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1375 |
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
|
1376 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
|
1377 { |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1378 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
|
1379 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1380 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
|
1381 #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
|
1382 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
|
1383 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
|
1384 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
|
1385 } |
1593
24508cb54f87
Fix a number of other memory errors (mostly leaks again) identified by valgrind
Michael Pavone <pavone@retrodev.com>
parents:
1591
diff
changeset
|
1386 gl_teardown(); |
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
|
1387 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
|
1388 } 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
|
1389 #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
|
1390 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
|
1391 #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
|
1392 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1393 #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
|
1394 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
|
1395 SDL_DestroyWindow(main_window); |
1820
70a1304b432b
Fix crash that occurs when changing video screen settings if the emulator window is currently fullscreen. Add a little more error handling to Open GL code
Mike Pavone <pavone@retrodev.com>
parents:
1810
diff
changeset
|
1396 main_window = NULL; |
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
|
1397 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
|
1398 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1399 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
|
1400 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
|
1401 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
|
1402 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1403 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
|
1404 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
|
1405 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
|
1406 } 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
|
1407 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
|
1408 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
|
1409 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1410 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
|
1411 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
|
1412 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
|
1413 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
|
1414 //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
|
1415 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
|
1416 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
|
1417 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
|
1418 } 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
|
1419 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
|
1420 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
|
1421 } |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1422 if (on_ui_fb_resized) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1423 on_ui_fb_resized(); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1424 } |
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
|
1425 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1426 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
|
1427 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
|
1428 #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
|
1429 //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
|
1430 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
|
1431 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
|
1432 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1433 #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
|
1434 |
1580
ea7d5ced2415
Fix deadlock when changing settings before loading first ROM
Michael Pavone <pavone@retrodev.com>
parents:
1574
diff
changeset
|
1435 uint8_t was_paused = SDL_GetAudioStatus() == SDL_AUDIO_PAUSED; |
ea7d5ced2415
Fix deadlock when changing settings before loading first ROM
Michael Pavone <pavone@retrodev.com>
parents:
1574
diff
changeset
|
1436 render_close_audio(); |
ea7d5ced2415
Fix deadlock when changing settings before loading first ROM
Michael Pavone <pavone@retrodev.com>
parents:
1574
diff
changeset
|
1437 quitting = 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
|
1438 init_audio(); |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1439 render_set_video_standard(video_standard); |
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
|
1440 |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1441 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
|
1442 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
|
1443 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
|
1444 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
|
1445 { |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1446 update_source(audio_sources[i], rc, old_sync_to_audio != sync_to_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
|
1447 } |
a051d8ee4528
Only save config file if something has changed. Re-initialize audio and video with new settings if config has changed
Michael Pavone <pavone@retrodev.com>
parents:
1567
diff
changeset
|
1448 unlock_audio(); |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1449 for (uint8_t i = 0; i < num_inactive_audio_sources; i++) |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1450 { |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1451 update_source(inactive_audio_sources[i], rc, old_sync_to_audio != sync_to_audio); |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1452 } |
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
|
1453 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
|
1454 in_toggle = 0; |
1590
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1455 if (!was_paused) { |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1456 SDL_PauseAudio(0); |
220ede292e97
Initial attempt at handling switches between sync modes at runtime. Needs work
Michael Pavone <pavone@retrodev.com>
parents:
1589
diff
changeset
|
1457 } |
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
|
1458 } |
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
|
1459 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1460 SDL_Window *render_get_window(void) |
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 return main_window; |
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 |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1465 void render_set_video_standard(vid_std std) |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1466 { |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1467 video_standard = std; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1468 source_hz = std == VID_PAL ? 50 : 60; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1469 uint32_t max_repeat = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1470 if (abs(source_hz - display_hz) < 2) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1471 memset(frame_repeat, 0, sizeof(int)*display_hz); |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1472 } else { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1473 int inc = display_hz * 100000 / source_hz; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1474 int accum = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1475 int dst_frames = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1476 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
|
1477 { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1478 frame_repeat[src_frame] = -1; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1479 accum += inc; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1480 while (accum > 100000) |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1481 { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1482 accum -= 100000; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1483 frame_repeat[src_frame]++; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1484 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
|
1485 dst_frames++; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1486 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1487 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1488 if (dst_frames != display_hz) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1489 frame_repeat[source_hz-1] += display_hz - dst_frames; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1490 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1491 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1492 source_frame = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1493 source_frame_count = frame_repeat[0]; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1494 //sync samples with audio thread approximately every 8 lines |
1686
475e84bfccbb
Small fix to sync sample calculation in render_sdl
Michael Pavone <pavone@retrodev.com>
parents:
1684
diff
changeset
|
1495 sync_samples = sync_to_audio ? buffer_samples : 8 * sample_rate / (source_hz * (std == VID_PAL ? 313 : 262)); |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1496 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
|
1497 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
|
1498 //min_buffered *= buffer_samples; |
1792
52a47611a273
Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
Michael Pavone <pavone@retrodev.com>
parents:
1693
diff
changeset
|
1499 debug_message("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
|
1500 max_adjust = BASE_MAX_ADJUST / source_hz; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1501 } |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1502 |
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
|
1503 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
|
1504 { |
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
|
1505 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
|
1506 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
|
1507 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
|
1508 } |
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
|
1509 |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1510 static char *screenshot_path; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1511 void render_save_screenshot(char *path) |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1512 { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1513 if (screenshot_path) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1514 free(screenshot_path); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1515 } |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1516 screenshot_path = path; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1517 } |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1518 |
1649
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1519 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height, window_close_handler close_handler) |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1520 { |
1642
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1521 uint8_t win_idx = 0xFF; |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1522 for (int i = 0; i < num_textures - FRAMEBUFFER_USER_START; i++) |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1523 { |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1524 if (!extra_windows[i]) { |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1525 win_idx = i; |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1526 break; |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1527 } |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1528 } |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1529 |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1530 if (win_idx == 0xFF) { |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1531 num_textures++; |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1532 sdl_textures = realloc(sdl_textures, num_textures * sizeof(*sdl_textures)); |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1533 extra_windows = realloc(extra_windows, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_windows)); |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1534 extra_renderers = realloc(extra_renderers, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_renderers)); |
1649
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1535 close_handlers = realloc(close_handlers, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*close_handlers)); |
1642
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1536 win_idx = num_textures - FRAMEBUFFER_USER_START - 1; |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1537 } |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1538 extra_windows[win_idx] = SDL_CreateWindow(caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0); |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1539 if (!extra_windows[win_idx]) { |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1540 goto fail_window; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1541 } |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1542 extra_renderers[win_idx] = SDL_CreateRenderer(extra_windows[win_idx], -1, SDL_RENDERER_ACCELERATED); |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1543 if (!extra_renderers[win_idx]) { |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1544 goto fail_renderer; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1545 } |
1642
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1546 uint8_t texture_idx = win_idx + FRAMEBUFFER_USER_START; |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1547 sdl_textures[texture_idx] = SDL_CreateTexture(extra_renderers[win_idx], SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height); |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1548 if (!sdl_textures[texture_idx]) { |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1549 goto fail_texture; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1550 } |
1649
b500e971da75
Allow closing VDP debug windows with the close button in the window title bar
Michael Pavone <pavone@retrodev.com>
parents:
1642
diff
changeset
|
1551 close_handlers[win_idx] = close_handler; |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1552 return texture_idx; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1553 |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1554 fail_texture: |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1555 SDL_DestroyRenderer(extra_renderers[win_idx]); |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1556 fail_renderer: |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1557 SDL_DestroyWindow(extra_windows[win_idx]); |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1558 fail_window: |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1559 num_textures--; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1560 return 0; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1561 } |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1562 |
1642
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1563 void render_destroy_window(uint8_t which) |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1564 { |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1565 uint8_t win_idx = which - FRAMEBUFFER_USER_START; |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1566 //Destroying the renderers also frees the textures |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1567 SDL_DestroyRenderer(extra_renderers[win_idx]); |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1568 SDL_DestroyWindow(extra_windows[win_idx]); |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1569 |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1570 extra_renderers[win_idx] = NULL; |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1571 extra_windows[win_idx] = NULL; |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1572 } |
c6b2c0f8cc61
Implemented support for toggling off a debug view
Michael Pavone <pavone@retrodev.com>
parents:
1635
diff
changeset
|
1573 |
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
|
1574 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
|
1575 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
|
1576 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
|
1577 { |
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
|
1578 #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
|
1579 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
|
1580 *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
|
1581 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
|
1582 } 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
|
1583 #endif |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1584 if (which == FRAMEBUFFER_UI && which >= num_textures) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1585 sdl_textures = realloc(sdl_textures, sizeof(*sdl_textures) * (FRAMEBUFFER_UI + 1)); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1586 for (; num_textures <= FRAMEBUFFER_UI; num_textures++) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1587 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1588 sdl_textures[num_textures] = NULL; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1589 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1590 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1591 if (which == FRAMEBUFFER_UI && !sdl_textures[which]) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1592 sdl_textures[which] = SDL_CreateTexture(main_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, main_width, main_height); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1593 } |
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
|
1594 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
|
1595 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
|
1596 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
|
1597 } |
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
|
1598 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
|
1599 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
|
1600 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
|
1601 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
|
1602 } |
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
|
1603 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
|
1604 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
|
1605 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
|
1606 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
|
1607 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
|
1608 } |
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
|
1609 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
|
1610 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
|
1611 *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
|
1612 } |
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
|
1613 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
|
1614 } |
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
|
1615 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
|
1616 #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
|
1617 } |
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
|
1618 #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
|
1619 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
1620 |
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
|
1621 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
|
1622 #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
|
1623 #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
|
1624 #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
|
1625 #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
|
1626 #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
|
1627 |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1628 static uint32_t last_width, last_height; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1629 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
|
1630 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
|
1631 { |
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
|
1632 static uint8_t last; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1633 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
|
1634 source_frame++; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1635 if (source_frame >= source_hz) { |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1636 source_frame = 0; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1637 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1638 source_frame_count = frame_repeat[source_frame]; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1639 //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
|
1640 return; |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1641 } |
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1642 |
1398
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1643 last_width = width; |
1184
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1644 uint32_t height = which <= FRAMEBUFFER_EVEN |
b1147418254a
Overscan is now configurable
Michael Pavone <pavone@retrodev.com>
parents:
1167
diff
changeset
|
1645 ? (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
|
1646 : 240; |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1647 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
|
1648 uint32_t shot_height, shot_width; |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1649 char *ext; |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1650 if (screenshot_path && which == FRAMEBUFFER_ODD) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1651 screenshot_file = fopen(screenshot_path, "wb"); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1652 if (screenshot_file) { |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1653 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1654 ext = path_extension(screenshot_path); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1655 #endif |
1851
419b458f93cd
Demote screenshot message to debug level so that a popup is not spawned when saving a screenshot
Michael Pavone <pavone@retrodev.com>
parents:
1839
diff
changeset
|
1656 debug_message("Saving screenshot to %s\n", screenshot_path); |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1657 } else { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1658 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
|
1659 } |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1660 free(screenshot_path); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1661 screenshot_path = NULL; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1662 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
|
1663 shot_width = width; |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1664 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1665 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
|
1666 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
|
1667 #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
|
1668 if (render_gl && which <= FRAMEBUFFER_EVEN) { |
1633
9b7cba9ba541
Use SDL_GL_MakeCurrent to make the SDL renderer API windows play nice with GL windows
Michael Pavone <pavone@retrodev.com>
parents:
1631
diff
changeset
|
1669 SDL_GL_MakeCurrent(main_window, main_context); |
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
|
1670 glBindTexture(GL_TEXTURE_2D, textures[which]); |
1658
fa9ae059e4d3
Added support for GLES in addition to desktop GL
Mike Pavone <pavone@retrodev.com>
parents:
1649
diff
changeset
|
1671 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, LINEBUF_SIZE, height, SRC_FORMAT, 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
|
1672 |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1673 if (screenshot_file) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1674 //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
|
1675 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1676 if (!strcasecmp(ext, "png")) { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1677 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1678 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
|
1679 } else { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1680 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1681 #endif |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1682 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
|
1683 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1684 } |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1685 #endif |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1686 } |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1687 } else { |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1688 #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
|
1689 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
|
1690 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
|
1691 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
|
1692 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
|
1693 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
|
1694 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
|
1695 { |
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
|
1696 //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
|
1697 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
|
1698 //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
|
1699 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
|
1700 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
|
1701 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
|
1702 } |
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
|
1703 height = 480; |
798
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1704 } |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1705 if (screenshot_file) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1706 uint32_t shot_pitch = locked_pitch; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1707 if (which == FRAMEBUFFER_EVEN) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1708 shot_height *= 2; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1709 } else { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1710 shot_pitch *= 2; |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1711 } |
1532
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1712 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1713 if (!strcasecmp(ext, "png")) { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1714 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1715 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
|
1716 } else { |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1717 free(ext); |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1718 #endif |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1719 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
|
1720 #ifndef DISABLE_ZLIB |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1721 } |
b505083dcd87
Added png screenshot support
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1722 #endif |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1723 } |
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
|
1724 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
|
1725 #ifndef DISABLE_OPENGL |
062a2199daf6
Use SDL2 renderer as a fallback
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
797
diff
changeset
|
1726 } |
797
65181c3ee560
Add pure SDL2 renderer
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
766
diff
changeset
|
1727 #endif |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1728 last_height = height; |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1729 if (which <= FRAMEBUFFER_EVEN) { |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1730 render_update_display(); |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1731 } else if (which == FRAMEBUFFER_UI) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1732 SDL_RenderCopy(main_renderer, sdl_textures[which], NULL, NULL); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1733 if (need_ui_fb_resize) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1734 SDL_DestroyTexture(sdl_textures[which]); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1735 sdl_textures[which] = NULL; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1736 if (on_ui_fb_resized) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1737 on_ui_fb_resized(); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1738 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1739 need_ui_fb_resize = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
1740 } |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1741 } else { |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1742 SDL_RenderCopy(extra_renderers[which - FRAMEBUFFER_USER_START], sdl_textures[which], NULL, NULL); |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1743 SDL_RenderPresent(extra_renderers[which - FRAMEBUFFER_USER_START]); |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
1744 } |
1263
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1745 if (screenshot_file) { |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1746 fclose(screenshot_file); |
5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
1258
diff
changeset
|
1747 } |
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
|
1748 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
|
1749 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
|
1750 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
|
1751 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
|
1752 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
|
1753 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
|
1754 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
|
1755 #ifdef __ANDROID__ |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1825
diff
changeset
|
1756 debug_message("%s - %.1f fps", caption, ((float)frame_counter) / (((float)(last_frame-start)) / 1000.0)); |
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
|
1757 #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
|
1758 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
|
1759 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
|
1760 } |
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
|
1761 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
|
1762 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
|
1763 #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
|
1764 } |
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
|
1765 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
|
1766 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
|
1767 } |
449
7696d824489d
Started work on OpenGL support in new branch
Mike Pavone <pavone@retrodev.com>
parents:
426
diff
changeset
|
1768 } |
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
|
1769 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
|
1770 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
|
1771 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
|
1772 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
|
1773 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
|
1774 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
|
1775 } |
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
|
1776 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
|
1777 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
|
1778 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
|
1779 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
|
1780 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
|
1781 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
|
1782 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
|
1783 } 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
|
1784 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
|
1785 } |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1786 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
|
1787 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
|
1788 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
|
1789 || (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
|
1790 || (average_change >0 && local_cur_min > 5 * min_buffered / 4) |
1635
022d01b64496
Fix edge case in DRC audio path
Michael Pavone <pavone@retrodev.com>
parents:
1633
diff
changeset
|
1791 || cur_min_buffered < 0 |
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
|
1792 ) { |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1793 |
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
|
1794 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
|
1795 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
|
1796 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
|
1797 last_buffered = NO_LAST_BUFFERED; |
1589
780604a036e4
Limit underflow warning spam
Michael Pavone <pavone@retrodev.com>
parents:
1588
diff
changeset
|
1798 cur_min_buffered = 0; |
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
|
1799 } else { |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1800 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
|
1801 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
|
1802 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
|
1803 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
|
1804 } |
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
|
1805 } |
1567
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1806 } 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
|
1807 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
|
1808 } |
66387b1645e4
Audio DRC seems to be working pretty well now. Removed debug printfs
Michael Pavone <pavone@retrodev.com>
parents:
1566
diff
changeset
|
1809 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
|
1810 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
|
1811 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
|
1812 { |
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
|
1813 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
|
1814 } |
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
|
1815 } |
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
|
1816 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
|
1817 { |
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
|
1818 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
|
1819 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
|
1820 } |
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
|
1821 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
|
1822 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
|
1823 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
|
1824 } |
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
|
1825 source_frame_count = frame_repeat[source_frame]; |
1563
6a62434d6bb1
WIP dynamic rate control
Michael Pavone <pavone@retrodev.com>
parents:
1562
diff
changeset
|
1826 } |
1474
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1827 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1828 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1829 static ui_render_fun render_ui; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1830 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
|
1831 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1832 render_ui = fun; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1833 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1834 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1835 void render_update_display() |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1836 { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1837 #ifndef DISABLE_OPENGL |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1838 if (render_gl) { |
1528
855210dca5b9
Set glClearColor back to black
Michael Pavone <pavone@retrodev.com>
parents:
1483
diff
changeset
|
1839 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
|
1840 glClear(GL_COLOR_BUFFER_BIT); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1841 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1842 glUseProgram(program); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1843 glActiveTexture(GL_TEXTURE0); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1844 glBindTexture(GL_TEXTURE_2D, textures[0]); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1845 glUniform1i(un_textures[0], 0); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1846 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1847 glActiveTexture(GL_TEXTURE1); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1848 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
|
1849 glUniform1i(un_textures[1], 1); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1850 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1851 glUniform1f(un_width, render_emulated_width()); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1852 glUniform1f(un_height, last_height); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1853 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1854 glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1855 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
|
1856 glEnableVertexAttribArray(at_pos); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1857 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1858 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffers[1]); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1859 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
|
1860 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1861 glDisableVertexAttribArray(at_pos); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1862 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1863 if (render_ui) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1864 render_ui(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1865 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1866 |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1867 SDL_GL_SwapWindow(main_window); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1868 } else { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1869 #endif |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1870 SDL_Rect src_clip = { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1871 .x = overscan_left[video_standard], |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1872 .y = overscan_top[video_standard], |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1873 .w = render_emulated_width(), |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1874 .h = last_height |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1875 }; |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1876 SDL_SetRenderDrawColor(main_renderer, 0, 0, 0, 255); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1877 SDL_RenderClear(main_renderer); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1878 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
|
1879 if (render_ui) { |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1880 render_ui(); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1881 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1882 SDL_RenderPresent(main_renderer); |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1883 #ifndef DISABLE_OPENGL |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1884 } |
c5c022c7aa54
Initial work on Nuklear-based UI
Michael Pavone <pavone@retrodev.com>
parents:
1441
diff
changeset
|
1885 #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
|
1886 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
|
1887 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
|
1888 } |
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
|
1889 events_processed = 0; |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1890 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1891 |
1398
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1892 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
|
1893 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1894 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
|
1895 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1896 |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1897 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
|
1898 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1899 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
|
1900 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1901 |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1902 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
|
1903 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1904 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
|
1905 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1906 |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1907 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
|
1908 { |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1909 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
|
1910 } |
08116cb5ffaa
Fix absolute mouse mode when non-default overscan settings are used
Michael Pavone <pavone@retrodev.com>
parents:
1397
diff
changeset
|
1911 |
43
3fc57e1a2c56
Add debug render mode and fix vertical flip bit for bg tiles
Mike Pavone <pavone@retrodev.com>
parents:
33
diff
changeset
|
1912 void render_wait_quit(vdp_context * context) |
20
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1913 { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1914 SDL_Event event; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1915 while(SDL_WaitEvent(&event)) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1916 switch (event.type) { |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1917 case SDL_QUIT: |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1918 return; |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1919 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1920 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1921 } |
f664eeb55cb4
Mostly broken VDP core and savestate viewer
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1922 |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1923 int render_lookup_button(char *name) |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1924 { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1925 static tern_node *button_lookup; |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1926 if (!button_lookup) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1927 for (int i = SDL_CONTROLLER_BUTTON_A; i < SDL_CONTROLLER_BUTTON_MAX; i++) |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1928 { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1929 button_lookup = tern_insert_int(button_lookup, SDL_GameControllerGetStringForButton(i), i); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1930 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1931 //alternative Playstation-style names |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1932 button_lookup = tern_insert_int(button_lookup, "cross", SDL_CONTROLLER_BUTTON_A); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1933 button_lookup = tern_insert_int(button_lookup, "circle", SDL_CONTROLLER_BUTTON_B); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1934 button_lookup = tern_insert_int(button_lookup, "square", SDL_CONTROLLER_BUTTON_X); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1935 button_lookup = tern_insert_int(button_lookup, "triangle", SDL_CONTROLLER_BUTTON_Y); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1936 button_lookup = tern_insert_int(button_lookup, "share", SDL_CONTROLLER_BUTTON_BACK); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1937 button_lookup = tern_insert_int(button_lookup, "select", SDL_CONTROLLER_BUTTON_BACK); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1938 button_lookup = tern_insert_int(button_lookup, "options", SDL_CONTROLLER_BUTTON_START); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1939 button_lookup = tern_insert_int(button_lookup, "l1", SDL_CONTROLLER_BUTTON_LEFTSHOULDER); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1940 button_lookup = tern_insert_int(button_lookup, "r1", SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1941 button_lookup = tern_insert_int(button_lookup, "l3", SDL_CONTROLLER_BUTTON_LEFTSTICK); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1942 button_lookup = tern_insert_int(button_lookup, "r3", SDL_CONTROLLER_BUTTON_RIGHTSTICK); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1943 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1944 return (int)tern_find_int(button_lookup, name, SDL_CONTROLLER_BUTTON_INVALID); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1945 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1946 |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1947 int render_lookup_axis(char *name) |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1948 { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1949 static tern_node *axis_lookup; |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1950 if (!axis_lookup) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1951 for (int i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1952 { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1953 axis_lookup = tern_insert_int(axis_lookup, SDL_GameControllerGetStringForAxis(i), i); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1954 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1955 //alternative Playstation-style names |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1956 axis_lookup = tern_insert_int(axis_lookup, "l2", SDL_CONTROLLER_AXIS_TRIGGERLEFT); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1957 axis_lookup = tern_insert_int(axis_lookup, "r2", SDL_CONTROLLER_AXIS_TRIGGERRIGHT); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1958 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1959 return (int)tern_find_int(axis_lookup, name, SDL_CONTROLLER_AXIS_INVALID); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1960 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1961 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1962 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
|
1963 { |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1964 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
|
1965 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
|
1966 return RENDER_NOT_PLUGGED_IN; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1967 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1968 |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1969 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
|
1970 return RENDER_NOT_MAPPED; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1971 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1972 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
|
1973 if (!control) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1974 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
|
1975 return RENDER_NOT_PLUGGED_IN; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
1976 } |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1977 |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1978 SDL_GameControllerButtonBind cbind; |
1804
34370330eaf3
Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents:
1799
diff
changeset
|
1979 int32_t is_positive = RENDER_AXIS_POS; |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1980 if (is_axis) { |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1981 |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1982 int sdl_axis = render_lookup_axis(name); |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1983 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
|
1984 SDL_GameControllerClose(control); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1985 return RENDER_INVALID_NAME; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1986 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1987 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
|
1988 } else { |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1989 int sdl_button = render_lookup_button(name); |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1990 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
|
1991 SDL_GameControllerClose(control); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1992 return RENDER_INVALID_NAME; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1993 } |
1804
34370330eaf3
Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents:
1799
diff
changeset
|
1994 if (sdl_button == SDL_CONTROLLER_BUTTON_DPAD_UP || sdl_button == SDL_CONTROLLER_BUTTON_DPAD_LEFT) { |
34370330eaf3
Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents:
1799
diff
changeset
|
1995 //assume these will be negative if they are an axis |
34370330eaf3
Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents:
1799
diff
changeset
|
1996 is_positive = 0; |
34370330eaf3
Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents:
1799
diff
changeset
|
1997 } |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
1998 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
|
1999 } |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2000 SDL_GameControllerClose(control); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2001 switch (cbind.bindType) |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2002 { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2003 case SDL_CONTROLLER_BINDTYPE_BUTTON: |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2004 return cbind.value.button; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2005 case SDL_CONTROLLER_BINDTYPE_AXIS: |
1804
34370330eaf3
Support controllers that have their dpad mapped to an axis
Michael Pavone <pavone@retrodev.com>
parents:
1799
diff
changeset
|
2006 return RENDER_AXIS_BIT | cbind.value.axis | is_positive; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2007 case SDL_CONTROLLER_BINDTYPE_HAT: |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2008 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
|
2009 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2010 return RENDER_NOT_MAPPED; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2011 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2012 |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2013 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
|
2014 { |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2015 return input >> 4 & 0xFFFFFF; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2016 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2017 |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2018 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
|
2019 { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2020 return input & 0xF; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2021 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1184
diff
changeset
|
2022 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2023 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
|
2024 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2025 return input & 0xFFFFFFF; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2026 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1205
diff
changeset
|
2027 |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
2028 void process_events() |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
2029 { |
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
|
2030 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
|
2031 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
|
2032 } |
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
|
2033 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
|
2034 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
|
2035 } |
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
|
2036 |
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
|
2037 #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
|
2038 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
|
2039 { |
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
|
2040 //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
|
2041 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
|
2042 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
|
2043 } |
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
|
2044 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
|
2045 |
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
|
2046 //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
|
2047 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
|
2048 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
|
2049 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
|
2050 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
|
2051 return; |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
2052 } |
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
|
2053 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
|
2054 |
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
|
2055 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
|
2056 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
|
2057 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
|
2058 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
|
2059 //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
|
2060 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
|
2061 //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
|
2062 //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
|
2063 //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
|
2064 //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
|
2065 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
|
2066 } |
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
|
2067 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
|
2068 //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
|
2069 //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
|
2070 //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
|
2071 //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
|
2072 //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
|
2073 //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
|
2074 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
|
2075 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
|
2076 in_toggle = 0; |
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
1820
diff
changeset
|
2077 need_ui_fb_resize = 1; |
409
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
2078 } |
c1bddeadc566
Process events in vgm player so that quitting works
Mike Pavone <pavone@retrodev.com>
parents:
398
diff
changeset
|
2079 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
2080 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
|
2081 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
2082 return buffer_samples; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
2083 } |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2084 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
2085 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
|
2086 { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
2087 return sample_rate; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
2088 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
2089 |
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
|
2090 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
|
2091 { |
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
|
2092 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
|
2093 } |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
2094 |
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
|
2095 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
|
2096 { |
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
|
2097 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
|
2098 } |
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
|
2099 |
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
|
2100 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
|
2101 { |
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
|
2102 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
|
2103 } |
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
|
2104 |
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
|
2105 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
|
2106 { |
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
|
2107 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
|
2108 } |
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
|
2109 |
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
|
2110 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
|
2111 { |
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
|
2112 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
|
2113 } |
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
|
2114 |
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
|
2115 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
|
2116 { |
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
|
2117 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
|
2118 } |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2119 |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2120 uint8_t render_get_active_framebuffer(void) |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2121 { |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2122 if (SDL_GetWindowFlags(main_window) & SDL_WINDOW_INPUT_FOCUS) { |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2123 return FRAMEBUFFER_ODD; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2124 } |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2125 for (int i = 0; i < num_textures - 2; i++) |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2126 { |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2127 if (extra_windows[i] && (SDL_GetWindowFlags(extra_windows[i]) & SDL_WINDOW_INPUT_FOCUS)) { |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2128 return FRAMEBUFFER_USER_START + i; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2129 } |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2130 } |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2131 return 0xFF; |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
2132 } |