comparison render_sdl.c @ 1117:928a65750345

Initial support for Genesis/Megadrive PBC mode. VDP still needs Mode 4 to be useful.
author Michael Pavone <pavone@retrodev.com>
date Thu, 22 Dec 2016 19:51:25 -0800
parents 22e87b739ad6
children e758ddbf0624
comparison
equal deleted inserted replaced
1116:fe8c79f82c22 1117:928a65750345
42 static SDL_mutex * audio_mutex; 42 static SDL_mutex * audio_mutex;
43 static SDL_cond * audio_ready; 43 static SDL_cond * audio_ready;
44 static SDL_cond * psg_cond; 44 static SDL_cond * psg_cond;
45 static SDL_cond * ym_cond; 45 static SDL_cond * ym_cond;
46 static uint8_t quitting = 0; 46 static uint8_t quitting = 0;
47 static uint8_t ym_enabled = 1;
47 48
48 static void audio_callback(void * userdata, uint8_t *byte_stream, int len) 49 static void audio_callback(void * userdata, uint8_t *byte_stream, int len)
49 { 50 {
50 //puts("audio_callback"); 51 //puts("audio_callback");
51 int16_t * stream = (int16_t *)byte_stream; 52 int16_t * stream = (int16_t *)byte_stream;
59 if (!psg_buf) { 60 if (!psg_buf) {
60 psg_buf = current_psg; 61 psg_buf = current_psg;
61 current_psg = NULL; 62 current_psg = NULL;
62 SDL_CondSignal(psg_cond); 63 SDL_CondSignal(psg_cond);
63 } 64 }
64 if (!ym_buf) { 65 if (ym_enabled && !ym_buf) {
65 ym_buf = current_ym; 66 ym_buf = current_ym;
66 current_ym = NULL; 67 current_ym = NULL;
67 SDL_CondSignal(ym_cond); 68 SDL_CondSignal(ym_cond);
68 } 69 }
69 if (!quitting && (!psg_buf || !ym_buf)) { 70 if (!quitting && (!psg_buf || (ym_enabled && !ym_buf))) {
70 SDL_CondWait(audio_ready, audio_mutex); 71 SDL_CondWait(audio_ready, audio_mutex);
71 } 72 }
72 } while(!quitting && (!psg_buf || !ym_buf)); 73 } while(!quitting && (!psg_buf || (ym_enabled && !ym_buf)));
73 74
74 local_quit = quitting; 75 local_quit = quitting;
75 SDL_UnlockMutex(audio_mutex); 76 SDL_UnlockMutex(audio_mutex);
76 if (!local_quit) { 77 if (!local_quit) {
77 for (int i = 0; i < samples; i++) { 78 if (ym_enabled) {
78 *(stream++) = psg_buf[i] + *(ym_buf++); 79 for (int i = 0; i < samples; i++)
79 *(stream++) = psg_buf[i] + *(ym_buf++); 80 {
80 } 81 *(stream++) = psg_buf[i] + *(ym_buf++);
81 } 82 *(stream++) = psg_buf[i] + *(ym_buf++);
83 }
84 } else {
85 for (int i = 0; i < samples; i++)
86 {
87 *(stream++) = psg_buf[i];
88 *(stream++) = psg_buf[i];
89 }
90 }
91 }
92 }
93
94 void render_disable_ym()
95 {
96 ym_enabled = 0;
97 }
98
99 void render_enable_ym()
100 {
101 ym_enabled = 1;
82 } 102 }
83 103
84 static void render_close_audio() 104 static void render_close_audio()
85 { 105 {
86 SDL_LockMutex(audio_mutex); 106 SDL_LockMutex(audio_mutex);