Skip to content

Commit f5e2268

Browse files
committed
Fix ym2610 reentrant write to port A
The logic to allow IRQ and common code to write to YM2610 port A relies on an intermediate byte in RAM to store the current register that is being written to. There was a bug in the logic in function ym2610_restore_context_port_a where we always restore a context, even if no write was being in progress which ended up configuring the YM2610 to write to register 0xff, which is invalid.
1 parent 03a5d24 commit f5e2268

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

nullsound/ym2610.s

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
.include "ym2610.inc"
2323

2424

25+
.lclequ CTX_NO_REGISTER, 0xff
26+
27+
2528
.area DATA
2629

2730

@@ -55,7 +58,7 @@ ym2610_write_port_a::
5558
out (PORT_YM2610_A_VALUE), a
5659
call _ym2610_wait_data_write
5760
;; reentrant: clear register context
58-
ld a, #0xff
61+
ld a, #CTX_NO_REGISTER
5962
ld (state_ym2610_context_port_a), a
6063
pop af
6164
ret
@@ -121,8 +124,11 @@ ym2610_wait_available::
121124
;;; (all registers are preserved)
122125
ym2610_restore_context_port_a::
123126
ld a, (state_ym2610_context_port_a)
127+
cp #CTX_NO_REGISTER
128+
jr z, _end_restore_context
124129
out (PORT_YM2610_A_ADDR), a
125130
call _ym2610_wait_address_write
131+
_end_restore_context:
126132
ret
127133

128134

0 commit comments

Comments
 (0)