From 7ac26e0546b1611beeb24048e19074019eee0195 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 27 Aug 2013 10:09:58 -0500 Subject: remove unused imports from sym.py --- pokemontools/sym.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pokemontools/sym.py b/pokemontools/sym.py index f78b9af..ee6ecae 100644 --- a/pokemontools/sym.py +++ b/pokemontools/sym.py @@ -2,10 +2,6 @@ import json -# from crystal import load_rom -# from gbz80disasm import load_labels - - def make_sym_from_json(filename = '../pokecrystal.sym', j = 'labels.json'): # todo: delete and remake labels.json at runtime with open(filename, 'w') as sym: -- cgit v1.2.3 From 22d5cc55e29cea8a188a175f1d2a1064786651ca Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 27 Aug 2013 10:10:53 -0500 Subject: rewrite the encoding line in sym.py --- pokemontools/sym.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pokemontools/sym.py b/pokemontools/sym.py index ee6ecae..3878faa 100644 --- a/pokemontools/sym.py +++ b/pokemontools/sym.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# coding: utf-8 import json -- cgit v1.2.3 From c8c8b32efb807250efffbf573c79a2802858578c Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 27 Aug 2013 10:23:19 -0500 Subject: refactor symfile parser Also add labels.json generator. see also: ff1536ddf9c70b9b98c5332c193ad099a103162d --- pokemontools/sym.py | 110 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 32 deletions(-) diff --git a/pokemontools/sym.py b/pokemontools/sym.py index 3878faa..ebd8532 100644 --- a/pokemontools/sym.py +++ b/pokemontools/sym.py @@ -1,50 +1,96 @@ # coding: utf-8 +import os +import sys import json def make_sym_from_json(filename = '../pokecrystal.sym', j = 'labels.json'): - # todo: delete and remake labels.json at runtime + output = '' + labels = json.load(open(j)) + for label in labels: + output += '{0:x}:{1:x} {2}\n'.format(label['bank'], label['address'], label['label']) with open(filename, 'w') as sym: - for label in json.load(open(j)): - sym.write('{0:x}:{1:x} {2}\n'.format(label['bank'], label['address']%0x4000 + (0x4000 if label['bank'] else 0), label['label'])) + sym.write(output) + +def make_json_from_mapfile(filename='labels.json', mapfile='../pokecrystal.map'): + output = [] + labels = filter_wram_addresses(read_mapfile(mapfile)) + with open(filename, 'w') as out: + out.write(json.dumps(labels)) + +def read_mapfile(filename='../pokecrystal.map'): + """ + Scrape label addresses from an rgbds mapfile. + """ + + labels = [] + + with open(filename, 'r') as mapfile: + lines = mapfile.readlines() + + for line in lines: + # bank # + if 'Bank #' in line: + cur_bank = int(line.lstrip('Bank #').strip(';\n').strip(' (HOME)')) + + # label definition + elif '=' in line: + address, label = line.split('=') + address = int(address.lstrip().replace('$', '0x'), 16) + label = label.strip() + # rgbds doesn't support ram banks yet + bank = cur_bank + offset = address + + ranges = [ + 0x8000 <= address < 0xa000, + 0xa000 <= address < 0xc000, + 0xc000 <= address < 0xd000, + 0xd000 <= address < 0xe000, + ] + + if any(ranges): + bank = 0 + else: + offset += (bank * 0x4000 - 0x4000) if bank > 0 else 0 + + labels += [{ + 'label': label, + 'bank': bank, + 'address': offset, + 'offset': offset, + 'local_address': address, + }] + + return labels + +def filter_wram_addresses(labels): + filtered_labels = [] + for label in labels: + if label['local_address'] < 0x8000: + filtered_labels += [label] + return filtered_labels def make_sym_from_mapfile(filename = '../pokecrystal.sym', mapfile = '../mapfile.txt'): # todo: sort label definitions by address output = '' - # get label definitions - with open(mapfile,'r') as map: - lines = map.readlines() - for line in lines: - # bank # - if 'Bank #' in line: - cur_bank = int(line.lstrip('Bank #').strip(':\n').strip(' (HOME)')) - - # label definition - elif '=' in line: - thing = line.split('=') - spacing = ' ' * 11 # arbitrary - addr = int(thing[0].lstrip(spacing)[1:5],16) - - # rgbds doesn't support wram banks yet, - # so this hack is applied instead - if addr > 0xbfff: # 0xc000+ (wram only) - cur_bank = 0 - if addr > 0xcfff: # 0xd000+ (wram only) - cur_bank = 1 - - # convert to sym format (bank:addr label) - label = thing[1].strip('\n') - output += hex(cur_bank)[2:] + ':' + hex(addr)[2:] + ' ' + label + '\n' + labels = read_mapfile() + + # convert to sym format (bank:addr label) + for label in labels: + output += '%.2x:%.4x %s\n' % (label['bank'], label['address'], label['label']) # dump contents to symfile with open(filename, 'w') as sym: sym.write(output) - if __name__ == "__main__": - # default behavior: generate sym file from rgbds mapfile - try: make_sym_from_mapfile() - # if no mapfile exists, generate from labels.json - except: make_sym_from_json() + #if os.path.exists('../pokecrystal.sym'): + # sys.exit() + #elif os.path.exists('../pokecrystal.map'): + # make_sym_from_mapfile() + #elif os.path.exists('labels.json'): + # make_sym_from_json() + make_json_from_mapfile() -- cgit v1.2.3 From 94dd0f6d63d1e140962f2d5784fc448b09a17323 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 27 Aug 2013 10:29:25 -0500 Subject: script command scripttalkerafter is an ender Also, reformat the list of enders for readability and to work better with diff tools in the future. see also: 92152c98fc0cd319f5fff1b0e7ee76dc2c0520d2 --- pokemontools/pksv.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/pokemontools/pksv.py b/pokemontools/pksv.py index 2f02ec0..ef3f425 100644 --- a/pokemontools/pksv.py +++ b/pokemontools/pksv.py @@ -293,13 +293,23 @@ pksv_crystal = { } #these cause the script to end; used in create_command_classes -pksv_crystal_more_enders = [0x03, 0x04, 0x05, 0x0C, 0x51, 0x52, - 0x53, 0x8D, 0x8F, 0x90, 0x91, 0x92, - 0x9B, - 0xB2, #maybe? - 0xCC, #maybe? - 0x9A, # describedecoration - ] +pksv_crystal_more_enders = [ + 0x03, # 2jump + 0x04, + 0x05, + 0x0C, + 0x51, + 0x52, + 0x53, + 0x65, + 0x8D, # priorityjump + 0x8F, # ptpriorityjump + 0x90, # return + 0x91, # end + 0x92, # reloadandreturn + 0x9A, # describedecoration + 0x9B, # fruittree +] # these have no pksv names as of pksv 2.1.1 pksv_crystal_unknowns = [ -- cgit v1.2.3 From 993162a6d7bc0f589db1552311c04a8ee981ad78 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 27 Aug 2013 10:41:21 -0500 Subject: manually apply crystal.py changes from upstream --- pokemontools/crystal.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pokemontools/crystal.py b/pokemontools/crystal.py index dcd95d9..2630991 100644 --- a/pokemontools/crystal.py +++ b/pokemontools/crystal.py @@ -1993,7 +1993,7 @@ movement_command_bases = { 0x45: "accelerate_last", 0x46: ["step_sleep", ["duration", DecimalParam]], 0x47: "step_end", - 0x49: "hide_person", + 0x49: "remove_person", # do these next two have any params ?? 0x4C: "teleport_from", @@ -2811,7 +2811,7 @@ pksv_crystal_more = { 0x8F: ["ptpriorityjump", ["pointer", ScriptPointerLabelParam]], 0x90: ["return"], 0x91: ["end"], - 0x92: ["reloadandreturn"], + 0x92: ["reloadandreturn", ["which_method", SingleByteParam]], 0x93: ["resetfuncs"], 0x94: ["pokemart", ["dialog_id", SingleByteParam], ["mart_id", MultiByteParam]], # maybe it should be a pokemark constant id/label? 0x95: ["elevator", ["floor_list_pointer", PointerLabelParam]], @@ -7360,13 +7360,17 @@ def write_all_labels(all_labels, filename="labels.json"): from wram import wram_labels def get_ram_label(address): - """returns a label assigned to a particular ram address""" + """ + returns a label assigned to a particular ram address + """ if address in wram_labels.keys(): return wram_labels[address][-1] return None def get_label_for(address): - """returns a label assigned to a particular rom address""" + """ + returns a label assigned to a particular address + """ global all_labels if address == None: -- cgit v1.2.3 From f0ef450967fa00377fb8d39211741e7d7a596396 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 27 Aug 2013 10:43:27 -0500 Subject: =?UTF-8?q?jp=20char=20=E3=82=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit see also: d4e6ccca3b8cf1d5efb851153af8d9dd8c9de1e9 --- pokemontools/chars.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pokemontools/chars.py b/pokemontools/chars.py index fc69fc5..f27bc90 100644 --- a/pokemontools/chars.py +++ b/pokemontools/chars.py @@ -270,6 +270,7 @@ jap_chars.update({ 0xE1: "ゅ", 0xE2: "ょ", 0xE3: "ー", + 0xE9: "ァ", }) #some of the japanese characters can probably fit into the english table -- cgit v1.2.3