improve event handling (still has problems though)
authornotaz <notasas@gmail.com>
Mon, 6 Dec 2010 22:06:21 +0000 (00:06 +0200)
committernotaz <notasas@gmail.com>
Tue, 14 Dec 2010 13:24:50 +0000 (15:24 +0200)
libpcsxcore/cdrom.c
libpcsxcore/new_dynarec/emu_if.c
libpcsxcore/psxdma.h
libpcsxcore/psxmem.h
libpcsxcore/sio.c

index 92e4b7f..0211865 100644 (file)
@@ -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; \
index 2560eb3..3df83e4 100644 (file)
@@ -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];
 
index 0db6533..71a3eb0 100644 (file)
@@ -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);
index d9fee00..222e6fb 100644 (file)
@@ -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
index 977c71d..230bfed 100644 (file)
@@ -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);
        }
 }