22 lines
829 B
Python
22 lines
829 B
Python
#!/usr/bin/env python3
|
|
"""Code ranges executed in run CDL but not in baseline CDL (CPU addresses, $80+ mirror).
|
|
usage: pw2_cdldiff.py BASE.cdl RUN.cdl [RUN.cdl...] -> ranges of code bytes only in RUN (union of runs)"""
|
|
import sys
|
|
base=open(sys.argv[1],'rb').read()
|
|
run=bytearray(len(base))
|
|
for p in sys.argv[2:]:
|
|
for i,b in enumerate(open(p,'rb').read()[:len(base)]): run[i]|=b
|
|
def cpu(o): return 0x800000|((o//0x8000)<<16)|0x8000|(o%0x8000)
|
|
rng=[];s=None
|
|
for i in range(len(base)):
|
|
new=(run[i]&1) and not (base[i]&1)
|
|
if new and s is None: s=i
|
|
if not new and s is not None:
|
|
rng.append((s,i-1)); s=None
|
|
# merge small gaps
|
|
m=[]
|
|
for a,b in rng:
|
|
if m and a-m[-1][1]<=8: m[-1]=(m[-1][0],b)
|
|
else: m.append((a,b))
|
|
print(' '.join(f'{cpu(a)>>16:02X}:{cpu(a)&0xffff:04X}-{cpu(b)&0xffff:04X}' for a,b in m))
|