Prev: E205 Up: Map Next: E235
E216: Find Map Address
Used by the routine at GetTile.
Finds the address in the map at TileMap of the tile at a column and a row. Each row of the map is 60 bytes, and rows zero and one both give the address of the first row, because the row that is given is that of the tile at the bottom of the two on the screen. The column wraps round from FF to 5F and from 60 to 00.
Input
DE 60
H Row
L Column
Output
C Column, wrapped
HL Address in the map
FindMapAddress E216 LD C,L C=L.
E217 LD A,H A=H.
E218 AND A Is A zero?
E219 LD B,H B=H.
E21A LD HL,$61BC The tile map.
E21D JR Z,FindMapAddress_Wrap Jump to FindMapAddress_Wrap if the zero flag is set.
E21F DEC B Step B back.
E220 JR Z,FindMapAddress_Wrap Jump to FindMapAddress_Wrap if the zero flag is set.
FindMapAddress_Loop E222 ADD HL,DE HL gains DE.
E223 DJNZ FindMapAddress_Loop Decrease B and jump to FindMapAddress_Loop until none remain.
FindMapAddress_Wrap E225 LD A,C A=C.
E226 CP $FF Jump to FindMapAddress_Wrapped if A is not FF.
E228 JR NZ,FindMapAddress_Wrapped
E22A LD C,$5F C=5F.
FindMapAddress_Wrapped E22C LD A,C A=C.
E22D CP $60 Jump to FindMapAddress_Return if A is not 60.
E22F JR NZ,FindMapAddress_Return
E231 LD C,$00 Clear C.
FindMapAddress_Return E233 ADD HL,BC HL gains BC.
E234 RET Return.
Prev: E205 Up: Map Next: E235