mirror of
https://github.com/thornAvery/kep-hack.git
synced 2025-11-12 08:15:00 +13:00
improve text printer, including TX_RAM and TX_NUM
hg-commit-id: 6ee4e09c729c
This commit is contained in:
parent
438456a3a7
commit
fe40cc4c74
|
|
@ -226,7 +226,7 @@ def parse_text_script(text_pointer, text_id, map_id, txfar=False):
|
||||||
"read_byte": read_byte, #split this up when we make a macro for this
|
"read_byte": read_byte, #split this up when we make a macro for this
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += 4 + 1
|
offset += 4
|
||||||
elif command_byte == 0xB:
|
elif command_byte == 0xB:
|
||||||
#0B = sound_86 (Hiro obtains ITEM)[same as 0F]
|
#0B = sound_86 (Hiro obtains ITEM)[same as 0F]
|
||||||
command = {"type": command_byte, "start_address": offset, "end_address": offset}
|
command = {"type": command_byte, "start_address": offset, "end_address": offset}
|
||||||
|
|
@ -401,30 +401,82 @@ def text_pretty_printer_at(start_address, label="SomeLabel"):
|
||||||
#start with zero please
|
#start with zero please
|
||||||
byte_count = 0
|
byte_count = 0
|
||||||
|
|
||||||
|
had_text_end_byte = False
|
||||||
|
had_text_end_byte_57_58 = False
|
||||||
|
had_db_last = False
|
||||||
first_line = True
|
first_line = True
|
||||||
for this_command in commands.keys():
|
for this_command in commands.keys():
|
||||||
if not "lines" in commands[this_command].keys():
|
if not "lines" in commands[this_command].keys():
|
||||||
command = commands[this_command]
|
command = commands[this_command]
|
||||||
if not "type" in command.keys():
|
if not "type" in command.keys():
|
||||||
output = "ERROR in command: " + str(command)
|
print "ERROR in command: " + str(command)
|
||||||
continue #dunno what to do here?
|
continue #dunno what to do here?
|
||||||
|
|
||||||
if command["type"] == 0x1:
|
if command["type"] == 0x1: #TX_RAM
|
||||||
if first_line:
|
if first_line:
|
||||||
output = "\n"
|
output = "\n"
|
||||||
output += label + ": ; " + hex(start_address) + "\n"
|
output += label + ": ; " + hex(start_address)
|
||||||
first_line = False
|
first_line = False
|
||||||
p1 = command["pointer"][0]
|
p1 = command["pointer"][0]
|
||||||
p2 = command["pointer"][1]
|
p2 = command["pointer"][1]
|
||||||
|
|
||||||
#remember to account for big endian -> little endian
|
#remember to account for big endian -> little endian
|
||||||
output += spacing + "TX_RAM $" + hex(p2)[2:] + hex(p1)[2:] + "\n"
|
output += "\n" + spacing + "TX_RAM $" + hex(p2)[2:] + hex(p1)[2:]
|
||||||
|
|
||||||
byte_count += 3
|
byte_count += 3
|
||||||
|
had_db_last = False
|
||||||
|
elif command["type"] == 0x17: #TX_FAR
|
||||||
|
if first_line:
|
||||||
|
output = "\n"
|
||||||
|
output += label + ": ; " + hex(start_address)
|
||||||
|
first_line = False
|
||||||
|
#p1 = command["pointer"][0]
|
||||||
|
#p2 = command["pointer"][1]
|
||||||
|
output += "\n" + spacing + "TX_FAR _" + label
|
||||||
|
byte_count += 4 #$17, bank, address word
|
||||||
|
had_db_last = False
|
||||||
|
elif command["type"] == 0x9: #TX_RAM_HEX2DEC
|
||||||
|
if first_line:
|
||||||
|
output = "\n" + label + ": ; " + hex(start_address)
|
||||||
|
first_line = False
|
||||||
|
#address, read_byte
|
||||||
|
output += "\n" + spacing + "TX_NUM $%.2x%.2x, $%.2x" % (command["address"][1], command["address"][0], command["read_byte"])
|
||||||
|
had_db_last = False
|
||||||
|
byte_count += 4
|
||||||
|
elif command["type"] == 0x50 and not had_text_end_byte:
|
||||||
|
#had_text_end_byte helps us avoid repeating $50s
|
||||||
|
if first_line:
|
||||||
|
output = "\n" + label + ": ; " + hex(start_address)
|
||||||
|
first_line = False
|
||||||
|
if had_db_last:
|
||||||
|
output += ", $50"
|
||||||
|
else:
|
||||||
|
output += "\n" + spacing + "db $50"
|
||||||
|
byte_count += 1
|
||||||
|
had_db_last = True
|
||||||
|
elif command["type"] in [0x57, 0x58] and not had_text_end_byte_57_58:
|
||||||
|
if first_line: #shouldn't happen, really
|
||||||
|
output = "\n" + label + ": ; " + hex(start_address)
|
||||||
|
first_line = False
|
||||||
|
if had_db_last:
|
||||||
|
output += ", $%.2x" % (command["type"])
|
||||||
|
else:
|
||||||
|
output += "\n" + spacing + "db $%.2x" % (command["type"])
|
||||||
|
byte_count += 1
|
||||||
|
had_db_last = True
|
||||||
|
elif command["type"] in [0x57, 0x58] and had_text_end_byte_57_58:
|
||||||
|
pass #this is ok
|
||||||
|
elif command["type"] == 0x50 and had_text_end_byte:
|
||||||
|
pass #this is also ok
|
||||||
|
else:
|
||||||
|
print "ERROR in command: " + hex(command["type"])
|
||||||
|
had_db_last = False
|
||||||
|
|
||||||
#everything else is for $0s, really
|
#everything else is for $0s, really
|
||||||
continue
|
continue
|
||||||
lines = commands[this_command]["lines"]
|
lines = commands[this_command]["lines"]
|
||||||
|
|
||||||
|
#reset this in case we have non-$0s later
|
||||||
|
had_db_last = False
|
||||||
|
|
||||||
#add the ending byte to the last line- always seems $57
|
#add the ending byte to the last line- always seems $57
|
||||||
#this should already be in there, but it's not because of a bug in the text parser
|
#this should already be in there, but it's not because of a bug in the text parser
|
||||||
|
|
@ -434,6 +486,8 @@ def text_pretty_printer_at(start_address, label="SomeLabel"):
|
||||||
output = "\n"
|
output = "\n"
|
||||||
output += label + ": ; " + hex(start_address) + "\n"
|
output += label + ": ; " + hex(start_address) + "\n"
|
||||||
first_line = False
|
first_line = False
|
||||||
|
else:
|
||||||
|
output += "\n"
|
||||||
|
|
||||||
first = True #first byte
|
first = True #first byte
|
||||||
for line_id in lines:
|
for line_id in lines:
|
||||||
|
|
@ -447,6 +501,11 @@ def text_pretty_printer_at(start_address, label="SomeLabel"):
|
||||||
first_byte = True
|
first_byte = True
|
||||||
was_byte = False
|
was_byte = False
|
||||||
for byte in line:
|
for byte in line:
|
||||||
|
if byte == 0x50:
|
||||||
|
had_text_end_byte = True #don't repeat it
|
||||||
|
if byte in [0x58, 0x57]:
|
||||||
|
had_text_end_byte_57_58 = True
|
||||||
|
|
||||||
if byte in txt_bytes:
|
if byte in txt_bytes:
|
||||||
if not quotes_open and not first_byte: #start text
|
if not quotes_open and not first_byte: #start text
|
||||||
output += ", \""
|
output += ", \""
|
||||||
|
|
@ -488,9 +547,10 @@ def text_pretty_printer_at(start_address, label="SomeLabel"):
|
||||||
quotes_open = False
|
quotes_open = False
|
||||||
|
|
||||||
output += "\n"
|
output += "\n"
|
||||||
|
include_newline = "\n"
|
||||||
#output += "\n"
|
if output[-1] == "\n":
|
||||||
output += "; " + hex(start_address + byte_count + 1)
|
include_newline = ""
|
||||||
|
output += include_newline + "; " + hex(start_address + byte_count + 1)
|
||||||
print output
|
print output
|
||||||
return (output, byte_count)
|
return (output, byte_count)
|
||||||
|
|
||||||
|
|
@ -536,10 +596,12 @@ def find_undone_texts():
|
||||||
for result in sorted_results:
|
for result in sorted_results:
|
||||||
print str(result[1]) + " times: " + hex(result[0])
|
print str(result[1]) + " times: " + hex(result[0])
|
||||||
|
|
||||||
def scan_rom_for_tx_fars():
|
def scan_rom_for_tx_fars(printer=True):
|
||||||
"""find TX_FARs
|
"""find TX_FARs
|
||||||
search only addresses that are INCBINed
|
search only addresses that are INCBINed
|
||||||
keep only TX_FARs that are valid"""
|
keep only TX_FARs that are valid
|
||||||
|
|
||||||
|
returns a list of [TX_FAR target address, TX_FAR address]"""
|
||||||
rom = extract_maps.rom
|
rom = extract_maps.rom
|
||||||
|
|
||||||
analyze_incbins.load_asm()
|
analyze_incbins.load_asm()
|
||||||
|
|
@ -568,18 +630,25 @@ def scan_rom_for_tx_fars():
|
||||||
possible_tx_fars.append(address)
|
possible_tx_fars.append(address)
|
||||||
possible_tx_far_targets.append([address2, address])
|
possible_tx_far_targets.append([address2, address])
|
||||||
|
|
||||||
pre_handled = []
|
if printer:
|
||||||
for address_bundle in possible_tx_far_targets:
|
pre_handled = []
|
||||||
if address_bundle[0] in [0xa82f8, 0xa8315]:
|
#address_bundle is [TX_FAR target address, TX_FAR address]
|
||||||
continue #bad
|
for address_bundle in possible_tx_far_targets:
|
||||||
if address_bundle[0] in pre_handled:
|
if address_bundle[0] in [0xa82f8, 0xa8315]:
|
||||||
continue #already did this
|
continue #bad
|
||||||
|
if address_bundle[0] in pre_handled:
|
||||||
|
continue #already did this
|
||||||
|
|
||||||
|
print "-------"
|
||||||
|
print "TX_FAR is at: " + hex(address_bundle[1])
|
||||||
|
|
||||||
|
#let's try printing out the TX_FAR?
|
||||||
|
text_pretty_printer_at(address_bundle[1], "blah")
|
||||||
|
|
||||||
print "-------"
|
text_pretty_printer_at(address_bundle[0], "_blah")
|
||||||
print "TX_FAR is at: " + hex(address_bundle[1])
|
print "-------"
|
||||||
text_pretty_printer_at(address_bundle[0], "blah")
|
pre_handled.append(address_bundle[0])
|
||||||
print "-------"
|
return possible_tx_far_targets
|
||||||
pre_handled.append(address_bundle[0])
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
extract_maps.load_rom()
|
extract_maps.load_rom()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue