def split_inner(self, segment, rom_bytes, base_path, generic_out_path): if not self.rom_start == self.rom_end: if self.type == "c": asm_out_dir = Segment.create_split_dir(base_path, os.path.join("asm", "nonmatchings")) for func in self.funcs_text: func_name = segment.get_symbol(func, type="func", local_only=True).name if func_name not in self.defined_funcs: segment.create_c_asm_file(self.funcs_text, func, asm_out_dir, self, func_name) if not os.path.exists(generic_out_path) and options.get("create_new_c_files", True): segment.create_c_file(self.funcs_text, self, asm_out_dir, base_path, generic_out_path) else: asm_out_dir = Segment.create_split_dir(base_path, "asm") out_lines = self.get_standalone_asm_header() for func in self.funcs_text: out_lines.extend(self.funcs_text[func][0]) out_lines.append("") outpath = Path(os.path.join(asm_out_dir, self.name + ".s")) outpath.parent.mkdir(parents=True, exist_ok=True) if self.type == "asm" or not os.path.exists(outpath): with open(outpath, "w", newline="\n") as f: f.write("\n".join(out_lines))
def split_inner(self, segment, rom_bytes, base_path, generic_out_path): if not self.rom_start == self.rom_end: asm_out_dir = Segment.create_split_dir(base_path, "asm") rom_addr = self.rom_start insns = [insn for insn in CodeSubsegment.md.disasm(rom_bytes[self.rom_start : self.rom_end], self.vram_start)] funcs = segment.process_insns(insns, rom_addr) # TODO: someday make func a subclass of symbol and store this disasm info there too for func in funcs: segment.get_symbol(func, type="func", create=True, define=True, local_only=True) funcs = segment.determine_symbols(funcs) segment.gather_jumptable_labels(rom_bytes) funcs_text = segment.add_labels(funcs) if self.type == "c": defined_funcs = set() if segment.options.get("do_c_func_detection", True) and os.path.exists(generic_out_path): defined_funcs = CodeSubsegment.get_funcs_defined_in_c(generic_out_path) segment.mark_c_funcs_as_defined(defined_funcs) asm_out_dir = Segment.create_split_dir(base_path, os.path.join("asm", "nonmatchings")) for func in funcs_text: func_name = segment.get_symbol(func, type="func", local_only=True).name if func_name not in defined_funcs: segment.create_c_asm_file(funcs_text, func, asm_out_dir, self, func_name) if not os.path.exists(generic_out_path) and segment.options.get("create_new_c_files", True): segment.create_c_file(funcs_text, self, asm_out_dir, base_path, generic_out_path) else: out_lines = self.get_asm_header() for func in funcs_text: out_lines.extend(funcs_text[func][0]) out_lines.append("") outpath = Path(os.path.join(asm_out_dir, self.name + ".s")) outpath.parent.mkdir(parents=True, exist_ok=True) with open(outpath, "w", newline="\n") as f: f.write("\n".join(out_lines))
def split(self, rom_bytes, base_path): out_dir = Segment.create_split_dir( base_path, self.options.get("assets_dir", "bin")) bin_path = os.path.join(out_dir, self.name + ".bin") Path(bin_path).parent.mkdir(parents=True, exist_ok=True) with open(bin_path, "wb") as f: f.write(rom_bytes[self.rom_start:self.rom_end]) self.log(f"Wrote {self.name} to {bin_path}")
def split_inner(self, segment, rom_bytes, base_path, generic_out_path): if not self.type.startswith("."): asm_out_dir = Segment.create_split_dir(base_path, os.path.join("asm", "data")) outpath = Path(os.path.join(asm_out_dir, self.name + f".{self.type}.s")) outpath.parent.mkdir(parents=True, exist_ok=True) if self.file_text: with open(outpath, "w", newline="\n") as f: f.write(self.file_text)
def split(self, rom_bytes, base_path): out_dir = Segment.create_split_dir(base_path, "asm") encoding = self.options.get("header_encoding", "ASCII") header_lines = [] header_lines.append(f".section .{self.name}, \"a\"\n") header_lines.append( self.get_line("word", rom_bytes[0x00:0x04], "PI BSB Domain 1 register")) header_lines.append( self.get_line("word", rom_bytes[0x04:0x08], "Clockrate setting")) header_lines.append( self.get_line("word", rom_bytes[0x08:0x0C], "Entrypoint address")) header_lines.append( self.get_line("word", rom_bytes[0x0C:0x10], "Revision")) header_lines.append( self.get_line("word", rom_bytes[0x10:0x14], "Checksum 1")) header_lines.append( self.get_line("word", rom_bytes[0x14:0x18], "Checksum 2")) header_lines.append( self.get_line("word", rom_bytes[0x18:0x1C], "Unknown 1")) header_lines.append( self.get_line("word", rom_bytes[0x1C:0x20], "Unknown 2")) header_lines.append( ".ascii \"" + rom_bytes[0x20:0x34].decode(encoding).strip().ljust(20) + "\" /* Internal name */") header_lines.append( self.get_line("word", rom_bytes[0x34:0x38], "Unknown 3")) header_lines.append( self.get_line("word", rom_bytes[0x38:0x3C], "Cartridge")) header_lines.append( self.get_line("ascii", rom_bytes[0x3C:0x3E], "Cartridge ID")) header_lines.append( self.get_line("ascii", rom_bytes[0x3E:0x3F], "Country code")) header_lines.append( self.get_line("byte", rom_bytes[0x3F:0x40], "Version")) header_lines.append("") s_path = os.path.join(out_dir, self.name + ".s") Path(s_path).parent.mkdir(parents=True, exist_ok=True) with open(s_path, "w", newline="\n") as f: f.write("\n".join(header_lines)) self.log(f"Wrote {self.name} to {s_path}")