Skip to content

Commit 008247e

Browse files
committed
GEN: Made the core 1 task workload configurable during runtime
1 parent 3265f58 commit 008247e

1 file changed

Lines changed: 62 additions & 35 deletions

File tree

gwenesis/main/main.c

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ static rg_surface_t *updates[2];
3232
static rg_surface_t *currentUpdate;
3333
static rg_app_t *app;
3434

35-
#ifdef USE_CORE1_TASK
3635
static rg_task_t *core1_task_handle;
37-
#endif
36+
static bool core1_task_rendering = true;
37+
static bool core1_task_sound = true;
3838

3939
static const char *SETTING_YFM_EMULATION = "yfm_enable";
4040
static const char *SETTING_Z80_EMULATION = "z80_enable";
@@ -197,33 +197,55 @@ static void event_handler(int event, void *arg)
197197
}
198198
}
199199

200-
static void options_handler(rg_gui_option_t *dest)
200+
static rg_gui_event_t core1_rendering_update_cb(rg_gui_option_t *option, rg_gui_event_t event)
201201
{
202-
*dest++ = (rg_gui_option_t){0, _("YM2612 audio "), "-", RG_DIALOG_FLAG_NORMAL, &yfm_update_cb};
203-
*dest++ = (rg_gui_option_t){0, _("SN76489 audio"), "-", RG_DIALOG_FLAG_NORMAL, &sn76489_update_cb};
204-
*dest++ = (rg_gui_option_t){0, _("Z80 emulation"), "-", RG_DIALOG_FLAG_NORMAL, &z80_update_cb};
205-
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
202+
if (event == RG_DIALOG_PREV || event == RG_DIALOG_NEXT)
203+
core1_task_rendering = !core1_task_rendering;
204+
strcpy(option->value, core1_task_rendering ? _("On") : _("Off"));
205+
return RG_DIALOG_VOID;
206+
}
207+
208+
static rg_gui_event_t core1_sound_update_cb(rg_gui_option_t *option, rg_gui_event_t event)
209+
{
210+
if (event == RG_DIALOG_PREV || event == RG_DIALOG_NEXT)
211+
core1_task_sound = !core1_task_sound;
212+
strcpy(option->value, core1_task_sound ? _("On") : _("Off"));
213+
return RG_DIALOG_VOID;
206214
}
207215

208-
#ifdef USE_CORE1_TASK
209216
static void core1_task(void *arg)
210217
{
211218
rg_task_msg_t msg;
212219
while (rg_task_receive(&msg))
213220
{
214-
if (msg.type == RG_TASK_MSG_STOP)
215-
break;
216-
if (msg.type == 1) // Sync
217-
continue;
218-
int target_cycles = msg.dataInt >> 9;
219-
int scan_line = msg.dataInt & 0x1FF;
220-
gwenesis_SN76489_run(target_cycles);
221-
ym2612_run(target_cycles);
222-
if (scan_line != 0x1FF)
223-
gwenesis_vdp_render_line(scan_line);
221+
switch (msg.type)
222+
{
223+
case 1: // Rendering
224+
gwenesis_vdp_render_line(msg.dataInt);
225+
break;
226+
case 2: // Sound
227+
gwenesis_SN76489_run(msg.dataInt);
228+
ym2612_run(msg.dataInt);
229+
break;
230+
case RG_TASK_MSG_STOP:
231+
return;
232+
default: // Sync/no-op
233+
continue;
234+
}
224235
}
225236
}
226-
#endif
237+
238+
static void options_handler(rg_gui_option_t *dest)
239+
{
240+
*dest++ = (rg_gui_option_t){0, _("YM2612 audio "), "-", RG_DIALOG_FLAG_NORMAL, &yfm_update_cb};
241+
*dest++ = (rg_gui_option_t){0, _("SN76489 audio"), "-", RG_DIALOG_FLAG_NORMAL, &sn76489_update_cb};
242+
*dest++ = (rg_gui_option_t){0, _("Z80 emulation"), "-", RG_DIALOG_FLAG_NORMAL, &z80_update_cb};
243+
244+
*dest++ = (rg_gui_option_t){0, _("Render on core 1"), "-", RG_DIALOG_FLAG_NORMAL, &core1_rendering_update_cb};
245+
*dest++ = (rg_gui_option_t){0, _("Sound on core 1"), "-", RG_DIALOG_FLAG_NORMAL, &core1_sound_update_cb};
246+
247+
*dest++ = (rg_gui_option_t)RG_DIALOG_END;
248+
}
227249

228250
void app_main(void)
229251
{
@@ -291,7 +313,7 @@ void app_main(void)
291313
}
292314

293315
rg_system_set_tick_rate(60);
294-
app->frameskip = 3;
316+
app->frameskip = 2;
295317

296318
extern unsigned char gwenesis_vdp_regs[0x20];
297319
extern unsigned int gwenesis_vdp_status;
@@ -358,26 +380,31 @@ void app_main(void)
358380
m68k_run(system_clock + VDP_CYCLES_PER_LINE);
359381
z80_run(system_clock + VDP_CYCLES_PER_LINE);
360382

361-
#ifdef USE_CORE1_TASK
362-
int packet = ((system_clock + VDP_CYCLES_PER_LINE) << 9)
363-
| ((drawFrame && scan_line < screen_height) ? scan_line : 0x1FF);
364-
rg_task_msg_t msg = {.type = 0, .dataInt = packet};
365-
rg_task_send(core1_task_handle, &msg);
366-
#else
367383
/* Audio */
368384
/* GWENESIS_AUDIO_ACCURATE:
369385
* =1 : cycle accurate mode. audio is refreshed when CPUs are performing a R/W access
370386
* =0 : line accurate mode. audio is refreshed every lines.
371387
*/
372388
if (GWENESIS_AUDIO_ACCURATE == 0) {
373-
gwenesis_SN76489_run(system_clock + VDP_CYCLES_PER_LINE);
374-
ym2612_run(system_clock + VDP_CYCLES_PER_LINE);
389+
if (core1_task_sound)
390+
{
391+
rg_task_send(core1_task_handle, &(rg_task_msg_t){.type = 2, .dataInt = system_clock + VDP_CYCLES_PER_LINE});
392+
}
393+
else
394+
{
395+
gwenesis_SN76489_run(system_clock + VDP_CYCLES_PER_LINE);
396+
ym2612_run(system_clock + VDP_CYCLES_PER_LINE);
397+
}
375398
}
376399

377400
/* Video */
378401
if (drawFrame && scan_line < screen_height)
379-
gwenesis_vdp_render_line(scan_line); /* render scan_line */
380-
#endif
402+
{
403+
if (core1_task_rendering)
404+
rg_task_send(core1_task_handle, &(rg_task_msg_t){.type = 1, .dataInt = scan_line});
405+
else
406+
gwenesis_vdp_render_line(scan_line); /* render scan_line */
407+
}
381408

382409
// On these lines, the line counter interrupt is reloaded
383410
if ((scan_line == 0) || (scan_line > screen_height)) {
@@ -415,12 +442,12 @@ void app_main(void)
415442
system_clock += VDP_CYCLES_PER_LINE;
416443
}
417444

418-
#ifdef USE_CORE1_TASK
419445
// Make sure all our previous messages have been processed before we continue
420-
rg_task_msg_t msg = {.type = 1, .dataInt = 0};
421-
rg_task_send(core1_task_handle, &msg);
422-
rg_task_send(core1_task_handle, &msg);
423-
#endif
446+
if (core1_task_rendering || core1_task_sound)
447+
{
448+
rg_task_send(core1_task_handle, &(rg_task_msg_t){0});
449+
rg_task_send(core1_task_handle, &(rg_task_msg_t){0});
450+
}
424451

425452
/* Audio
426453
* synchronize YM2612 and SN76489 to system_clock

0 commit comments

Comments
 (0)