From 33451307ae4e3a4119dd6be46b25aec03aa51b5d Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Fri, 10 May 2024 17:49:56 +0200 Subject: Ensure long irs sequencer_tick can be interrupted --- src/gba/gba.h | 8 ++++++++ src/gba/interrupts.s | 4 ++++ 2 files changed, 12 insertions(+) (limited to 'src/gba') diff --git a/src/gba/gba.h b/src/gba/gba.h index 3f629fd..1bb3afd 100644 --- a/src/gba/gba.h +++ b/src/gba/gba.h @@ -534,6 +534,14 @@ void irs_set(IrqIndex idx, IrsFunc func); // assembly and enable interrupts. void irq_init(void); +// Only should be used inside an IrsFunc to enable it being interrupted by the +// given interrupt (nested IRS). +static inline void +irs_interruptible(IrqIndex idx) { + IRQ_ENABLE |= (1 << idx); + IRQ_CTRL = 1; +} + // // BIOS function declarations. // diff --git a/src/gba/interrupts.s b/src/gba/interrupts.s index 67b9fe9..1d3e001 100644 --- a/src/gba/interrupts.s +++ b/src/gba/interrupts.s @@ -67,6 +67,10 @@ irs_main_handle_irs: bx r2 ldmfd sp!, {lr} + @ Clear IRQ enable again just in case it was enabled from within the IRS. + mov r3, #0 @ r3 = 0 + strh r3, [ip, #8] @ *(ip + 0x8) = r3 + @ Set CPU to irq mode mrs r3, cpsr bic r3, r3, #0xDF -- cgit v1.2.1