Prev: A9DD Up: Map Next: AA58
AA1A: Move Up
Used by the routines at MoveEntity and MoveRobot.
Moves an entity in direction one, which increases the Y 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
HL New Y position
F The zero flag is reset if the entity has been blocked
MoveUp AA1A LD A,B Return if there are no steps left.
AA1B AND A
AA1C RET Z
AA1D LD A,L Jump if the entity is at the start of a cell.
AA1E AND A
AA1F JR Z,MoveUp_CellStart
AA21 ADD A,B Add the steps to the fraction, and jump if that goes into the next cell.
AA22 JR C,MoveUp_NextCell
AA24 LD L,A Store the new fraction.
MoveUp_Finish AA25 XOR A Clear the number of steps that are left, and return with the zero flag set.
AA26 LD B,A
AA27 RET
MoveUp_NextCell AA28 LD B,A Keep the steps that are left over.
AA29 LD A,H Fetch the Y cell...
AA2A INC A ...and add one...
AA2B AND $3F ...making sure that the cell is within the map.
AA2D LD H,A
AA2E XOR A Move to the start of the cell, and return with the zero flag set.
AA2F LD L,A
AA30 RET Return.
MoveUp_CellStart AA31 ADD A,B Add the steps to the fraction...
AA32 LD L,A ...and keep it.
AA33 LD ($9655),HL Keep this position.
AA36 PUSH HL Save the Y position.
AA37 LD A,H Fetch the Y cell...
AA38 INC A ...and add one...
AA39 AND $3F ...making sure that the cell is within the map.
AA3B LD H,A
AA3C CALL FindMapCell Find the cell using FindMapCell.
AA3F JR Z,MoveUp_Clear Jump if the cell is empty.
AA41 PUSH HL Save the Y position.
AA42 LD HL,($962E) Fetch the address of the cell...
AA45 LD A,(HL) ...and its contents...
AA46 POP HL ...and restore the Y position.
AA47 AND $0F Jump if the cell has no type.
AA49 JR Z,MoveUp_Clear
AA4B CP $0F Jump if the cell is not type 0F, which is an obstacle.
AA4D JR NZ,MoveUp_Blocked
MoveUp_Clear AA4F POP HL Restore the Y position...
AA50 JR MoveUp_Finish ...and jump to finish the move.
MoveUp_Blocked AA52 POP HL The entity is blocked, so restore the old Y position.
AA53 XOR A Clear the number of steps that are left...
AA54 LD B,A
AA55 LD L,A ...and the fraction...
AA56 INC A ...and set A to 01.
AA57 RET Return.
Prev: A9DD Up: Map Next: AA58