Cycle count coming up:
Code: Select all
ld a,(hl) ; (7)
out (6),a ;(11)
in a,(3) ;(11)
inc hl ; (6)
ld a,(hl) ; (7)
out (6),a ;(11)
in a,(3) ;(11)
This code has 35 cycles (T states) between the end of one IN(3) and the end of the next one. However it also has the latch being changed while the sound chip is still reading it.
Getting really technical (possibly too technical!) :
Looking at the timing diagrams in the Z80 manual, it would appear that IORQ goes high on the 4th T state of the final machine cycle of IN(3).
It will go low again at the start of the 2nd T state of the 3rd machine cycle of the following OUT (6), that's the 9th T state over all.
SO to leave a minimum 32 cycle gap between activations of the IORQ line would need 24 Cycles between the end of the IN (3) and the start of the OUT (6) . At the moment there are 13. Push/Pop 21 is cycles, more than enough to work, 3 NOPs would be 12, but that's a byte more if you're short of space.
However if it fits with other code you could also use IX for the pointer instead of HL which would increase the cycle count past 24.
Code: Select all
ld a,(IX+0) ;(19)
out (6),a ;(11)
in a,(3) ;(11)
inc IX ;(10)
ld a,(IX+0) ;(19)
out (6),a ;(11)
in a,(3) ;(11)
NB a call and return is 25 cycles, so pretty much guarantees that if you put the OUT(6) / IN (3) sequence as a subroutine you can't mess up the timing (at 4 MHz anyway) and may also save space if called from enough locations.