8 extern int pending_exception;
10 //#define evprintf printf
13 u32 event_cycles[PSXINT_COUNT];
15 u32 schedule_timeslice(void)
17 u32 i, c = psxRegs.cycle;
18 u32 irqs = psxRegs.interrupt;
22 for (i = 0; irqs != 0; i++, irqs >>= 1) {
25 dif = event_cycles[i] - c;
26 //evprintf(" ev %d\n", dif);
27 if (0 < dif && dif < min)
30 next_interupt = c + min;
34 static void irqNoOp() {
37 typedef void (irq_func)();
39 static irq_func * const irq_funcs[] = {
40 [PSXINT_SIO] = sioInterrupt,
41 [PSXINT_CDR] = cdrInterrupt,
42 [PSXINT_CDREAD] = cdrPlayReadInterrupt,
43 [PSXINT_GPUDMA] = gpuInterrupt,
44 [PSXINT_MDECOUTDMA] = mdec1Interrupt,
45 [PSXINT_SPUDMA] = spuInterrupt,
46 [PSXINT_MDECINDMA] = mdec0Interrupt,
47 [PSXINT_GPUOTCDMA] = gpuotcInterrupt,
48 [PSXINT_CDRDMA] = cdrDmaInterrupt,
49 [PSXINT_NEWDRC_CHECK] = irqNoOp,
50 [PSXINT_CDRLID] = cdrLidSeekInterrupt,
51 [PSXINT_IRQ10] = irq10Interrupt,
52 [PSXINT_SPU_UPDATE] = spuUpdate,
53 [PSXINT_SPU_IRQ] = spuDelayedIrq,
54 [PSXINT_RCNT] = psxRcntUpdate,
57 /* local dupe of psxBranchTest, using event_cycles */
58 void irq_test(psxCP0Regs *cp0)
60 u32 cycle = psxRegs.cycle;
63 for (irq = 0, irq_bits = psxRegs.interrupt; irq_bits != 0; irq++, irq_bits >>= 1) {
66 if ((s32)(cycle - event_cycles[irq]) >= 0) {
67 // note: irq_funcs() also modify psxRegs.interrupt
68 psxRegs.interrupt &= ~(1u << irq);
73 cp0->n.Cause &= ~0x400;
74 if (psxHu32(0x1070) & psxHu32(0x1074))
75 cp0->n.Cause |= 0x400;
76 if (((cp0->n.Cause | 1) & cp0->n.SR & 0x401) == 0x401) {
77 psxException(0, 0, cp0);
78 pending_exception = 1;
82 void gen_interupt(psxCP0Regs *cp0)
84 evprintf(" +ge %08x, %u->%u (%d)\n", psxRegs.pc, psxRegs.cycle,
85 next_interupt, next_interupt - psxRegs.cycle);
88 //pending_exception = 1;
92 evprintf(" -ge %08x, %u->%u (%d)\n", psxRegs.pc, psxRegs.cycle,
93 next_interupt, next_interupt - psxRegs.cycle);
96 void events_restore(void)
99 for (i = 0; i < PSXINT_COUNT; i++)
100 event_cycles[i] = psxRegs.intCycle[i].sCycle + psxRegs.intCycle[i].cycle;
102 event_cycles[PSXINT_RCNT] = psxNextsCounter + psxNextCounter;
103 psxRegs.interrupt |= 1 << PSXINT_RCNT;
104 psxRegs.interrupt &= (1 << PSXINT_COUNT) - 1;