Prev: 6F93 Up: Map Next: 7030
6FDD: Handler: Move Ship Right
Used by the routine at Handler_ShipMovement.
Moves the player's ship one pixel to the right by shifting the ship graphic and updating the player position. Movement timing is controlled by the movement animation frame counter (counts down from 07 to 00).
Check if the ship is already at the right edge (DD) and whether this frame should perform a movement step.
Handler_MoveShip_Right 6FDD POP AF Restore the player position from the stack.
6FDE CP $DD Compare the player position with DD.
6FE0 LD A,($66A6) Load the movement animation frame counter from MovementAnimationFrameCounter.
6FE3 JR NZ,MoveShipRight_UpdateCounter Jump to MoveShipRight_UpdateCounter if the ship is not at the right edge.
6FE5 OR A Jump to Handler_UpdateShipPosition if the movement animation frame counter is zero (skip movement while touching the edge).
6FE6 JR Z,Handler_UpdateShipPosition
Decrement the movement animation frame counter, wrapping from 00 back to 07. Only when the counter wraps (value 07) is the player position updated.
MoveShipRight_UpdateCounter 6FE8 OR A Jump to MoveShipRight_ResetCounter if the movement animation frame counter is zero (wrap to 07).
6FE9 JR Z,MoveShipRight_ResetCounter
6FEB DEC A Decrease the movement animation frame counter by one.
6FEC JR MoveShipRight_SaveCounter Jump to MoveShipRight_SaveCounter.
MoveShipRight_ResetCounter 6FEE LD A,$07 Load 07 into the movement animation frame counter.
MoveShipRight_SaveCounter 6FF0 LD ($66A6),A Write the updated counter back to *MovementAnimationFrameCounter.
Move the ship only when the counter has just wrapped (value 07).
6FF3 CP $07 Compare the counter with 07.
6FF5 LD A,($66ED) Load the player position from PlayerAttributeBufferPosition.
6FF8 JR NZ,MoveShipRight_Setup Jump to MoveShipRight_Setup if the counter is not 07 (no movement on this frame).
6FFA INC A Increment the player position by one (move right).
6FFB LD ($66ED),A Write the updated position to *PlayerAttributeBufferPosition.
Prepare the screen position and animate the ship graphic by shifting pixels to the right.
MoveShipRight_Setup 6FFE PUSH AF Stash the ship position on the stack.
6FFF ADD A,$02 Add 02 to A to point to the rightmost ship column.
7001 LD L,A Copy the screen column into L.
7002 LD B,$02 Set a height counter in B for 02 rows (ship height).
Process each row of the ship graphic.
MoveShipRight_RowLoop 7004 PUSH BC Stash the row counter and screen position on the stack.
7005 PUSH HL
7006 LD B,$08 Set a line counter in B for 08 pixel lines.
Process each pixel line in the current row.
MoveShipRight_LineLoop 7008 PUSH BC Stash the line counter and screen position on the stack.
7009 PUSH HL
700A LD B,$03 Set a width counter in B for 03 bytes (ship width).
Shift each byte of the ship graphic right by one pixel, propagating the carry between adjacent bytes.
MoveShipRight_ByteLoop 700C SRL (HL) Shift the byte at *HL right.
700E DEC HL Move to the previous byte in the ship graphic.
700F BIT 0,(HL) Test bit 0 of the previous byte to see if a bit needs to carry.
7011 RES 0,(HL) Clear bit 0 of that byte ready for the carry.
7013 INC HL Move back to the current byte.
7014 JR Z,MoveShipRight_NextByte Jump to MoveShipRight_NextByte if the width counter has reached zero (no carry to set).
7016 SET 7,(HL) Set bit 7 of the current byte (propagate the carry from the left).
MoveShipRight_NextByte 7018 DEC HL Move to the previous byte again.
7019 DJNZ MoveShipRight_ByteLoop Decrease the width counter by one and loop back to MoveShipRight_ByteLoop until the 03 bytes are shifted.
Clean up after shifting the line.
701B INC HL Move to the next byte.
701C RES 7,(HL) Clear bit 7 of that byte (remove any overflow).
701E POP HL Restore the screen position from the stack.
701F INC H Move down one pixel line in the screen buffer.
7020 POP BC Restore the line counter from the stack.
7021 DJNZ MoveShipRight_LineLoop Decrease the line counter by one and loop back to MoveShipRight_LineLoop until all 08 lines are processed.
Move to the next row and continue processing.
7023 POP HL Restore the screen position from the stack.
7024 SET 5,L Move to the next row position (set bit 5 of L, add 20).
7026 POP BC Restore the row counter from the stack.
7027 DJNZ MoveShipRight_RowLoop Decrease the row counter by one and loop back to MoveShipRight_RowLoop until both rows are processed.
7029 POP AF Restore the ship position from the stack.
702A CALL CheckCollision Call the collision detection routine at CheckCollision.
702D JP Handler_UpdateShipPosition Jump to Handler_UpdateShipPosition.
Continue on to Handler_UpdateShipPosition.
Prev: 6F93 Up: Map Next: 7030