Skip to content

Commit 8bd4563

Browse files
committed
nullsound: fix race when handling NMI and INT concurrently
When a Timer interrupts the current sound driver, the interrupt handler has to save current registers. During this execution, new interrupts are masked, but a NMI can still occur and interrupt the interrupt handler. To avoid losing the state of the original sound driver, one cannot use shadow registers for both Timer and NMI handlers. Instead, make the Timer interrupt handler save register on the stack. Closes #115
1 parent caebcc3 commit 8bd4563

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

nullsound/entrypoint.s

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@
5959
;;;
6060
.org 0x0038
6161
di
62-
ex af, af'
63-
exx
6462
call update_timer_state_tracker
65-
exx
66-
ex af', af
6763
ei
6864
reti
6965

nullsound/timer.s

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ init_timer_state_tracker::
6060
ret
6161

6262

63+
;;; Acknowledge and re-arm YM2610 timers
64+
;;; all registers must be preserved, no shadow register must be
65+
;;; used as they are currently reserved for processing NMI
66+
;;; ------
6367
update_timer_state_tracker::
68+
push af
69+
push bc
6470
ld a, #TIMER_CONSUMER_ALL
6571
ld (state_timer_tick_reached), a
6672
;; keep track of the new interrupt
@@ -89,6 +95,8 @@ update_timer_state_tracker::
8995
;; interrupt handler
9096
call ym2610_restore_context_port_a
9197

98+
pop bc
99+
pop af
92100
ret
93101

94102

0 commit comments

Comments
 (0)