Prev: A9C3 Up: Map Next: AA1A
A9DD: Move Left
Used by the routines at MoveEntity and MoveRobot.
Moves an entity in direction zero, which decreases the X position. See MoveEntity for how the move works.
Input
B Number of steps to take
DE X position
HL Y position
Output
A 01 if the entity has been blocked
B Number of steps that are left
DE New X position
F The zero flag is reset if the entity has been blocked
MoveLeft A9DD LD A,B Return if there are no steps left.
A9DE AND A
A9DF RET Z
A9E0 LD A,E Jump if the entity is at the start of a cell.
A9E1 AND A
A9E2 JR Z,MoveLeft_CellStart
A9E4 SUB B Take the steps off the fraction, and jump if that goes back into the previous cell.
A9E5 JR C,MoveLeft_NextCell
A9E7 LD E,A Store the new fraction.
MoveLeft_Finish A9E8 XOR A Clear the number of steps that are left, and return with the zero flag set.
A9E9 LD B,A
A9EA RET
MoveLeft_NextCell A9EB NEG Work out how many steps are left over...
A9ED LD B,A ...and keep them in B.
A9EE XOR A Move to the start of the cell, and return with the zero flag set.
A9EF LD E,A
A9F0 RET Return.
MoveLeft_CellStart A9F1 PUSH DE Save the X position.
A9F2 SUB B Take the steps off the fraction, which goes back into the previous cell...
A9F3 LD E,A ...and keep it.
A9F4 LD A,D Fetch the X cell...
A9F5 SBC A,$00 ...and take one off...
A9F7 AND $3F ...making sure that the cell is within the map.
A9F9 LD D,A
A9FA LD ($9653),DE Keep this position.
A9FE CALL FindMapCell Find the cell using FindMapCell.
AA01 JR Z,MoveLeft_Clear Jump if the cell is empty.
AA03 PUSH HL Save the Y position.
AA04 LD HL,($962E) Fetch the address of the cell...
AA07 LD A,(HL) ...and its contents...
AA08 POP HL ...and restore the Y position.
AA09 AND $0F Jump if the cell has no type.
AA0B JR Z,MoveLeft_Clear
AA0D CP $0F Jump if the cell is not type 0F, which is an obstacle.
AA0F JR NZ,MoveLeft_Blocked
MoveLeft_Clear AA11 INC SP Discard the old X position...
AA12 INC SP
AA13 JR MoveLeft_Finish ...and jump to finish the move.
MoveLeft_Blocked AA15 POP DE The entity is blocked, so restore the old X position.
AA16 XOR A Clear the number of steps that are left...
AA17 LD B,A
AA18 INC A ...and set A to 01.
AA19 RET Return.
Prev: A9C3 Up: Map Next: AA1A