← 9B67 Inertia speed ramp Map 9C99 → Drag the bat's extension up
9BEE: Move the bat with inertia
Moves the bat while a direction is held, faster the longer it is held, and restarts from rest on a reversal.
It tests the travel bounds tabled in the bat mover, and drags the bat extension and any caught ball.
Input
IX the bat's sprite record
apply_inertia_control 9BEE LD HL,controls Read the live control bits into HL.
9BF1 BIT 3,(HL) Up held?
9BF3 JP Z,inertia_down
9BF6 LD A,(IX+$01) Bat Y
9BF9 CP $26 At the top edge? Stop and reset the accumulator.
9BFB JP C,inertia_idle
9BFE LD A,(bat_move_dir) Was the previous move also up?
9C01 CP $01
9C03 JR Z,inertia_up_step
9C05 XOR A A reversal resets the accumulator, so acceleration restarts from rest.
9C06 LD (bat_velocity),A
inertia_up_step 9C09 LD A,(bat_velocity) Index the inertia speed ramp by the accumulator.
9C0C LD E,A
9C0D LD D,$00
9C0F LD HL,inertia_speed_ramp
9C12 ADD HL,DE
9C13 LD B,(HL) Take this frame's step (it grows as the accumulator ramps).
9C14 LD A,(IX+$01) Move the bat up by that step.
9C17 SUB B
9C18 LD (IX+$01),A
9C1B CALL drag_attached_up Drag the bat extension and any caught ball up too.
9C1E LD A,B
9C1F CALL drag_caught_up
9C22 LD A,(bat_velocity) Add the inertia rate to the accumulator while it is below the ramp threshold. The sum can overshoot the threshold.
9C25 CP $78
9C27 JR NC,inertia_up_done
9C29 LD A,(bat_velocity)
9C2C LD B,A
9C2D LD A,(inertia_accel)
9C30 ADD A,B
9C31 LD (bat_velocity),A
inertia_up_done 9C34 LD A,$01 Remember this frame moved up.
9C36 LD (bat_move_dir),A
9C39 RET
inertia_down 9C3A LD HL,controls Down held?
9C3D BIT 2,(HL)
9C3F JR Z,inertia_idle
9C41 LD A,(expand_active) An attached extension raises the bottom travel limit.
9C44 OR A
9C45 JR Z,inertia_down_clamp
9C47 LD A,(IX+$01) With the extension attached, the bat stops short so the extension has room.
9C4A CP $8A
9C4C JR NC,inertia_idle
9C4E JR inertia_down_dir
inertia_down_clamp 9C50 LD A,(IX+$01) Without one it runs to the floor of its travel.
9C53 CP $9A
9C55 JR NC,inertia_idle
inertia_down_dir 9C57 LD A,(bat_move_dir) Was the previous move also down?
9C5A CP $02
9C5C JR Z,inertia_down_step
9C5E LD A,$01 On a reversal, restart the acceleration ramp from the bottom.
9C60 LD (bat_velocity),A
inertia_down_step 9C63 LD A,(bat_velocity) Index the inertia speed ramp by the accumulator.
9C66 LD E,A
9C67 LD D,$00
9C69 LD HL,inertia_speed_ramp
9C6C ADD HL,DE
9C6D LD B,(HL)
9C6E LD A,(IX+$01) Move the bat down by the table step.
9C71 ADD A,B
9C72 LD (IX+$01),A
9C75 CALL drag_attached_down Drag the bat extension and any caught ball down too.
9C78 LD A,B
9C79 CALL drag_caught_down
9C7C LD A,(bat_velocity)
9C7F CP $78 Add the inertia rate to the accumulator while it is below the ramp threshold. The sum can overshoot the threshold.
9C81 JR NC,inertia_down_done
9C83 LD A,(bat_velocity)
9C86 LD B,A
9C87 LD A,(inertia_accel)
9C8A ADD A,B
9C8B LD (bat_velocity),A
inertia_down_done 9C8E LD A,$02 Remember this frame moved down.
9C90 LD (bat_move_dir),A
9C93 RET
inertia_idle 9C94 XOR A Neither direction held (or blocked): reset the accumulator so the next press starts slow.
9C95 LD (bat_velocity),A
9C98 RET
← 9B67 Inertia speed ramp Map 9C99 → Drag the bat's extension up
Fork me on GitHub