Prev: A69C Up: Map Next: A6DD
A6AB: Computes address position in tile type buffer based on (x,y) position on screen
X-position is stored in $A248 and y-position in $A249. Used by the routines at 9470, B694, C691, C794, CAF6 and CEE5.
Input
A Tile position $00 Previous tile (x,y) - $01 Tile in (x,y)
Output
HL Address position into tile type buffer
A6AB PUSH AF Save AF
A6AC LD A,($A249) Set A the y-position
A6AF LD L,A Computes the offset of the tile based on the y-position y-offset = (y-position / 8) * 32 (32 tiles per row and 8 pixels height per row)
A6B0 LD H,$00
A6B2 SRL H
A6B4 RR L
A6B6 SRL H
A6B8 RR L
A6BA SRL H
A6BC RR L
A6BE ADD HL,HL
A6BF ADD HL,HL
A6C0 ADD HL,HL
A6C1 ADD HL,HL
A6C2 ADD HL,HL
A6C3 LD A,($A248) Set A the x-position
A6C6 SRL A Computes the offset of the tile based on the x-position x-offset = x-position / 8
A6C8 SRL A
A6CA SRL A
A6CC LD E,A Adds the two offsets
A6CD LD D,$00
A6CF ADD HL,DE
A6D0 LD DE,$E19F Set DE the base address to the tile type buffer
A6D3 POP AF Recover A
A6D4 OR A Is 0?
A6D5 JP NZ,$A6DB Jump if not
A6D8 LD DE,$E19E If it's 0 then change the base address of tile type buffer to get the previous tile
A6DB ADD HL,DE Set HL to the base address of the location of the tile in tile buffer
A6DC RET
Prev: A69C Up: Map Next: A6DD