Prev: A4F4 Up: Map Next: A535
A503: Computes address position in tile type buffer based on (x,y) position on screen
X-position is stored in A0AF and y-position in A0B0. Used by the routines at 947A, B64E, C0E0, C2FD, C620, C72B, CAA7, CB03 and D14D.
Input
A Tile position $00 Previous tile (x,y) - $01 Tile in (x,y)
Output
HL Address position into tile type buffer
A503 PUSH AF Save AF
A504 LD A,($A0B0) Set A the y-position
A507 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)
A508 LD H,$00
A50A SRL H
A50C RR L
A50E SRL H
A510 RR L
A512 SRL H
A514 RR L
A516 ADD HL,HL
A517 ADD HL,HL
A518 ADD HL,HL
A519 ADD HL,HL
A51A ADD HL,HL
A51B LD A,($A0AF) Set A the x-position
A51E SRL A Computes the offset of the tile based on the x-position x-offset = x-position / 8
A520 SRL A
A522 SRL A
A524 LD E,A Adds the two offsets
A525 LD D,$00
A527 ADD HL,DE
A528 LD DE,$E19F Set DE the base address to the tile type buffer
A52B POP AF Recover A
A52C OR A Is 0?
A52D JP NZ,$A533 Jump if not
A530 LD DE,$E19E If it's 0 then change the base address of tilr type buffer to get the previous tile
A533 ADD HL,DE Set HL to the base address of the location of the tile in tile buffer
A534 RET
Prev: A4F4 Up: Map Next: A535