improve event handling again
authornotaz <notasas@gmail.com>
Tue, 7 Dec 2010 16:10:47 +0000 (18:10 +0200)
committernotaz <notasas@gmail.com>
Tue, 14 Dec 2010 13:25:04 +0000 (15:25 +0200)
libpcsxcore/cdrom.c
libpcsxcore/new_dynarec/emu_if.c
libpcsxcore/psxdma.h
libpcsxcore/psxmem.h
libpcsxcore/sio.c

index 0211865..d7f4d80 100644 (file)
@@ -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) { \
index 3df83e4..dff7f21 100644 (file)
@@ -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)
index 71a3eb0..6736cdb 100644 (file)
@@ -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);
index 222e6fb..b409603 100644 (file)
@@ -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_; \
        } \
 }
 
index 230bfed..b63f56b 100644 (file)
@@ -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);
        }
 }