Files
siegeandClaude Opus 5.5 12ee5d17c6 re: big clear, danger, round-win mark, pause-screen moods, stock orbs/netting, preview minis
re/notes/anim_battle_extra.md + re/tools/anim_extra.py (ROM-only renders, flight path validated
frame-exact vs capture) + re/lua/anim_pause.lua. Corrects battle.md: stocks are netted at each
state 00 (81:D6AE), confirmed in Mesen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-21 17:03:39 -05:00

140 lines
6.1 KiB
Python

#!/usr/bin/env python3
"""Battle extras from ROM data alone (re/notes/anim_battle_extra.md): round-win mark, preview minis, stock orbs,
the win-mark flight path; optionally validated against captures.
usage: anim_extra.py ROM OUTDIR [--captures re/runs/anim]
Writes OUTDIR/winmark.png (spin + landing frames, P1 row 9 / P2 row 10), OUTDIR/minis.png (preview minis
10-2D, row 8), OUTDIR/orbs.png (A0 lit / A8 empty, rows 9 / 10) and prints the flight paths. With --captures
it checks the path/tiles against capture `ko` (P2 wins its first round) and the big-clear flash against `xbig`."""
import os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from gfx_decomp import decompress, lorom # noqa: E402
from gfx_snes import palette, tile, write_png # noqa: E402
FR = 0x220 + 0x200 + 0x1000
BASE_CGRAM = 0x85EC27
def s8(b):
return b - 256 if b >= 128 else b
def sprite16(obj, t, pal, img, w, ox, oy, scale):
"""Draw the 2x2 OBJ tiles t, t+1, t+16, t+17 at (ox, oy)."""
for k, (dx, dy) in enumerate(((0, 0), (8, 0), (0, 8), (8, 8))):
px = tile(obj, (t + (k & 1) + (k >> 1) * 16) * 32, 4)
for i, c in enumerate(px):
if c == 0:
continue
for sy in range(scale):
for sx in range(scale):
o = (((oy + dy + i // 8) * scale + sy) * w + (ox + dx + i % 8) * scale + sx) * 3
img[o:o + 3] = bytes(pal[c])
def flight(rom, player, wins):
"""The win mark's OAM positions/tiles, one entry per drawn step (81:FBF2). player 0/1, wins = DP+22 after INC."""
rd = lambda a, n: rom[lorom(a):lorom(a) + n]
path = rd(0x81FD75 if player == 0 else 0x81FD91, 28)
spin = [rd(0x81FCD8 + 4 * k, 1)[0] for k in range(6)] # 81:FCC2 -> 81:FCD8.. first tiles
land = [rd(0x81FCD0 + 2 * k, 2) for k in range(4)]
land = [rom[lorom(0x810000 | (p[0] | p[1] << 8))] for p in land]
x, y = 0x78 - player, 0x55 # 81:FD0D
out = [(0, x, y - 1, 0x30, 2)] # drawn with priority 2 first; OAM y = y - 1
idx = rd(0x81FC82, 3)[wins]
t = 1
for step in range(wins + 12):
x += s8(path[2 * step])
y += s8(path[2 * step + 1])
out.append((t, x, y - 1, spin[idx], 3 if step >= 3 else 2))
idx = (idx + 1) % 6
t += 4
for k in range(4):
out.append((t, x, y - 1, land[k], 3))
t += 5
return out
def main():
rom = open(sys.argv[1], 'rb').read()
out = sys.argv[2]
caps = sys.argv[sys.argv.index('--captures') + 1] if '--captures' in sys.argv else None
os.makedirs(out, exist_ok=True)
obj = decompress(rom, 0x9F8000)[0]
cg = rom[lorom(BASE_CGRAM):lorom(BASE_CGRAM) + 512]
row = lambda r: palette(cg[r * 32:r * 32 + 32])
frames = [0x30, 0x32, 0x34, 0x36, 0x38, 0x3A, 0x3C, 0x3E, 0x50]
sc = 2
w, h = len(frames) * 18 * sc, 2 * 18 * sc
img = bytearray(b'\x28' * (w * h * 3))
for pi, r in enumerate((9, 10)):
for fi, t in enumerate(frames):
sprite16(obj, t, row(r), img, w, fi * 18, pi * 18, sc)
write_png(f'{out}/winmark.png', w, h, img)
w, h = 7 * 18 * sc, 2 * 10 * sc
img = bytearray(b'\x28' * (w * h * 3))
for k in range(7):
for c in range(2):
for half in range(2):
px = tile(obj, (0x10 + 0x10 * c + 2 * k + half) * 32, 4)
for i, ci in enumerate(px):
if ci == 0:
continue
for sy in range(sc):
for sx in range(sc):
o = (((c * 10 + i // 8) * sc + sy) * w + (k * 18 + half * 8 + i % 8) * sc + sx) * 3
img[o:o + 3] = bytes(row(8)[ci])
write_png(f'{out}/minis.png', w, h, img)
w, h = 2 * 10 * sc, 2 * 10 * sc
img = bytearray(b'\x28' * (w * h * 3))
for pi, r in enumerate((9, 10)):
for k, t in enumerate((0xA0, 0xA8)):
px = tile(obj, t * 32, 4)
for i, ci in enumerate(px):
if ci == 0:
continue
for sy in range(sc):
for sx in range(sc):
o = (((pi * 10 + i // 8) * sc + sy) * w + (k * 10 + i % 8) * sc + sx) * 3
img[o:o + 3] = bytes(row(r)[ci])
write_png(f'{out}/orbs.png', w, h, img)
for player in (0, 1):
for wins in (1, 2):
f = flight(rom, player, wins)
print(f'P{player + 1} win {wins}: ' + ' '.join(f'{t}:({x},{y}) {tl:02X}' for t, x, y, tl, _ in f))
if caps:
d = open(f'{caps}/ko/frames.bin', 'rb').read()
start = 853 # first frame the mark is on screen
bad = 0
for t, x, y, tl, pr in flight(rom, 1, 1):
o = d[(start + t) * FR:(start + t) * FR + 0x220]
ex, ey, et, ea = o[88 * 4], o[88 * 4 + 1], o[88 * 4 + 2], o[88 * 4 + 3]
ok = (ex, ey, et, (ea >> 4) & 3, (ea >> 1) & 7) == (x, y, tl, pr, 2)
bad += not ok
if not ok:
print(' mismatch at +%d: model (%d,%d) %02X pri %d, capture (%d,%d) %02X attr %02X' % (t, x, y, tl, pr, ex, ey, et, ea))
print(f'win-mark flight vs ko: {"OK" if not bad else f"{bad} mismatches"}')
cgcap = d[853 * FR + 0x220:853 * FR + 0x420]
# colours the sprites use (mark 1,2,11-15 of rows 9/10; minis 3-9 of row 8; row 8 colour 2 and rows 9/10
# colours 3-10 are animated during play)
same = lambda r, cols: all(cg[r * 32 + 2 * k:r * 32 + 2 * k + 2] == cgcap[r * 32 + 2 * k:r * 32 + 2 * k + 2] for k in cols)
print('ROM palettes == capture: mark', same(9, (1, 2, 11, 12, 13, 14, 15)) and same(10, (1, 2, 11, 12, 13, 14, 15)),
'minis', same(8, range(3, 10)))
x = open(f'{caps}/xbig/frames.bin', 'rb').read()
white = []
for i in range(len(x) // FR):
c = x[i * FR + 0x220 + 0x80:i * FR + 0x220 + 0x100]
if all((c[k] | c[k + 1] << 8) & 0x7FFF == 0x7FFF for k in range(0, 0x80, 2)):
white.append(i)
print('big clear: CGRAM 64-127 all white at the end of frames', white)
if __name__ == '__main__':
main()