From: notaz Date: Mon, 24 Oct 2011 20:02:51 +0000 (+0300) Subject: make root counters use generic event scheduling code X-Git-Tag: r11~29 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b8c000f969c365d48418781d8f88f9c58d65611;p=pcsx_rearmed.git make root counters use generic event scheduling code simplifies event handling code a bit --- diff --git a/libpcsxcore/misc.c b/libpcsxcore/misc.c index 68ad17ed..38e6385f 100644 --- a/libpcsxcore/misc.c +++ b/libpcsxcore/misc.c @@ -530,6 +530,8 @@ int SaveState(const char *file) { gzclose(f); + new_dyna_after_save(); + return 0; } diff --git a/libpcsxcore/new_dynarec/emu_if.c b/libpcsxcore/new_dynarec/emu_if.c index 3cd4f8e2..852d881e 100644 --- a/libpcsxcore/new_dynarec/emu_if.c +++ b/libpcsxcore/new_dynarec/emu_if.c @@ -30,28 +30,19 @@ u32 event_cycles[PSXINT_COUNT]; static void schedule_timeslice(void) { u32 i, c = psxRegs.cycle; + u32 irqs = psxRegs.interrupt; s32 min, dif; - min = psxNextsCounter + psxNextCounter - c; - for (i = 0; i < ARRAY_SIZE(event_cycles); i++) { + min = PSXCLK; + for (i = 0; irqs != 0; i++, irqs >>= 1) { + if (!(irqs & 1)) + continue; dif = event_cycles[i] - c; //evprintf(" ev %d\n", dif); if (0 < dif && dif < min) min = dif; } next_interupt = c + min; - -#if 0 - static u32 cnt, last_cycle; - static u64 sum; - if (last_cycle) { - cnt++; - sum += psxRegs.cycle - last_cycle; - if ((cnt & 0xff) == 0) - printf("%u\n", (u32)(sum / cnt)); - } - last_cycle = psxRegs.cycle; -#endif } typedef void (irq_func)(); @@ -68,6 +59,7 @@ static irq_func * const irq_funcs[] = { [PSXINT_CDRDMA] = cdrDmaInterrupt, [PSXINT_CDRLID] = cdrLidSeekInterrupt, [PSXINT_CDRPLAY] = cdrPlayInterrupt, + [PSXINT_RCNT] = psxRcntUpdate, }; /* local dupe of psxBranchTest, using event_cycles */ @@ -77,9 +69,6 @@ static void irq_test(void) u32 cycle = psxRegs.cycle; u32 irq, irq_bits; - if ((psxRegs.cycle - psxNextsCounter) >= psxNextCounter) - psxRcntUpdate(); - // irq_funcs() may queue more irqs psxRegs.interrupt = 0; @@ -131,15 +120,26 @@ void pcsx_mtc0_ds(u32 reg, u32 val) void new_dyna_save(void) { + psxRegs.interrupt &= ~(1 << PSXINT_RCNT); // old savestate compat + // psxRegs.intCycle is always maintained, no need to convert } +void new_dyna_after_save(void) +{ + psxRegs.interrupt |= 1 << PSXINT_RCNT; +} + void new_dyna_restore(void) { int i; for (i = 0; i < PSXINT_COUNT; i++) event_cycles[i] = psxRegs.intCycle[i].sCycle + psxRegs.intCycle[i].cycle; + event_cycles[PSXINT_RCNT] = psxNextsCounter + psxNextCounter; + psxRegs.interrupt |= 1 << PSXINT_RCNT; + psxRegs.interrupt &= (1 << PSXINT_COUNT) - 1; + new_dyna_pcsx_mem_load_state(); } diff --git a/libpcsxcore/psxcounters.c b/libpcsxcore/psxcounters.c index 6781c291..3f6e1395 100644 --- a/libpcsxcore/psxcounters.c +++ b/libpcsxcore/psxcounters.c @@ -176,6 +176,9 @@ void psxRcntSet() psxNextCounter = countToUpdate; } } + + psxRegs.interrupt |= (1 << PSXINT_RCNT); + new_dyna_set_event(PSXINT_RCNT, psxNextCounter); } /******************************************************************************/ diff --git a/libpcsxcore/r3000a.h b/libpcsxcore/r3000a.h index aced3818..76f42bcb 100644 --- a/libpcsxcore/r3000a.h +++ b/libpcsxcore/r3000a.h @@ -157,7 +157,7 @@ enum { PSXINT_GPUOTCDMA, PSXINT_CDRDMA, PSXINT_NEWDRC_CHECK, - DUMMY2, + PSXINT_RCNT, PSXINT_CDRLID, PSXINT_CDRPLAY, PSXINT_COUNT @@ -182,6 +182,7 @@ extern u32 event_cycles[PSXINT_COUNT]; extern u32 next_interupt; void new_dyna_save(void); +void new_dyna_after_save(void); void new_dyna_restore(void); #define new_dyna_set_event(e, c) { \