Prev: 57861 Up: Map Next: 57909
57878: 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 96 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 255 to 95 and from 96 to 0.
Input
DE 96
H Row
L Column
Output
C Column, wrapped
HL Address in the map
FindMapAddress 57878 LD C,L C=L.
57879 LD A,H A=H.
57880 AND A Is A zero?
57881 LD B,H B=H.
57882 LD HL,25020 The tile map.
57885 JR Z,FindMapAddress_Wrap Jump to FindMapAddress_Wrap if the zero flag is set.
57887 DEC B Step B back.
57888 JR Z,FindMapAddress_Wrap Jump to FindMapAddress_Wrap if the zero flag is set.
FindMapAddress_Loop 57890 ADD HL,DE HL gains DE.
57891 DJNZ FindMapAddress_Loop Decrease B and jump to FindMapAddress_Loop until none remain.
FindMapAddress_Wrap 57893 LD A,C A=C.
57894 CP 255 Jump to FindMapAddress_Wrapped if A is not 255.
57896 JR NZ,FindMapAddress_Wrapped
57898 LD C,95 C=95.
FindMapAddress_Wrapped 57900 LD A,C A=C.
57901 CP 96 Jump to FindMapAddress_Return if A is not 96.
57903 JR NZ,FindMapAddress_Return
57905 LD C,0 Clear C.
FindMapAddress_Return 57907 ADD HL,BC HL gains BC.
57908 RET Return.
Prev: 57861 Up: Map Next: 57909