    .ifndef WITH_GAP_BRAKE
    .equ WITH_GAP_BRAKE,0
    .endif
| Hard defensive pair: nearer back contains the carrier goal-side;
| partner protects a dangerous slot receiver. Native skating/checking retained.
    .text
    .globl _start
_start:
    lea 0xE594,%a0
    movem.l %d2-%d7/%a1-%a2,-(%sp)
    link.w %a6,#-24
    move.w %d0,-2(%a6)
    move.w %d1,-4(%a6)
    cmpi.w #1,0xFFFFF07A
    bne.w native
    btst #3,0x62(%a3)
    bne.w native
    btst #5,0x62(%a3)
    bne.w native
    btst #2,0x63(%a3)
    bne.w native
    cmpi.w #1,0x34(%a3)
    blt.w native
    cmpi.w #2,0x34(%a3)
    bgt.w native
    btst #0,0xFFFFC2EA
    bne.w native
    btst #7,0xFFFFC2EC
    bne.w native
    btst #7,0xFFFFC2EE
    bne.w native
    btst #2,0xFFFFC2F2
    bne.w native
    btst #0,0xFFFFC2FA
    bne.w native
    btst #2,0xFFFFC2FA
    bne.w native
    .if WITH_PASS_CONTINUITY
    bsr.w flight_owner
    .else
    move.w 0xFFFFB7AA,%d2
    .endif
    cmpi.w #11,%d2
    bhi.w native
    move.w 0x52(%a3),%d3
    subi.w #6,%d2
    subi.w #6,%d3
    eor.w %d3,%d2
    bpl.w native
    move.w 0xFFFFB75E,%d3
    btst #7,0x62(%a3)
    bne.s depth_ready
    neg.w %d3
depth_ready:
    cmpi.w #-80,%d3
    bgt.w native
    cmpi.w #-264,%d3
    blt.w native
    move.w 0xFFFFB74A,%d4
    cmpi.w #-144,%d4
    blt.w native
    cmpi.w #144,%d4
    bgt.w native
    move.w %d4,-6(%a6)              | actual carrier world X, own attack-oriented depth
    move.w %d3,-8(%a6)
    lea 0xFFFFB04A,%a1
    cmpi.w #6,0x52(%a3)
    bcs.s own_base
    adda.w #768,%a1
own_base:
    move.l #0x7FFFFFFF,%d6
    moveq #-1,%d5
    .if WITH_REAL_ACTORS
    moveq #5,%d7
    .else
    moveq #4,%d7
    .endif
nearest:
    cmpi.w #1,0x34(%a1)
    blt.s next_back
    cmpi.w #2,0x34(%a1)
    bgt.s next_back
    btst #2,0x63(%a1)
    bne.s next_back
    btst #5,0x62(%a1)
    bne.s next_back
    move.w (%a1),%d0
    sub.w %d4,%d0
    muls.w %d0,%d0
    move.w 0x14(%a1),%d1
    sub.w 0xFFFFB75E,%d1
    muls.w %d1,%d1
    add.l %d1,%d0
    cmp.l %d6,%d0
    bge.s next_back
    move.l %d0,%d6
    move.w 0x52(%a1),%d5
next_back:
    adda.w #128,%a1
    dbra %d7,nearest
    cmp.w 0x52(%a3),%d5
    bne.w cover
    move.w -6(%a6),%d0
    move.w %d0,%d1
    asr.w #3,%d1
    sub.w %d1,%d0                    | stay slightly inside the carrying lane
    move.w -8(%a6),%d1
    subi.w #20,%d1                   | goal-side containment gap
    .if WITH_GAP_BRAKE
    jsr 0x228000
    lea 0x228040,%a0                 | retain the native target-arrival brake command
    .endif
    cmpi.w #-238,%d1
    bge.w store
    move.w #-238,%d1
    bra.w store
cover:
    moveq #30,%d0                    | weak post if there is no dangerous receiver
    tst.w -6(%a6)
    bmi.s cover_depth
    neg.w %d0
cover_depth:
    move.w -8(%a6),%d1
    subi.w #32,%d1
    cmpi.w #-224,%d1
    bge.s cover_min
    move.w #-224,%d1
cover_min:
    cmpi.w #-140,%d1
    ble.s find_threat
    move.w #-140,%d1
find_threat:
    move.w #0x7FFF,%d6
    lea 0xFFFFB04A,%a1
    cmpi.w #6,0x52(%a3)
    bcc.s opp_base
    adda.w #768,%a1
opp_base:
    .if WITH_REAL_ACTORS
    moveq #5,%d7
    .else
    moveq #4,%d7
    .endif
threat:
    tst.w 0x34(%a1)
    ble.w next_threat
    btst #2,0x63(%a1)
    bne.w next_threat
    move.w 0x52(%a1),%d2
    cmp.w 0xFFFFB7AA,%d2
    beq.w next_threat
    move.w (%a1),%d2
    move.w %d2,%d4
    bpl.s threat_abs
    neg.w %d4
threat_abs:
    cmpi.w #92,%d4
    bgt.w next_threat
    move.w 0x14(%a1),%d3
    btst #7,0x62(%a3)
    bne.s threat_depth
    neg.w %d3
threat_depth:
    cmpi.w #-140,%d3
    bgt.w next_threat
    cmpi.w #-252,%d3
    blt.w next_threat
    move.w %d3,%d5
    addi.w #224,%d5
    bpl.s threat_cost
    neg.w %d5
threat_cost:
    add.w %d5,%d5
    add.w %d4,%d5
    cmp.w %d6,%d5
    bge.s next_threat
    move.w %d5,%d6
    move.w %d2,%d0
    asr.w #2,%d2
    sub.w %d2,%d0                    | shadow inside the receiver, protect the pass lane
    move.w %d3,%d1
    subi.w #12,%d1
    cmpi.w #-236,%d1
    bge.s next_threat
    move.w #-236,%d1
next_threat:
    adda.w #128,%a1
    dbra %d7,threat
store:
    btst #7,0x62(%a3)
    bne.s output
    neg.w %d1
output:
    move.w %d0,-2(%a6)
    move.w %d1,-4(%a6)
native:
    move.w -2(%a6),%d0
    move.w -4(%a6),%d1
    unlk %a6
    movem.l (%sp)+,%d2-%d7/%a1-%a2
    jmp 0x103C8

    .if WITH_PASS_CONTINUITY
flight_owner:
    jsr 0x2DD680
    rts
    .endif
