44
55#include <gwenesis.h>
66
7+ #define USE_CORE1_TASK
8+
79#define AUDIO_SAMPLE_RATE (53267)
810#define AUDIO_BUFFER_LENGTH (AUDIO_SAMPLE_RATE / 60 + 1)
911
@@ -30,6 +32,10 @@ static rg_surface_t *updates[2];
3032static rg_surface_t * currentUpdate ;
3133static rg_app_t * app ;
3234
35+ #ifdef USE_CORE1_TASK
36+ static rg_task_t * core1_task_handle ;
37+ #endif
38+
3339static const char * SETTING_YFM_EMULATION = "yfm_enable" ;
3440static const char * SETTING_Z80_EMULATION = "z80_enable" ;
3541static const char * SETTING_SN76489_EMULATION = "sn_enable" ;
@@ -197,6 +203,26 @@ static void options_handler(rg_gui_option_t *dest)
197203 * dest ++ = (rg_gui_option_t )RG_DIALOG_END ;
198204}
199205
206+ #ifdef USE_CORE1_TASK
207+ static void core1_task (void * arg )
208+ {
209+ rg_task_msg_t msg ;
210+ while (rg_task_receive (& msg ))
211+ {
212+ if (msg .type == RG_TASK_MSG_STOP )
213+ break ;
214+ if (msg .type == 1 ) // Sync
215+ continue ;
216+ int target_cycles = msg .dataInt >> 9 ;
217+ int scan_line = msg .dataInt & 0x1FF ;
218+ gwenesis_SN76489_run (target_cycles );
219+ ym2612_run (target_cycles );
220+ if (scan_line != 0x1FF )
221+ gwenesis_vdp_render_line (scan_line );
222+ }
223+ }
224+ #endif
225+
200226void app_main (void )
201227{
202228 const rg_handlers_t handlers = {
@@ -226,6 +252,12 @@ void app_main(void)
226252
227253 VRAM = rg_alloc (VRAM_MAX_SIZE , MEM_FAST );
228254
255+ #ifdef USE_CORE1_TASK
256+ // Set up multicore audio
257+ core1_task_handle = rg_task_create ("core1_task" , & core1_task , NULL , 2048 , RG_TASK_PRIORITY_6 , 1 );
258+ RG_ASSERT (core1_task_handle , "Failed to create core1 task!" );
259+ #endif
260+
229261 RG_LOGI ("Genesis start\n" );
230262
231263 size_t rom_size ;
@@ -324,6 +356,12 @@ void app_main(void)
324356 m68k_run (system_clock + VDP_CYCLES_PER_LINE );
325357 z80_run (system_clock + VDP_CYCLES_PER_LINE );
326358
359+ #ifdef USE_CORE1_TASK
360+ int packet = ((system_clock + VDP_CYCLES_PER_LINE ) << 9 )
361+ | ((drawFrame && scan_line < screen_height ) ? scan_line : 0x1FF );
362+ rg_task_msg_t msg = {.type = 0 , .dataInt = packet };
363+ rg_task_send (core1_task_handle , & msg );
364+ #else
327365 /* Audio */
328366 /* GWENESIS_AUDIO_ACCURATE:
329367 * =1 : cycle accurate mode. audio is refreshed when CPUs are performing a R/W access
@@ -337,6 +375,7 @@ void app_main(void)
337375 /* Video */
338376 if (drawFrame && scan_line < screen_height )
339377 gwenesis_vdp_render_line (scan_line ); /* render scan_line */
378+ #endif
340379
341380 // On these lines, the line counter interrupt is reloaded
342381 if ((scan_line == 0 ) || (scan_line > screen_height )) {
@@ -374,6 +413,13 @@ void app_main(void)
374413 system_clock += VDP_CYCLES_PER_LINE ;
375414 }
376415
416+ #ifdef USE_CORE1_TASK
417+ // Make sure all our previous messages have been processed before we continue
418+ rg_task_msg_t msg = {.type = 1 , .dataInt = 0 };
419+ rg_task_send (core1_task_handle , & msg );
420+ rg_task_send (core1_task_handle , & msg );
421+ #endif
422+
377423 /* Audio
378424 * synchronize YM2612 and SN76489 to system_clock
379425 * it completes the missing audio sample for accurate audio mode
0 commit comments