Prev: B97A Up: Map Next: B9BB
B980: Move a record across the world by its speed
Used by the routines at leave_slope, place_collision_box and move_object.
Adds the speed (+7 +8) to the position (+2 +3), and steps the page (+1) when the position leaves 8 to $E7: up a page past $E7, wrapping from $5F to 0, down a page below 8, wrapping from 0 to $5F. Both a run past the end and an 8-bit overflow count, so speeds up to 32 pixels a pass are safe. The record is not changed: move_object stores the result, and place_collision_box uses it as the place to test.
Input
IX the record
Output
H the page across
L the x
E the fraction
move_across B980 LD H,(IX+$02) HL = x and fraction plus the speed; E the fraction, L the x, H the page, C the old x
B983 LD L,(IX+$03)
B986 LD D,(IX+$07)
B989 LD E,(IX+$08)
B98C ADD HL,DE
B98D LD E,L
B98E LD L,H
B98F LD H,(IX+$01)
B992 LD C,(IX+$02)
B995 LD A,L moving right: in the page still
B996 BIT 7,D
B998 JR NZ,move_across_1
B99A CP $E8
B99C JR NC,move_across_0
B99E CP C
B99F RET NC
move_across_0 B9A0 SUB $E0 into the next page, from $5F round to 0
B9A2 LD L,A
B9A3 INC H
B9A4 LD A,H
B9A5 SUB $60
B9A7 RET NZ
B9A8 LD H,A
B9A9 RET
move_across_1 B9AA CP $08 moving left: in the page still
B9AC JR C,move_across_2
B9AE CP C
B9AF RET C
B9B0 RET Z
move_across_2 B9B1 ADD A,$E0 into the page before, from 0 round to $5F
B9B3 LD L,A
B9B4 DEC H
B9B5 LD A,H
B9B6 INC A
B9B7 RET NZ
B9B8 LD H,$5F
B9BA RET
Prev: B97A Up: Map Next: B9BB