Prev: 43608 Up: Map Next: 43731
43671: Move Down
Used by the routines at MoveEntity and MoveRobot.
Moves an entity in direction three, which decreases 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
MoveDown 43671 LD A,B Return if there are no steps left.
43672 AND A
43673 RET Z
43674 LD A,L Jump if the entity is at the start of a cell.
43675 AND A
43676 JR Z,MoveDown_CellStart
43678 SUB B Take the steps off the fraction, and jump if that goes back into the previous cell.
43679 JR C,MoveDown_NextCell
43681 LD L,A Store the new fraction.
MoveDown_Finish 43682 XOR A Clear the number of steps that are left, and return with the zero flag set.
43683 LD B,A
43684 RET
MoveDown_NextCell 43685 NEG Work out how many steps are left over...
43687 LD B,A ...and keep them in B.
43688 XOR A Move to the start of the cell, and return with the zero flag set.
43689 LD L,A
43690 RET Return.
MoveDown_CellStart 43691 PUSH HL Save the Y position.
43692 SUB B Take the steps off the fraction, which goes back into the previous cell...
43693 LD L,A ...and keep it.
43694 LD A,H Fetch the Y cell...
43695 SBC A,0 ...and take one off...
43697 AND 63 ...making sure that the cell is within the map.
43699 LD H,A
43700 LD (38485),HL Keep this position.
43703 CALL FindMapCell Find the cell using FindMapCell.
43706 JR Z,MoveDown_Clear Jump if the cell is empty.
43708 PUSH HL Save the Y position.
43709 LD HL,(38446) Fetch the address of the cell...
43712 LD A,(HL) ...and its contents...
43713 POP HL ...and restore the Y position.
43714 AND 15 Jump if the cell has no type.
43716 JR Z,MoveDown_Clear
43718 CP 15 Jump if the cell is not type 15, which is an obstacle.
43720 JR NZ,MoveDown_Blocked
MoveDown_Clear 43722 INC SP Discard the old Y position...
43723 INC SP
43724 JR MoveDown_Finish ...and jump to finish the move.
MoveDown_Blocked 43726 POP HL The entity is blocked, so restore the old Y position.
43727 XOR A Clear the number of steps that are left...
43728 LD B,A
43729 INC A ...and set A to 1.
43730 RET Return.
Prev: 43608 Up: Map Next: 43731