diff --git a/cdrom.jam b/cdrom.jam index 3418f4a..88744cc 100644 --- a/cdrom.jam +++ b/cdrom.jam @@ -843,7 +843,7 @@ pub const Cdrom = struct { } // Only raise CPU IRQ if the corresponding IER bit is enabled. if ((self.ifr as u32 & self.ier as u32 & 0x1F) == 0) { return; } - irqRaise(ic, cop0, IC_CDROM()); + irqRaise(ic, cop0, IC_CDROM); } pub fn handleRead(self: mut Self, disc: *mut[] Disc, spu: *mut[] u8) { diff --git a/dma.jam b/dma.jam index f392053..45f458a 100644 --- a/dma.jam +++ b/dma.jam @@ -22,7 +22,6 @@ const { Disc } = import("disc"); const SPU_TFIFO_OFF: u32 = 0x1A8; - // d[0..20] = 7 channels × 3 regs (MADR/BCR/CHCR) // d[21] = DPCR // d[22] = DICR @@ -503,7 +502,7 @@ pub fn dmaUpdate(d: *mut[] u32, ic: *mut[] u32, cop0: *mut[] u32) { const signal: bool = forceB || (flagsB && irqEn); - if (signal && !prev) { irqRaise(ic, cop0, IC_DMA()); } + if (signal && !prev) { irqRaise(ic, cop0, IC_DMA); } d[22] = d[22] & (~DICR_IRQSI); if (signal) { d[22] = d[22] | DICR_IRQSI; } diff --git a/irq.jam b/irq.jam index ea27ee5..9a2f20f 100644 --- a/irq.jam +++ b/irq.jam @@ -15,17 +15,17 @@ const { Vec } = import("std/collections"); // IRQ line bits (psxe ic.h: IC_VBLANK = 0x001, etc.). -pub fn IC_VBLANK() u32 { return 0x001; } -pub fn IC_GPU() u32 { return 0x002; } -pub fn IC_CDROM() u32 { return 0x004; } -pub fn IC_DMA() u32 { return 0x008; } -pub fn IC_TIMER0() u32 { return 0x010; } -pub fn IC_TIMER1() u32 { return 0x020; } -pub fn IC_TIMER2() u32 { return 0x040; } -pub fn IC_JOY() u32 { return 0x080; } -pub fn IC_SIO() u32 { return 0x100; } -pub fn IC_SPU() u32 { return 0x200; } -pub fn IC_LP_PIO() u32 { return 0x400; } +pub const IC_VBLANK: u32 = 0x001; +pub const IC_GPU: u32 = 0x002; +pub const IC_CDROM: u32 = 0x004; +pub const IC_DMA: u32 = 0x008; +pub const IC_TIMER0: u32 = 0x010; +pub const IC_TIMER1: u32 = 0x020; +pub const IC_TIMER2: u32 = 0x040; +pub const IC_JOY: u32 = 0x080; +pub const IC_SIO: u32 = 0x100; +pub const IC_SPU: u32 = 0x200; +pub const IC_LP_PIO: u32 = 0x400; // COP0 CAUSE bit that signals "external IRQ pending". The R3000's // general exception handler dispatches on this when SR.IEC and SR.IM2 diff --git a/main.jam b/main.jam index 1522d9c..11dd738 100644 --- a/main.jam +++ b/main.jam @@ -330,7 +330,7 @@ fn runOneFrame(c: mut Cpu, bus: Bus, regs: *mut[] u32, cop0: *mut[] u32, line = line + 1; if (line == SCANLINES_VDRAW) { bus.timer.vblankBegin(bus.irq.ptr, cop0); - irqRaise(bus.irq.ptr, cop0, IC_VBLANK()); + irqRaise(bus.irq.ptr, cop0, IC_VBLANK); } else if (line == SCANLINES_TOTAL) { bus.timer.vblankEnd(); line = 0; diff --git a/pad.jam b/pad.jam index a335e80..1b92596 100644 --- a/pad.jam +++ b/pad.jam @@ -323,5 +323,5 @@ pub fn padUpdate(p: *mut[] u8, ic: *mut[] u32, cop0: *mut[] u32, cyc: u32) { padSetU16(p, P_STAT_LO, stat); p[P_IRQ_BIT] = 0; } - irqRaise(ic, cop0, IC_JOY()); + irqRaise(ic, cop0, IC_JOY); } diff --git a/sdl.jam b/sdl.jam index 026ee8c..e606cf8 100644 --- a/sdl.jam +++ b/sdl.jam @@ -358,21 +358,23 @@ const BTN_SQUARE: u32 = 0x8000; // for unmapped keys. Keep close to the standard PCSX / DuckStation / // PSXE keybinding layout so it feels familiar. pub fn scancodeToBtn(scan: u32) u32 { - if (scan == SC_UP) { return BTN_UP; } - if (scan == SC_DOWN) { return BTN_DOWN; } - if (scan == SC_LEFT) { return BTN_LEFT; } - if (scan == SC_RIGHT) { return BTN_RIGHT; } - if (scan == SC_Z) { return BTN_CROSS; } - if (scan == SC_X) { return BTN_CIRCLE; } - if (scan == SC_A) { return BTN_SQUARE; } - if (scan == SC_S) { return BTN_TRIANGLE; } - if (scan == SC_Q) { return BTN_L1; } - if (scan == SC_W) { return BTN_R1; } - if (scan == SC_1) { return BTN_L2; } - if (scan == SC_2) { return BTN_R2; } - if (scan == SC_RETURN) { return BTN_START; } - if (scan == SC_RSHIFT) { return BTN_SELECT; } - return 0; + match (scan) { + SC_UP { return BTN_UP; } + SC_DOWN { return BTN_DOWN; } + SC_LEFT { return BTN_LEFT; } + SC_RIGHT { return BTN_RIGHT; } + SC_Z { return BTN_CROSS; } + SC_X { return BTN_CIRCLE; } + SC_A { return BTN_SQUARE; } + SC_S { return BTN_TRIANGLE; } + SC_Q { return BTN_L1; } + SC_W { return BTN_R1; } + SC_1 { return BTN_L2; } + SC_2 { return BTN_R2; } + SC_RETURN { return BTN_START; } + SC_RSHIFT { return BTN_SELECT; } + _ { return 0; } + } } // Pump SDL events. Returns non-zero when the user has requested quit diff --git a/sio1.jam b/sio1.jam index 59881e0..fe89417 100644 --- a/sio1.jam +++ b/sio1.jam @@ -222,7 +222,7 @@ pub const Sio1 = struct { // response byte we staged in writeData is "received"). if ((ctrl & (CTRL_TX_IE | CTRL_RX_IE)) != 0) { self.stat = self.stat | STAT_IRQ; - irqRaise(ic, cop0, IC_SIO()); + irqRaise(ic, cop0, IC_SIO); } } }; diff --git a/spu.jam b/spu.jam index 4044222..83f0940 100644 --- a/spu.jam +++ b/spu.jam @@ -881,11 +881,11 @@ pub fn spuGetSample(s: *mut[] u8, ram: *mut[] u8, const irq9: u32 = getU16(s, R_IRQADDR) << 3; const spucnt: u32 = getU16(s, R_SPUCNT); if (irq9 == getU32(s, rt + D_CURADDR) && (spucnt & 0x40) != 0) { - irqRaise(ic, cop0, IC_SPU()); + irqRaise(ic, cop0, IC_SPU); } setU32(s, rt + D_CURADDR, getU32(s, rt + D_CURADDR) + 0x10); if (irq9 == getU32(s, rt + D_CURADDR) && (spucnt & 0x40) != 0) { - irqRaise(ic, cop0, IC_SPU()); + irqRaise(ic, cop0, IC_SPU); } } else if (lp == 1) { setU32(s, rt + D_CURADDR, getU32(s, rt + D_REPADDR)); diff --git a/tests.jam b/tests.jam index 0fa1321..7457136 100644 --- a/tests.jam +++ b/tests.jam @@ -541,7 +541,7 @@ fn emuRunOneFrame(c: mut Cpu, bus: Bus, regs: Vec(u32), cop0: Vec(u32)) { bus.timer.hblankEnd(); if (line == SCANLINES_VDRAW) { bus.timer.vblankBegin(bus.irq.ptr, cop0.ptr); - irqRaise(bus.irq.ptr, cop0.ptr, IC_VBLANK()); + irqRaise(bus.irq.ptr, cop0.ptr, IC_VBLANK); } line = line + 1; } diff --git a/timer.jam b/timer.jam index 708a4e8..81ecf90 100644 --- a/timer.jam +++ b/timer.jam @@ -175,10 +175,10 @@ pub const Timer = struct { self.channels[idx].irq = 1; if (trigger) { - var line: u32 = IC_TIMER0(); + var line: u32 = IC_TIMER0; match (idx) { - 1 { line = IC_TIMER1(); } - 2 { line = IC_TIMER2(); } + 1 { line = IC_TIMER1; } + 2 { line = IC_TIMER2; } _ {} } irqRaise(ic, cop0, line);