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 ++++ src/sequencer.c | 11 +++++------ 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'src') 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 diff --git a/src/sequencer.c b/src/sequencer.c index d2a0054..a70ae85 100644 --- a/src/sequencer.c +++ b/src/sequencer.c @@ -628,6 +628,9 @@ env_start: void sequencer_tick(void) { + irs_interruptible(IRQ_VBLANK); // Audio mix. + irs_interruptible(IRQ_TIMER_1); // Audio click sync. + irs_interruptible(IRQ_TIMER_3); // Link cable sync. // switch (settings.sync) { // case SYNC_OUT_LINK_96BPQ: { gate_on(); } break; // case SYNC_OUT_LINK_48BPQ: { if (sync_ticks++ % 2 == 0) { gate_on(); } } break; @@ -647,17 +650,13 @@ sequencer_tick(void) { // default: break; // } if (nseq_ticks++ == 0) { - if (step_counter % 16 == 0) { - // first_pulse = true; - } - step_counter = (step_counter + 1) % 16; - // play_step(); + play_step(); } if (sync_ticks++ % 4 == 0) { lsdj_pulse(); } if (nseq_ticks == 24) { nseq_ticks = 0; } - // wave_ad_tick(); + wave_ad_tick(); } void -- cgit v1.2.1