make root counters use generic event scheduling code
authornotaz <notasas@gmail.com>
Mon, 24 Oct 2011 20:02:51 +0000 (23:02 +0300)
committernotaz <notasas@gmail.com>
Sun, 30 Oct 2011 21:48:08 +0000 (23:48 +0200)
simplifies event handling code a bit

libpcsxcore/misc.c
libpcsxcore/new_dynarec/emu_if.c
libpcsxcore/psxcounters.c
libpcsxcore/r3000a.h

index 68ad17e..38e6385 100644 (file)
@@ -530,6 +530,8 @@ int SaveState(const char *file) {
 
        gzclose(f);
 
+       new_dyna_after_save();
+
        return 0;
 }
 
index 3cd4f8e..852d881 100644 (file)
@@ -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();
 }
 
index 6781c29..3f6e139 100644 (file)
@@ -176,6 +176,9 @@ void psxRcntSet()
             psxNextCounter = countToUpdate;
         }
     }
+
+    psxRegs.interrupt |= (1 << PSXINT_RCNT);
+    new_dyna_set_event(PSXINT_RCNT, psxNextCounter);
 }
 
 /******************************************************************************/
index aced381..76f42bc 100644 (file)
@@ -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) { \