From 2e9caa75d77d368ead271268406a24a1052b9d85 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 3 Aug 2013 13:44:03 -0500 Subject: Move extras/ into a git submodule. --- extras | 1 + extras/dump_sections.py | 130 ------------------------------------------------ 2 files changed, 1 insertion(+), 130 deletions(-) create mode 160000 extras delete mode 100755 extras/dump_sections.py (limited to 'extras/dump_sections.py') diff --git a/extras b/extras new file mode 160000 index 000000000..13dfbba8d --- /dev/null +++ b/extras @@ -0,0 +1 @@ +Subproject commit 13dfbba8d21b843cc3bb871ed06088ca72cde8c3 diff --git a/extras/dump_sections.py b/extras/dump_sections.py deleted file mode 100755 index 91306e40f..000000000 --- a/extras/dump_sections.py +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -""" -Use this tool to dump an asm file for a new source code or disassembly project. - -usage: - - from dump_sections import dump_sections - - output = dump_sections("../../butt.gbc") - - file_handler = open("main.asm", "w") - file_handler.write(output) - file_handler.close() - -You can also use this script from the shell, where it will look for -"baserom.gbc" in the current working path or whatever file path you pass in the -first positional argument. -""" - -import os -import sys -import argparse - -def upper_hex(input): - """ - Converts the input to an uppercase hex string. - """ - if input in [0, "0"]: - return "0" - elif input <= 0xF: - return ("%.x" % (input)).upper() - else: - return ("%.2x" % (input)).upper() - -def format_bank_number(address, bank_size=0x4000): - """ - Returns a str of the hex number of the bank based on the address. - """ - return upper_hex(address / bank_size) - -def calculate_bank_quantity(path, bank_size=0x4000): - """ - Returns the number of 0x4000 banks in the file at path. - """ - return float(os.lstat(path).st_size) / bank_size - -def dump_section(bank_number, separator="\n\n"): - """ - Returns a str of a section header for the asm file. - """ - output = "SECTION \"" - if bank_number in [0, "0"]: - output += "bank0\",HOME" - else: - output += "bank" - output += bank_number - output += "\",DATA,BANK[$" - output += bank_number - output += "]" - output += separator - return output - -def dump_incbin_for_section(address, bank_size=0x4000, baserom="baserom.gbc", separator="\n\n"): - """ - Returns a str for an INCBIN line for an entire section. - """ - output = "INCBIN \"" - output += baserom - output += "\",$" - output += upper_hex(address) - output += ",$" - output += upper_hex(bank_size) - output += separator - return output - -def dump_sections(path, bank_size=0x4000, initial_bank=0, last_bank=None, separator="\n\n"): - """ - Returns a str of assembly source code. The source code delineates each - SECTION and includes bytes from the file specified by baserom. - """ - if not last_bank: - last_bank = calculate_bank_quantity(path, bank_size=bank_size) - - if last_bank < initial_bank: - raise Exception("last_bank must be greater than or equal to initial_bank") - - baserom_name = os.path.basename(path) - - output = "" - - banks = range(initial_bank, last_bank) - - for bank_number in banks: - address = bank_number * bank_size - - # get a formatted hex number of the bank based on the address - formatted_bank_number = format_bank_number(address, bank_size=bank_size) - - # SECTION - output += dump_section(formatted_bank_number, separator=separator) - - # INCBIN a range of bytes from the ROM - output += dump_incbin_for_section(address, bank_size=bank_size, baserom=baserom_name, separator=separator) - - # clean up newlines at the end of the output - if output[-2:] == "\n\n": - output = output[:-2] - output += "\n" - - return output - -if __name__ == "__main__": - parser = argparse.ArgumentParser() - parser.add_argument("rompath", nargs="?", metavar="rompath", type=str) - args = parser.parse_args() - - # default to "baserom.gbc" in the current working directory - baserom = "baserom.gbc" - - # but let the user override the default - if args.rompath: - baserom = args.rompath - - # generate some asm - output = dump_sections(baserom) - - # dump everything to stdout - sys.stdout.write(output) - -- cgit v1.2.3 From a5f1029d1cefb93ddbaad3261d27eefa3b17929f Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 3 Aug 2013 16:17:25 -0500 Subject: update extras submodule to latest master branch --- extras | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extras/dump_sections.py') diff --git a/extras b/extras index 13dfbba8d..a14c36ead 160000 --- a/extras +++ b/extras @@ -1 +1 @@ -Subproject commit 13dfbba8d21b843cc3bb871ed06088ca72cde8c3 +Subproject commit a14c36eadb75ea3d6fbc4cb3f382d7c9785d9fe9 -- cgit v1.2.3 From 2b7b3b6dc2bf8052de8747b353205963b6aa22f4 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 3 Aug 2013 16:22:08 -0500 Subject: update extras submodule on the "organizing" branch The eggified version of all of the python stuff will probably not work immediately. --- extras | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extras/dump_sections.py') diff --git a/extras b/extras index a14c36ead..a76acbadd 160000 --- a/extras +++ b/extras @@ -1 +1 @@ -Subproject commit a14c36eadb75ea3d6fbc4cb3f382d7c9785d9fe9 +Subproject commit a76acbadd2571c0d73b0797b2b68e205ab882b64 -- cgit v1.2.3 From 4619cf13def369c9612621c4689bad364b14bee3 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 3 Aug 2013 16:54:28 -0500 Subject: reset extras submodule to branch master The eggify branch was a success, so the submodule's upstream changes have been merged in. --- extras | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extras/dump_sections.py') diff --git a/extras b/extras index a76acbadd..0403a4a90 160000 --- a/extras +++ b/extras @@ -1 +1 @@ -Subproject commit a76acbadd2571c0d73b0797b2b68e205ab882b64 +Subproject commit 0403a4a90d473cc0a4bf5c53677c0a84406bc4ad -- cgit v1.2.3 From 268a2d28fdbacf48ea5e9d0cbac37ac4deee7082 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sat, 3 Aug 2013 20:13:37 -0500 Subject: probably fix the pngs target for make Update the submodule to a version where gfx.py is able to handle the current paths. Make some other fixes to Makefile to call gfx.py correctly. --- extras | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extras/dump_sections.py') diff --git a/extras b/extras index 0403a4a90..3011f9243 160000 --- a/extras +++ b/extras @@ -1 +1 @@ -Subproject commit 0403a4a90d473cc0a4bf5c53677c0a84406bc4ad +Subproject commit 3011f9243cbe4b0de7ab2392941385c705697909 -- cgit v1.2.3 From 94f5f61265b9654925b66dca7c3256668435eeea Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 27 Aug 2013 11:15:19 -0500 Subject: bump extras submodule to v1.1.0 The extras submodule is provided by pokemon-reverse-engineering-tools v1.1.0 at commit 016f0206b5029fc83a6200be29b0f980c76dfd90. --- extras | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'extras/dump_sections.py') diff --git a/extras b/extras index 3011f9243..016f0206b 160000 --- a/extras +++ b/extras @@ -1 +1 @@ -Subproject commit 3011f9243cbe4b0de7ab2392941385c705697909 +Subproject commit 016f0206b5029fc83a6200be29b0f980c76dfd90 -- cgit v1.2.3