Prev: BEEE Up: Map Next: BF37
BEEF: Calculate the distance between two pairs of coordinates.
The result is stored in total_distance. The value in the A register is compared with the result.
calculate_distance BEEF PUSH BC Preserve registers.
BEF0 PUSH HL
BEF1 PUSH DE
BEF2 PUSH AF
BEF3 XOR A Clear A and flags. This is unnecessary.
BEF4 LD HL,(unknown75) Load unknown75 into HL.
BEF7 LD DE,(unknown76) Load unknown76 into DE.
BEFB LD A,D If y-coordinate of unknown76 is greater than or equal to y-coordinate of unknown75, store D-H in y_difference.
BEFC CP H
BEFD JP M,D_less_than_H
BF00 SUB H
BF01 LD (y_difference),A
BF04 JR calculate_distance_0
D_less_than_H BF06 LD A,H Else store H-D in y_difference.
BF07 SUB D
BF08 LD (y_difference),A
calculate_distance_0 BF0B LD A,E If x-coordinate of unknown76 is greater than or equal to y-coordinate of unknown75, store E-L in x_difference.
BF0C CP L
BF0D JP M,E_less_than_L
BF10 SUB L
BF11 LD (x_difference),A
BF14 JR done_x_diff
E_less_than_L BF16 LD A,L Else store L-E in x_difference.
BF17 SUB E
BF18 LD (x_difference),A
done_x_diff BF1B LD HL,(x_difference) Load y_difference into H and x_difference into L.
BF1E LD A,H
BF1F CP L If y_difference is greater than or equal to x_difference, double it and add x_difference.
BF20 JP M,y_diff_less
BF23 SLA H
BF25 LD A,H
BF26 ADD A,L
BF27 JR done_difference
y_diff_less BF29 SLA L Else double x_difference and add y_difference.
BF2B LD A,L
BF2C ADD A,H
done_difference BF2D LD E,A Store result in total_distance.
BF2E LD (total_distance),A
BF31 POP AF Restore A register and compare with result.
BF32 CP E
BF33 POP DE Restore remaining registers and return.
BF34 POP HL
BF35 POP BC
BF36 RET
Prev: BEEE Up: Map Next: BF37