From fabc78f5db572d63d3225cafd97884825e4e7f04 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 17 Nov 2013 20:35:44 -0600 Subject: call it button_new instead of new "new" is sometimes a reserved keyword and it would be nice to not use that name. --- pokemontools/map_editor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pokemontools/map_editor.py b/pokemontools/map_editor.py index c30fcd8..78edee0 100644 --- a/pokemontools/map_editor.py +++ b/pokemontools/map_editor.py @@ -149,10 +149,10 @@ class Application(Frame): self.picker_frame = Frame(self) self.picker_frame.grid(row=1, column=1) - self.new = Button(self.button_frame) - self.new["text"] = "New" - self.new["command"] = self.new_map - self.new.grid(row=0, column=0, padx=2) + self.button_new = Button(self.button_frame) + self.button_new["text"] = "New" + self.button_new["command"] = self.new_map + self.button_new.grid(row=0, column=0, padx=2) self.open = Button(self.button_frame) self.open["text"] = "Open" -- cgit v1.2.3 From d3f19c01581e2a7e977d226e6697ff7446c28b49 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Sun, 17 Nov 2013 20:39:53 -0600 Subject: remove two unused methods from map_editor.py --- pokemontools/map_editor.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pokemontools/map_editor.py b/pokemontools/map_editor.py index 78edee0..1cd9b02 100644 --- a/pokemontools/map_editor.py +++ b/pokemontools/map_editor.py @@ -683,14 +683,6 @@ def macro_values(line, macro): values = values[1:] return values -def db_value(line): - macro = 'db' - return macro_values(line, macro) - -def db_values(line): - macro = 'db' - return macro_values(line, macro) - def asm_at_label(asm, label): label_def = label + ':' lines = asm.split('\n') -- cgit v1.2.3 From 0cdd66e1b57b7ddd8e7006c3782e446ad91e3913 Mon Sep 17 00:00:00 2001 From: Bryan Bishop Date: Tue, 19 Nov 2013 22:27:50 -0600 Subject: return constants after parsing --- pokemontools/map_editor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pokemontools/map_editor.py b/pokemontools/map_editor.py index 1cd9b02..43042cb 100644 --- a/pokemontools/map_editor.py +++ b/pokemontools/map_editor.py @@ -128,6 +128,7 @@ def get_constants(config=config): name, value = [s.strip() for s in line.split(' EQU ')] constants[name] = eval(value.split(';')[0].replace('$','0x').replace('%','0b')) config.constants = constants + return constants class Application(Frame): def __init__(self, master=None, config=config): -- cgit v1.2.3 From 0fd121a81e1cbbf1a42e72a5d7c9e8099ef59f97 Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 5 Dec 2013 16:38:31 -0500 Subject: wram: try to determine addresses for section defs without any --- pokemontools/wram.py | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/pokemontools/wram.py b/pokemontools/wram.py index 60001aa..e467a01 100644 --- a/pokemontools/wram.py +++ b/pokemontools/wram.py @@ -14,22 +14,48 @@ def make_wram_labels(wram_sections): wram_labels[label['address']] += [label['label']] return wram_labels +def bracket_value(string, i=0): + return string.split('[')[1 + i*2].split(']')[0] + def read_bss_sections(bss): sections = [] section = { - "labels": [], } address = None if type(bss) is not list: bss = bss.split('\n') for line in bss: line = line.lstrip() - if 'SECTION' in line: - if section: sections.append(section) # last section + if 'SECTION' == line[:7]: + if section: # previous + sections += [section] + + section_def = line.split(',') + name = section_def[0].split('"')[1] + type_ = section_def[1].strip() + if len(section_def) > 2: + bank = bracket_value(section_def[2]) + else: + bank = None + + if '[' in type_: + address = int(bracket_value(type_).replace('$','0x'), 16) + else: + if address == None or bank != section['bank']: + for type__, addr in [ + ('VRAM', 0x8000), + ('SRAM', 0xa000), + ('WRAM0', 0xc000), + ('WRAMX', 0xd000), + ('HRAM', 0xff80), + ]: + if type__ == type_ and section['type'] == type__: + address = addr + # else: keep going from this address - address = eval(line[line.find('[')+1:line.find(']')].replace('$','0x')) section = { - 'name': line.split('"')[1], - #'type': line.split(',')[1].split('[')[0].strip(), + 'name': name, + 'type': type_, + 'bank': bank, 'start': address, 'labels': [], } -- cgit v1.2.3 From 806fd657c2424a7328c21a4246da038a6dafed0e Mon Sep 17 00:00:00 2001 From: yenatch Date: Thu, 5 Dec 2013 20:33:43 -0500 Subject: use file includes in rgbasm objects to generate dependencies --- pokemontools/scan_includes.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pokemontools/scan_includes.py diff --git a/pokemontools/scan_includes.py b/pokemontools/scan_includes.py new file mode 100644 index 0000000..138f011 --- /dev/null +++ b/pokemontools/scan_includes.py @@ -0,0 +1,34 @@ +# coding: utf-8 + +""" +Recursively scan an asm file for rgbasm INCLUDEs and INCBINs. +Used to generate dependencies for each rgbasm object. +""" + +import os +import sys + +import configuration +conf = configuration.Config() + +def recursive_scan(filename, includes = []): + if (filename[-4:] == '.asm' or filename[-3] == '.tx') and os.path.exists(filename): + lines = open(filename).readlines() + for line in lines: + for directive in ('INCLUDE', 'INCBIN'): + if directive in line: + line = line[:line.find(';')] + if directive in line: + include = line.split('"')[1] + if include not in includes: + includes += [include] + includes = recursive_scan(include, includes) + break + return includes + +if __name__ == '__main__': + filenames = sys.argv[1:] + for filename in filenames: + dependencies = recursive_scan(os.path.join(conf.path, filename)) + sys.stdout.write(' '.join(dependencies)) + -- cgit v1.2.3 From 1be104b8e8beb964783fdd7de82569c291f9cdfc Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 6 Dec 2013 19:39:34 -0500 Subject: sym: rgbds does ram banks now --- pokemontools/sym.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/pokemontools/sym.py b/pokemontools/sym.py index ebd8532..b1e755f 100644 --- a/pokemontools/sym.py +++ b/pokemontools/sym.py @@ -4,7 +4,7 @@ import os import sys import json -def make_sym_from_json(filename = '../pokecrystal.sym', j = 'labels.json'): +def make_sym_from_json(filename = 'pokecrystal.sym', j = 'labels.json'): output = '' labels = json.load(open(j)) for label in labels: @@ -12,13 +12,13 @@ def make_sym_from_json(filename = '../pokecrystal.sym', j = 'labels.json'): with open(filename, 'w') as sym: sym.write(output) -def make_json_from_mapfile(filename='labels.json', mapfile='../pokecrystal.map'): +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'): +def read_mapfile(filename='pokecrystal.map'): """ Scrape label addresses from an rgbds mapfile. """ @@ -29,9 +29,15 @@ def read_mapfile(filename='../pokecrystal.map'): lines = mapfile.readlines() for line in lines: - # bank # - if 'Bank #' in line: - cur_bank = int(line.lstrip('Bank #').strip(';\n').strip(' (HOME)')) + if line[0].strip(): # section type def + section_type = line.split(' ')[0] + if section_type == 'Bank': # ROM + cur_bank = int(line.split(' ')[1].split(':')[0][1:]) + elif section_type in ['WRAM0', 'HRAM']: + cur_bank = 0 + elif section_type in ['WRAM, VRAM']: + cur_bank = int(line.split(' ')[2].split(':')[0][1:]) + cur_bank = int(line.split(' ')[2].split(':')[0][1:]) # label definition elif '=' in line: @@ -39,21 +45,10 @@ def read_mapfile(filename='../pokecrystal.map'): 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 + if address < 0x8000 and bank: # ROM + offset += (bank - 1) * 0x4000 labels += [{ 'label': label, -- cgit v1.2.3 From 460171a2c52d6fcd591559ab1c5fff09e9bc49cb Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 6 Dec 2013 19:42:58 -0500 Subject: wram: cleaner line parsing fixes 0fd121a8 --- pokemontools/wram.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pokemontools/wram.py b/pokemontools/wram.py index e467a01..7bc017d 100644 --- a/pokemontools/wram.py +++ b/pokemontools/wram.py @@ -20,11 +20,19 @@ def bracket_value(string, i=0): def read_bss_sections(bss): sections = [] section = { + 'name': None, + 'type': None, + 'bank': None, + 'start': None, + 'labels': [], } address = None if type(bss) is not list: bss = bss.split('\n') for line in bss: - line = line.lstrip() + + comment_index = line.find(';') + line, comment = line[:comment_index].lstrip(), line[comment_index:] + if 'SECTION' == line[:7]: if section: # previous sections += [section] @@ -71,7 +79,7 @@ def read_bss_sections(bss): }] elif line[:3] == 'ds ': - length = eval(line[3:line.find(';')].replace('$','0x')) + length = eval(line[3:].replace('$','0x')) address += length # adjacent labels use the same space for label in section['labels'][::-1]: -- cgit v1.2.3 From 05b622e7c019a97bb69007a43de733f64076e59a Mon Sep 17 00:00:00 2001 From: yenatch Date: Fri, 6 Dec 2013 19:44:02 -0500 Subject: labels: grab labels from a mapfile instead of an old json dump labels.json had to be deleted manually to be updated, and rgbasm is better at scanning labels anyway --- pokemontools/labels.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/pokemontools/labels.py b/pokemontools/labels.py index 96e34b9..87e9990 100644 --- a/pokemontools/labels.py +++ b/pokemontools/labels.py @@ -8,33 +8,39 @@ import json import logging import pointers +import sym class Labels(object): """ Store all labels. """ - filename = "labels.json" - def __init__(self, config): + def __init__(self, config, filename="pokecrystal.map"): """ Setup the instance. """ self.config = config - self.path = os.path.join(self.config.path, Labels.filename) + self.filename = filename + self.path = os.path.join(self.config.path, self.filename) def initialize(self): """ Handle anything requiring file-loading and such. """ + # Look for a mapfile if it's not given if not os.path.exists(self.path): - logging.info( - "Running crystal.scan_for_predefined_labels to create \"{0}\". Trying.." - .format(Labels.filename) - ) - import crystal - crystal.scan_for_predefined_labels() + self.filename = find_mapfile_in_dir(self.config.path) + if self.filename == None: + raise Exception, "Couldn't find any mapfiles. Run rgblink -m to create a mapfile." + self.path = os.path.join(self.config.path, self.filename) - self.labels = json.read(open(self.path, "r").read()) + self.labels = sym.read_mapfile(self.path) + +def find_mapfile_in_dir(path): + for filename in os.listdir(path): + if os.path.splitext(filename)[1] == '.map': + return filename + return None def remove_quoted_text(line): """get rid of content inside quotes -- cgit v1.2.3 From f5ddc3370560a4b5f58ea79a513d4bf1207fa9f4 Mon Sep 17 00:00:00 2001 From: yenatch Date: Sat, 7 Dec 2013 05:05:54 -0500 Subject: preprocessor: dont write to globals.asm for each process --- pokemontools/preprocessor.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pokemontools/preprocessor.py b/pokemontools/preprocessor.py index 5fe0851..24a74e1 100644 --- a/pokemontools/preprocessor.py +++ b/pokemontools/preprocessor.py @@ -483,22 +483,18 @@ class Preprocessor(object): for l in lines: self.read_line(l) - self.update_globals() - def update_globals(self): """ Add any labels not already in globals.asm. """ - # TODO: pokered needs to be fixed - try: - globes = open(os.path.join(self.config.path, 'globals.asm'), 'r+') + path = os.path.join(self.config.path, 'globals.asm') + if os.path.exists(path): + globes = open(path, 'r+') lines = globes.readlines() for globe in self.globes: line = 'GLOBAL ' + globe + '\n' if line not in lines: globes.write(line) - except Exception as exception: - pass # don't care if it's not there... def read_line(self, l): """ -- cgit v1.2.3 From f35bb2c5cc390ec0008cede2721104592dbcb29d Mon Sep 17 00:00:00 2001 From: yenatch Date: Sun, 8 Dec 2013 01:26:09 -0500 Subject: scan_includes: join names properly and actually use conf.path --- pokemontools/scan_includes.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pokemontools/scan_includes.py b/pokemontools/scan_includes.py index 138f011..7f34e92 100644 --- a/pokemontools/scan_includes.py +++ b/pokemontools/scan_includes.py @@ -22,13 +22,15 @@ def recursive_scan(filename, includes = []): include = line.split('"')[1] if include not in includes: includes += [include] - includes = recursive_scan(include, includes) + includes = recursive_scan(os.path.join(conf.path, include), includes) break return includes if __name__ == '__main__': filenames = sys.argv[1:] + dependencies = [] for filename in filenames: - dependencies = recursive_scan(os.path.join(conf.path, filename)) - sys.stdout.write(' '.join(dependencies)) + dependencies += recursive_scan(os.path.join(conf.path, filename)) + dependencies = list(set(dependencies)) + sys.stdout.write(' '.join(dependencies)) -- cgit v1.2.3 From b0fa67a51191a9ddc2a4ce548ade0243b6be554c Mon Sep 17 00:00:00 2001 From: yenatch Date: Wed, 11 Dec 2013 20:28:25 -0500 Subject: wram: fix section address allocation who wrote this? --- pokemontools/wram.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pokemontools/wram.py b/pokemontools/wram.py index 7bc017d..87af4a2 100644 --- a/pokemontools/wram.py +++ b/pokemontools/wram.py @@ -48,16 +48,16 @@ def read_bss_sections(bss): if '[' in type_: address = int(bracket_value(type_).replace('$','0x'), 16) else: - if address == None or bank != section['bank']: - for type__, addr in [ - ('VRAM', 0x8000), - ('SRAM', 0xa000), - ('WRAM0', 0xc000), - ('WRAMX', 0xd000), - ('HRAM', 0xff80), - ]: - if type__ == type_ and section['type'] == type__: - address = addr + types = { + 'VRAM': 0x8000, + 'SRAM': 0xa000, + 'WRAM0': 0xc000, + 'WRAMX': 0xd000, + 'HRAM': 0xff80, + } + if address == None or bank != section['bank'] or section['type'] != type_: + if type_ in types.keys(): + address = types[type_] # else: keep going from this address section = { -- cgit v1.2.3