mirror of
https://github.com/autinerd/game_and_watch_emulator.git
synced 2025-12-16 07:16:26 +01:00
28 lines
901 B
Python
28 lines
901 B
Python
#!/usr/bin/python3
|
|
|
|
def read_hexfile(filename: str) -> dict:
|
|
f = open(filename, 'r')
|
|
lines = f.readlines()
|
|
f.close()
|
|
current_addr = 0
|
|
high_addr = 0
|
|
start_addr = 0
|
|
data = {}
|
|
for line in lines:
|
|
if line[0] != ':':
|
|
return None
|
|
size = int(line[1:3], base=16)
|
|
low_addr = int(line[3:7], base=16)
|
|
typ = int(line[7:9], base=16)
|
|
if typ == 0:
|
|
if (high_addr << 16) + low_addr > current_addr + 1:
|
|
start_addr = (high_addr << 16) + low_addr
|
|
if not start_addr in data:
|
|
data[start_addr] = bytearray.fromhex(line[9:9+(size*2)])
|
|
else:
|
|
data[start_addr] += bytearray.fromhex(line[9:9+(size*2)])
|
|
current_addr = (high_addr << 16) + low_addr + size
|
|
elif typ == 4:
|
|
high_addr = int(line[9:9+(size*2)], base=16)
|
|
return data
|