nfl-instant-replay-static-recomp

NFL Instant Replay is a static recompilation of the Philips CD-i game for Windows, featuring a Direct3D 11 video presenter and Digital Video cartridge support.

README

NFL Instant Replay: CD-i static recompilation

A native Windows build of NFL Instant Replay (Philips CD-i, Capitol Multimedia / NFL Films). You play an NFL referee: watch a real play, then make the call before the clock runs out.

The game's 68000 code is translated ahead of time into C. A runtime provides the parts of the player the code expects:

  • the CD-RTOS (OS-9) kernel, including events;
  • the CD file manager;
  • the video decoder (Direct3D 11 presenter at any window size);
  • the ADPCM audio processor;
  • the Digital Video (FMV) cartridge, which provides the MPEG-1 video (/mv) and audio (/ma) drivers. Every play, and every referee scene, is MPEG video.

The project started from the CD-i recompilation template. The runtime and tools were then taken from the Thunder in Paradise port, which added the FMV cartridge. The recompiled build is bit-identical to a pure-interpreter run (--interp): frame hashes compare equal over 14,000 fields of intro, menus and gameplay.

Installing a release

Download from the releases page:

  • NFLInstantReplay-<version>-setup.exe: a single-file installer.
    • It installs per user, without administrator rights, to %LOCALAPPDATA%\Programs\NFL Instant Replay.
    • It asks for the folder that holds your .cue/.bin.
    • It adds Start menu and (optionally) desktop shortcuts.
  • NFLInstantReplay-<version>-portable.zip: unzip anywhere and run instantreplay.exe. The first time, it asks you to select the .cue or .bin.

No game files are included: you need your own disc image of NFL Instant Replay.

The program is always portable. Everything it writes stays in saves\ next to the executable: the game's save, quicksaves, settings.ini, disc_path.txt (the disc location) and the log. Nothing goes to AppData or the registry, apart from the installer's own uninstall entry. The shaders are compiled in memory from source built into the executable, and the C runtime is linked statically, so nothing else needs installing. The shortcuts pass --portable; it is accepted but is already the default.

At start-up the program checks this repository's latest GitHub release. If it's newer than the running version, the program offers to install it. The *-portable.zip is downloaded and unpacked over the program folder, so saves\ is kept, and the game restarts. Answering No skips that version. --no-update-check turns the check off; headless and scripted runs never check.

Making a release
powershell -ExecutionPolicy Bypass -File tools\package.ps1

This builds the interpreter-only executable (-DRECOMP_INTERP_ONLY=ON, in build\release). That executable loads the program from the player's disc and runs it in the 68000 interpreter, so it contains none of the game's code. Its output is identical to the recompiled build: frame hashes match over 14,000 fields. It runs at about 136 displayed fields per second with 2 fields of run-ahead, against 166 for the recompiled build.

The script writes dist\NFLInstantReplay-<version>-portable.zip. With Inno Setup 6 (installer\instantreplay.iss), it also writes dist\NFLInstantReplay-<version>-setup.exe. The version and the update repository are set in runtime/version.h. Attach both files to a GitHub release tagged v<version>. The updater looks for the *-portable.zip asset of the latest release.

gen/, extracted/ and rom/ are made from the disc and are not in the repository. Without gen/, CMake builds the interpreter-only version automatically.

Building

Requirements: Windows 10+, Visual Studio 2022 (C compiler), CMake 3.19+ and Python 3.8+.

  1. Put the disc image in rom/: NFL Instant Replay (USA).bin and .cue, with raw 2352-byte sectors.
  2. Run build.bat. It extracts the program modules from the disc, recompiles them into gen/, builds with MSVC and copies instantreplay.exe to the project root.
  3. Run instantreplay.exe. It looks for the disc image in rom/ next to the program, or you can pass the path of the .cue or .bin.

Saves go to saves/: the game's NVRAM file (nvr_nfl), quicksaves, settings.ini and the log (recomp.log).

Controls

ActionKeyboardGamepad (XInput)
Move the pointer / choose a directionArrow keys (Shift = faster)Left stick or D-pad
Button 1 (select)Z, Space, A or EnterA
Button 2X, Ctrl or SB or Y
Fast-forward while heldTab
Quicksave / next slot / loadF2 / F3 / F4
FMV upscaler on/offF8
Aspect ratio / filterF9 / F10
FullscreenF11 or Alt+Enter
QuitEsc

Making a call. The four answers sit next to up, right, left and down arrows. Hold the direction of your answer and press button 1 while still holding it. The game reads the pointer as a joystick: it un-selects the answer as soon as the stick returns to the centre, so releasing the direction first and then pressing the button does nothing.

In the locker-room menu, the green arrow cursor follows the pointer and the label shows the choice under it (for example 1 PLAYER GAME, PLAY GAME and EXIT).

Command-line options: --fullscreen, --windowed, --size WxH, --aspect N, --filter N, --upscale 0|1, --gdi (software presenter), --runahead N (0–4 fields, default 2) and --no-smoothing.

Run-ahead and 60 fps cursor

  • Run-ahead. Every field, the real field runs first, which keeps the game and the audio exactly as normal. Then a snapshot is taken, N more fields run with the current input, that picture is shown, and the snapshot is restored. The game shows pointer movement 2 fields after the input and reacts to a button after 4, so the default of 2 fields removes the whole pointer delay and never shows a reaction early.
    • Checked: with run-ahead 2, the picture shown at field k is bit-identical to field k+2 of a normal run over 14,000 fields. The only exceptions are the 7 fields where the input itself changed, which is the prediction run-ahead makes.
    • Only the shown field is drawn. The real field and the earlier look-ahead fields run their display tables (the game counts their video interrupts) but skip the pixel work, which halves the cost.
    • If the PC can't keep up with 60 Hz, run-ahead steps down to 1 field, then off, and says so on screen. It's skipped while fast-forwarding.
  • Cursor at 60 fps. The game moves the hardware cursor irregularly, about every 1.5 fields, in steps of 12 units with gaps. The cursor is drawn every field, gliding from where it was shown to the new position over the usual update interval. Measured on the menu: an even 6 units every field, against 12, 0, 6, 0 without smoothing. --no-smoothing turns it off. The cursor is the only freely moving sprite in this game. Everything else is MPEG video (about 30 pictures per second) or pre-drawn DYUV animation frames, which have no positions to interpolate.

What this game needed beyond Thunder in Paradise

Tools

  • Initialized data in a separate module. cdi_replay has no idata of its own. At start-up it loads the data module cdi_replay_data, copies the idata block that the module's offset 0x30 points to, and applies the irefs that follow it. tools/analyze.py now reads idata and irefs from extracted/<program>_data when the program has none. That recovers the Microware a6 jump table (jsr d16(a6) into jmp abs.l stubs) and the function-pointer tables: 351 functions instead of 285.
  • tools/cdi_extract.py looks at the first 64 sectors of a file, not just the first, to decide whether it's a real-time stream. replay.rtf (630 MB) starts with a plain Form 1 data sector and was being dumped in full.
  • tools/gen.py writes a placeholder entry when no function names are known. An empty C initializer list made MSVC crash.

Kernel (runtime/os9.c)

  • F$Event: Ev$Link, Creat, Delet, Wait/WaitR, Read, Signl, Pulse, Set/SetR. The video driver's line_event is pulsed with the value 1 every field. The game waits on it (Ev$Wait 1..1) to pace its fades and animations. A wait is re-executed like F$Sleep and is satisfied by any pulse since it began.
  • I$ChgDir, F$SUser and F$Julian.
  • /cd@ (the raw CD device) opens as the device itself. SS_Enable and SS_Disable on it (the game's "ss_enable controls") succeed.

Video (runtime/video.c)

  • The first LCT line runs before the field control tables, as the display processor fetches each line's instructions during the previous line. The game leaves "both planes off" (C0001010) in LCT line 0 and turns the planes on from the FCT (C0041513, plane B DYUV), which must win. Before this change every DYUV screen (the distribution logo, the main menu, the game screens) was black.

  • Cursor blink. GC_Blnk takes the on time in d3 and the off time in d4; the cursor blinks only when both are set. The game passes on 16, off 0 (a steady cursor). Reading both times from d3 hid the menu cursor for good.

FMV cartridge (runtime/mpeg.c)

  • Stream selection. The gameplay clips multiplex two video streams (0xE0, 0xE1) and two audio streams (0xC0, 0xC1) on one channel. Only the selected stream reaches each decoder: MV_SelStrm (0x111, stream in d3), or stream 0 by default. The MPEG system header is used to choose when available, and a single-stream disc whose stream has another number is locked onto after a few packets. Feeding both streams to one decoder gave blocky garbage.
  • Audio triggers. MA_Trigger (0x126) is implemented. At the end of the audio stream the trigger signal is sent with event 0x008 (and 0x010, if masked). The game waits for it before starting the next intro clip.

Layout

PathContents
game.jsonModules to recompile: cdi_drivers (boot) at 0xF0000, cdi_replay at 0x100000
tools/Disc extractor, 68000 decoder, OS-9 module reader, analyzer, C generator
runtime/frontend.cTop-level field loop: run-ahead, quicksave slots, on-screen messages
runtime/state.cSnapshots for quicksaves and run-ahead
runtime/mpeg.c, pl_mpeg.hFMV cartridge: /mv and /ma drivers, demultiplexer, clock; MPEG-1 decoder (MIT)
runtime/os9.cOS-9 kernel, CSD (with the cartridge's devices) and events
runtime/cdfm.c, video.c, audio.cCD file manager, video decoder and compositor, audio processor
runtime/interp_only/Stand-ins for gen/ when building without the recompiled code
docs/CDI_NOTES.mdCD-i, CD-RTOS and Digital Video facts worked out so far

The disc

FileWhat it is
cdi_driversBoot program. Reads /nvr/csd; on some player models it loads a replacement CD/audio driver (.cdapdriv.605/.910/.220_37) and dspdriv. Then chains to cdi_replay.
cdi_replay, cdi_replay_dataThe game, and its initialized data
cdi_driversd, cdi_replayd, cdi_replayd_dataA debug build of the same pair, with progress messages on stdout
replay.rtfAll video, pictures and sound: MPEG on channel 15, DYUV/RL7 pictures on 16, data on 31, ADPCM on 13–15

The replacement drivers are not loaded on the emulated player and aren't needed: the runtime provides the devices itself.

Debugging

  • --trace / --trace3 log syscalls with callers, signals, disc activity, MPEG driver activity and display-table writes. Unimplemented calls are always logged to saves/recomp.log.
  • --headless --frames N --dump K [--dump-from F] runs without a window and writes every Kth field as a BMP (python tools/bmp2png.py file.bmp).
  • --script "field:key:dur,..." scripts input. Keys: 1, 2, L R U D (normal speed) and l r u d (fast). Entries may overlap. To make a call, hold the direction across the button press, for example 12700:U:40,12720:1:6.
  • --hashlog logs a checksum of every field. Comparing a recompiled run with an --interp run checks the translation.
  • CDI_BP=addr,... (with --interp) logs the registers at those addresses. CDI_PLANES=1 or 2 renders plane B or plane A alone.
  • The debug build on the disc explains a lot of what the game is doing ("Main menu init", "Here's pixmap 5", "AnswerSelected", "Input handler now ..."). To run it, point game.json at cdi_driversd and cdi_replayd with a different exe_name, run python tools/gen.py and build into a separate CMake folder (for example build\dbg). Then restore game.json and run python tools/gen.py again. Its console output goes to the log as [console] lines.

Known limitations

  • The game was tested by scripted, headless play: intro, main menu, game set-up, briefings, several plays with answers and time-outs, and Weeks 1–3 of the regular season. A complete season and the two-player mode have not been played through.
  • The debug build reports "Can't get devname from CSD for ptr device 2": the emulated player's CSD lists only one pointer device. Two-player mode probably needs a second one; it hasn't been tried.
  • The camera angle is always stream 0. If the game switches angles with MV_SelStrm during replays, the switch happens at once and may show a few damaged pictures until the next I-frame.