Skip to content

Instantly share code, notes, and snippets.

@jamchamb
Last active August 31, 2021 02:35
Show Gist options
  • Save jamchamb/635b99bc561b4bc1adaf2216ef691945 to your computer and use it in GitHub Desktop.
Save jamchamb/635b99bc561b4bc1adaf2216ef691945 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
import argparse
GROUP_COUNT = 38
GROUP_ENTRY_COUNT = 96
# Debug register group names
SHORT_NAMES = ' SOPQMYDUIZCNKXcsiWAVHGmnBdkb*********'
LONG_NAMES = [
'REG',
'SREG',
'OREG',
'PREG',
'QREG',
'MREG',
'SBREG',
'DREG',
'UREG',
'IREG',
'ZREG',
'CRV',
'NS1',
'SND',
'XREG',
'CRV2',
'DEMOREG',
'TREG',
'WREG',
'AREG',
'VREG',
'HREG',
'GREG',
'MREG',
'NREG',
'BREG',
'DORO',
'KREG',
'BAK',
'PLAYERREG',
'NMREG',
'NIIREG',
'GENREG',
'MYKREG',
'CAMREG',
'SAKREG',
'TAKREG',
'PL2REG'
]
def get_offset(group, entry):
"""offset of 16-bit register entry in debug_mode"""
if group < 0 or group > GROUP_COUNT - 1:
raise ValueError('group out of bounds')
if entry < 0 or entry > GROUP_ENTRY_COUNT - 1:
raise ValueError('entry out of bounds')
offset = group * GROUP_ENTRY_COUNT + entry
offset *= 2 # multiply by size of short
offset += 0x14 # add base offset
return offset
def print_table(group=None):
if group is None:
groups = range(GROUP_COUNT)
else:
groups = [group]
# group
for x in groups:
# page
for y in range(GROUP_ENTRY_COUNT):
offset = get_offset(x, y)
print '%s(%s)\t%u\t@ offset 0x%04x' % (
SHORT_NAMES[x],
LONG_NAMES[x],
y,
offset)
# Table mapping debug_mode offset to register entry
TABLE = {}
for x in range(GROUP_COUNT):
for y in range(GROUP_ENTRY_COUNT):
key = get_offset(x, y)
value = (x, y)
TABLE[key] = value
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--find', type=str)
parser.add_argument('-r', '--range', type=str)
args = parser.parse_args()
if args.find is not None:
find = int(args.find, 0)
print 'entry for debug_mode+0x%04x:' % (find)
if find in TABLE:
result = TABLE[find]
print '%s(%s) %u' % (
SHORT_NAMES[result[0]],
LONG_NAMES[result[0]],
result[1])
else:
print 'not found'
elif args.range is not None:
if args.range in LONG_NAMES:
index = LONG_NAMES.index(args.range)
elif args.range in SHORT_NAMES:
index = SHORT_NAMES.index(args.range)
else:
print 'reg name not found'
return
print_table(index)
else:
print_table()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment