When I started z80 assembly I used routines written by other people to determine screen addresses. A commonly used routine is 'Move register pair down one pixel line'.
Code: Select all
;;; Move HL down one pixel line
Pixel_Address_Down: INC H ; Go down onto the next pixel line
LD A,H ; Check first three bits of high byte (Y0-Y2)
AND 7
RET NZ ; If any bits are set (we are inside a char line), we are done
;next char line
LD A,L ; we crossed the char line ((Y0-Y2)=0 i.e Y6=1)
ADD A,32 ; (move down 1 char line) add the extra bit into (Y3-Y5)
LD L,A
RET C ; Check for a carry bit (crossed a third), if C is set we are done
;did not cross a third
LD A,H ; We better clean up the bit from (Y6)
SUB 8
LD H,A
RET ; we are done