← A4E6 Unused bytes Map A594 → Ball velocity vectors by heading
A4F6: Advance the active ball by its velocity
Advances the active ball one frame. Its pool object moves by the pixels its sub-pixel accumulators earn.
step_ball A4F6 LD A,(active_ball) Select the active ball state record: this arm takes ball A.
A4F9 OR A
A4FA JR NZ,step_ball_use_b
A4FC LD IY,ball_a_x_accum
A500 JR step_ball_init_passes
step_ball_use_b A502 LD IY,ball_b_x_accum This arm takes ball B.
step_ball_init_passes A506 LD (IY+$07),$00 Reset its pass counter.
step_ball_pass A50A XOR A Each pass: clear the X-step flag.
A50B LD (x_stepped),A
A50E LD A,(IY+$02) Does the X axis move? (a zero threshold means no X motion)
A511 OR A
A512 JR Z,step_ball_y_axis
A514 LD B,$05 Each pass adds a fixed sub-pixel increment to the X accumulator.
step_ball_x_accumulate A516 INC (IY+$00) It goes on one unit at a time.
A519 LD A,(IY+$00) Each unit is weighed against the threshold.
A51C LD C,(IY+$02)
A51F CP C
A520 JR NZ,step_ball_x_loop
A522 XOR A At that value, the accumulator wraps and flags an X pixel step.
A523 LD (IY+$00),A
A526 INC A
A527 LD (x_stepped),A
step_ball_x_loop A52A DJNZ step_ball_x_accumulate Repeat until the pass's five sub-pixel units are done.
step_ball_y_axis A52C XOR A Same for the Y axis, on its own accumulator and threshold.
A52D LD (y_stepped),A
A530 LD A,(IY+$03)
A533 OR A
A534 JR Z,step_ball_locate_object
A536 LD B,$05
step_ball_y_accumulate A538 INC (IY+$01) Add one sub-pixel unit to the Y accumulator and weigh it against the threshold.
A53B LD A,(IY+$01)
A53E LD C,(IY+$03)
A541 CP C
A542 JR NZ,step_ball_y_loop
A544 XOR A At the threshold, the accumulator wraps and flags a Y pixel step.
A545 LD (IY+$01),A
A548 INC A
A549 LD (y_stepped),A
step_ball_y_loop A54C DJNZ step_ball_y_accumulate Repeat until the pass's five sub-pixel units are done.
step_ball_locate_object A54E LD A,(active_ball) Point IX at the ball's screen object.
A551 OR A
A552 JR NZ,step_ball_object_b
A554 LD IX,ball_a_object
A558 JR step_ball_apply_x
step_ball_object_b A55A LD IX,obj2_object Ball B steers its own record instead.
step_ball_apply_x A55E LD A,(x_stepped) Did X step on the current pass?
A561 OR A
A562 JR Z,step_ball_apply_y
A564 LD A,(IY+$04) If so, a leftward X sign moves the object one pixel left.
A567 OR A
A568 JR NZ,step_ball_x_positive
A56A DEC (IX+$00)
A56D JR step_ball_apply_y
step_ball_x_positive A56F INC (IX+$00) A rightward sign moves it right.
step_ball_apply_y A572 LD A,(y_stepped) Did Y step on the current pass?
A575 OR A
A576 JR Z,step_ball_next_pass
A578 LD A,(IY+$05) If so, an upward Y sign moves it one pixel up.
A57B OR A
A57C JR NZ,step_ball_y_positive
A57E DEC (IX+$01)
A581 JR step_ball_next_pass
step_ball_y_positive A583 INC (IX+$01) A downward sign moves it down.
step_ball_next_pass A586 INC (IY+$07) Count the pass and loop until passes are done.
A589 LD A,(IY+$07)
A58C LD C,(IY+$06)
A58F CP C
A590 RET Z
A591 JP step_ball_pass
← A4E6 Unused bytes Map A594 → Ball velocity vectors by heading
Fork me on GitHub