Files

5.1 KiB
Raw Permalink Blame History

TBG (J) — non-battle screens: how to reproduce them exactly

Key result [C]: the screens can be reproduced by running the game's own scene code. re/tools/scr_snes.py (a small SNES model: 65816 CPU + PPU/DMA/HDMA/NMI/joypad registers) runs the ROM from reset with no captured state, and re/tools/scr_ppu.py (scanline PPU: modes 0/1/7, windows, colour math, brightness, HDMA per line) renders its frames. re/tools/scr_compare.py checks them against Mesen screenshots (re/runs/scr/main, a boot → title → character select → Battle World → battle capture; the capture is used only to align frame numbers, everything is computed from the ROM):

Mesen frame screen pixels differing
200 BPS logo (mode 7) 0.00 %
400 BPS logo + emblems (mode 7) 0.00 %
1000 title book (mode 7, tilted) 0.00 %
1700 book closing → character select (mode 1) 6.5 % (animation phase, input timing)
2600 Battle World map (mode 1) 2.1 % (palette-cycle phase)

(scr_compare.py rom/tbg_jp.sfc re/runs/scr/main --frames 200,400,1000 and, with --plan "300:start,500:start,700:start,1100:start,1300:start,2000:a,2200:a", --frames 1700,2600; side-by-side images in --out.) The remaining few percent are timing (our scripted presses vs the capture's) and the colour-cycle phase, not missing graphics.

Screen timeline (scr_timeline.py re/runs/scr/main, frames at 60 Hz)

frames mode / layers NMI handler what
1-129 blank 7E:6D09 boot, driver upload
130-503 mode 7, OBJ 86:D796 BPS logo: the lion emblem rotates/zooms in (mode 7 matrix per frame), the three orb emblems are sprites; fade in 130-273
505-840 mode 1, BG3 83:A5EB copyright text (asset 90:E8D0), fade in/out
933-1521 mode 7, OBJ 83:F2E2 title: the TETRIS book (assets 93:D06F, 85:B9CC, 9A:E125; palette 85:F627 + CGRAM shadow 7E:2C11 re-uploaded every frame = colour cycling) tilts in, then the menu (OBJ text, cursor)
1523-2280 mode 1, BG1-3 + OBJ, BG1 scrolls 83:99B3 book opening → character select (BG1 alternates between two maps every 4 frames during the page turn, f1753-1781; portraits per graphics_cutins.md)
2282-3305 mode 1, BG1-3 + OBJ, colour math on sub 84:A23D Battle World map (map 9B:8000, 87:D90F, …; animated icons) and the VS sequence
3306-3761 mode 1 81:BCCB stage intro (stage background fades in, BG1 frame), then battle

Boss intros (84:8128 Dragon, 84:81AC Queen), continue (84:FBxx), results, ending (83:B747) and the options screen run the same way (same scene engine, other entry points; not yet captured/compared).

Do not re-author these screens: run the game's scene code, exactly like the sound engine runs bank $88.

  1. CPU: reuse src/audio/cpu65816.* (already a full 65816 interpreter in C++) — add what scr_snes.py adds on top of snd_cpu: RTI, WAI, XCE, PER, PEI, BRK/COP, decimal mode, cycle counting per scanline.
  2. Hardware model (port scr_snes.py, ~700 lines Python): WRAM 128 KiB, PPU registers with write-twice latches, VRAM/CGRAM/OAM ports and increment modes, multiply/divide registers, NMI at line 225, joypad auto-read (feed our menu input as the SNES pad), general DMA, HDMA tables (applied per scanline).
  3. Renderer (port scr_ppu.py, ~340 lines): BG modes 0/1/7 (mode 7 per scanline matrix + HDMA), OBJ with sizes/priorities, windows, colour math (add/sub/half, fixed colour, sub-screen), brightness — render to a 256×224 RGBA texture each frame, draw it at 2× (512×448) centred on the 960×560 canvas (x 224, y 56), with the active stage/title backdrop or a dark frame filling the margins.
  4. Driving it: start the ROM at reset and let it run to the wanted scene (logo, title) — or jump in at a scene's entry (title 83:ECE5, char select 83:8000, map 84:8000, ending 83:B747) after the battle-setup style init, with WRAM variables set from our game state ($E0/$E1 characters, $E2 beaten mask, $DE mode, $D2 difficulty). Read back the result (e.g. the chosen character $E0) when the scene returns. Run 1 scene frame per 60 Hz tick; the cost is small (Python does ~1000 frames in 5 s; C++ ≈100× faster).
  5. Hybrid with our own menus: keep our VS setup / controls / options screens (they have no original), and use the ROM scenes for the boot logo, title (attract), the intro/book, character select (1-2 players), Battle World map, boss intros, continue and ending. For 3-4 player character select, draw our own UI over the ROM's select backdrop.

Open questions

  • Exact entry conditions for jumping straight into each scene (which init routines must run first, e.g. the scene loader 80:8047 sequence) — or simply run from reset and feed scripted presses (as scr_compare does).
  • Boss intros, continue, ending, options: not yet compared (expected to work the same way).
  • Sound: the scene code also issues sound commands to 88:8000 — route them to tbg_audio instead of the APU ports so music/SFX stay in sync with the ROM scenes.