diff --git a/inc/n64_cp0.inc b/inc/n64_cp0.inc index 03a88d9..060acb7 100644 --- a/inc/n64_cp0.inc +++ b/inc/n64_cp0.inc @@ -43,7 +43,7 @@ constant CP0_STATUS_IM4($1000) // Interrupt Mask 4 (External) constant CP0_STATUS_IM5($2000) // Interrupt Mask 5 (External) constant CP0_STATUS_IM6($4000) // Interrupt Mask 6 (External) constant CP0_STATUS_IM7($8000) // Interrupt Mask 7 (External) -constant CP0_STATUS_IM_ALL($FF01) // enable all interrupts +constant CP0_STATUS_IM_ALL($FF00) // all interrupt masks // note that these are all masks. constant CP0_CAUSE_CODE($007C) // actually supposed to be called ExcCode diff --git a/inc/n64_sp.inc b/inc/n64_sp.inc index 6e3fce5..b758df1 100644 --- a/inc/n64_sp.inc +++ b/inc/n64_sp.inc @@ -77,7 +77,7 @@ macro SP_BUSY_WAIT() { - lw t0, SP_STATUS(a0) andi t0, 0x1C - sltu t0, r0, t0 // TODO: rewrite this + sltu t0, r0, t0 bnez t0,- nop } diff --git a/inc/n64_util.inc b/inc/n64_util.inc index a42a88a..f82435e 100644 --- a/inc/n64_util.inc +++ b/inc/n64_util.inc @@ -1,4 +1,20 @@ macro EnableInt() { + // careful not to touch unrelated flags here + mfc0 t0, CP0_Status + addiu at, r0, CP0_STATUS_IE + or t0, at + mtc0 t0, CP0_Status +} + +macro DisableInt() { + // careful not to touch unrelated flags here + mfc0 t0, CP0_Status + addiu at, r0, ~CP0_STATUS_IE + and t0, at + mtc0 t0, CP0_Status +} + +macro SetIntMask() { lli t0, MI_INTR_MASK_ALL_SET lui a0, MI_BASE sw t0, MI_INTR_MASK(a0) @@ -9,7 +25,7 @@ macro EnableInt() { mtc0 t1, CP0_Status } -macro DisableInt() { +macro ClearIntMask() { lli t0, MI_INTR_MASK_ALL_CLR lui a0, MI_BASE sw t0, MI_INTR_MASK(a0) diff --git a/kernel.asm b/kernel.asm index a7320eb..24e5d1d 100644 --- a/kernel.asm +++ b/kernel.asm @@ -40,7 +40,7 @@ Start: // enable CPU interrupts. mfc0 t1, CP0_Status - ori t1, t1, CP0_STATUS_IM_ALL + ori t1, t1, CP0_STATUS_IM_ALL | CP0_STATUS_IE mtc0 t1, CP0_Status // enable even more interrupts. @@ -440,7 +440,7 @@ K_MI_SP: lui a1, SP_BASE sw t0, SP_STATUS(a1) - // then check andi t1, SG1 | SG2 ? + // then check andi t1, SP_SG1 | SP_SG2 ? lw t0, K_HISTORY(k0) ori t0, 0x01 diff --git a/main.asm b/main.asm index 19e8419..5523ff1 100644 --- a/main.asm +++ b/main.asm @@ -85,7 +85,7 @@ include "dlist.asm" // takes a0 nop Start3D: - DisableInt() + ClearIntMask() // stuff i'm borrowing from zelda: lui a0, SP_BASE @@ -126,7 +126,7 @@ Start3D: sw t0, SP_STATUS(a0) nop - EnableInt() + SetIntMask() MainLoop: lui a0, K_BASE