    .ifndef FINISH_POSITION_ENABLED
    .equ FINISH_POSITION_ENABLED,1
    .endif
| Native receiving is retained; brake only while already within8units of the
| future pass course. Near the actual puck, cap the separate native target
| cache to2ticks (the established Hard steering cadence) and meet it normally.
| No direct position/velocity writes; native103C8 applies motion/turn/braking.
 .text
 .globl _start
_start:
 .if FINISH_POSITION_ENABLED
 bra.w steer
 .else
 bra.w no_steer
 .endif
 .if FINISH_POSITION_ENABLED
 bra.w close_receive
 .else
 bra.w no_steer
 .endif
 bra.w geometry
steer:
 movem.l %d0-%d7/%a0-%a1,-(%sp)
 clr.l (%sp)
 move.w (%a3),%d0
 move.w 0x14(%a3),%d1
 move.w 0xFFFFB74A,%d2
 move.w 0xFFFFB75E,%d3
 move.w 0xFFFFB772,%d4
 move.w 0xFFFFB774,%d5
 bsr.w geometry
 tst.w %d2
 beq.s steer_done
 sub.w (%a3),%d0
 cmpi.w #-8,%d0
 blt.s steer_done
 cmpi.w #8,%d0
 bgt.s steer_done
 sub.w 0x14(%a3),%d1
 cmpi.w #-8,%d1
 blt.s steer_done
 cmpi.w #8,%d1
 bgt.s steer_done
 move.l #1,(%sp)
 movem.l 4(%sp),%d1-%d7/%a0-%a1
 jsr 0x105A2                       | retain real interception/facing before native braking
 movem.l 4(%sp),%d1-%d7/%a0-%a1
 moveq #9,%d0
 jsr 0x10750                       | native brake, no direct position/velocity writes
steer_done:
 movem.l (%sp)+,%d0-%d7/%a0-%a1
 tst.w %d0
 rts

| D0/D1 receiver point,D2/D3 puck,D4/D5 native signed velocity lowwords.
| D0/D1 closest point if within32units/component, D2 boolean. Other GPR/SR
| preserved; input upperwords D0/D1 retained. Invalid or nonapproaching ->false.
geometry:
 move.w %sr,-(%sp)
 link.w %a6,#-24
 movem.l %d3-%d7,-(%sp)
 move.l %d0,-4(%a6)
 move.l %d1,-8(%a6)
 cmpi.w #-192,%d0
 blt.w invalid
 cmpi.w #192,%d0
 bgt.w invalid
 cmpi.w #-352,%d1
 blt.w invalid
 cmpi.w #352,%d1
 bgt.w invalid
 cmpi.w #-192,%d2
 blt.w invalid
 cmpi.w #192,%d2
 bgt.w invalid
 cmpi.w #-352,%d3
 blt.w invalid
 cmpi.w #352,%d3
 bgt.w invalid
 sub.w %d2,%d0
 sub.w %d3,%d1
 move.w %d0,-10(%a6)
 move.w %d1,-12(%a6)
normalize:
 move.w %d4,%d6
 bpl.s norm_vx
 neg.w %d6
norm_vx:
 move.w %d5,%d7
 bpl.s norm_vy
 neg.w %d7
norm_vy:
 or.w %d7,%d6
 cmpi.w #127,%d6
 bls.s normalized
 asr.w #1,%d4
 asr.w #1,%d5
 bra.s normalize
normalized:
 move.w %d4,%d6
 muls.w %d4,%d6
 move.w %d5,%d7
 muls.w %d5,%d7
 add.l %d7,%d6
 beq.w invalid
 move.w %d6,-18(%a6)
 move.w %d0,%d6
 muls.w %d4,%d6
 move.w %d1,%d7
 muls.w %d5,%d7
 add.l %d7,%d6
 ble.w invalid
 move.w %d0,%d6
 muls.w %d5,%d6
 move.w %d1,%d7
 muls.w %d4,%d7
 sub.l %d7,%d6
 move.l %d6,-16(%a6)
 | Cross can exceed a signed word. Divide its products safely using
 | native32/16 quotient: delta bounded by world geometry (<1024).
 move.l %d6,%d7
 | 68000MULS consumes only lowword. Cross up to122k needs32xword product.
 bsr.w multiply_cross_vy
 divs.w -18(%a6),%d7
 cmpi.w #-32,%d7
 blt.s invalid
 cmpi.w #32,%d7
 bgt.s invalid
 move.w %d7,-20(%a6)
 move.l -16(%a6),%d6
 bsr.w multiply_cross_vx
 divs.w -18(%a6),%d7
 cmpi.w #-32,%d7
 blt.s invalid
 cmpi.w #32,%d7
 bgt.s invalid
 move.l -4(%a6),%d0
 move.l -8(%a6),%d1
 sub.w -20(%a6),%d0
 add.w %d7,%d1
 moveq #1,%d2
 bra.s geometry_done
invalid:
 move.l -4(%a6),%d0
 move.l -8(%a6),%d1
 moveq #0,%d2
geometry_done:
 movem.l (%sp)+,%d3-%d7
 unlk %a6
 move.w (%sp)+,%sr
 rts
| Signed32 cross x signed16 bounded normalized velocity -> signed32 product.
| cross32 is split high16/low16. Use unsigned lowword plus signed highword.
multiply_cross_vy:
 move.w %d5,%d3
 bra.s multiply_cross
multiply_cross_vx:
 move.w %d4,%d3
multiply_cross:
 move.l %d6,%d7
 move.l %d6,%d0
 swap %d0
 eor.w %d3,%d0
 move.w %d0,-22(%a6)
 tst.l %d7
 bpl.s cross_magnitude
 neg.l %d7
cross_magnitude:
 tst.w %d3
 bpl.s multiplier_magnitude
 neg.w %d3
multiplier_magnitude:
 move.l %d7,%d0
 swap %d0
 andi.l #0xFFFF,%d0
 mulu.w %d3,%d0
 swap %d0
 clr.w %d0
 andi.l #0xFFFF,%d7
 mulu.w %d3,%d7
 add.l %d0,%d7
 tst.w -22(%a6)
 bpl.s multiply_done
 neg.l %d7
multiply_done:
 rts

no_steer:
 moveq #0,%d0
 rts

close_receive:
 movem.l %d1-%d7/%a0-%a3,-(%sp)
 cmpi.b #2,0x42(%a3)
 ble.s native
 move.b #2,0x42(%a3)
native:
 jsr 0x105A2
 movem.l (%sp)+,%d1-%d7/%a0-%a3
 moveq #1,%d0
 rts
