hg-commit-id: 261be761c726
This commit is contained in:
Bryan Bishop 2012-01-14 12:19:46 -06:00
commit 1113f19b18
28 changed files with 9200 additions and 1483 deletions

View file

@ -1,6 +1,8 @@
RED EQU 1
BLUE EQU 0
GREEN EQU 0
_JAPAN EQU 0
_RED EQU 1
_BLUE EQU 0
_GREEN EQU 0
_YELLOW EQU 0
;\1 = X
;\2 = Y

View file

@ -385,7 +385,10 @@ def find_missing_08s(all_texts):
def text_pretty_printer_at(start_address, label="SomeLabel"):
commands = parse_text_script(start_address, None, None)
needs_to_begin_with_0 = False
wanted_command = None
if needs_to_begin_with_0:
wanted_command = None
for command_id in commands:
command = commands[command_id]
@ -395,25 +398,32 @@ def text_pretty_printer_at(start_address, label="SomeLabel"):
if wanted_command == None:
raise "error: address did not start with a $0 text"
lines = commands[wanted_command]["lines"]
#start with zero please
byte_count = 0
first_line = True
for this_command in commands.keys():
lines = commands[this_command]["lines"]
#add the ending byte to the last line- always seems $57
lines[len(lines.keys())-1].append(commands[1]["type"])
if first_line:
output = "\n"
output += label + ": ; " + hex(start_address) + "\n"
first = True
first_line = False
first = True #first byte
for line_id in lines:
line = lines[line_id]
output += spacing + "db "
if first:
if first and needs_to_begin_with_0:
output += "$0, "
first = False
quotes_open = False
first_byte = True
was_byte = False
byte_count = 0
for byte in line:
if byte in txt_bytes:
if not quotes_open and not first_byte: #start text
@ -459,7 +469,7 @@ def text_pretty_printer_at(start_address, label="SomeLabel"):
#output += "\n"
print output
return output
return (output, byte_count)
def is_label_in_asm(label):
for line in analyze_incbins.asm:

View file

@ -60,9 +60,9 @@ maps = {
0x22: "Route 23",
0x23: "Route 24",
0x24: "Route 25",
0x25: "Ash's House F1",
0x26: "Ash's House F2",
0x27: "Gary's House",
0x25: "Red's House 1F",
0x26: "Red's House 2F",
0x27: "Blue's House",
0x28: "Oak's Lab",
0x29: "Viridian Poke Center",
0x2A: "Viridian Mart",
@ -267,7 +267,7 @@ maps = {
0xF2: "FREEZE",
0xF3: "FREEZE",
0xF4: "FREEZE",
0xF5: "Loreli",
0xF5: "Lorelei",
0xF6: "Bruno",
0xF7: "Agatha"
}

View file

@ -0,0 +1,38 @@
#!/usr/bin/python
#author: Bryan Bishop <kanzure@gmail.com>
#date: 2012-01-14
#throw tilesets into separate files
import extract_maps
extract_maps.load_rom()
locations = {
"Tset00_GFX": [0x64000, 0x645E0, "00"],
"Tset01_GFX": [0x64DE0, 0x65270, "01"],
"Tset08_GFX": [0x653A0, 0x65980, "08"],
"Tset13_GFX": [0x65BB0, 0x66190, "13"],
"Tset0E_GFX": [0x66610, 0x66BF0, "0e"],
"Tset10_GFX": [0x66D60, 0x67350, "10"],
"Tset17_GFX": [0x676F0, 0x67B50, "17"],
"Tset05_GFX": [0x6807F, 0x6867F, "05"],
"Tset02_GFX": [0x68DBF, 0x693BF, "02"],
"Tset09_GFX": [0x6960F, 0x69BFF, "09"],
"Tset03_GFX": [0x6A3FF, 0x6A9FF, "03"],
"Tset16_GFX": [0x6B1FF, 0x6B7FF, "16"],
"Tset0F_GFX": [0x6C000, 0x6C5C0, "0f"],
"Tset11_GFX": [0x6CCA0, 0x6D0C0, "11"],
"Tset12_GFX": [0x6D8C0, 0x6DEA0, "12"],
"Tset0D_GFX": [0x6E390, 0x6E930, "0d"],
"Tset14_GFX": [0x6ED10, 0x6F2D0, "14"],
"Tset15_GFX": [0x6F670, 0x6FB20, "15"],
"Tset0B_GFX": [0x6FD60, 0x6FEF0, "0b"],
}
for tileset_id in locations.keys():
tileset = locations[tileset_id]
print "writing ../gfx/tilesets/" + tileset[2] + ".2bpp"
fh = open("../gfx/tilesets/" + tileset[2] + ".2bpp", "w")
fh.write(extract_maps.rom[tileset[0]:tileset[1]])
fh.close()
print "Done."

View file

@ -4,6 +4,7 @@
import extract_maps
from copy import copy, deepcopy
from pretty_map_headers import random_hash, map_name_cleaner
from ctypes import c_int8
import sys
spacing = " "
@ -545,7 +546,7 @@ end_08_scripts_with = [
0xc9, #ret
###0xda, 0xe9, 0xd2, 0xc2, 0xca, 0xc3, 0x38, 0x30, 0x20, 0x28, 0x18, 0xd8, 0xd0, 0xc0, 0xc8, 0xc9
]
relative_jumps = [0x38, 0x30, 0x20, 0x28, 0x18]
relative_jumps = [0x38, 0x30, 0x20, 0x28, 0x18, 0xc3]
relative_unconditional_jumps = [0xc3, 0x18]
#TODO: replace call and a pointer with call and a label
@ -562,11 +563,16 @@ asm_commands = {
"3e6d": "Predef", #library of pre-defined asm routines
"00b5": "CopyData",
"2ff3": "GetMachineName",
"24d7": "TextScriptEnd",
}
def random_asm_label():
return ".ASM_" + random_hash()
def asm_label(address):
# why using a random value when you can use the eff. address?
return ".ASM_" + hex(address)[2:]
def output_bank_opcodes(original_offset, max_byte_count=0x4000):
#fs = current_address
#b = bank_byte
@ -576,6 +582,10 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
#ad = end_address
#a, oa = current_byte_number
last_hl_address = None #for when we're scanning the main map script
last_a_address = None
used_3d97 = False
rom = extract_maps.rom
offset = original_offset
current_byte_number = 0 #start from the beginning
@ -599,11 +609,12 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
line_label = byte_labels[offset]["name"]
byte_labels[offset]["usage"] += 1
else:
line_label = random_asm_label()
line_label = asm_label(offset)
byte_labels[offset] = {}
byte_labels[offset]["name"] = line_label
byte_labels[offset]["usage"] = 0
output += line_label.lower() + " ; " + hex(offset) + "\n"
byte_labels[offset]["definition"] = True
output += line_label.lower() + "\n" #" ; " + hex(offset) + "\n"
#find out if there's a two byte key like this
temp_maybe = maybe_byte
@ -666,18 +677,21 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
if current_byte == 0x18 or current_byte==0x20 or current_byte in relative_jumps: #jr or jr nz
#generate a label for the byte we're jumping to
target_address = offset + 2 + ord(rom[offset + 1])
target_address = offset + 2 + c_int8(ord(rom[offset + 1])).value
if target_address in byte_labels.keys():
byte_labels[target_address]["usage"] = 1 + byte_labels[target_address]["usage"]
line_label2 = byte_labels[target_address]["name"]
else:
line_label2 = random_asm_label()
line_label2 = asm_label(target_address)
byte_labels[target_address] = {}
byte_labels[target_address]["name"] = line_label2
byte_labels[target_address]["usage"] = 1
byte_labels[target_address]["definition"] = False
insertion = line_label2.lower()
include_comment = True
elif current_byte == 0x3e:
last_a_address = ord(rom[offset + 1])
opstr = opstr[:opstr.find("x")].lower() + insertion + opstr[opstr.find("x")+1:].lower()
output += spacing + opstr
@ -720,8 +734,15 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
current_byte_number += 1
offset += 1
if current_byte == 0x21:
last_hl_address = byte1 + (byte2 << 8)
if current_byte == 0xcd:
if number == 0x3d97: used_3d97 = True
#duck out if this is jp $24d7
if current_byte == 0xc3 or current_byte in relative_unconditional_jumps:
if current_byte == 0xc3:
if number == 0x3d97: used_3d97 = True
#if number == 0x24d7: #jp
if not has_outstanding_labels(byte_labels):
keep_reading = False
@ -731,8 +752,8 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
is_data = True
#stop reading at a jump, relative jump or return
if current_byte in end_08_scripts_with:
if not has_outstanding_labels(byte_labels):
if current_byte in end_08_scripts_with or (current_byte == 0x18 and target_address < offset):
if not has_outstanding_labels(byte_labels) or (current_byte == 0x18 and target_address < offset):
keep_reading = False
is_data = False #cleanup
break
@ -753,12 +774,12 @@ def output_bank_opcodes(original_offset, max_byte_count=0x4000):
address = label_line
label_line = byte_labels[label_line]
if label_line["usage"] == 0:
output = output.replace((label_line["name"] + " ; " + hex(address) + "\n").lower(), "")
output = output.replace((label_line["name"] + "\n").lower(), "")
#add the offset of the final location
output += "; " + hex(offset)
return (output, offset)
return (output, offset, last_hl_address, last_a_address, used_3d97)
def has_outstanding_labels(byte_labels):
"""
@ -766,7 +787,7 @@ def has_outstanding_labels(byte_labels):
"""
for label_line in byte_labels.keys():
real_line = byte_labels[label_line]
if real_line["usage"] == 1: return True
if real_line["definition"] == False: return True
return False
def text_asm_pretty_printer(label, address_of_08, include_08=True):

View file

@ -3,12 +3,12 @@
#date: 2012-01-07
#insert TX_FAR targets into pokered.asm
import extract_maps
from analyze_texts import analyze_texts
from analyze_texts import analyze_texts, text_pretty_printer_at
from pretty_map_headers import map_name_cleaner, make_text_label, map_constants, find_all_tx_fars, tx_far_pretty_printer, tx_far_label_maker
import pretty_map_headers
from analyze_incbins import asm, offset_to_pointer, find_incbin_to_replace_for, split_incbin_line_into_three, generate_diff_insert, load_asm, isolate_incbins, process_incbins, reset_incbins, apply_diff
import analyze_incbins
from gbz80disasm import text_asm_pretty_printer
from gbz80disasm import text_asm_pretty_printer, output_bank_opcodes
import os, sys
import subprocess
spacing = " "
@ -106,7 +106,7 @@ def all_texts_are_tx_fars(map_id):
def texts_label_pretty_printer(map_id):
"output a texts label for map if all texts are TX_FARs and in the asm already"
#extract_maps.map_headers[map_id]["texts"][text_id][0]["TX_FAR"]
if not all_texts_are_tx_fars(map_id): return None
#if not all_texts_are_tx_fars(map_id): return None
map2 = extract_maps.map_headers[map_id]
#pointer to the list of texts
@ -139,7 +139,7 @@ def texts_label_pretty_printer(map_id):
return output
def insert_texts_label(map_id):
if not all_texts_are_tx_fars(map_id): return None
#if not all_texts_are_tx_fars(map_id): return None
map2 = extract_maps.map_headers[map_id]
base_label = map_name_cleaner(map2["name"], None)[:-2]
@ -359,7 +359,8 @@ def insert_all_08s():
isolate_incbins()
process_incbins()
def insert_asm(start_address, label):
def insert_asm(start_address, label, text_asm=None, end_address=None):
if text_asm == None and end_address == None:
(text_asm, end_address) = text_asm_pretty_printer(label, start_address, include_08=False)
print "end address is: " + hex(end_address)
@ -367,7 +368,12 @@ def insert_asm(start_address, label):
line_number = find_incbin_to_replace_for(start_address)
if line_number == None:
print "skipping asm because the address is taken"
return
return False
#name check
if (label + ":") in "\n".join(analyze_incbins.asm):
print "skipping asm because the label is taken"
return False
newlines = split_incbin_line_into_three(line_number, start_address, end_address - start_address )
@ -387,7 +393,198 @@ def insert_asm(start_address, label):
diff = generate_diff_insert(line_number, newlines)
print diff
result = apply_diff(diff, try_fixing=False)
result = apply_diff(diff, try_fixing=True)
return True
def insert_text(address, label):
"inserts a text script (but not $8s)"
start_address = address
line_number = find_incbin_to_replace_for(start_address)
if line_number == None:
print "skipping text at " + hex(start_address) + " with address " + label
return
text_asm, byte_count = text_pretty_printer_at(start_address, label)
end_address = start_address + byte_count
newlines = split_incbin_line_into_three(line_number, start_address, byte_count)
newlines = newlines.split("\n")
if len(newlines) == 2: index = 0 #replace the 1st line with new content
elif len(newlines) == 3: index = 1 #replace the 2nd line with new content
newlines[index] = text_asm
if len(newlines) == 3 and newlines[2][-2:] == "$0":
#get rid of the last incbin line if it is only including 0 bytes
del newlines[2]
#note that this has to be done after adding in the new asm
newlines = "\n".join(line for line in newlines)
newlines = newlines.replace("$x", "$") #where does this keep coming from??
#Char52 doesn't work yet
newlines = newlines.replace("Char52", "$52")
diff = generate_diff_insert(line_number, newlines)
print diff
#apply_diff(diff)
#move this into another file?
def scan_for_map_scripts_pointer():
for map_id in extract_maps.map_headers.keys(): #skip id=0 (Pallet Town) because the naming conventions are wonky
map2 = extract_maps.map_headers[map_id]
if map_id in extract_maps.bad_maps or map_id in [0, 39, 37, 38]: continue #skip
script_pointer = int(map2["script_pointer"], 16)
main_asm_output, offset, last_hl_address, last_a_address, used_3d97 = output_bank_opcodes(script_pointer)
hl_pointer = "None"
first_script_text = ""
if last_hl_address != None and last_hl_address != "None" and used_3d97==True:
if last_hl_address > 0x3fff:
hl_pointer = extract_maps.calculate_pointer(last_hl_address, int(map2["bank"], 16))
else:
hl_pointer = last_hl_address
byte1 = ord(extract_maps.rom[hl_pointer])
byte2 = ord(extract_maps.rom[hl_pointer+1])
address = byte1 + (byte2 << 8)
if address > 0x3fff:
first_script_pointer = extract_maps.calculate_pointer(address, int(map2["bank"], 16))
else:
first_script_pointer = address
#for later output
first_script_text = " first_script=" + hex(first_script_pointer)
#go ahead and insert this script pointer
insert_asm(first_script_pointer, map_name_cleaner(map2["name"], None)[:-2] + "Script0")
#reset everything
#analyze_incbins.reset_incbins()
asm = None
incbin_lines = []
processed_incbins = {}
analyze_incbins.asm = None
analyze_incbins.incbin_lines = []
analyze_incbins.processed_incbins = {}
#reload
load_asm()
isolate_incbins()
process_incbins()
a_numbers = [0]
last_a_id = 0
script_pointers = [hex(first_script_pointer)]
latest_script_pointer = first_script_pointer
while last_a_id == (max(a_numbers)) or last_a_id==0:
asm_output, offset, last_hl_address2, last_a_id, byte1, byte2, address = None, None, None, None, None, None, None
asm_output, offset, last_hl_address2, last_a_id, used_3d97_2 = output_bank_opcodes(latest_script_pointer)
if last_a_id == (max(a_numbers) + 1):
a_numbers.append(last_a_id)
else:
break
byte1 = ord(extract_maps.rom[hl_pointer + (2*last_a_id)])
byte2 = ord(extract_maps.rom[hl_pointer + (2*last_a_id) + 1])
address2 = byte1 + (byte2 << 8)
if address2 > 0x3fff:
latest_script_pointer = extract_maps.calculate_pointer(address2, int(map2["bank"], 16))
else:
latest_script_pointer = address2
script_pointers.append(hex(latest_script_pointer))
#print "latest script pointer (part 1): " + hex(address2)
#print "latest script pointer: " + hex(latest_script_pointer)
#go ahead and insert the asm for this script
result = insert_asm(latest_script_pointer, map_name_cleaner(map2["name"], None)[:-2] + "Script" + str(len(script_pointers) - 1))
if result:
#reset everything
#analyze_incbins.reset_incbins()
asm = None
incbin_lines = []
processed_incbins = {}
analyze_incbins.asm = None
analyze_incbins.incbin_lines = []
analyze_incbins.processed_incbins = {}
#reload
load_asm()
isolate_incbins()
process_incbins()
print "map_id=" + str(map_id) + " scripts are: " + str(script_pointers)
if last_hl_address == None: last_hl_address = "None"
else: last_hl_address = hex(last_hl_address)
if hl_pointer != None and hl_pointer != "None": hl_pointer = hex(hl_pointer)
print "map_id=" + str(map_id) + " " + map2["name"] + " script_pointer=" + hex(script_pointer) + " script_pointers=" + hl_pointer + first_script_text
print main_asm_output
print "\n\n"
#insert asm for the main script
result = insert_asm(script_pointer, map_name_cleaner(map2["name"], None)[:-2] + "Script")
if result:
#reset everything
#analyze_incbins.reset_incbins()
asm = None
incbin_lines = []
processed_incbins = {}
analyze_incbins.asm = None
analyze_incbins.incbin_lines = []
analyze_incbins.processed_incbins = {}
#reload
load_asm()
isolate_incbins()
process_incbins()
#insert script pointer list asm if there's anything of value
if hl_pointer != None and hl_pointer != "None" and used_3d97==True:
start_address = int(hl_pointer, 16) #where to insert this list
total_size = len(a_numbers) * 2
script_label = map_name_cleaner(map2["name"], None)[:-2] + "Script"
scripts_label = script_label + "s"
script_asm = scripts_label + ": ; " + hex(start_address) + "\n"
script_asm += spacing + "dw"
first = True
for id in a_numbers:
if first:
script_asm += " "
first = False
else:
script_asm += ", "
script_asm += script_label + str(id)
script_asm += "\n" #extra newline?
result = insert_asm(start_address, scripts_label, text_asm=script_asm, end_address=start_address + total_size)
if result:
#reset everything
#analyze_incbins.reset_incbins()
asm = None
incbin_lines = []
processed_incbins = {}
analyze_incbins.asm = None
analyze_incbins.incbin_lines = []
analyze_incbins.processed_incbins = {}
#reload
load_asm()
isolate_incbins()
process_incbins()
else:
print "trouble inserting map script pointer list"
print script_asm
sys.exit(0)
if __name__ == "__main__":
#load map headers and object data
@ -403,6 +600,8 @@ if __name__ == "__main__":
#load incbins
reset_incbins()
scan_for_map_scripts_pointer()
#insert _ViridianCityText10
#insert_tx_far(1, 10)
@ -426,24 +625,10 @@ if __name__ == "__main__":
#insert_08_asm(83, 1)
#insert_all_08s()
#insert_asm(0x758df, "CinnabarGymText1")
#insert_asm(0x1da56, "NameRaterText1")
#insert_text_label_tx_far(91, 1)
#insert_text_label_tx_far(95, 1)
missed_17s = [] #[[95, 1], [95, 2], [96, 1], [97, 1], [99, 1], [99, 2], [99, 3], [100, 1], [100, 2], [100, 3], [100, 4], [100, 5], [100, 6], [124, 8], [124, 10], [124, 12], [124, 16], [124, 17], [133, 3], [139, 1], [139, 2], [139, 3], [141, 2], [141, 3], [154, 2], [154, 3], [169, 4], [171, 2], [171, 3], [174, 2], [174, 3], [176, 4], [176, 5], [182, 3], [215, 5], [91, 2], [91, 3], [124, 8], [124, 10], [124, 12], [124, 16], [124, 17], [139, 1], [139, 2], [139, 3], [141, 2], [169, 4], [171, 2], [174, 2], [176, 4], [176, 5]]
for missed_17 in missed_17s:
insert_text_label_tx_far(missed_17[0], missed_17[1])
#insert_text(0x44276, "ViridianPokeCenterText4")
#insert_texts_label(4)
#insert_all_texts_labels()
asm = None
incbin_lines = []
processed_incbins = {}
analyze_incbins.asm = None
analyze_incbins.incbin_lines = []
analyze_incbins.processed_incbins = {}
load_asm()
isolate_incbins()
process_incbins()
if len(failed_attempts) > 0:
print "-- FAILED ATTEMPTS --"
print str(failed_attempts)

26
extras/romvisualizer.py Normal file
View file

@ -0,0 +1,26 @@
#!/usr/bin/python
#author: Bryan Bishop <kanzure@gmail.com>
#date: 2012-01-13
import os
changeset_numbers = range(266, 635)
def take_snapshot_image(changeset_number):
"turn pokered.asm into an image at a certain version"
print "reverting pokered.asm to r" + str(changeset_number)
#revert the file
os.system("hg revert ../pokered.asm -r" + str(changeset_number))
print "generating the image.."
#draw the image
os.system("python romviz.py")
#move the file
os.system("mv test.png versions/" + str(changeset_number) + ".png")
for changeset_number in changeset_numbers:
take_snapshot_image(changeset_number)

BIN
gfx/redgreenversion.1bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/00.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/01.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/02.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/03.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/05.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/08.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/09.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/0b.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/0d.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/0e.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/0f.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/10.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/11.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/12.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/13.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/14.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/15.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/16.2bpp Normal file

Binary file not shown.

BIN
gfx/tilesets/17.2bpp Normal file

Binary file not shown.

File diff suppressed because it is too large Load diff