diff options
author | yenatch <yenatch@gmail.com> | 2013-11-07 00:41:44 -0500 |
---|---|---|
committer | yenatch <yenatch@gmail.com> | 2013-11-07 00:41:44 -0500 |
commit | ea28149195b9fa75803253837eaf1917c97b4759 (patch) | |
tree | acf6f37bc6313d61f265bc8ab30d010187726aee | |
parent | ec52d627003ee42ba37c644a3b58acf870abc45b (diff) |
preprocessor: from_asm method and is_rgbasm_macro in command classes
enjoy this half-assed implementation
-rw-r--r-- | pokemontools/crystal.py | 16 | ||||
-rw-r--r-- | pokemontools/preprocessor.py | 18 |
2 files changed, 29 insertions, 5 deletions
diff --git a/pokemontools/crystal.py b/pokemontools/crystal.py index dd2461a..e5ffd80 100644 --- a/pokemontools/crystal.py +++ b/pokemontools/crystal.py @@ -764,6 +764,10 @@ class SingleByteParam(): else: return str(self.byte) + @staticmethod + def from_asm(value): + return value + class DollarSignByte(SingleByteParam): def to_asm(self): return hex(self.byte).replace("0x", "$") @@ -822,6 +826,10 @@ class MultiByteParam(): decimal = int("0x"+"".join([("%.2x")%x for x in reversed(self.bytes)]), 16) return str(decimal) + @staticmethod + def from_asm(value): + return value + class PointerLabelParam(MultiByteParam): # default size is 2 bytes @@ -1000,6 +1008,7 @@ class RAMAddressParam(MultiByteParam): class MoneyByteParam(MultiByteParam): size = 3 + byte_type = "db" max_value = 0x0F423F should_be_decimal = True def parse(self): @@ -1236,6 +1245,7 @@ class Command: # use this when the "byte id" doesn't matter # .. for example, a non-script command doesn't use the "byte id" override_byte_check = False + is_rgbasm_macro = False base_label = "UnseenLabel_" def __init__(self, address=None, *pargs, **kwargs): @@ -1723,6 +1733,7 @@ class TextCommand(Command): #def get_dependencies(self, recompute=False, global_dependencies=set()): # return [] + # this is a regular command in a TextScript for writing text # but unlike other macros that preprocessor.py handles, # the preprocessor-parser is custom and MainText is not @@ -2376,6 +2387,7 @@ class BigEndianParam: """big-endian word""" size = 2 should_be_decimal = False + byte_type = "bigdw" def __init__(self, *args, **kwargs): self.prefix = '$' @@ -2394,6 +2406,10 @@ class BigEndianParam: decimal = int("0x"+"".join([("%.2x")%x for x in self.bytes]), 16) return str(decimal) + @staticmethod + def from_asm(value): + return value + class DecimalBigEndianParam(BigEndianParam): should_be_decimal = True diff --git a/pokemontools/preprocessor.py b/pokemontools/preprocessor.py index 5fe0851..f4e92b6 100644 --- a/pokemontools/preprocessor.py +++ b/pokemontools/preprocessor.py @@ -556,8 +556,6 @@ class Preprocessor(object): # remove trailing newline if line[-1] == "\n": line = line[:-1] - else: - original_line += "\n" # remove first tab has_tab = False @@ -589,6 +587,12 @@ class Preprocessor(object): sys.stdout.write(original_line) return + # rgbasm can handle other macros too + if "is_rgbasm_macro" in dir(macro): + if macro.is_rgbasm_macro: + sys.stdout.write(original_line) + return + # certain macros don't need an initial byte written # do: all scripting macros # don't: signpost, warp_def, person_event, xy_trigger @@ -608,7 +612,7 @@ class Preprocessor(object): index = 0 while index < len(params): param_type = macro.param_types[index - correction] - description = param_type["name"] + description = param_type["name"].strip() param_klass = param_type["class"] byte_type = param_klass.byte_type # db or dw size = param_klass.size @@ -638,7 +642,7 @@ class Preprocessor(object): index += 2 correction += 1 elif size == 3 and "from_asm" in dir(param_klass): - output += ("db " + param_klass.from_asm(param) + "\n") + output += ("\t" + byte_type + " " + param_klass.from_asm(param) + "\n") index += 1 else: raise exceptions.MacroException( @@ -649,9 +653,13 @@ class Preprocessor(object): ) ) + elif "from_asm" in dir(param_klass): + output += ("\t" + byte_type + " " + param_klass.from_asm(param) + " ; " + description + "\n") + index += 1 + # or just print out the byte else: - output += (byte_type + " " + param + " ; " + description + "\n") + output += ("\t" + byte_type + " " + param + " ; " + description + "\n") index += 1 |