Here's an interesting tidbit that tripped me up for hours and hours. I couldn't for the life of me figure out why my console output code wasn't working. It was behaving as if it wasn't waiting for the transmit buffer to be empty, even though I literally copied and pasted the same code from another program, where it worked fine. The code is:
Code:
; siost is the status register, and sioda is data
co:
;console output (arrive with character in c)
in a,(siost)
and a,01h
jr z,co
ld a,c
out (sioda),a
ret
I wrote this code in the VFII diagnostic program and copied it over for a GETSYS program I'm writing. It worked just fine when I compiled it in the diagnostic program.
Well, it turns out that the line
assembled into the correct opcode E6
byte in the previous program only because I used ZASMB on CP/M (which is a fairly buggy assembler). For this new program I was using z80asm, which interpreted that line as
which is opcode A7. The register A anded with A can't be relied on to set the Z flag in this case, and thus the code would never wait for the transmit buffer to be empty.
The correct code is, of course:
which ands A with 0x01, the mask for checking the transmit status bit.
This isn't the first bug that's tripped me up in ZASMB, and hopefully I won't need to use that compiler anymore.