Skip to content

Commit

Permalink
Added util to print PS2's ROMDIR
Browse files Browse the repository at this point in the history
  • Loading branch information
socram8888 committed May 21, 2021
1 parent a3fadc9 commit c9bb490
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions util/print-ps2-romdir.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3

import struct
import sys

assert(len(sys.argv) == 2)

def find_romdir(f):
while True:
line = f.read(16)
if len(line) != 16:
return False

if line[0:10] == b'RESET\0\0\0\0\0':
# Unread reset entry
f.seek(-16, 1)
return True

def print_romdir(f):
address = 0xBFC00000

while True:
line = f.read(16)
if len(line) != 16:
return

entry = struct.unpack('10sHI', line)

entry_name = entry[0].rstrip(b'\0').decode('ascii')
if len(entry_name) == 0:
return
print('%10s: %08X' % (entry_name, address))

address = (address + entry[2] + 0xF) & 0xFFFFFFF0

with open(sys.argv[1], 'rb') as f:
if find_romdir(f):
print('ROMDIR found at %08X' % f.tell())
print_romdir(f)
else:
print('ROMDIR not found', file=sys.stderr)

0 comments on commit c9bb490

Please sign in to comment.