Prev: 28408 Up: Map Next: 28563
28483: Handler: Move Ship Left
Used by the routine at Handler_ShipMovement.
Handles moving the player's ship left by animating the ship graphic and updating the ship position. The movement is frame-based, controlled by the movement animation frame counter.
Check if the ship is at the left edge of the screen and if movement should be skipped this frame.
Handler_MoveShip_Left 28483 POP AF Restore the player position from the stack.
28484 CP 192 Jump to MoveShipLeft_Animate if the player position is not at the left edge (192).
28486 JR NZ,MoveShipLeft_Animate
28488 LD A,(26278) Jump to Handler_UpdateShipPosition if the movement animation frame counter at *MovementAnimationFrameCounter is equal to 3 (skip movement this frame).
28491 CP 3
28493 JR Z,Handler_UpdateShipPosition
The ship is at the left edge, so load the player position to prepare for animation.
28495 LD A,(26349) Load the low byte of the player position from PlayerAttributeBufferPosition into L.
Set up the screen position and animate the ship graphic by shifting pixels left.
MoveShipLeft_Animate 28498 LD L,A Load L with the low byte of the player position.
28499 LD B,2 Set a height counter in B for 2 rows (the ship height).
Process each row of the ship graphic, shifting all pixels left by one position.
MoveShipLeft_RowLoop 28501 PUSH BC Stash the row counter and screen position on the stack.
28502 PUSH HL
28503 LD B,8 Set a line counter in B (8 lines in a UDG).
Process each pixel line within the current row.
MoveShipLeft_LineLoop 28505 PUSH BC Stash the line counter and screen position on the stack.
28506 PUSH HL
28507 LD B,3 Set a width counter in B for 3 bytes (the ship width).
Shift each byte of the ship graphic left by one pixel, propagating the carry bit between bytes to create smooth scrolling.
MoveShipLeft_ByteLoop 28509 SLA (HL) Shift the byte at *HL left by one bit.
28511 INC HL Move to the next byte in the ship graphic.
28512 BIT 7,(HL) Test bit 7 of the next byte to check if a bit was carried over.
28514 DEC HL Move back to the previous byte.
28515 JR Z,MoveShipLeft_NextByte Jump to MoveShipLeft_NextByte if bit 7 was not set (no carry).
28517 SET 0,(HL) Set bit 0 of the current byte (propagate the carry from the previous byte).
MoveShipLeft_NextByte 28519 INC HL Move to the next byte in the ship graphic.
28520 DJNZ MoveShipLeft_ByteLoop Decrease the width counter by one and loop back to MoveShipLeft_ByteLoop until all 3 bytes are shifted.
Clean up after shifting the bytes in this line.
28522 DEC HL Move back to the last byte.
28523 RES 0,(HL) Reset bit 0 of the last byte (clear any overflow).
28525 POP HL Restore the screen position from the stack.
28526 INC H Move down one pixel line in the screen buffer.
28527 POP BC Restore the line counter from the stack.
28528 DJNZ MoveShipLeft_LineLoop Decrease the line counter by one and loop back to MoveShipLeft_LineLoop until all 8 lines have been processed.
Move to the next row and continue processing.
28530 POP HL Restore the screen position from the stack.
28531 SET 5,L Move to the next row position (set bit 5 of L, add 32).
28533 POP BC Restore the row counter from the stack.
28534 DJNZ MoveShipLeft_RowLoop Decrease the row counter by one and loop back to MoveShipLeft_RowLoop until both rows are processed.
Update the movement animation frame counter. The counter cycles from 0 to 7 and the ship position is only updated when the counter completes a full cycle (wraps from 7 to 0).
28536 LD A,(26278) Jump to MoveShipLeft_ResetCounter if the movement animation frame counter at *MovementAnimationFrameCounter is equal to 7 (wrap to 0).
28539 CP 7
28541 JR Z,MoveShipLeft_ResetCounter
28543 INC A Increment the movement animation frame counter.
28544 JR MoveShipLeft_UpdatePosition Jump to MoveShipLeft_UpdatePosition.
MoveShipLeft_ResetCounter 28546 XOR A Reset the movement animation frame counter to 0 (complete cycle).
MoveShipLeft_UpdatePosition 28547 LD (26278),A Write the updated movement animation frame counter to *MovementAnimationFrameCounter.
28550 OR A Test if the counter is zero (movement frame complete).
28551 LD A,(26349) Load the player position from PlayerAttributeBufferPosition.
28554 JR NZ,MoveShipLeft_SavePosition Jump to MoveShipLeft_SavePosition if the counter is not zero (don't move position yet).
The movement animation frame counter has completed a cycle, so update the ship position.
28556 DEC A Decrease the player position by one (move ship left).
MoveShipLeft_SavePosition 28557 LD (26349),A Write the updated player position to *PlayerAttributeBufferPosition.
28560 CALL CheckCollision Call the collision detection routine at CheckCollision.
Continue on to Handler_UpdateShipPosition.
Prev: 28408 Up: Map Next: 28563