Prev: 56110 Up: Map Next: 56293
56190: Move Tile Right
Used by the routines at 61025 and 62526.
Get the current tile horizontal co-ordinate.
MoveTile_Right 56190 LD A,(59229) Take *Tile_Horizontal_Position and decrease it by one, which adjusts the value for the tile width. Write this value back to *Tile_Horizontal_Coordinate.
56193 DEC A
56194 LD (59231),A
Set the total of how many spaces the tile will be moving.
56197 LD A,(59233) B=*Tile_SpacesToMove.
56200 LD B,A
This is the tile loop, each space moved will decrease this counter by one.
MoveTile_Right_Loop 56201 PUSH BC Stash the number of spaces left to move on the stack.
Get the current tile vertical co-ordinate.
56202 LD A,(59230) Take *Tile_Vertical_Position and add 2 which adjusts the value for the tile height. Write this value back to *Tile_Vertical_Coordinate.
56205 ADD A,2
56207 LD (59232),A
Start moving the tile a single space.
56210 LD B,4 Set a counter in B for the height of the tile in bytes (4 rows).
MoveTile_Right_RowLoop 56212 PUSH BC Stash the row counter (tile height) on the stack.
Get the screen buffer address from the co-ordinates.
56213 LD A,(59231) B=*Tile_Horizontal_Coordinate.
56216 LD B,A
56217 LD A,(59232) C=*Tile_Vertical_Coordinate.
56220 LD C,A
56221 CALL Calculate_ScreenBlockAddress Call Calculate_ScreenBlockAddress.
56224 LD A,8 Set the number of bytes in a character block to A.
56226 LD BC,4 Set a counter in B for the number of bytes in a row (4), and set C to 0 which is used for erasing the left-over tile pixels.
56229 PUSH HL HL=screen buffer address of the tile.
56230 POP DE DE=screen buffer address of the tile (using the stack) + 1.
56231 INC DE
56232 PUSH HL Stash the current screen buffer address of the tile on the stack.
Start moving the current row.
MoveTile_Right_ColumnLoop 56233 PUSH HL Stash the current screen buffer address of the tile on the stack.
56234 LDDR Move 0004 screen data bytes from right to left.
This leaves the last byte unprocessed - which should be blank. So, let's erase it.
56236 INC HL Erase the right-most byte (C contains 0).
56237 LD (HL),C
56238 POP HL Restore the current screen buffer address from the stack.
56239 INC H Move down one row.
Update the screen buffer address for the next loop iteration.
56240 PUSH HL HL=screen buffer address of the tile.
56241 POP DE DE=screen buffer address of the tile (using the stack) + 1.
56242 INC DE
56243 LD BC,4 Restore BC back to 0004.
56246 DEC A Decrease the column/ byte counter by one.
56247 JP NZ,MoveTile_Right_ColumnLoop Jump to MoveTile_Right_ColumnLoop until all four bytes in this row have been moved.
Now onto the attribute buffer bytes.
Convert the screen buffer location into a corresponding attribute buffer address.
56250 POP HL Restore the current screen buffer address from the stack.
56251 CALL Calculate_AttributeAddress Call Calculate_AttributeAddress.
56254 PUSH DE HL=attribute buffer address of the tile (using the stack).
56255 POP HL
56256 INC DE DE=attribute buffer address of the tile + 1.
56257 LD BC,5 Move 0005 attribute bytes from right to left.
56260 LDDR
This leaves the last attribute space unprocessed - which should be blank. So, let's erase it.
56262 LD A,71 A=INK: WHITE, PAPER: BLACK (BRIGHT) .
56264 INC DE Erase the right-most attribute block.
56265 LD (DE),A
Move to the next attribute row.
56266 LD HL,59231 Increment *Tile_Horizontal_Coordinate by one.
56269 INC (HL)
56270 POP BC Restore the attribute row counter from the stack.
56271 DJNZ MoveTile_Right_RowLoop Decrease the attribute row counter by one and loop back to MoveTile_Right_RowLoop until the whole row has been processed.
The tile has successfully moved one space!
56273 POP BC Using the number of spaces left to move (from the stack) call Sound_TileMovement.
56274 PUSH BC
56275 CALL Sound_TileMovement
56278 LD A,(59229) Take *Tile_Horizontal_Position and decrease it by one, which adjusts the value for the tile width. Write it back to *Tile_Horizontal_Coordinate.
56281 DEC A
56282 LD (59231),A
56285 LD HL,59230 Increment *Tile_Vertical_Position by one.
56288 INC (HL)
56289 POP BC Restore the number of spaces left to move from the stack.
56290 DJNZ MoveTile_Right_Loop Decrease the number of spaces counter by one and loop back to MoveTile_Right_Loop until the tile is in the destination space.
56292 RET Return.
Prev: 56110 Up: Map Next: 56293