Prev: A8E7 Up: Map Next: A9A0
A8F4: Plot vertical tiles (common)
This plots a single vertical row of tiles to the screen buffer.
Simultaneously updates the visible tiles buffer.
Used by the routines at plot_all_tiles and plot_rightmost_tiles.
Input
A Map X position
DE Pointer into the 24x17 visible tiles array ("tile_buf")
HL' Pointer into the 7x5 supertile indices buffer ("map_buf")
DE' Pointer into the 24x17x8 screen buffer ("window_buf")
plot_vertical_tiles_common A8F4 AND $03 Compute the column offset within a supertile from the map's X position (0, 1, 2 or 3)
A8F6 LD ($A94D),A Self modify the "LD A,$xx" instruction at $A94C to load the column offset
A8F9 LD C,A Preserve the column offset in C for the next step
A8FA LD A,($81BC) Compute the row offset within a supertile from the map's Y position (0, 4, 8 or 12)
A8FD AND $03
A8FF ADD A,A
A900 ADD A,A
A901 ADD A,C Now add it to the column offset - giving the combined offset
A902 EX AF,AF' Bank the combined offset
Initial edge. This draws up to 4 tiles.
A903 LD A,(HL) Fetch a supertile index from map_buf
A904 EXX Switch register banks for the initial edge
A905 LD L,A Point HL at super_tiles[A]
A906 LD H,$00
A908 ADD HL,HL
A909 ADD HL,HL
A90A ADD HL,HL
A90B ADD HL,HL
A90C LD A,$5B
A90E ADD A,H
A90F LD H,A
A910 EX AF,AF' Unbank the combined offset
A911 ADD A,L Add on the combined offset to HL to point us at the appropriate part of the supertile
A912 LD L,A
A913 RRA Turn 0,4,8,12 into 4,3,2,1 - the number of initial loop iterations
A914 RRA
A915 AND $03
A917 NEG
A919 AND $03
A91B JR NZ,plot_vertical_tiles_common_0
A91D LD A,$04
plot_vertical_tiles_common_0 A91F EX DE,HL Transpose tile_buf and map_buf pointers
A920 LD BC,$0018 Set visible tiles stride
Start loop
plot_vertical_tiles_common_1 A923 PUSH AF Save the loop counter
A924 LD A,(DE) Fetch a tile index from the super tile pointer
A925 LD (HL),A Store it in the visible tiles (DE' on entry)
A926 CALL plot_tile_then_advance Plot the tile in A to the screen buffer at DE' using supertile pointer HL' then advance DE' by a row
A929 LD A,$04 Advance the tile pointer by a supertile row (4)
A92B ADD A,E
A92C LD E,A
A92D ADD HL,BC Advance the visible tiles pointer by a row (24)
A92E POP AF Restore the loop counter
A92F DEC A ...loop
A930 JP NZ,plot_vertical_tiles_common_1
A933 EX DE,HL Transpose the tile_buf and map_buf pointers back
A934 EXX Unbank
A935 LD A,L Advance the map buffer pointer by a row (7)
A936 ADD A,$07
A938 LD L,A
A939 JR NC,plot_vertical_tiles_common_2
A93B INC H
Middle loop.
plot_vertical_tiles_common_2 A93C LD B,$03 There are always three iterations (three supertiles in the middle section).
Start loop (outer) -- advanced for each supertile
plot_vertical_tiles_common_3 A93E PUSH BC Preserve the loop counter
A93F LD A,(HL) Fetch a supertile index from the map buffer pointer
A940 EXX Switch register banks during the middle loop
A941 LD L,A Point HL at super_tiles[A]
A942 LD H,$00
A944 ADD HL,HL
A945 ADD HL,HL
A946 ADD HL,HL
A947 ADD HL,HL
A948 LD BC,$5B00
A94B ADD HL,BC
supertile_plot_vertical_common_iters A94C LD A,$00 Load the column offset - self modified by $A8F6
A94E ADD A,L Add on the column offset to HL
A94F LD L,A
A950 LD BC,$0018 Set visible tiles stride
A953 EX DE,HL Transpose the tile_buf and map_buf pointers
A954 LD A,$04 Supertiles are four tiles high
Start loop (inner) -- advanced for each tile
plot_vertical_tiles_common_4 A956 PUSH AF Preserve the loop counter
A957 LD A,(DE) Fetch a tile index from the super tile pointer
A958 LD (HL),A Store it in visible tiles
A959 CALL plot_tile_then_advance Plot the tile in A to the screen buffer at DE' using supertile pointer HL' then advance DE' by a row
A95C ADD HL,BC Advance the visible tiles pointer by a row
A95D LD A,$04 Advance the tiles pointer by a row
A95F ADD A,E
A960 LD E,A
A961 POP AF Restore the loop counter
A962 DEC A ...loop (inner)
A963 JP NZ,plot_vertical_tiles_common_4
A966 EX DE,HL Transpose the tile_buf and map_buf pointers back
A967 EXX Unbank
A968 LD A,L Advance the map buffer pointer
A969 ADD A,$07
A96B LD L,A
A96C JR NC,plot_vertical_tiles_common_5
A96E INC H
plot_vertical_tiles_common_5 A96F POP BC Restore the loop counter
A970 DJNZ plot_vertical_tiles_common_3 ...loop (outer)
Trailing edge.
A972 LD A,(HL) Fetch a supertile index from map_buf
A973 EXX Switch register banks during the trailing loop
A974 LD L,A Point HL at super_tiles[A]
A975 LD H,$00
A977 ADD HL,HL
A978 ADD HL,HL
A979 ADD HL,HL
A97A ADD HL,HL
A97B LD BC,$5B00
A97E ADD HL,BC
A97F LD A,($A94D) Load the column offset from (self modified) $A94D
A982 ADD A,L Add on the column offset to HL
A983 LD L,A
A984 LD A,($81BC) Form the trailing loop iteration counter
A987 AND $03
A989 INC A
A98A LD BC,$0018 Set visible tiles stride
A98D EX DE,HL Transpose the tile_buf and map_buf pointers
Start loop
plot_vertical_tiles_common_6 A98E PUSH AF Preserve the loop counter
A98F LD A,(DE) Fetch a tile index from the super tile pointer
A990 LD (HL),A Store it in visible tiles
A991 CALL plot_tile_then_advance Plot the tile in A to the screen buffer at DE' using supertile pointer HL' then advance DE' by a row
A994 LD A,$04 Advance the tiles pointer by a row
A996 ADD A,E
A997 LD E,A
A998 ADD HL,BC Advance the visible tiles pointer by a row
A999 POP AF Restore the loop counter
A99A DEC A ...loop
A99B JP NZ,plot_vertical_tiles_common_6
A99E EX DE,HL Transpose the tile_buf and map_buf pointers back
A99F RET Return
Prev: A8E7 Up: Map Next: A9A0