| Preserve the fouled attacker's physical pad across native penalty-shot setup.
| +0 accepted getBAplayerInfo capture, +4 puckpenshot controller assignment.
| F654..F659: transient signature / physical offset+1 / attacking side1/2.
| Native collisions run at AEB8, after both adapter input banks are restored.
| No per-frame hook, side-setting persistence, shot selection or RNG change.
    .equ RECORD,0xFFFFF654
    .equ PAD,RECORD+2
    .equ SIDE,RECORD+4
    .equ OBJ,0xFFFFB04A
    .text
    .globl _start
_start:
    bra.w capture
    bra.w setup
capture:
    move.w %d0,0xFFFFD406           | both displaced native instructions
    lea OBJ,%a1
    move.w %sr,-(%sp)
    movem.l %d0-%d3/%a0,-(%sp)
    clr.l RECORD
    clr.w SIDE
    cmpi.w #11,%d0
    bhi.s captured
    move.w %d0,%d2
    lsl.w #7,%d2
    btst #3,0x62(%a1,%d2.w)
    beq.s captured
    tst.w 0x34(%a1,%d2.w)
    ble.s captured
    moveq #1,%d3
    cmpi.w #6,%d0
    bcs.s capture_side
    moveq #2,%d3
capture_side:
    lea 0xFFFFC320,%a0
    moveq #0,%d1
capture_pad:
    cmp.w (%a0,%d1.w),%d0
    bne.s capture_next
    cmp.w 8(%a0,%d1.w),%d3
    bne.s capture_next
    addq.w #1,%d1
    move.w %d1,PAD
    move.w %d3,SIDE
    move.w #0x5053,RECORD
    bra.s captured
capture_next:
    addq.w #2,%d1
    cmpi.w #8,%d1
    bcs.s capture_pad
captured:
    movem.l (%sp)+,%d0-%d3/%a0
    move.w (%sp)+,%sr
    rts

setup:
    move.w %sr,-(%sp)
    movem.l %d0-%d7/%a0-%a6,-(%sp)
    cmpi.w #0x5053,RECORD
    bne.w ordinary
    btst #0,0xFFFFC2FA            | OT/standalone shootout retains its rotation
    bne.w ordinary
    btst #2,0xFFFFC2F2
    beq.w ordinary
    move.w PAD,%d4
    subq.w #1,%d4
    cmpi.w #6,%d4
    bhi.w ordinary
    btst #0,%d4
    bne.w ordinary
    move.w SIDE,%d5
    cmpi.w #1,%d5
    beq.s valid_side
    cmpi.w #2,%d5
    bne.w ordinary
valid_side:
    lea 0xFFFFC328,%a0
    cmp.w (%a0,%d4.w),%d5
    bne.w ordinary
    move.w 0xFFFFD404,%d0
    addq.w #1,%d0
    cmp.w %d5,%d0
    bne.w ordinary
    | Only actual participants may claim the two live actors. Keep all public
    | side choices on the stack and restore them before returning to the game.
    ori.w #0x700,%sr
    move.l (%a0),-(%sp)
    move.l 4(%a0),-(%sp)
    moveq #0,%d3
    moveq #0,%d2
select_sides:
    move.w (%a0,%d2.w),%d0
    cmp.w %d2,%d4
    beq.s keep_side
    tst.w %d0
    beq.s keep_side
    cmp.w %d5,%d0
    beq.s hide_side
    tst.w %d3
    bne.s hide_side
    moveq #1,%d3                  | first native defending pad keeps the goalie
    bra.s keep_side
hide_side:
    clr.w (%a0,%d2.w)
keep_side:
    addq.w #2,%d2
    cmpi.w #8,%d2
    bcs.s select_sides
    | All nonparticipants are parked. Remove stale ownership before the real
    | FD22/C0F8 assignment, including the secondary adapter bank's old objects.
    lea OBJ,%a1
    moveq #11,%d2
clear_ownership:
    bclr #3,0x62(%a1)
    adda.w #128,%a1
    dbra %d2,clear_ownership
    moveq #-1,%d0
    move.l %d0,0xFFFFC320
    move.l %d0,0xFFFFC324
    jsr 0xFD22
    move.l (%sp)+,0xFFFFC32C
    move.l (%sp)+,0xFFFFC328
    bra.s assigned
ordinary:
    movem.l (%sp)+,%d0-%d7/%a0-%a6
    move.w (%sp)+,%sr
    jsr 0xFD22
    clr.w RECORD
    move.w 0xFFFFD408,%d0
    rts
assigned:
    clr.w RECORD                 | each accepted award is consumed once
    movem.l (%sp)+,%d0-%d7/%a0-%a6
    move.w (%sp)+,%sr
    move.w 0xFFFFD408,%d0        | original instruction following BSR FD22
    rts
