On Tue, Dec 13, 2016 at 10:49 PM, Ethan Dicks <ethan.dicks at gmail.com> wrote:
Hi, All,
I'm disassembling a vintage program and ran across this bit of code
that is causing emulators to hang...
MYSUB:
LD A,R
JP M, MYSUB
JR Z, MYSUB
CP 0x65
RET M
LD A, 0x32
RET
I know plenty of 8-bit assembler (mostly 6502, 1802, and a couple
others), but I'm by no means expert on the Z-80. It appears that this
subroutine is spinning on the value of the refresh register if it's
zero or negative, then if it's below 0x65, return the former contents
of the refresh register and if not, return 0x32?
Well, I'm not a programmer, but...
As I understand it, the R register -- the refresh counter -- is
actually a 7 bit counter. The
top bit can be loaded or read, but when the refresh counter is
incremented at the end of
each instruction it will not be changed. This was actually a problem
when using some types
of 64K bit DRAMs which expected an 8 bit refresh address. The entire R
registers is put on
the low half of the address bus when RFSH/ is asserted, but only
A0...A6 will be incremented.
A7 will not change unless a program changes it.
Which means that if R is negative (the top bit is set for some
reason), MYSUB on a real
Z80 will get into an endless loop.
-tony