From ae602c19f527fbc1f44cdb744cf824d04b8eceb1 Mon Sep 17 00:00:00 2001 From: notaz Date: Tue, 7 Dec 2010 00:06:21 +0200 Subject: [PATCH] improve event handling (still has problems though) --- libpcsxcore/cdrom.c | 8 ++++++-- libpcsxcore/new_dynarec/emu_if.c | 21 ++++++++++++++++++--- libpcsxcore/psxdma.h | 3 +++ libpcsxcore/psxmem.h | 13 +++++++++++++ libpcsxcore/sio.c | 1 + 5 files changed, 41 insertions(+), 5 deletions(-) diff --git a/libpcsxcore/cdrom.c b/libpcsxcore/cdrom.c index 92e4b7f2..02118657 100644 --- a/libpcsxcore/cdrom.c +++ b/libpcsxcore/cdrom.c @@ -94,12 +94,16 @@ static struct SubQ *subq; #define CDR_INT(eCycle) { \ psxRegs.interrupt |= 0x4; \ psxRegs.intCycle[2 + 1] = eCycle; \ - psxRegs.intCycle[2] = psxRegs.cycle; } + psxRegs.intCycle[2] = psxRegs.cycle; \ + new_dyna_set_event(0, psxRegs.cycle + eCycle); \ +} #define CDREAD_INT(eCycle) { \ psxRegs.interrupt |= 0x40000; \ psxRegs.intCycle[2 + 16 + 1] = eCycle; \ - psxRegs.intCycle[2 + 16] = psxRegs.cycle; } + psxRegs.intCycle[2 + 16] = psxRegs.cycle; \ + new_dyna_set_event(2, psxRegs.cycle + eCycle); \ +} #define StartReading(type, eCycle) { \ cdr.Reading = type; \ diff --git a/libpcsxcore/new_dynarec/emu_if.c b/libpcsxcore/new_dynarec/emu_if.c index 2560eb3a..3df83e43 100644 --- a/libpcsxcore/new_dynarec/emu_if.c +++ b/libpcsxcore/new_dynarec/emu_if.c @@ -6,12 +6,15 @@ #include "../psxmem.h" #include "../psxhle.h" +#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) + //#define memprintf printf #define memprintf(...) //#define evprintf printf #define evprintf(...) char invalid_code[0x100000]; +u32 event_cycles[6]; void MTC0_() { @@ -24,6 +27,9 @@ void MTC0_() void gen_interupt() { + u32 c, min; + int i; + evprintf("ari64_gen_interupt\n"); evprintf(" +ge %08x, %d->%d\n", psxRegs.pc, psxRegs.cycle, next_interupt); #ifdef DRC_DBG @@ -32,7 +38,16 @@ void gen_interupt() psxBranchTest(); - next_interupt = psxNextsCounter + psxNextCounter; + 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; + + //next_interupt = psxNextsCounter + psxNextCounter; evprintf(" -ge %08x, %d->%d\n", psxRegs.pc, psxRegs.cycle, next_interupt); pending_exception = 1; /* FIXME */ @@ -110,7 +125,7 @@ static int ari64_init() new_dynarec_init(); - for (i = 0; i < sizeof(readmem) / sizeof(readmem[0]); i++) { + for (i = 0; i < ARRAY_SIZE(readmem); i++) { readmemb[i] = read_mem8; readmemh[i] = read_mem16; readmem[i] = read_mem32; @@ -119,7 +134,7 @@ static int ari64_init() writemem[i] = write_mem32; } - for (i = 0; i < sizeof(gte_handlers) / sizeof(gte_handlers[0]); i++) + for (i = 0; i < ARRAY_SIZE(gte_handlers); i++) if (psxCP2[i] != psxNULL) gte_handlers[i] = psxCP2[i]; diff --git a/libpcsxcore/psxdma.h b/libpcsxcore/psxdma.h index 0db6533f..71a3eb05 100644 --- a/libpcsxcore/psxdma.h +++ b/libpcsxcore/psxdma.h @@ -33,18 +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); \ } #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); \ } #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); \ } void psxDma2(u32 madr, u32 bcr, u32 chcr); diff --git a/libpcsxcore/psxmem.h b/libpcsxcore/psxmem.h index d9fee002..222e6fbf 100644 --- a/libpcsxcore/psxmem.h +++ b/libpcsxcore/psxmem.h @@ -138,6 +138,19 @@ void psxMemWrite16(u32 mem, u16 value); void psxMemWrite32(u32 mem, u32 value); void *psxMemPointer(u32 mem); +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_; \ + } \ +} + #ifdef __cplusplus } #endif diff --git a/libpcsxcore/sio.c b/libpcsxcore/sio.c index 977c71d1..230bfed1 100644 --- a/libpcsxcore/sio.c +++ b/libpcsxcore/sio.c @@ -73,6 +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); } } -- 2.39.5