Prev: C6A0 Up: Map Next: C7B9
C79A: Move towards
This moves the first value toward the second.
Used by the routine at move_a_character.
Input
A' Largest movement allowed. Either 2 or 6.
B Return code. Incremented if delta is zero.
DE Pointer to the first value (byte).
HL Pointer to the second value (byte).
Output
B Incremented by one when no change.
move_towards C79A EX AF,AF' Set C to the largest movement allowed
C79B LD C,A
C79C EX AF,AF'
C79D LD A,(DE) delta = first - second
C79E SUB (HL)
C79F JR NZ,move_towards_0 Was the delta zero? Jump if not
Delta was zero
C7A1 INC B Otherwise increment the result by one
C7A2 RET Return
move_towards_0 C7A3 JR NC,move_towards_2 Was the delta negative? Jump if not
Delta was negative
C7A5 NEG Get the absolute value
C7A7 CP C Clamp the delta to the largest movement
C7A8 JR C,move_towards_1
C7AA LD A,C
move_towards_1 C7AB LD C,A Move the first value towards second
C7AC LD A,(DE)
C7AD ADD A,C
C7AE LD (DE),A
C7AF RET Return
Delta was positive
move_towards_2 C7B0 CP C Clamp the delta to the largest movement
C7B1 JR C,move_towards_3
C7B3 LD A,C
move_towards_3 C7B4 LD C,A Move the first value towards second
C7B5 LD A,(DE)
C7B6 SUB C
C7B7 LD (DE),A
C7B8 RET Return
Prev: C6A0 Up: Map Next: C7B9