#!/usr/bin/env python3 """Show both playfields at the cast frame and the frame the power ends ($27 back to FF). usage: pw2_boards.py RUNDIR [RUNDIR...]""" import sys, os for d in sys.argv[1:]: rows=[l.split() for l in open(os.path.join(d,'log.txt'))][1:] bb=open(os.path.join(d,'boards.bin'),'rb').read() act=[i for i,r in enumerate(rows) if r[2]!='FF'] if not act: print(os.path.basename(d),'never active'); continue end=min(act[-1]+40, len(rows)-1) frames=[0,end] fmt=lambda c:'.' if c==0 else ('%X'%c) print(f'== {os.path.basename(d)} power {rows[act[0]][2]} active {act[0]}-{act[-1]}') H=rows[0]; E=rows[end] if end{E[4]} P2 {H[10]}->{E[10]} stock P1 {H[5]}->{E[5]} P2 {H[11]}->{E[11]}') print(' P1@cast P2@cast P1@end P2@end') top=min([y for f in frames for k in (0,1) for y in range(22) if any(bb[f*440+k*220+y*10:f*440+k*220+y*10+10])]+[21]) for y in range(top,22): line=[] for f in frames: b=bb[f*440:(f+1)*440] line.append(''.join(fmt(c) for c in b[y*10:y*10+10])+' '+''.join(fmt(c) for c in b[220+y*10:220+y*10+10])) print(f'{y:2d} '+' '.join(line))