diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/dump_decompress.py | 2 | ||||
-rw-r--r-- | tools/xor_compress.py | 33 |
2 files changed, 18 insertions, 17 deletions
diff --git a/tools/dump_decompress.py b/tools/dump_decompress.py index 2776c2b..0fcc897 100644 --- a/tools/dump_decompress.py +++ b/tools/dump_decompress.py @@ -10,7 +10,7 @@ bank_addr = argv[1].split(':') bank = int(bank_addr[0], 16) addr = int(bank_addr[1], 16) length = int(argv[2], 16) -offset = bank * 0x4000 + addr - (0x4000 if bank else 0) +offset = bank * 0x4000 + (addr & 0x3fff) output = [] i = offset diff --git a/tools/xor_compress.py b/tools/xor_compress.py index 30418db..6deb2aa 100644 --- a/tools/xor_compress.py +++ b/tools/xor_compress.py @@ -1,46 +1,47 @@ #!/usr/bin/env python3 -# Usage: ./xor_compress.py [source.bin] [dest.bin.xor] +# Usage: ./xor_compress.py sources.bin... > dest.bin.xor import sys -with (open(sys.argv[1], 'rb') if len(sys.argv) > 1 else sys.stdin) as f: - data = f.read() +data = bytearray() +for filename in sys.argv[1:]: + with open(filename, 'rb') as f: + data.extend(f.read()) n = len(data) -output = [] -v = 0 +output = bytearray() +v = 0x00 i = 0 while i < n: - val = data[i] + byte = data[i] i += 1 - if data[i] == v: #>=0x80 + if data[i] == v: # Alternating (>= 0x80) # Run stops at 0x81 bytes or when the values stop alternating size = 1 - while i < n and size < 0x81 and data[i] == (v if size % 2 else val): + while i < n and size < 0x81 and data[i] == (v if size % 2 else byte): size += 1 i += 1 output.append(size + 0x7e) - output.append(v ^ val) + output.append(v ^ byte) if size % 2: - v = val + v = byte else: # Sequential (< 0x80) # Run stops at 0x80 bytes or when the value two ahead is equal to v - buffer = [v ^ val] + buffer = [v ^ byte] while i < n: - v = val + v = byte if len(buffer) > 0x7f or (i + 1 < n and data[i + 1] == v): break - val = data[i] - buffer.append(v ^ val) + byte = data[i] + buffer.append(v ^ byte) i += 1 output.append(len(buffer) - 1) output.extend(buffer) -with (open(sys.argv[2], 'wb') if len(sys.argv) > 2 else sys.stdout) as f: - f.write(bytes(output)) +sys.stdout.buffer.write(output) |