    .ifndef WITH_CRIT_OPTION
    .equ WITH_CRIT_OPTION,1
    .endif
| Critical shots: rating 0..100, RNG(1000) < rating, +25% release power.
| The table is independent of native packed ratings and of battery RAM.
| Shot hook runs once after aim/spread, immediately before native velocity math.
    .equ RATINGS,0x2FF800
    .text
    .globl _start
_start:
    .if WITH_CRIT_OPTION
    bra.w shotgate
    .else
    bra.w shot
    .endif
    bra.w attribute
    bra.w lookup

| D0=team 0..31, D1=zero-based roster slot 0..25 -> D0=rating.
| Keep all other registers; unsigned bounds also reject negative inputs.
lookup:
    movem.l %d1/%a0,-(%sp)
    cmpi.w #32,%d0
    bcc.s absent
    cmpi.w #26,%d1
    bcc.s absent
    mulu.w #26,%d0
    add.w %d1,%d0
    lea RATINGS,%a0
    move.b (%a0,%d0.w),%d0
    andi.w #255,%d0
    bra.s found
absent:
    moveq #0,%d0
found:
    movem.l (%sp)+,%d1/%a0
    rts

shot:
    movem.l %d0-%d1/%a0,-(%sp)
    moveq #0,%d1
    move.b 0x66(%a3),%d1            | actual roster slot, not on-ice object index
    moveq #0,%d0
    move.b 0xFFC331,%d0
    btst #6,0x62(%a3)              | team membership, independent of attack direction
    beq.s home
    move.b 0xFFC333,%d0
home:
    bsr.w lookup
    tst.w %d0
    beq.s ordinary
    move.w %d0,%d1
    move.w #1000,%d0
    jsr 0x11086
    cmp.w %d1,%d0
    bcc.s ordinary
    move.w 0xFFBEDE,%d0
    lsr.w #2,%d0
    add.w %d0,0xFFBEDE             | native power + floor(power/4)
ordinary:
    movem.l (%sp)+,%d0-%d1/%a0
    move.w 0xFFBEDE,%d2            | both displaced original instructions
    muls.w #68,%d2
    jmp 0x2ED800                    | wide velocity math above native signed-word limit

| Native attribute renderer at $8D68. Our additional row is mask=0/mode=12.
| A2 is the selected team's stats block, +$1E points at its ROM team record.
| Match that pointer, so pre-game/away/editor views do not depend on a side flag.
attribute:
    cmpi.l #12,%d4
    bne.s native
    move.w %d0,%d1                 | selected roster slot
    moveq #0,%d0
    lea 0x30E,%a0
    movea.l 0x1E(%a2),%a1
team:
    cmpa.l (%a0)+,%a1
    beq.s selected
    addq.w #1,%d0
    cmpi.w #32,%d0
    bcs.s team
selected:
    bsr.w lookup
    jmp 0x8E4C                     | native integer formatter and renderer, 0..100
native:
    cmpi.w #2,%d4                 | original branch, flags and continuation
    bls.s low_mode
    jmp 0x8D70
low_mode:
    jmp 0x8D78

    .if WITH_CRIT_OPTION
| Preserve every published entry/patch offset; direct shot calls also honor Off.
shotgate:
    tst.w 0xFFF0EC
    beq.w shot
    movem.l %d0-%d1/%a0,-(%sp)
    clr.w 0xFFF060
    clr.b 0xFFF0B0
    bra.w ordinary
    .endif
