chore: version Zelda 1 port and engineering records
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Native edge-search oracle plus generated terrain/collision regression."""
|
||||
import json,re
|
||||
from pathlib import Path
|
||||
from PIL import Image,ImageChops
|
||||
from overworld_data import manifest,step_edge
|
||||
from nes_object_graphics import P
|
||||
from extract_graphics import ROOT
|
||||
import validate_collision_rom as leaf
|
||||
|
||||
def native_edge(tiles,cell):
|
||||
m=bytearray(65536);m[0x8000:0xc000]=P[5*16384:6*16384];m[0xc000:]=P[7*16384:8*16384];m[0x525]=cell
|
||||
sig=bytes.fromhex('ad2505850aa010a50a290f');pc=0x8000+P[5*16384:6*16384].index(sig)
|
||||
# Real code, with only the two address helpers substituted against a synthetic tilemap.
|
||||
for col in range(32):
|
||||
for row in range(22):m[0x1000+col*22+row]=tiles[row*32+col]
|
||||
a=y=0;c=z=False
|
||||
def nz(v):
|
||||
nonlocal z
|
||||
v&=255;z=v==0;return v
|
||||
def byte():
|
||||
nonlocal pc
|
||||
v=m[pc];pc+=1;return v
|
||||
def word():return byte()|byte()<<8
|
||||
for _ in range(20000):
|
||||
at=pc;op=byte()
|
||||
if op==0x60:return m[0x525]
|
||||
if op==0xad:a=nz(m[word()])
|
||||
elif op==0xa5:a=nz(m[byte()])
|
||||
elif op==0xa9:a=nz(byte())
|
||||
elif op==0xa0:y=nz(byte())
|
||||
elif op==0x85:m[byte()]=a
|
||||
elif op==0x8d:m[word()]=a
|
||||
elif op==0x29:a=nz(a&byte())
|
||||
elif op in (0xc9,0xcd):
|
||||
v=byte() if op==0xc9 else m[word()];c=a>=v;nz(a-v)
|
||||
elif op in (0xf0,0xd0,0x90):
|
||||
off=byte();yes=z if op==0xf0 else not z if op==0xd0 else not c
|
||||
if yes:pc+=off if off<128 else off-256
|
||||
elif op==0x98:a=nz(y)
|
||||
elif op==0xa8:y=nz(a)
|
||||
elif op==0x88:y=nz(y-1)
|
||||
elif op==0x18:c=False
|
||||
elif op==0x38:c=True
|
||||
elif op in (0x65,0xe9):
|
||||
v=m[byte()] if op==0x65 else byte();r=a+v+c if op==0x65 else a-v-(not c);c=r>255 if op==0x65 else r>=0;a=nz(r)
|
||||
elif op in (0xe6,0xc6):
|
||||
addr=byte();m[addr]=nz(m[addr]+(1 if op==0xe6 else -1))
|
||||
elif op==0x4a:c=bool(a&1);a=nz(a>>1)
|
||||
elif op==0x4c:pc=word()
|
||||
elif op==0xb1:
|
||||
p=byte();a=nz(m[(m[p]|m[(p+1)&255]<<8)+y])
|
||||
elif op==0x20:
|
||||
target=word()
|
||||
if m[target:target+3]==bytes.fromhex('a5eb29') or target==fetch:
|
||||
m[0]=0;m[1]=16
|
||||
elif target==add:
|
||||
value=(m[0]|m[1]<<8)+a;m[0]=value&255;m[1]=value>>8
|
||||
else:raise AssertionError(hex(target))
|
||||
else:raise AssertionError((hex(op),hex(at)))
|
||||
raise AssertionError('Native edge search did not terminate')
|
||||
# Native JSR operands from this exact verified routine, rather than recalled addresses.
|
||||
start=P[5*16384:6*16384].index(bytes.fromhex('ad2505850aa010a50a290f'));code=P[5*16384+start:5*16384+start+150]
|
||||
calls=[code[i+1]|code[i+2]<<8 for i in range(len(code)-2) if code[i]==0x20];fetch,add=calls[:2]
|
||||
|
||||
def main():
|
||||
result={'rooms':[],'native_edge_cases':0,'collision_cases':0}
|
||||
for e in manifest():
|
||||
room=json.loads((ROOT/f'extracted/overworld/{e["name"]}/room.json').read_text());tiles=[v for row in room['tilemap'][8:] for v in row]
|
||||
if e['managed']:
|
||||
source=(ROOT/f'src/stages/{e["module"]}/room.generated.pbs').read_text();assert list(map(int,re.findall(r'\d+',source.split('= [')[1].split('];')[0])))==tiles
|
||||
for col in range(32):
|
||||
addr=leaf.BASE[0xe400+col*2]|leaf.BASE[0xe401+col*2]<<8
|
||||
for row in range(22):leaf.BASE[addr+row]=tiles[row*32+col]
|
||||
leaf.DATA=dict(leaf.DATA,tiles=tiles)
|
||||
for y in range(77,206,8):
|
||||
for x in range(16,225,8):
|
||||
for d in (1,2,4,8):
|
||||
actual=leaf.rom_probe(x,y,d,room_id=e['room']);expected=leaf.port_probe(x,y,d);assert actual==expected,(e,x,y,d,actual,expected);result['collision_cases']+=1
|
||||
if e['stage']>=6:
|
||||
cells={64};cell=64
|
||||
for _ in range(80):cell=step_edge(cell);cells.add(cell)
|
||||
for origin in cells:
|
||||
cell=origin
|
||||
for _ in range(64):
|
||||
cell=step_edge(cell);col=cell%16*2;row=(cell//16*16-64)//8
|
||||
if tiles[row*32+col]<132 or cell==origin:break
|
||||
assert native_edge(tiles,origin)==cell,(e,origin);result['native_edge_cases']+=1
|
||||
result['rooms'].append(e['room'])
|
||||
(ROOT/'extracted/overworld/expansion/native-validation.json').write_text(json.dumps(result,indent=2)+'\n');print(json.dumps(result))
|
||||
if __name__=='__main__':main()
|
||||
Reference in New Issue
Block a user