Prev: C918 Up: Map Next: CA49
CA11: Vischar move X
This moves a character on the X axis.
Used by the routine at character_behaviour.
Input
HL Pointer to vischar.target.
IY Pointer to visible character block.
Output
A New input: input_RIGHT + input_DOWN (8) if x > pos.x, input_LEFT + input_UP (4) if x < pos.x, input_NONE (0) if x == pos.x
F Z set if zero returned, NZ otherwise
HL Pointer to visible character block + 5. (Ready to pass into vischar_move_y)
vischar_move_x CA11 LD A,(HL) Read vischar.target.x (target position)
CA12 CALL multiply_by_8 Multiply it by 1, 4 or 8 (self modified by cb_self_modify)
CA15 LD A,L Point HL at vischar.mi.pos.x (current position)
CA16 ADD A,$0B
CA18 LD L,A
CA19 LD E,(HL) Read vischar.mi.pos.x
CA1A INC L
CA1B LD D,(HL)
CA1C EX DE,HL Free up HL
CA1D SBC HL,BC Compute the delta: current position - target position
CA1F JR Z,vmx_equal Jump if it's zero
CA21 JP M,vmx_negative Jump if it's negative
The delta was positive
vmx_positive CA24 LD A,H Delta >= 256?
CA25 AND A
CA26 JR NZ,vmx_delta_too_big Jump if so
CA28 LD A,L Delta < 3?
CA29 CP $03
CA2B JR C,vmx_equal Jump if it's in range
The delta was three or greater
vmx_delta_too_big CA2D LD A,$08 Return input_RIGHT + input_DOWN (6 + 2)
CA2F RET
The delta was negative
vmx_negative CA30 LD A,H Delta < -256?
CA31 CP $FF
CA33 JR NZ,vmx_delta_too_small Jump if so
CA35 LD A,L Delta >= -2?
CA36 CP $FE
CA38 JP NC,vmx_equal Jump if it's in range
The delta was less than negative three
vmx_delta_too_small CA3B LD A,$04 Return input_LEFT + input_UP (3 + 1)
CA3D RET
The delta was -2..2
vmx_equal CA3E EX DE,HL Move vischar back into HL
CA3F LD A,L Point HL at vischar->mi.pos.x
CA40 SUB $0B
CA42 LD L,A
CA43 SET 5,(IY+$07) Set vischar.counter_and_flags flag vischar_BYTE7_Y_DOMINANT so that next time we'll use vischar_move_y in preference
CA47 XOR A Return input_NONE (0)
CA48 RET
Prev: C918 Up: Map Next: CA49