adjust bios handling again
[pcsx_rearmed.git] / libpcsxcore / new_dynarec / events.c
CommitLineData
6d75addf 1#include <stdio.h>
2#include "../r3000a.h"
3#include "../cdrom.h"
4#include "../psxdma.h"
5#include "../mdec.h"
6#include "events.h"
7
8extern int pending_exception;
9
10//#define evprintf printf
11#define evprintf(...)
12
13u32 event_cycles[PSXINT_COUNT];
14
15void schedule_timeslice(void)
16{
17 u32 i, c = psxRegs.cycle;
18 u32 irqs = psxRegs.interrupt;
19 s32 min, dif;
20
21 min = PSXCLK;
22 for (i = 0; irqs != 0; i++, irqs >>= 1) {
23 if (!(irqs & 1))
24 continue;
25 dif = event_cycles[i] - c;
26 //evprintf(" ev %d\n", dif);
27 if (0 < dif && dif < min)
28 min = dif;
29 }
30 next_interupt = c + min;
31}
32
33static void unusedInterrupt()
34{
35}
36
37typedef void (irq_func)();
38
39static 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_CDRLID] = cdrLidSeekInterrupt,
50 [PSXINT_CDRPLAY_OLD] = unusedInterrupt,
51 [PSXINT_SPU_UPDATE] = spuUpdate,
52 [PSXINT_RCNT] = psxRcntUpdate,
53};
54
55/* local dupe of psxBranchTest, using event_cycles */
56static void irq_test(psxCP0Regs *cp0)
57{
58 u32 cycle = psxRegs.cycle;
59 u32 irq, irq_bits;
60
61 for (irq = 0, irq_bits = psxRegs.interrupt; irq_bits != 0; irq++, irq_bits >>= 1) {
62 if (!(irq_bits & 1))
63 continue;
64 if ((s32)(cycle - event_cycles[irq]) >= 0) {
65 // note: irq_funcs() also modify psxRegs.interrupt
66 psxRegs.interrupt &= ~(1u << irq);
67 irq_funcs[irq]();
68 }
69 }
70
71 if ((psxHu32(0x1070) & psxHu32(0x1074)) && (cp0->n.Status & 0x401) == 0x401) {
72 psxException(0x400, 0, cp0);
73 pending_exception = 1;
74 }
75}
76
77void gen_interupt(psxCP0Regs *cp0)
78{
79 evprintf(" +ge %08x, %u->%u (%d)\n", psxRegs.pc, psxRegs.cycle,
80 next_interupt, next_interupt - psxRegs.cycle);
81
82 irq_test(cp0);
83 //pending_exception = 1;
84
85 schedule_timeslice();
86
87 evprintf(" -ge %08x, %u->%u (%d)\n", psxRegs.pc, psxRegs.cycle,
88 next_interupt, next_interupt - psxRegs.cycle);
89}
90
91