    .ifndef WITH_REFINEMENTS
    .equ WITH_REFINEMENTS,0
    .endif
    .ifndef WITH_REPLAY_HUD
    .equ WITH_REPLAY_HUD,0
    .endif
    .ifndef WITH_FRAMED_PP_REPLAY
    .equ WITH_FRAMED_PP_REPLAY,0
    .endif
    .if WITH_FRAMED_PP_REPLAY
    .equ PANEL_BYTES,180             | rows18..27: PP/fallback plus original clock/shot
    .else
    .equ PANEL_BYTES,90
    .endif
| Automatic goal replay (jdc 2026-10-25-r25): 1.5 s after every goal the game's own
| Instant Replay ($9FD0, the pause menu's VCR) starts by itself, plays the buffer with a
| scripted C press (r4: was "hold C", a still picture), then leaves with Start, Start (options menu, return to game).
| A + C held on either pad (Xbox X + B, as Abandon Season) skips to the end at once.
| +0 tick: called every frame by crowd.s (score watch, countdown, pause request)
| +4 pause: replaces bsr $7CF8 / bra $7938 at $7948 (the main loop's pause call)
| +8 pad: replaces tst.w $D046 / bne.w $A434 at $A41E (the replay's pad read)
    .equ ARST,0xFFF738                 | $A500 idle, $A501 requested, $A502 playing, $A503..$A506 exit
                                       | (2026-10-26-r3: anything else = idle. Menu screens write text over
                                       | $FFF7xx; a stale 1..6 made the pad hook feed fake input to the
                                       | pre-game menu after the season results: "Start Game" hung)
| Maintenance HUD code uses A507 for postgame ownership; it never scripts input.
    .equ ARCNT,0xFFF73A
    .equ CNTDN,0xFFF73C
    .equ LASTG,0xFFF73E
    .equ PLAYLEN,540                   | frames of play: the whole buffer (about 520)
    .text
    .globl _start
_start:
    bra.w tick
    bra.w pause
    bra.w pad

tick:
    movem.l %d0,-(%sp)
    move.w 0xFFFFC6DA,%d0              | goals of both teams
    add.w 0xFFFFCA3E,%d0
    andi.w #0xFF,%d0
    ori.w #0xA500,%d0                  | r30: tagged; at the final horn the game zeroes this
    cmpi.w #1,0xFFFFF0DE               | Auto Replays Off: resync, discard pending countdown
    bne.s enabled
    move.w %d0,LASTG
    clr.w CNTDN
    bra.w 9f
enabled:
    cmp.w LASTG,%d0                    | RAM (LASTG 0 looked like 3 new goals: a replay after
    beq.s 3f                           | the game), so an untagged LASTG only resyncs
    cmpi.b #0xA5,LASTG
    bne.s 2f
    cmp.w LASTG,%d0
    bcs.s 2f                           | fewer (a new game): no replay
    btst #0,0xFFFFC2FA                 | shootout: no replay
    bne.s 2f
    move.w #90,CNTDN
2:  move.w %d0,LASTG
3:  tst.w CNTDN
    beq.s 9f
    subq.w #1,CNTDN
    bne.s 9f
    move.w ARST,%d0                    | a replay already requested / running?
    subi.w #0xA501,%d0
    cmpi.w #5,%d0
    bls.s 9f
    move.w #0xA501,ARST                | ask the main loop for a pause: ours
    bset #0,0xFFFFC2EC
9:  movem.l (%sp)+,%d0
    rts

pause:
    cmpi.w #0xA501,ARST
    beq.s 1f
    jsr 0x7CF8                         | an ordinary Start: the pause menu
    jmp 0x7938
1:  bsr.s auto
    jmp 0x7938
auto:                                  | the pause routine's frame, with the replay instead of the menu
    move.w #0xA502,ARST
    clr.w ARCNT
    jsr 0x10F32
    move.w %d0,-(%sp)
    move.w 0xFFFFB03E,%d0
1:  cmp.w 0xFFFFB03E,%d0
    beq.s 1b
    move.w (%sp)+,%d0
    jsr 0x1A264
    move.w 0xFFFFC2EC,-(%sp)
    .if WITH_REPLAY_HUD
    suba.w #PANEL_BYTES+4,%sp
    move.l %a0,PANEL_BYTES(%sp)
    movea.l %sp,%a0
    jsr 0x2EC004                       | save the actual lower-left panel before native clear
    movea.l PANEL_BYTES(%sp),%a0
    .endif
    jsr 0x7E0E
    jsr 0x9FD0                         | Instant Replay
    .if WITH_REPLAY_HUD
    adda.w #PANEL_BYTES+4,%sp
    clr.l 0xFFFFF670
    .endif
    bclr #1,0xFFFFC2F6                 | consume replay's redraw latch; no menu dispatcher ran here
    move.w #0xA500,ARST
    clr.w 0xFFF728                     | crowd.s TICK: its meter tiles (replaced by REPLAY) next frame
    jmp 0x7D66                         | the pause routine's own exit (pops $C2EC, rts to pause)

pad:
    move.l %d0,-(%sp)
    move.w ARST,%d0                    | scripted only while our replay runs ($A502..$A506)
    subi.w #0xA502,%d0
    cmpi.w #4,%d0
    movem.l (%sp)+,%d0                 | (movem keeps the flags)
    bls.s 1f
    .if WITH_REFINEMENTS
    | A41E is the native MENU/VCR input reader (enumerated16 UI callers),
    | separate from skating input. Preserve native non-input registers/status.
    tst.w 0xFFFFD046
    beq.s menu_single_pad
    jsr 0xA434
    bra.s menu_input_ready
menu_single_pad:
    jsr 0xA426
menu_input_ready:
    move.w %sr,-(%sp)
    jsr 0x25B038                      | explicit native caller -> contextual footer
    jsr 0x25B028                      | XboxA/nativeB aliases native Start/back
    move.w (%sp)+,%sr
    rts
    .else
    tst.w 0xFFFFD046                   | native
    beq.s 0f
    jmp 0xA434
0:  jmp 0xA426
    .endif
1:  movem.l %d4,-(%sp)
    jsr 0x11340                        | both real pads: A + C held = skip
    move.w %d3,%d4
    jsr 0x11358
    or.w %d3,%d4
    andi.w #0x60,%d4
    cmpi.w #0x60,%d4
    bne.s 2f
    cmpi.w #0xA502,ARST
    bne.s 2f
    move.w #0xA503,ARST
2:  movem.l (%sp)+,%d4
    moveq #8,%d0                       | no direction
    moveq #0,%d1
    moveq #0,%d2
    moveq #0,%d3
    cmpi.w #0xA502,ARST
    bne.s 3f
    addq.w #1,ARCNT                    | playing
    cmpi.w #PLAYLEN,ARCNT
    bcs.s 21f
    move.w #0xA503,ARST
21: jsr 0x2EC000                       | replaytitle.s: big "REPLAY" instead of the VCR box (r23)
    cmpi.w #2,ARCNT                    | 2026-10-26-r4: a NEW C press (d1 bit5, $A25E) toggles
    bne.s 22f                          | play; holding C (d3) only showed the first frame
    moveq #0x20,%d1
    moveq #0x20,%d2
    moveq #0x20,%d3
22: rts
3:  cmpi.w #0xA503,ARST                 | r25: one Start leaves at once: with $C2F6 bit0 (options menu
    bne.s 5f                           | open) the native loop exits on Start ($A358 -> $A39E); the
    bset #0,0xFFFFC2F6                 | Options / Reverse Angle box no longer flashes before the game
4:  move.w #0x80,%d1
    move.w #0x80,%d2
    move.w #0x80,%d3
5:  cmpi.w #0xA506,ARST
    bcc.s 6f
    addq.w #1,ARST
6:  rts
