From 7b02a2c3e3ac5cfb5925f4b3ca30fb615968673a Mon Sep 17 00:00:00 2001 From: kub Date: Tue, 20 Dec 2022 21:34:13 +0000 Subject: [PATCH] 32x, improve sh2 scheduling --- pico/32x/32x.c | 16 +++++++--------- pico/32x/pwm.c | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/pico/32x/32x.c b/pico/32x/32x.c index f7654360..19b3f505 100644 --- a/pico/32x/32x.c +++ b/pico/32x/32x.c @@ -55,15 +55,13 @@ void p32x_update_irls(SH2 *active_sh2, unsigned int m68k_cycles) mrun = sh2_irl_irq(&msh2, mlvl, msh2.state & SH2_STATE_RUN); if (mrun) { p32x_sh2_poll_event(&msh2, SH2_IDLE_STATES & ~SH2_STATE_SLEEP, m68k_cycles); - if (msh2.state & SH2_STATE_RUN) - sh2_end_run(&msh2, 0); + p32x_sync_other_sh2(&msh2, m68k_cycles); } srun = sh2_irl_irq(&ssh2, slvl, ssh2.state & SH2_STATE_RUN); if (srun) { p32x_sh2_poll_event(&ssh2, SH2_IDLE_STATES & ~SH2_STATE_SLEEP, m68k_cycles); - if (ssh2.state & SH2_STATE_RUN) - sh2_end_run(&ssh2, 0); + p32x_sync_other_sh2(&ssh2, m68k_cycles); } elprintf(EL_32X, "update_irls: m %d/%d, s %d/%d", mlvl, mrun, slvl, srun); @@ -256,9 +254,9 @@ static void p32x_start_blank(void) Pico32xSwapDRAM(Pico32x.pending_fb ^ 1); } - p32x_trigger_irq(NULL, SekCyclesDone(), P32XI_VINT); - p32x_sh2_poll_event(&msh2, SH2_STATE_VPOLL, SekCyclesDone()); - p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, SekCyclesDone()); + p32x_trigger_irq(NULL, Pico.t.m68c_aim, P32XI_VINT); + p32x_sh2_poll_event(&msh2, SH2_STATE_VPOLL, Pico.t.m68c_aim); + p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, Pico.t.m68c_aim); } static void p32x_end_blank(void) @@ -270,8 +268,8 @@ static void p32x_end_blank(void) if (!(Pico32x.sh2_regs[0] & 0x80)) p32x_schedule_hint(NULL, SekCyclesDone()); - p32x_sh2_poll_event(&msh2, SH2_STATE_VPOLL, SekCyclesDone()); - p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, SekCyclesDone()); + p32x_sh2_poll_event(&msh2, SH2_STATE_VPOLL, Pico.t.m68c_aim); + p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, Pico.t.m68c_aim); } void p32x_schedule_hint(SH2 *sh2, unsigned int m68k_cycles) diff --git a/pico/32x/pwm.c b/pico/32x/pwm.c index ed8d761e..1b10103a 100644 --- a/pico/32x/pwm.c +++ b/pico/32x/pwm.c @@ -41,13 +41,13 @@ void p32x_pwm_ctl_changed(void) pwm.irq_reload = pwm.irq_timer; pwm.irq_state = pwm_irq_opt ? PWM_IRQ_STOPPED: PWM_IRQ_LOCKED; - if (Pico32x.pwm_irq_cnt == 0) + if (Pico32x.pwm_irq_cnt <= 0) Pico32x.pwm_irq_cnt = pwm.irq_reload; } static void do_pwm_irq(SH2 *sh2, unsigned int m68k_cycles) { - p32x_trigger_irq(sh2, m68k_cycles, P32XI_PWM); + p32x_trigger_irq(NULL, m68k_cycles, P32XI_PWM); if (Pico32x.regs[0x30 / 2] & P32XP_RTP) { p32x_event_schedule(m68k_cycles, P32X_EVENT_PWM, pwm.cycles / 3 + 1); @@ -110,7 +110,7 @@ static void consume_fifo_do(SH2 *sh2, unsigned int m68k_cycles, mem->pwm[pwm.ptr * 2 + 1] = pwm.current[1]; pwm.ptr = (pwm.ptr + 1) & (PWM_BUFF_LEN - 1); - if (--Pico32x.pwm_irq_cnt == 0) { + if (--Pico32x.pwm_irq_cnt <= 0) { Pico32x.pwm_irq_cnt = pwm.irq_reload; do_pwm_irq(sh2, m68k_cycles); } else if (Pico32x.pwm_p[1] == 0 && pwm.irq_state >= PWM_IRQ_LOW) { -- 2.39.5