Prev: DB7E Up: Map Next: DC4B
DBE5: Move Tile Left
Used by the routines at EE61 and F43E.
MoveTile_Left DBE5 LD A,($E75D) 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.
DBE8 DEC A
DBE9 LD ($E75F),A
Set the total of how many spaces the tile will be moving.
DBEC LD A,($E761) B=*Tile_SpacesToMove.
DBEF LD B,A
This is the tile loop, each space moved will decrease this counter by one.
MoveTile_Left_Loop DBF0 PUSH BC Stash the number of spaces left to move on the stack.
DBF1 LD A,($E75E) Take *Tile_Vertical_Position and subtract 01 which adjusts the value for the tile height. Write this value back to *Tile_Vertical_Coordinate.
DBF4 DEC A
DBF5 LD ($E760),A
Start moving the tile a single space.
DBF8 LD B,$04 Set a counter in B for the height of the tile in bytes (04 rows).
MoveTile_Left_RowLoop DBFA PUSH BC Stash the row counter (tile height) on the stack.
Get the screen buffer address from the co-ordinates.
DBFB LD A,($E75F) B=*Tile_Horizontal_Coordinate.
DBFE LD B,A
DBFF LD A,($E760) C=*Tile_Vertical_Coordinate.
DC02 LD C,A
DC03 CALL Calculate_ScreenBlockAddress Call Calculate_ScreenBlockAddress.
DC06 LD A,$08 Set the number of bytes in a character block to A.
DC08 LD BC,$0004 Set a counter in B for the number of bytes in a row (04), and set C to 00 which is used for erasing the left-over tile pixels.
DC0B PUSH HL HL=screen buffer address of the tile.
DC0C POP DE DE=screen buffer address of the tile (using the stack) - 01.
DC0D DEC DE
DC0E PUSH HL Stash the current screen buffer address of the tile on the stack.
Start moving the current row.
MoveTile_Left_ColumnLoop DC0F PUSH HL Stash the current screen buffer address of the tile on the stack.
DC10 LDIR Move 0004 screen data bytes from left to right.
This leaves the last byte unprocessed - which should be blank. So, let's erase it.
DC12 DEC HL Erase the right-most byte (C contains 00).
DC13 LD (HL),C
DC14 POP HL Restore the current screen buffer address from the stack.
DC15 INC H Move down one row.
Update the screen buffer address for the next loop iteration.
DC16 PUSH HL HL=screen buffer address of the tile.
DC17 POP DE DE=screen buffer address of the tile (using the stack) - 01.
DC18 DEC DE
DC19 LD BC,$0004 Restore BC back to 0004.
DC1C DEC A Decrease the column/ byte counter by one.
DC1D JP NZ,MoveTile_Left_ColumnLoop Jump to MoveTile_Left_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.
DC20 POP HL Restore the current screen buffer address from the stack.
DC21 CALL Calculate_AttributeAddress Call Calculate_AttributeAddress.
DC24 PUSH DE HL=attribute buffer address of the tile (using the stack).
DC25 POP HL
DC26 DEC DE DE=attribute buffer address of the tile - 01.
DC27 LD BC,$0005 Move 0005 attribute bytes from left to right.
DC2A LDIR
This leaves the last attribute space unprocessed - which should be blank. So, let's erase it.
DC2C LD A,$47 A=INK: WHITE, PAPER: BLACK (BRIGHT) .
DC2E DEC DE Erase the right-most attribute block.
DC2F LD (DE),A
Move to the next attribute row.
DC30 LD HL,$E75F Increment *Tile_Horizontal_Coordinate by one.
DC33 INC (HL)
DC34 POP BC Restore the attribute row counter from the stack.
DC35 DJNZ MoveTile_Left_RowLoop Decrease the attribute row counter by one and loop back to MoveTile_Left_RowLoop until the whole row has been processed.
The tile has successfully moved one space!
DC37 POP BC Using the number of spaces left to move (from the stack) call Sound_TileMovement.
DC38 PUSH BC
DC39 CALL Sound_TileMovement
DC3C LD A,($E75D) Take *Tile_Horizontal_Position and decrease it by one, which adjusts the value for the tile width. Write it back to *Tile_Horizontal_Coordinate.
DC3F DEC A
DC40 LD ($E75F),A
DC43 LD HL,$E75E Decrease *Tile_Vertical_Position by one.
DC46 DEC (HL)
DC47 POP BC Restore the number of spaces left to move from the stack.
DC48 DJNZ MoveTile_Left_Loop Decrease the number of spaces counter by one and loop back to MoveTile_Left_Loop until the tile is in the destination space.
DC4A RET Return.
Prev: DB7E Up: Map Next: DC4B