aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2024-05-10 17:49:56 +0200
committerBad Diode <bd@badd10de.dev>2024-05-10 17:49:56 +0200
commit33451307ae4e3a4119dd6be46b25aec03aa51b5d (patch)
tree3dde87e12187e3400cd60f9045678f3fb29adca1
parent901ba917a3b4812f7eacf93d55389978a907a44d (diff)
downloadstepper-33451307ae4e3a4119dd6be46b25aec03aa51b5d.tar.gz
stepper-33451307ae4e3a4119dd6be46b25aec03aa51b5d.zip
Ensure long irs sequencer_tick can be interrupted
-rw-r--r--src/gba/gba.h8
-rw-r--r--src/gba/interrupts.s4
-rw-r--r--src/sequencer.c11
3 files changed, 17 insertions, 6 deletions
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);
534// assembly and enable interrupts. 534// assembly and enable interrupts.
535void irq_init(void); 535void irq_init(void);
536 536
537// Only should be used inside an IrsFunc to enable it being interrupted by the
538// given interrupt (nested IRS).
539static inline void
540irs_interruptible(IrqIndex idx) {
541 IRQ_ENABLE |= (1 << idx);
542 IRQ_CTRL = 1;
543}
544
537// 545//
538// BIOS function declarations. 546// BIOS function declarations.
539// 547//
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:
67 bx r2 67 bx r2
68 ldmfd sp!, {lr} 68 ldmfd sp!, {lr}
69 69
70 @ Clear IRQ enable again just in case it was enabled from within the IRS.
71 mov r3, #0 @ r3 = 0
72 strh r3, [ip, #8] @ *(ip + 0x8) = r3
73
70 @ Set CPU to irq mode 74 @ Set CPU to irq mode
71 mrs r3, cpsr 75 mrs r3, cpsr
72 bic r3, r3, #0xDF 76 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:
628 628
629void 629void
630sequencer_tick(void) { 630sequencer_tick(void) {
631 irs_interruptible(IRQ_VBLANK); // Audio mix.
632 irs_interruptible(IRQ_TIMER_1); // Audio click sync.
633 irs_interruptible(IRQ_TIMER_3); // Link cable sync.
631 // switch (settings.sync) { 634 // switch (settings.sync) {
632 // case SYNC_OUT_LINK_96BPQ: { gate_on(); } break; 635 // case SYNC_OUT_LINK_96BPQ: { gate_on(); } break;
633 // case SYNC_OUT_LINK_48BPQ: { if (sync_ticks++ % 2 == 0) { gate_on(); } } break; 636 // case SYNC_OUT_LINK_48BPQ: { if (sync_ticks++ % 2 == 0) { gate_on(); } } break;
@@ -647,17 +650,13 @@ sequencer_tick(void) {
647 // default: break; 650 // default: break;
648 // } 651 // }
649 if (nseq_ticks++ == 0) { 652 if (nseq_ticks++ == 0) {
650 if (step_counter % 16 == 0) { 653 play_step();
651 // first_pulse = true;
652 }
653 step_counter = (step_counter + 1) % 16;
654 // play_step();
655 } 654 }
656 if (sync_ticks++ % 4 == 0) { lsdj_pulse(); } 655 if (sync_ticks++ % 4 == 0) { lsdj_pulse(); }
657 if (nseq_ticks == 24) { 656 if (nseq_ticks == 24) {
658 nseq_ticks = 0; 657 nseq_ticks = 0;
659 } 658 }
660 // wave_ad_tick(); 659 wave_ad_tick();
661} 660}
662 661
663void 662void