Prev: A819 Up: Map Next: A8A2
A826: Plot horizontal tiles (common)
This plots a single horizontal row of tiles to the screen buffer.
Simultaneously updates the visible tiles buffer.
Used by the routine at plot_bottommost_tiles.
Input
A Map Y 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_horizontal_tiles_common A826 AND $03 Compute the row offset within a supertile from the map's Y position (0, 4, 8 or 12)
A828 ADD A,A
A829 ADD A,A
A82A LD ($A86A),A Self modify the "LD A,$xx" instruction at supertile_plot_horizontal_common_iters to load the row offset
A82D LD C,A Preserve the row offset in C for the next step
A82E LD A,($81BB) Compute the column offset within a supertile from the map's X position (0, 1, 2 or 3)
A831 AND $03
A833 ADD A,C Now add it to the row offset - giving the combined offset
A834 EX AF,AF' Bank the combined offset
Initial edge. This draws up to 4 tiles.
A835 LD A,(HL) Fetch a supertile index from map_buf
A836 EXX Switch register banks for the initial edge
A837 LD L,A Point HL at super_tiles[A]
A838 LD H,$00
A83A ADD HL,HL
A83B ADD HL,HL
A83C ADD HL,HL
A83D ADD HL,HL
A83E LD A,$5B
A840 ADD A,H
A841 LD H,A
A842 EX AF,AF' Unbank the combined offset
A843 ADD A,L Add on the combined offset to HL to point us at the appropriate part of the supertile
A844 LD L,A
A845 NEG Turn 0,1,2,3 into 4,3,2,1 - the number of initial loop iterations
A847 AND $03
A849 JR NZ,plot_horizontal_tiles_common_0
A84B LD A,$04
plot_horizontal_tiles_common_0 A84D LD B,A Set 1..4 iterations
Start loop
plot_horizontal_tiles_common_1 A84E LD A,(HL) Fetch a tile index from the super tile pointer
A84F LD (DE),A Store it in visible tiles (DE' on entry)
A850 CALL plot_tile Plot the tile in A to the screen buffer at DE' using supertile pointer HL'
A853 INC L Advance the tile pointer
A854 INC DE Advance the visible tiles pointer
A855 DJNZ plot_horizontal_tiles_common_1 ...loop
A857 EXX Unbank
A858 INC HL Advance the map buffer pointer
Middle loop.
A859 LD B,$05 There are always five iterations (five supertiles in the middle section).
Start loop (outer) -- advanced for each supertile
plot_horizontal_tiles_common_2 A85B PUSH BC Preserve the loop counter
A85C LD A,(HL) Fetch a supertile index from the map buffer pointer
A85D EXX Switch register banks during the middle loop
A85E LD L,A Point HL at super_tiles[A]
A85F LD H,$00
A861 ADD HL,HL
A862 ADD HL,HL
A863 ADD HL,HL
A864 ADD HL,HL
A865 LD BC,$5B00
A868 ADD HL,BC
supertile_plot_horizontal_common_iters A869 LD A,$00 Load the row offset - self modified by $A82A
A86B ADD A,L Add on the row offset to HL
A86C LD L,A
A86D LD B,$04 Supertiles are four tiles wide
Start loop (inner) -- advanced for each tile
plot_horizontal_tiles_common_3 A86F LD A,(HL) Fetch a tile index from the super tile pointer
A870 LD (DE),A Store it in visible tiles
A871 CALL plot_tile Plot the tile in A to the screen buffer at DE' using supertile pointer HL'
A874 INC HL Advance the tiles pointer
A875 INC DE Advance the visible tiles pointer
A876 DJNZ plot_horizontal_tiles_common_3 ...loop (inner)
A878 EXX Unbank
A879 INC HL Advance the map buffer pointer
A87A POP BC Restore the loop counter
A87B DJNZ plot_horizontal_tiles_common_2 ...loop (outer)
Trailing edge.
A87D LD A,C Spurious instructions
A87E EX AF,AF'
A87F LD A,(HL) Fetch a supertile index from map_buf
A880 EXX Switch register banks during the trailing loop
A881 LD L,A Point HL at super_tiles[A]
A882 LD H,$00
A884 ADD HL,HL
A885 ADD HL,HL
A886 ADD HL,HL
A887 ADD HL,HL
A888 LD BC,$5B00
A88B ADD HL,BC
A88C LD A,($A86A) Load the row offset from (self modified) $A86A
A88F ADD A,L Add on the row offset to HL
A890 LD L,A
A891 LD A,($81BB) Form the trailing loop iteration counter
A894 AND $03
A896 RET Z Return if no iterations are required
A897 LD B,A Move iterations into B
Start loop
plot_horizontal_tiles_common_4 A898 LD A,(HL) Fetch a tile index from the super tile pointer
A899 LD (DE),A Store it in visible tiles
A89A CALL plot_tile Plot the tile in A to the screen buffer at DE' using supertile pointer HL'
A89D INC L Advance the tiles pointer
A89E INC DE Advance the visible tiles pointer
A89F DJNZ plot_horizontal_tiles_common_4 ...loop
A8A1 RET Return
Prev: A819 Up: Map Next: A8A2