#!/usr/bin/env python3

instr = {
    0x61: ('ADC (dp,X)',2),
    0x63: ('ADC sr,S',2),
    0x65: ('ADC dp',2),
    0x67: ('ADC [dp]',2),
    0x69: ('ADC #const',2),
    0x6D: ('ADC addr',3),
    0x6F: ('ADC long',4),
    0x71: ('ADC (dp),Y',2),
    0x72: ('ADC (dp)',2),
    0x73: ('ADC (sr,S),Y',2),
    0x75: ('ADC dp,X',2),
    0x77: ('ADC [dp],Y',2),
    0x79: ('ADC addr,Y',3),
    0x7D: ('ADC addr,X',3),
    0x7F: ('ADC long,X',4),
    0x21: ('AND (dp,X)',2),
    0x23: ('AND sr,S',2),
    0x25: ('AND dp',2),
    0x27: ('AND [dp]',2),
    0x29: ('AND #const',2),
    0x2D: ('AND addr',3),
    0x2F: ('AND long',4),
    0x31: ('AND (dp),Y',2),
    0x32: ('AND (dp)',2),
    0x33: ('AND (sr,S),Y',2),
    0x35: ('AND dp,X',2),
    0x37: ('AND [dp],Y',2),
    0x39: ('AND addr,Y',3),
    0x3D: ('AND addr,X',3),
    0x3F: ('AND long,X',4),
    0x06: ('ASL dp',2),
    0x0A: ('ASL A',1),
    0x0E: ('ASL addr',3),
    0x16: ('ASL dp,X',2),
    0x1E: ('ASL addr,X',3),
    0x90: ('BCC nearlabel',2),
    0xB0: ('BCS nearlabel',2),
    0xF0: ('BEQ nearlabel',2),
    0x24: ('BIT dp',2),
    0x2C: ('BIT addr',3),
    0x34: ('BIT dp,X',2),
    0x3C: ('BIT addr,X',3),
    0x89: ('BIT #const',2),
    0x30: ('BMI nearlabel',2),
    0xD0: ('BNE nearlabel',2),
    0x10: ('BPL nearlabel',2),
    0x80: ('BRA nearlabel',2),
    0x00: ('BRK',1),
    0x82: ('BRL label',3),
    0x50: ('BVC nearlabel',2),
    0x70: ('BVS nearlabel',2),
    0x18: ('CLC',1),
    0xD8: ('CLD',1),
    0x58: ('CLI',1),
    0xB8: ('CLV',1),
    0xC1: ('CMP (dp,X)',2),
    0xC3: ('CMP sr,S',2),
    0xC5: ('CMP dp',2),
    0xC7: ('CMP [dp]',2),
    0xC9: ('CMP #const',2),
    0xCD: ('CMP addr',3),
    0xCF: ('CMP long',4),
    0xD1: ('CMP (dp),Y',2),
    0xD2: ('CMP (dp)',2),
    0xD3: ('CMP (sr,S),Y',2),
    0xD5: ('CMP dp,X',2),
    0xD7: ('CMP [dp],Y',2),
    0xD9: ('CMP addr,Y',3),
    0xDD: ('CMP addr,X',3),
    0xDF: ('CMP long,X',4),
    0x02: ('COP const',2),
    0xE0: ('CPX #const',2),
    0xE4: ('CPX dp',2),
    0xEC: ('CPX addr',3),
    0xC0: ('CPY #const',2),
    0xC4: ('CPY dp',2),
    0xCC: ('CPY addr',3),
    0x3A: ('DEC A',1),
    0xC6: ('DEC dp',2),
    0xCE: ('DEC addr',3),
    0xD6: ('DEC dp,X',2),
    0xDE: ('DEC addr,X',3),
    0xCA: ('DEX',1),
    0x88: ('DEY',1),
    0x41: ('EOR (dp,X)',2),
    0x43: ('EOR sr,S',2),
    0x45: ('EOR dp',2),
    0x47: ('EOR [dp]',2),
    0x49: ('EOR #const',2),
    0x4D: ('EOR addr',3),
    0x4F: ('EOR long',4),
    0x51: ('EOR (dp),Y',2),
    0x52: ('EOR (dp)',2),
    0x53: ('EOR (sr,S),Y',2),
    0x55: ('EOR dp,X',2),
    0x57: ('EOR [dp],Y',2),
    0x59: ('EOR addr,Y',3),
    0x5D: ('EOR addr,X',3),
    0x5F: ('EOR long,X',4),
    0x1A: ('INC A',1),
    0xE6: ('INC dp',2),
    0xEE: ('INC addr',3),
    0xF6: ('INC dp,X',2),
    0xFE: ('INC addr,X',3),
    0xE8: ('INX',1),
    0xC8: ('INY',1),
    0x4C: ('JMP addr',3),
    0x5C: ('JMP long',4),
    0x6C: ('JMP (addr)',3),
    0x7C: ('JMP (addr,X)',3),
    0xDC: ('JMP [addr]',3),
    0x20: ('JSR addr',3),
    0x22: ('JSR long',4),
    0xFC: ('JSR (addr,X))',3),
    0xA1: ('LDA (dp,X)',2),
    0xA3: ('LDA sr,S',2),
    0xA5: ('LDA dp',2),
    0xA7: ('LDA [dp]',2),
    0xA9: ('LDA #const',2),
    0xAD: ('LDA addr',3),
    0xAF: ('LDA long',4),
    0xB1: ('LDA (dp),Y',2),
    0xB2: ('LDA (dp)',2),
    0xB3: ('LDA (sr,S),Y',2),
    0xB5: ('LDA dp,X',2),
    0xB7: ('LDA [dp],Y',2),
    0xB9: ('LDA addr,Y',3),
    0xBD: ('LDA addr,X',3),
    0xBF: ('LDA long,X',4),
    0xA2: ('LDX #const',1),
    0xA6: ('LDX dp',2),
    0xAE: ('LDX addr',3),
    0xB6: ('LDX dp,Y',2),
    0xBE: ('LDX addr,Y',3),
    0xA0: ('LDY #const',1),
    0xA4: ('LDY dp',2),
    0xAC: ('LDY addr',3),
    0xB4: ('LDY dp,X',2),
    0xBC: ('LDY addr,X',3),
    0x46: ('LSR dp',2),
    0x4A: ('LSR A',1),
    0x4E: ('LSR addr',3),
    0x56: ('LSR dp,X',2),
    0x5E: ('LSR addr,X',3),
    0x54: ('MVN srcbk,destbk',3),
    0x44: ('MVN srcbk,destbk',3),
    0xEA: ('NOP',1),
    0x01: ('ORA (dp,X)',2),
    0x03: ('ORA sr,S',2),
    0x05: ('ORA dp',2),
    0x07: ('ORA [dp]',2),
    0x09: ('ORA #const',2),
    0x0D: ('ORA addr',3),
    0x0F: ('ORA long',4),
    0x11: ('ORA (dp),Y',2),
    0x12: ('ORA (dp)',2),
    0x13: ('ORA (sr,S),Y',2),
    0x15: ('ORA dp,X',2),
    0x17: ('ORA [dp],Y',2),
    0x19: ('ORA addr,Y',3),
    0x1D: ('ORA addr,X',3),
    0x1F: ('ORA long,X',4),
    0xF4: ('PEA addr',3),
    0xD4: ('PEI (dp)',2),
    0x62: ('PER label',3),
    0x48: ('PHA',1),
    0x8B: ('PHB',1),
    0x0B: ('PHD',1),
    0x4B: ('PHK',1),
    0x08: ('PHP',1),
    0xDA: ('PHX',1),
    0x5A: ('PHY',1),
    0x68: ('PLA',1),
    0xAB: ('PLB',1),
    0x2B: ('PLD',1),
    0x28: ('PLP',1),
    0xFA: ('PLX',1),
    0x7A: ('PLY',1),
    0xC2: ('REP #const',2),
    0x26: ('ROL dp',2),
    0x2A: ('ROL A',1),
    0x2E: ('ROL addr',3),
    0x36: ('ROL dp,X',2),
    0x3E: ('ROL addr,X',3),
    0x66: ('ROR dp',2),
    0x6A: ('ROR A',1),
    0x6E: ('ROR addr',3),
    0x76: ('ROR dp,X',2),
    0x7E: ('ROR addr,X',3),
    0x40: ('RTI',1),
    0x6B: ('RTL',1),
    0x60: ('RTS',1),
    0xE1: ('SBC (dp,X)',2),
    0xE3: ('SBC sr,S',2),
    0xE5: ('SBC dp',2),
    0xE7: ('SBC [dp]',2),
    0xE9: ('SBC #const',2),
    0xED: ('SBC addr',3),
    0xEF: ('SBC long',4),
    0xF1: ('SBC (dp),Y',2),
    0xF2: ('SBC (dp)',2),
    0xF3: ('SBC (sr,S),Y',2),
    0xF5: ('SBC dp,X',2),
    0xF7: ('SBC [dp],Y',2),
    0xF9: ('SBC addr,Y',3),
    0xFD: ('SBC addr,X',3),
    0xFF: ('SBC long,X',4),
    0x38: ('SEC',1),
    0xF8: ('SED',1),
    0x78: ('SEI',1),
    0xE2: ('SEP',2),
    0x81: ('STA (dp,X)',2),
    0x83: ('STA sr,S',2),
    0x85: ('STA dp',2),
    0x87: ('STA [dp]',2),
    0x8D: ('STA addr',3),
    0x8F: ('STA long',4),
    0x91: ('STA (dp),Y',2),
    0x92: ('STA (dp)',2),
    0x93: ('STA (sr,S),Y',2),
    0x95: ('STA dpX',2),
    0x97: ('STA [dp],Y',2),
    0x99: ('STA addr,Y',3),
    0x9D: ('STA addr,X',3),
    0x9F: ('STA long,X',4),
    0xDB: ('STP',1),
    0x86: ('STX dp',2),
    0x8E: ('STX addr',3),
    0x96: ('STX dp,Y',2),
    0x84: ('STY dp',2),
    0x8C: ('STY addr',3),
    0x94: ('STY dp,X',2),
    0x64: ('STZ dp',2),
    0x74: ('STZ dp,X',2),
    0x9C: ('STZ addr',3),
    0x9E: ('STZ addr,X',3),
    0xAA: ('TAX',1),
    0xA8: ('TAY',1),
    0x5B: ('TCD',1),
    0x1B: ('TCS',1),
    0x7B: ('TDC',1),
    0x14: ('TRB dp',2),
    0x1C: ('TRB addr',3),
    0x04: ('TSB dp',2),
    0x0C: ('TSB addr',3),
    0x3B: ('TSC',1),
    0xBA: ('TSX',1),
    0x8A: ('TXA',1),
    0x9A: ('TXS',1),
    0x9B: ('TXY',1),
    0x98: ('TYA',1),
    0xBB: ('TYX',1),
    0xCB: ('WAI',1),
    0x42: ('WDM',1),
    0xEB: ('XBA',1),
    0xFB: ('XCE',1),
}

def lorom_to_offset(addr):
    return (addr & 0x7fff) | (addr & 0x1f0000) >> 1
with open('rom.sfc','rb') as f:
    rom = bytes(f.read())
def read_u16(offset):
    return rom[offset] | rom[offset+1] << 8
for i in range(128):
    addr = 0x09_9f99 + 2*i
    offs = lorom_to_offset(addr)
    target = read_u16(offs)
    if target >= 0x8000:
        target_offs = lorom_to_offset(target | 0x09_0000)
        first_five = rom[target_offs:target_offs + 5]
        inst0, inst0_len = instr[first_five[0]]
        inst1, _         = instr[first_five[inst0_len]]
        print(f'v={i+1:02x} tgt=09:{target:04x} data=', ' '.join(f'{x:02x}' for x in first_five), f'inst={inst0} ; {inst1}')
    else:
        print(f'v={i+1:02x} tgt=09:{target:04x}')

9c221475d4552463b7ebfbc7b9b9e67eeef2950f
<mask token>


def lorom_to_offset(addr):
    return addr & 32767 | (addr & 2031616) >> 1


<mask token>

<mask token>


def lorom_to_offset(addr):
    return addr & 32767 | (addr & 2031616) >> 1


<mask token>


def read_u16(offset):
    return rom[offset] | rom[offset + 1] << 8


<mask token>

<mask token>


def lorom_to_offset(addr):
    return addr & 32767 | (addr & 2031616) >> 1


with open('rom.sfc', 'rb') as f:
    rom = bytes(f.read())


def read_u16(offset):
    return rom[offset] | rom[offset + 1] << 8


for i in range(128):
    addr = 630681 + 2 * i
    offs = lorom_to_offset(addr)
    target = read_u16(offs)
    if target >= 32768:
        target_offs = lorom_to_offset(target | 589824)
        first_five = rom[target_offs:target_offs + 5]
        inst0, inst0_len = instr[first_five[0]]
        inst1, _ = instr[first_five[inst0_len]]
        print(f'v={i + 1:02x} tgt=09:{target:04x} data=', ' '.join(
            f'{x:02x}' for x in first_five), f'inst={inst0} ; {inst1}')
    else:
        print(f'v={i + 1:02x} tgt=09:{target:04x}')

instr = {(97): ('ADC (dp,X)', 2), (99): ('ADC sr,S', 2), (101): ('ADC dp', 
    2), (103): ('ADC [dp]', 2), (105): ('ADC #const', 2), (109): (
    'ADC addr', 3), (111): ('ADC long', 4), (113): ('ADC (dp),Y', 2), (114):
    ('ADC (dp)', 2), (115): ('ADC (sr,S),Y', 2), (117): ('ADC dp,X', 2), (
    119): ('ADC [dp],Y', 2), (121): ('ADC addr,Y', 3), (125): ('ADC addr,X',
    3), (127): ('ADC long,X', 4), (33): ('AND (dp,X)', 2), (35): (
    'AND sr,S', 2), (37): ('AND dp', 2), (39): ('AND [dp]', 2), (41): (
    'AND #const', 2), (45): ('AND addr', 3), (47): ('AND long', 4), (49): (
    'AND (dp),Y', 2), (50): ('AND (dp)', 2), (51): ('AND (sr,S),Y', 2), (53
    ): ('AND dp,X', 2), (55): ('AND [dp],Y', 2), (57): ('AND addr,Y', 3), (
    61): ('AND addr,X', 3), (63): ('AND long,X', 4), (6): ('ASL dp', 2), (
    10): ('ASL A', 1), (14): ('ASL addr', 3), (22): ('ASL dp,X', 2), (30):
    ('ASL addr,X', 3), (144): ('BCC nearlabel', 2), (176): ('BCS nearlabel',
    2), (240): ('BEQ nearlabel', 2), (36): ('BIT dp', 2), (44): ('BIT addr',
    3), (52): ('BIT dp,X', 2), (60): ('BIT addr,X', 3), (137): (
    'BIT #const', 2), (48): ('BMI nearlabel', 2), (208): ('BNE nearlabel', 
    2), (16): ('BPL nearlabel', 2), (128): ('BRA nearlabel', 2), (0): (
    'BRK', 1), (130): ('BRL label', 3), (80): ('BVC nearlabel', 2), (112):
    ('BVS nearlabel', 2), (24): ('CLC', 1), (216): ('CLD', 1), (88): ('CLI',
    1), (184): ('CLV', 1), (193): ('CMP (dp,X)', 2), (195): ('CMP sr,S', 2),
    (197): ('CMP dp', 2), (199): ('CMP [dp]', 2), (201): ('CMP #const', 2),
    (205): ('CMP addr', 3), (207): ('CMP long', 4), (209): ('CMP (dp),Y', 2
    ), (210): ('CMP (dp)', 2), (211): ('CMP (sr,S),Y', 2), (213): (
    'CMP dp,X', 2), (215): ('CMP [dp],Y', 2), (217): ('CMP addr,Y', 3), (
    221): ('CMP addr,X', 3), (223): ('CMP long,X', 4), (2): ('COP const', 2
    ), (224): ('CPX #const', 2), (228): ('CPX dp', 2), (236): ('CPX addr', 
    3), (192): ('CPY #const', 2), (196): ('CPY dp', 2), (204): ('CPY addr',
    3), (58): ('DEC A', 1), (198): ('DEC dp', 2), (206): ('DEC addr', 3), (
    214): ('DEC dp,X', 2), (222): ('DEC addr,X', 3), (202): ('DEX', 1), (
    136): ('DEY', 1), (65): ('EOR (dp,X)', 2), (67): ('EOR sr,S', 2), (69):
    ('EOR dp', 2), (71): ('EOR [dp]', 2), (73): ('EOR #const', 2), (77): (
    'EOR addr', 3), (79): ('EOR long', 4), (81): ('EOR (dp),Y', 2), (82): (
    'EOR (dp)', 2), (83): ('EOR (sr,S),Y', 2), (85): ('EOR dp,X', 2), (87):
    ('EOR [dp],Y', 2), (89): ('EOR addr,Y', 3), (93): ('EOR addr,X', 3), (
    95): ('EOR long,X', 4), (26): ('INC A', 1), (230): ('INC dp', 2), (238):
    ('INC addr', 3), (246): ('INC dp,X', 2), (254): ('INC addr,X', 3), (232
    ): ('INX', 1), (200): ('INY', 1), (76): ('JMP addr', 3), (92): (
    'JMP long', 4), (108): ('JMP (addr)', 3), (124): ('JMP (addr,X)', 3), (
    220): ('JMP [addr]', 3), (32): ('JSR addr', 3), (34): ('JSR long', 4),
    (252): ('JSR (addr,X))', 3), (161): ('LDA (dp,X)', 2), (163): (
    'LDA sr,S', 2), (165): ('LDA dp', 2), (167): ('LDA [dp]', 2), (169): (
    'LDA #const', 2), (173): ('LDA addr', 3), (175): ('LDA long', 4), (177):
    ('LDA (dp),Y', 2), (178): ('LDA (dp)', 2), (179): ('LDA (sr,S),Y', 2),
    (181): ('LDA dp,X', 2), (183): ('LDA [dp],Y', 2), (185): ('LDA addr,Y',
    3), (189): ('LDA addr,X', 3), (191): ('LDA long,X', 4), (162): (
    'LDX #const', 1), (166): ('LDX dp', 2), (174): ('LDX addr', 3), (182):
    ('LDX dp,Y', 2), (190): ('LDX addr,Y', 3), (160): ('LDY #const', 1), (
    164): ('LDY dp', 2), (172): ('LDY addr', 3), (180): ('LDY dp,X', 2), (
    188): ('LDY addr,X', 3), (70): ('LSR dp', 2), (74): ('LSR A', 1), (78):
    ('LSR addr', 3), (86): ('LSR dp,X', 2), (94): ('LSR addr,X', 3), (84):
    ('MVN srcbk,destbk', 3), (68): ('MVN srcbk,destbk', 3), (234): ('NOP', 
    1), (1): ('ORA (dp,X)', 2), (3): ('ORA sr,S', 2), (5): ('ORA dp', 2), (
    7): ('ORA [dp]', 2), (9): ('ORA #const', 2), (13): ('ORA addr', 3), (15
    ): ('ORA long', 4), (17): ('ORA (dp),Y', 2), (18): ('ORA (dp)', 2), (19
    ): ('ORA (sr,S),Y', 2), (21): ('ORA dp,X', 2), (23): ('ORA [dp],Y', 2),
    (25): ('ORA addr,Y', 3), (29): ('ORA addr,X', 3), (31): ('ORA long,X', 
    4), (244): ('PEA addr', 3), (212): ('PEI (dp)', 2), (98): ('PER label',
    3), (72): ('PHA', 1), (139): ('PHB', 1), (11): ('PHD', 1), (75): ('PHK',
    1), (8): ('PHP', 1), (218): ('PHX', 1), (90): ('PHY', 1), (104): ('PLA',
    1), (171): ('PLB', 1), (43): ('PLD', 1), (40): ('PLP', 1), (250): (
    'PLX', 1), (122): ('PLY', 1), (194): ('REP #const', 2), (38): ('ROL dp',
    2), (42): ('ROL A', 1), (46): ('ROL addr', 3), (54): ('ROL dp,X', 2), (
    62): ('ROL addr,X', 3), (102): ('ROR dp', 2), (106): ('ROR A', 1), (110
    ): ('ROR addr', 3), (118): ('ROR dp,X', 2), (126): ('ROR addr,X', 3), (
    64): ('RTI', 1), (107): ('RTL', 1), (96): ('RTS', 1), (225): (
    'SBC (dp,X)', 2), (227): ('SBC sr,S', 2), (229): ('SBC dp', 2), (231):
    ('SBC [dp]', 2), (233): ('SBC #const', 2), (237): ('SBC addr', 3), (239
    ): ('SBC long', 4), (241): ('SBC (dp),Y', 2), (242): ('SBC (dp)', 2), (
    243): ('SBC (sr,S),Y', 2), (245): ('SBC dp,X', 2), (247): ('SBC [dp],Y',
    2), (249): ('SBC addr,Y', 3), (253): ('SBC addr,X', 3), (255): (
    'SBC long,X', 4), (56): ('SEC', 1), (248): ('SED', 1), (120): ('SEI', 1
    ), (226): ('SEP', 2), (129): ('STA (dp,X)', 2), (131): ('STA sr,S', 2),
    (133): ('STA dp', 2), (135): ('STA [dp]', 2), (141): ('STA addr', 3), (
    143): ('STA long', 4), (145): ('STA (dp),Y', 2), (146): ('STA (dp)', 2),
    (147): ('STA (sr,S),Y', 2), (149): ('STA dpX', 2), (151): ('STA [dp],Y',
    2), (153): ('STA addr,Y', 3), (157): ('STA addr,X', 3), (159): (
    'STA long,X', 4), (219): ('STP', 1), (134): ('STX dp', 2), (142): (
    'STX addr', 3), (150): ('STX dp,Y', 2), (132): ('STY dp', 2), (140): (
    'STY addr', 3), (148): ('STY dp,X', 2), (100): ('STZ dp', 2), (116): (
    'STZ dp,X', 2), (156): ('STZ addr', 3), (158): ('STZ addr,X', 3), (170):
    ('TAX', 1), (168): ('TAY', 1), (91): ('TCD', 1), (27): ('TCS', 1), (123
    ): ('TDC', 1), (20): ('TRB dp', 2), (28): ('TRB addr', 3), (4): (
    'TSB dp', 2), (12): ('TSB addr', 3), (59): ('TSC', 1), (186): ('TSX', 1
    ), (138): ('TXA', 1), (154): ('TXS', 1), (155): ('TXY', 1), (152): (
    'TYA', 1), (187): ('TYX', 1), (203): ('WAI', 1), (66): ('WDM', 1), (235
    ): ('XBA', 1), (251): ('XCE', 1)}


def lorom_to_offset(addr):
    return addr & 32767 | (addr & 2031616) >> 1


with open('rom.sfc', 'rb') as f:
    rom = bytes(f.read())


def read_u16(offset):
    return rom[offset] | rom[offset + 1] << 8


for i in range(128):
    addr = 630681 + 2 * i
    offs = lorom_to_offset(addr)
    target = read_u16(offs)
    if target >= 32768:
        target_offs = lorom_to_offset(target | 589824)
        first_five = rom[target_offs:target_offs + 5]
        inst0, inst0_len = instr[first_five[0]]
        inst1, _ = instr[first_five[inst0_len]]
        print(f'v={i + 1:02x} tgt=09:{target:04x} data=', ' '.join(
            f'{x:02x}' for x in first_five), f'inst={inst0} ; {inst1}')
    else:
        print(f'v={i + 1:02x} tgt=09:{target:04x}')

#!/usr/bin/env python3

instr = {
    0x61: ('ADC (dp,X)',2),
    0x63: ('ADC sr,S',2),
    0x65: ('ADC dp',2),
    0x67: ('ADC [dp]',2),
    0x69: ('ADC #const',2),
    0x6D: ('ADC addr',3),
    0x6F: ('ADC long',4),
    0x71: ('ADC (dp),Y',2),
    0x72: ('ADC (dp)',2),
    0x73: ('ADC (sr,S),Y',2),
    0x75: ('ADC dp,X',2),
    0x77: ('ADC [dp],Y',2),
    0x79: ('ADC addr,Y',3),
    0x7D: ('ADC addr,X',3),
    0x7F: ('ADC long,X',4),
    0x21: ('AND (dp,X)',2),
    0x23: ('AND sr,S',2),
    0x25: ('AND dp',2),
    0x27: ('AND [dp]',2),
    0x29: ('AND #const',2),
    0x2D: ('AND addr',3),
    0x2F: ('AND long',4),
    0x31: ('AND (dp),Y',2),
    0x32: ('AND (dp)',2),
    0x33: ('AND (sr,S),Y',2),
    0x35: ('AND dp,X',2),
    0x37: ('AND [dp],Y',2),
    0x39: ('AND addr,Y',3),
    0x3D: ('AND addr,X',3),
    0x3F: ('AND long,X',4),
    0x06: ('ASL dp',2),
    0x0A: ('ASL A',1),
    0x0E: ('ASL addr',3),
    0x16: ('ASL dp,X',2),
    0x1E: ('ASL addr,X',3),
    0x90: ('BCC nearlabel',2),
    0xB0: ('BCS nearlabel',2),
    0xF0: ('BEQ nearlabel',2),
    0x24: ('BIT dp',2),
    0x2C: ('BIT addr',3),
    0x34: ('BIT dp,X',2),
    0x3C: ('BIT addr,X',3),
    0x89: ('BIT #const',2),
    0x30: ('BMI nearlabel',2),
    0xD0: ('BNE nearlabel',2),
    0x10: ('BPL nearlabel',2),
    0x80: ('BRA nearlabel',2),
    0x00: ('BRK',1),
    0x82: ('BRL label',3),
    0x50: ('BVC nearlabel',2),
    0x70: ('BVS nearlabel',2),
    0x18: ('CLC',1),
    0xD8: ('CLD',1),
    0x58: ('CLI',1),
    0xB8: ('CLV',1),
    0xC1: ('CMP (dp,X)',2),
    0xC3: ('CMP sr,S',2),
    0xC5: ('CMP dp',2),
    0xC7: ('CMP [dp]',2),
    0xC9: ('CMP #const',2),
    0xCD: ('CMP addr',3),
    0xCF: ('CMP long',4),
    0xD1: ('CMP (dp),Y',2),
    0xD2: ('CMP (dp)',2),
    0xD3: ('CMP (sr,S),Y',2),
    0xD5: ('CMP dp,X',2),
    0xD7: ('CMP [dp],Y',2),
    0xD9: ('CMP addr,Y',3),
    0xDD: ('CMP addr,X',3),
    0xDF: ('CMP long,X',4),
    0x02: ('COP const',2),
    0xE0: ('CPX #const',2),
    0xE4: ('CPX dp',2),
    0xEC: ('CPX addr',3),
    0xC0: ('CPY #const',2),
    0xC4: ('CPY dp',2),
    0xCC: ('CPY addr',3),
    0x3A: ('DEC A',1),
    0xC6: ('DEC dp',2),
    0xCE: ('DEC addr',3),
    0xD6: ('DEC dp,X',2),
    0xDE: ('DEC addr,X',3),
    0xCA: ('DEX',1),
    0x88: ('DEY',1),
    0x41: ('EOR (dp,X)',2),
    0x43: ('EOR sr,S',2),
    0x45: ('EOR dp',2),
    0x47: ('EOR [dp]',2),
    0x49: ('EOR #const',2),
    0x4D: ('EOR addr',3),
    0x4F: ('EOR long',4),
    0x51: ('EOR (dp),Y',2),
    0x52: ('EOR (dp)',2),
    0x53: ('EOR (sr,S),Y',2),
    0x55: ('EOR dp,X',2),
    0x57: ('EOR [dp],Y',2),
    0x59: ('EOR addr,Y',3),
    0x5D: ('EOR addr,X',3),
    0x5F: ('EOR long,X',4),
    0x1A: ('INC A',1),
    0xE6: ('INC dp',2),
    0xEE: ('INC addr',3),
    0xF6: ('INC dp,X',2),
    0xFE: ('INC addr,X',3),
    0xE8: ('INX',1),
    0xC8: ('INY',1),
    0x4C: ('JMP addr',3),
    0x5C: ('JMP long',4),
    0x6C: ('JMP (addr)',3),
    0x7C: ('JMP (addr,X)',3),
    0xDC: ('JMP [addr]',3),
    0x20: ('JSR addr',3),
    0x22: ('JSR long',4),
    0xFC: ('JSR (addr,X))',3),
    0xA1: ('LDA (dp,X)',2),
    0xA3: ('LDA sr,S',2),
    0xA5: ('LDA dp',2),
    0xA7: ('LDA [dp]',2),
    0xA9: ('LDA #const',2),
    0xAD: ('LDA addr',3),
    0xAF: ('LDA long',4),
    0xB1: ('LDA (dp),Y',2),
    0xB2: ('LDA (dp)',2),
    0xB3: ('LDA (sr,S),Y',2),
    0xB5: ('LDA dp,X',2),
    0xB7: ('LDA [dp],Y',2),
    0xB9: ('LDA addr,Y',3),
    0xBD: ('LDA addr,X',3),
    0xBF: ('LDA long,X',4),
    0xA2: ('LDX #const',1),
    0xA6: ('LDX dp',2),
    0xAE: ('LDX addr',3),
    0xB6: ('LDX dp,Y',2),
    0xBE: ('LDX addr,Y',3),
    0xA0: ('LDY #const',1),
    0xA4: ('LDY dp',2),
    0xAC: ('LDY addr',3),
    0xB4: ('LDY dp,X',2),
    0xBC: ('LDY addr,X',3),
    0x46: ('LSR dp',2),
    0x4A: ('LSR A',1),
    0x4E: ('LSR addr',3),
    0x56: ('LSR dp,X',2),
    0x5E: ('LSR addr,X',3),
    0x54: ('MVN srcbk,destbk',3),
    0x44: ('MVN srcbk,destbk',3),
    0xEA: ('NOP',1),
    0x01: ('ORA (dp,X)',2),
    0x03: ('ORA sr,S',2),
    0x05: ('ORA dp',2),
    0x07: ('ORA [dp]',2),
    0x09: ('ORA #const',2),
    0x0D: ('ORA addr',3),
    0x0F: ('ORA long',4),
    0x11: ('ORA (dp),Y',2),
    0x12: ('ORA (dp)',2),
    0x13: ('ORA (sr,S),Y',2),
    0x15: ('ORA dp,X',2),
    0x17: ('ORA [dp],Y',2),
    0x19: ('ORA addr,Y',3),
    0x1D: ('ORA addr,X',3),
    0x1F: ('ORA long,X',4),
    0xF4: ('PEA addr',3),
    0xD4: ('PEI (dp)',2),
    0x62: ('PER label',3),
    0x48: ('PHA',1),
    0x8B: ('PHB',1),
    0x0B: ('PHD',1),
    0x4B: ('PHK',1),
    0x08: ('PHP',1),
    0xDA: ('PHX',1),
    0x5A: ('PHY',1),
    0x68: ('PLA',1),
    0xAB: ('PLB',1),
    0x2B: ('PLD',1),
    0x28: ('PLP',1),
    0xFA: ('PLX',1),
    0x7A: ('PLY',1),
    0xC2: ('REP #const',2),
    0x26: ('ROL dp',2),
    0x2A: ('ROL A',1),
    0x2E: ('ROL addr',3),
    0x36: ('ROL dp,X',2),
    0x3E: ('ROL addr,X',3),
    0x66: ('ROR dp',2),
    0x6A: ('ROR A',1),
    0x6E: ('ROR addr',3),
    0x76: ('ROR dp,X',2),
    0x7E: ('ROR addr,X',3),
    0x40: ('RTI',1),
    0x6B: ('RTL',1),
    0x60: ('RTS',1),
    0xE1: ('SBC (dp,X)',2),
    0xE3: ('SBC sr,S',2),
    0xE5: ('SBC dp',2),
    0xE7: ('SBC [dp]',2),
    0xE9: ('SBC #const',2),
    0xED: ('SBC addr',3),
    0xEF: ('SBC long',4),
    0xF1: ('SBC (dp),Y',2),
    0xF2: ('SBC (dp)',2),
    0xF3: ('SBC (sr,S),Y',2),
    0xF5: ('SBC dp,X',2),
    0xF7: ('SBC [dp],Y',2),
    0xF9: ('SBC addr,Y',3),
    0xFD: ('SBC addr,X',3),
    0xFF: ('SBC long,X',4),
    0x38: ('SEC',1),
    0xF8: ('SED',1),
    0x78: ('SEI',1),
    0xE2: ('SEP',2),
    0x81: ('STA (dp,X)',2),
    0x83: ('STA sr,S',2),
    0x85: ('STA dp',2),
    0x87: ('STA [dp]',2),
    0x8D: ('STA addr',3),
    0x8F: ('STA long',4),
    0x91: ('STA (dp),Y',2),
    0x92: ('STA (dp)',2),
    0x93: ('STA (sr,S),Y',2),
    0x95: ('STA dpX',2),
    0x97: ('STA [dp],Y',2),
    0x99: ('STA addr,Y',3),
    0x9D: ('STA addr,X',3),
    0x9F: ('STA long,X',4),
    0xDB: ('STP',1),
    0x86: ('STX dp',2),
    0x8E: ('STX addr',3),
    0x96: ('STX dp,Y',2),
    0x84: ('STY dp',2),
    0x8C: ('STY addr',3),
    0x94: ('STY dp,X',2),
    0x64: ('STZ dp',2),
    0x74: ('STZ dp,X',2),
    0x9C: ('STZ addr',3),
    0x9E: ('STZ addr,X',3),
    0xAA: ('TAX',1),
    0xA8: ('TAY',1),
    0x5B: ('TCD',1),
    0x1B: ('TCS',1),
    0x7B: ('TDC',1),
    0x14: ('TRB dp',2),
    0x1C: ('TRB addr',3),
    0x04: ('TSB dp',2),
    0x0C: ('TSB addr',3),
    0x3B: ('TSC',1),
    0xBA: ('TSX',1),
    0x8A: ('TXA',1),
    0x9A: ('TXS',1),
    0x9B: ('TXY',1),
    0x98: ('TYA',1),
    0xBB: ('TYX',1),
    0xCB: ('WAI',1),
    0x42: ('WDM',1),
    0xEB: ('XBA',1),
    0xFB: ('XCE',1),
}

def lorom_to_offset(addr):
    return (addr & 0x7fff) | (addr & 0x1f0000) >> 1
with open('rom.sfc','rb') as f:
    rom = bytes(f.read())
def read_u16(offset):
    return rom[offset] | rom[offset+1] << 8
for i in range(128):
    addr = 0x09_9f99 + 2*i
    offs = lorom_to_offset(addr)
    target = read_u16(offs)
    if target >= 0x8000:
        target_offs = lorom_to_offset(target | 0x09_0000)
        first_five = rom[target_offs:target_offs + 5]
        inst0, inst0_len = instr[first_five[0]]
        inst1, _         = instr[first_five[inst0_len]]
        print(f'v={i+1:02x} tgt=09:{target:04x} data=', ' '.join(f'{x:02x}' for x in first_five), f'inst={inst0} ; {inst1}')
    else:
        print(f'v={i+1:02x} tgt=09:{target:04x}')
