Prev: 43485 Up: Map Next: 43608
43546: 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 1 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 43546 LD A,B Return if there are no steps left.
43547 AND A
43548 RET Z
43549 LD A,L Jump if the entity is at the start of a cell.
43550 AND A
43551 JR Z,MoveUp_CellStart
43553 ADD A,B Add the steps to the fraction, and jump if that goes into the next cell.
43554 JR C,MoveUp_NextCell
43556 LD L,A Store the new fraction.
MoveUp_Finish 43557 XOR A Clear the number of steps that are left, and return with the zero flag set.
43558 LD B,A
43559 RET
MoveUp_NextCell 43560 LD B,A Keep the steps that are left over.
43561 LD A,H Fetch the Y cell...
43562 INC A ...and add one...
43563 AND 63 ...making sure that the cell is within the map.
43565 LD H,A
43566 XOR A Move to the start of the cell, and return with the zero flag set.
43567 LD L,A
43568 RET Return.
MoveUp_CellStart 43569 ADD A,B Add the steps to the fraction...
43570 LD L,A ...and keep it.
43571 LD (38485),HL Keep this position.
43574 PUSH HL Save the Y position.
43575 LD A,H Fetch the Y cell...
43576 INC A ...and add one...
43577 AND 63 ...making sure that the cell is within the map.
43579 LD H,A
43580 CALL FindMapCell Find the cell using FindMapCell.
43583 JR Z,MoveUp_Clear Jump if the cell is empty.
43585 PUSH HL Save the Y position.
43586 LD HL,(38446) Fetch the address of the cell...
43589 LD A,(HL) ...and its contents...
43590 POP HL ...and restore the Y position.
43591 AND 15 Jump if the cell has no type.
43593 JR Z,MoveUp_Clear
43595 CP 15 Jump if the cell is not type 15, which is an obstacle.
43597 JR NZ,MoveUp_Blocked
MoveUp_Clear 43599 POP HL Restore the Y position...
43600 JR MoveUp_Finish ...and jump to finish the move.
MoveUp_Blocked 43602 POP HL The entity is blocked, so restore the old Y position.
43603 XOR A Clear the number of steps that are left...
43604 LD B,A
43605 LD L,A ...and the fraction...
43606 INC A ...and set A to 1.
43607 RET Return.
Prev: 43485 Up: Map Next: 43608