MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / init

Method init

python/examples/nsf.py:57–139  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

55 return True
56
57 def init(self):
58 try:
59 hdr = self.parent_view.read(0, 128)
60 self.version = int(hdr[5])
61 self.song_count = int(hdr[6])
62 self.starting_song = int(hdr[7])
63 self.load_address = struct.unpack("<H", hdr[8:10])[0]
64 self.init_address = struct.unpack("<H", hdr[10:12])[0]
65 self.play_address = struct.unpack("<H", hdr[12:14])[0]
66 self.song_name = int(hdr[15])
67 self.artist_name = int(hdr[46])
68 self.copyright_name = int(hdr[78])
69 self.play_speed_ntsc = struct.unpack("<H", hdr[110:112])[0]
70 self.bank_switching = hdr[112:120]
71 self.play_speed_pal = struct.unpack("<H", hdr[120:122])[0]
72 self.pal_ntsc_bits = int(hdr[122])
73 self.pal = True if (self.pal_ntsc_bits & 1) == 1 else False
74 self.ntsc = not self.pal
75 if self.pal_ntsc_bits & 2 == 2:
76 self.pal = True
77 self.ntsc = True
78 self.extra_sound_bits = int(hdr[123])
79
80 if self.bank_switching == "\0" * 8:
81 # no bank switching
82 self.load_address & 0xFFF
83 self.rom_offset = 128
84
85 else:
86 # bank switching not implemented
87 log_info("Bank switching not implemented in this loader.")
88
89 # Add mapping for RAM and hardware registers, not backed by file contents
90 self.add_auto_segment(
91 0, 0x8000, 0, 0, SegmentFlag.SegmentReadable | SegmentFlag.SegmentWritable | SegmentFlag.SegmentExecutable
92 )
93
94 # Add ROM mappings
95 self.add_auto_segment(
96 0x8000, 0x4000, self.rom_offset, 0x4000, SegmentFlag.SegmentReadable | SegmentFlag.SegmentExecutable
97 )
98
99 self.define_auto_symbol(Symbol(SymbolType.FunctionSymbol, self.play_address, "_play"))
100 self.define_auto_symbol(Symbol(SymbolType.FunctionSymbol, self.init_address, "_init"))
101 self.add_entry_point(self.init_address)
102 self.add_function(self.play_address)
103
104 # Hardware registers
105 self.define_auto_symbol(Symbol(SymbolType.DataSymbol, 0x2000, "PPUCTRL"))
106 self.define_auto_symbol(Symbol(SymbolType.DataSymbol, 0x2001, "PPUMASK"))
107 self.define_auto_symbol(Symbol(SymbolType.DataSymbol, 0x2002, "PPUSTATUS"))
108 self.define_auto_symbol(Symbol(SymbolType.DataSymbol, 0x2003, "OAMADDR"))
109 self.define_auto_symbol(Symbol(SymbolType.DataSymbol, 0x2004, "OAMDATA"))
110 self.define_auto_symbol(Symbol(SymbolType.DataSymbol, 0x2005, "PPUSCROLL"))
111 self.define_auto_symbol(Symbol(SymbolType.DataSymbol, 0x2006, "PPUADDR"))
112 self.define_auto_symbol(Symbol(SymbolType.DataSymbol, 0x2007, "PPUDATA"))
113 self.define_auto_symbol(Symbol(SymbolType.DataSymbol, 0x4000, "SQ1_VOL"))
114 self.define_auto_symbol(Symbol(SymbolType.DataSymbol, 0x4001, "SQ1_SWEEP"))

Callers

nothing calls this directly

Calls 8

log_infoFunction · 0.90
SymbolClass · 0.90
log_errorFunction · 0.90
add_auto_segmentMethod · 0.80
readMethod · 0.45
define_auto_symbolMethod · 0.45
add_entry_pointMethod · 0.45
add_functionMethod · 0.45

Tested by

no test coverage detected