Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: whitequark/libfx2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c171d9f60a42
Choose a base ref
...
head repository: whitequark/libfx2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d3e37f640d70
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on Jan 25, 2020

  1. Copy the full SHA
    818dbb5 View commit details
  2. Copy the full SHA
    d3e37f6 View commit details
Showing with 19 additions and 10 deletions.
  1. +19 −10 software/fx2/format.py
29 changes: 19 additions & 10 deletions software/fx2/format.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ def flatten_data(data):
"""
data_flat = bytearray(max([addr + len(chunk) for (addr, chunk) in data]))
for (addr, chunk) in data:
data_flat[addr:len(chunk)] = chunk
data_flat[addr:addr+len(chunk)] = chunk
return data_flat


@@ -193,6 +193,7 @@ def input_data(file_or_data, fmt="auto", offset=0):
RE_HDR = re.compile(rb":([0-9a-f]{8})", re.I)
RE_WS = re.compile(rb"\s*")

segoff = 0
bankoff = 0
resoff = 0
resbuf = []
@@ -215,34 +216,42 @@ def input_data(file_or_data, fmt="auto", offset=0):
raise ValueError("Invalid record data at offset {}".format(pos))
if sum(rechdr + recdata + [recsum]) & 0xff != 0:
raise ValueError("Invalid record checksum at offset {}".format(pos))
if rectype not in [0x00, 0x01, 0x04]:
raise ValueError("Unknown record type at offset {}".format(pos))

if rectype == 0x01:
break
elif rectype == 0x04:
res.append((offset + resoff + bankoff, resbuf))

# If we switch banks, we know there is a discontinuity, so
elif rectype in (0x02, 0x04):
res.append((offset + resoff + segoff + bankoff, resbuf))

# If we switch segments/banks, we know there is a discontinuity, so
# make no assumption about previous position or buffer contents.
resoff = 0
resbuf = []
bankoff = ((recdata[0] << 8) | recdata[1]) << 16
else:
if rectype == 0x02:
segoff = ((recdata[0] << 8) | recdata[1]) << 4
elif rectype == 0x04:
bankoff = ((recdata[0] << 8) | recdata[1]) << 16
else:
assert False

elif rectype == 0x00:
recoff = (recoffh << 8) | recoffl
if resoff + len(resbuf) == recoff:
resbuf += recdata
else:
if len(resbuf) > 0:
res.append((offset + resoff + bankoff, resbuf))
res.append((offset + resoff + segoff + bankoff, resbuf))
resoff = recoff
resbuf = recdata

else:
raise ValueError("Unknown record type {:02x} at offset {}".format(rectype, pos))

match = RE_WS.match(data, match.end(0) + len(recdatahex))
pos = match.end(0)

# Handle last record that was seen before Record Type 0x01.
if len(resbuf) > 0:
res.append((offset + resoff + bankoff, resbuf))
res.append((offset + resoff + segoff + bankoff, resbuf))

return res