From 654e8cfb205bebc40b26761a900db354b4920931 Mon Sep 17 00:00:00 2001 From: notaz Date: Tue, 7 Dec 2010 18:10:47 +0200 Subject: [PATCH] improve event handling again --- libpcsxcore/cdrom.c | 4 +-- libpcsxcore/new_dynarec/emu_if.c | 58 +++++++++++++++++++++----------- libpcsxcore/psxdma.h | 6 ++-- libpcsxcore/psxmem.h | 13 +++---- libpcsxcore/sio.c | 2 +- 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/libpcsxcore/cdrom.c b/libpcsxcore/cdrom.c index 02118657..d7f4d80c 100644 --- a/libpcsxcore/cdrom.c +++ b/libpcsxcore/cdrom.c @@ -95,14 +95,14 @@ static struct SubQ *subq; psxRegs.interrupt |= 0x4; \ psxRegs.intCycle[2 + 1] = eCycle; \ psxRegs.intCycle[2] = psxRegs.cycle; \ - new_dyna_set_event(0, psxRegs.cycle + eCycle); \ + new_dyna_set_event(0, eCycle); \ } #define CDREAD_INT(eCycle) { \ psxRegs.interrupt |= 0x40000; \ psxRegs.intCycle[2 + 16 + 1] = eCycle; \ psxRegs.intCycle[2 + 16] = psxRegs.cycle; \ - new_dyna_set_event(2, psxRegs.cycle + eCycle); \ + new_dyna_set_event(2, eCycle); \ } #define StartReading(type, eCycle) { \ diff --git a/libpcsxcore/new_dynarec/emu_if.c b/libpcsxcore/new_dynarec/emu_if.c index 3df83e43..dff7f21b 100644 --- a/libpcsxcore/new_dynarec/emu_if.c +++ b/libpcsxcore/new_dynarec/emu_if.c @@ -25,30 +25,47 @@ void MTC0_() pending_exception = 1; /* FIXME? */ } -void gen_interupt() +static void schedule_timeslice(void) { - u32 c, min; - int i; + u32 i, c = psxRegs.cycle; + s32 min, dif; + + min = psxNextsCounter + psxNextCounter - c; + for (i = 0; i < ARRAY_SIZE(event_cycles); i++) { + 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 +} - evprintf("ari64_gen_interupt\n"); - evprintf(" +ge %08x, %d->%d\n", psxRegs.pc, psxRegs.cycle, next_interupt); +void gen_interupt() +{ + //evprintf("ari64_gen_interupt\n"); + evprintf(" +ge %08x, %u->%u\n", psxRegs.pc, psxRegs.cycle, next_interupt); #ifdef DRC_DBG psxRegs.cycle += 2; #endif psxBranchTest(); - min = psxNextsCounter + psxNextCounter; - for (i = 0; i < ARRAY_SIZE(event_cycles); i++) { - c = event_cycles[i]; - evprintf(" ev %d\n", c - psxRegs.cycle); - if (psxRegs.cycle < c && c < min) - min = c; - } - next_interupt = min; + schedule_timeslice(); - //next_interupt = psxNextsCounter + psxNextCounter; - evprintf(" -ge %08x, %d->%d\n", psxRegs.pc, psxRegs.cycle, next_interupt); + evprintf(" -ge %08x, %u->%u (%d)\n", psxRegs.pc, psxRegs.cycle, + next_interupt, next_interupt - psxRegs.cycle); pending_exception = 1; /* FIXME */ } @@ -149,12 +166,15 @@ static void ari64_reset() static void ari64_execute() { - next_interupt = psxNextsCounter + psxNextCounter; + schedule_timeslice(); + + evprintf("ari64_execute %08x, %u->%u (%d)\n", psxRegs.pc, + psxRegs.cycle, next_interupt, next_interupt - psxRegs.cycle); - evprintf("psxNextsCounter %d, psxNextCounter %d\n", psxNextsCounter, psxNextCounter); - evprintf("ari64_execute %08x, %d->%d\n", psxRegs.pc, psxRegs.cycle, next_interupt); new_dyna_start(); - evprintf("ari64_execute end %08x, %d->%d\n", psxRegs.pc, psxRegs.cycle, next_interupt); + + evprintf("ari64_execute end %08x, %u->%u (%d)\n", psxRegs.pc, + psxRegs.cycle, next_interupt, next_interupt - psxRegs.cycle); } static void ari64_clear(u32 Addr, u32 Size) diff --git a/libpcsxcore/psxdma.h b/libpcsxcore/psxdma.h index 71a3eb05..6736cdb2 100644 --- a/libpcsxcore/psxdma.h +++ b/libpcsxcore/psxdma.h @@ -33,21 +33,21 @@ extern "C" { psxRegs.interrupt |= 0x01000000; \ psxRegs.intCycle[3 + 24 + 1] = eCycle; \ psxRegs.intCycle[3 + 24] = psxRegs.cycle; \ - new_dyna_set_event(3, psxRegs.cycle + eCycle); \ + new_dyna_set_event(3, eCycle); \ } #define SPUDMA_INT(eCycle) { \ psxRegs.interrupt |= 0x04000000; \ psxRegs.intCycle[1 + 24 + 1] = eCycle; \ psxRegs.intCycle[1 + 24] = psxRegs.cycle; \ - new_dyna_set_event(5, psxRegs.cycle + eCycle); \ + new_dyna_set_event(5, eCycle); \ } #define MDECOUTDMA_INT(eCycle) { \ psxRegs.interrupt |= 0x02000000; \ psxRegs.intCycle[5 + 24 + 1] = eCycle; \ psxRegs.intCycle[5 + 24] = psxRegs.cycle; \ - new_dyna_set_event(4, psxRegs.cycle + eCycle); \ + new_dyna_set_event(4, eCycle); \ } void psxDma2(u32 madr, u32 bcr, u32 chcr); diff --git a/libpcsxcore/psxmem.h b/libpcsxcore/psxmem.h index 222e6fbf..b4096034 100644 --- a/libpcsxcore/psxmem.h +++ b/libpcsxcore/psxmem.h @@ -142,12 +142,13 @@ extern u32 event_cycles[6]; extern u32 next_interupt; #define new_dyna_set_event(e, c) { \ - u32 c_ = c; \ - event_cycles[e] = c_; \ - if (c_ < next_interupt) { \ - /*printf("%u: next_interupt %d -> %d\n", psxRegs.cycle, \ - next_interupt - psxRegs.cycle, c_ - psxRegs.cycle);*/ \ - next_interupt = c_; \ + s32 c_ = c; \ + u32 abs_ = psxRegs.cycle + c_; \ + s32 odi_ = next_interupt - psxRegs.cycle; \ + event_cycles[e] = abs_; \ + if (c_ < odi_) { \ + /*printf("%u: next_interupt %d -> %d (%u)\n", psxRegs.cycle, odi_, c_, abs_);*/ \ + next_interupt = abs_; \ } \ } diff --git a/libpcsxcore/sio.c b/libpcsxcore/sio.c index 230bfed1..b63f56b9 100644 --- a/libpcsxcore/sio.c +++ b/libpcsxcore/sio.c @@ -73,7 +73,7 @@ static inline void SIO_INT() { psxRegs.interrupt |= 0x80; psxRegs.intCycle[7 + 1] = 400; psxRegs.intCycle[7] = psxRegs.cycle; - new_dyna_set_event(1, psxRegs.cycle + 400); + new_dyna_set_event(1, 400); } } -- 2.39.2