Prev: AA1A Up: Map Next: AA97
AA58: Move Right
Used by the routines at MoveEntity and MoveRobot.
Moves an entity in direction two, which increases 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
MoveRight AA58 LD A,B Return if there are no steps left.
AA59 AND A
AA5A RET Z
AA5B LD A,E Jump if the entity is at the start of a cell.
AA5C AND A
AA5D JR Z,MoveRight_CellStart
AA5F ADD A,B Add the steps to the fraction, and jump if that goes into the next cell.
AA60 JR C,MoveRight_NextCell
AA62 LD E,A Store the new fraction.
MoveRight_Finish AA63 XOR A Clear the number of steps that are left, and return with the zero flag set.
AA64 LD B,A
AA65 RET
MoveRight_NextCell AA66 LD B,A Keep the steps that are left over.
AA67 LD A,D Fetch the X cell...
AA68 INC A ...and add one...
AA69 AND $3F ...making sure that the cell is within the map.
AA6B LD D,A
AA6C XOR A Move to the start of the cell, and return with the zero flag set.
AA6D LD E,A
AA6E RET Return.
MoveRight_CellStart AA6F ADD A,B Add the steps to the fraction...
AA70 LD E,A ...and keep it.
AA71 LD ($9653),DE Keep this position.
AA75 PUSH DE Save the X position.
AA76 LD A,D Fetch the X cell...
AA77 INC A ...and add one...
AA78 AND $3F ...making sure that the cell is within the map.
AA7A LD D,A
AA7B CALL FindMapCell Find the cell using FindMapCell.
AA7E JR Z,MoveRight_Clear Jump if the cell is empty.
AA80 PUSH HL Save the Y position.
AA81 LD HL,($962E) Fetch the address of the cell...
AA84 LD A,(HL) ...and its contents...
AA85 POP HL ...and restore the Y position.
AA86 AND $0F Jump if the cell has no type.
AA88 JR Z,MoveRight_Clear
AA8A CP $0F Jump if the cell is not type 0F, which is an obstacle.
AA8C JR NZ,MoveRight_Blocked
MoveRight_Clear AA8E POP DE Restore the X position...
AA8F JR MoveRight_Finish ...and jump to finish the move.
MoveRight_Blocked AA91 POP DE The entity is blocked, so restore the old X position.
AA92 XOR A Clear the number of steps that are left...
AA93 LD B,A
AA94 LD E,A ...and the fraction...
AA95 INC A ...and set A to 01.
AA96 RET Return.
Prev: AA1A Up: Map Next: AA97