    .ifndef WITH_CATCH_AI
    .equ WITH_CATCH_AI,1
    .endif
| Leave an AI goalie under AI control when he catches/collects the puck.
| Hook $15322, after ownership/statistics are recorded but before automatic controller assignment.
| Explicit Y/B goalie selection uses a different path and remains available.
| Scope: one to four teammates with Goalie Ctrl Manual; opposing humans stay native.
        .text
        .globl _start
_start:
        move.l  %d1,-(%sp)              | a new accepted pickup cancels any previous-possession B request,
        move.w  %sr,-(%sp)
        ori.w   #0x700,%sr
        move.w  0x52(%a2),%d1           | except one queued for this very goalie just before his catch
        cmp.w   0xFFFFF066,%d1          | (outlet.s incoming, 2026-10-26-r13)
        beq.s   1f
        clr.l   0xFFFFF064
1:      move.w  (%sp)+,%sr
        move.l  (%sp)+,%d1
        tst.w   0x34(%a2)              | only the goalie; pulled-goalie substitutes remain skaters
        bne.s   original
        tst.w   0xFFD052                | Goalie Ctrl Manual
        bne.s   original
        tst.w   0xFFC32C
        bne.s   four_players
        tst.w   0xFFC32E
        bne.s   four_players
        btst    #0,0xFFC2FA             | shootout still needs the normal goalie assignment
        bne.s   original
        move.l  %d1,-(%sp)
        move.w  0xFFC328,%d1            | controller 1's side: 0 none, 1 home, 2 away
        beq.s   keep_ai
        cmp.w   0xFFC32A,%d1
        beq.s   keep_ai                 | both controllers are teammates
        tst.w   0xFFC32A
        beq.s   keep_ai                 | only one human
        move.l  (%sp)+,%d1              | opposing human teams: original behaviour
original:
        cmp.w   0xFFC320,%d0            | original instructions at $15322
        beq.s   done
        jmp     0x1532A
keep_ai:
        move.l  (%sp)+,%d1
catch_handoff:
    .if WITH_CATCH_AI
        jsr     0x2DBC00
    .endif
done:   rts
four_players:
        btst    #0,0xFFC2FA
        bne.s   original
        jsr     0x2EA610                | keep AI for3/4 teammates, native assignment for opposing humans
        beq.s   catch_handoff
        bra.s   original
