Prev: A7C7 Up: Map Next: A80A
A7C9: Get supertiles
This uses the position in map_position to choose which supertile indices to copy from map_tiles into the map_buf buffer at $FF58.
Get vertical offset.
get_supertiles A7C9 LD A,($81BC) Get the map position's Y component and round it down to a multiple of four
A7CC AND $FC
Multiply the Y component by 13.5 producing 0, 54, 108, 162, ...
A7CE LD L,A Copy A into HL
A7CF LD H,$00
A7D1 RRA Halve A
A7D2 AND $7F
A7D4 ADD A,L Add A to HL, giving us Y multiplied by 1.5
A7D5 LD L,A
A7D6 JR NC,get_supertiles_0
A7D8 INC H
get_supertiles_0 A7D9 LD E,L Copy HL into DE
A7DA LD D,H
A7DB ADD HL,HL Multiply by nine, giving us Y multiplied by 13.5
A7DC ADD HL,HL
A7DD ADD HL,HL
A7DE ADD HL,DE
A7DF LD DE,$BCB8 Point DE at map_tiles but minus a whole row
A7E2 ADD HL,DE Combine
Add the X component.
A7E3 LD A,($81BB) Get the map position's X component and divide it by 4
A7E6 RRA
A7E7 RRA
A7E8 AND $3F
A7EA LD E,A Move A into DE
A7EB LD D,$00
A7ED ADD HL,DE Combine. Now we have a pointer into map_tiles
Populate map_buf with 7x5 array of supertile refs.
A7EE LD A,$05 Five rows
A7F0 LD DE,$FF58 Point DE at map_buf (a 7x5 scratch buffer which holds copied-out supertile indices)
Start loop
get_supertiles_1 A7F3 LDI Fill the buffer row with seven bytes from HL
A7F5 LDI
A7F7 LDI
A7F9 LDI
A7FB LDI
A7FD LDI
A7FF LDI
A801 LD BC,$002F Move HL forward by (stride - width of map_buf)
A804 ADD HL,BC
A805 DEC A ...loop
A806 JP NZ,get_supertiles_1
A809 RET Return
Prev: A7C7 Up: Map Next: A80A