summaryrefslogtreecommitdiff
path: root/tools/asm_processor/asm_processor.py
diff options
context:
space:
mode:
authorTharo <17233964+Thar0@users.noreply.github.com>2020-05-20 12:37:28 +0100
committerGitHub <noreply@github.com>2020-05-20 07:37:28 -0400
commit43dfaa7518e0a9048b9be9e62ba9ded339321a68 (patch)
tree483cbfe7745fce8ae9732b81a295f1474729b8de /tools/asm_processor/asm_processor.py
parent2bccbe76792617865667777692d748e3ab7fb651 (diff)
Create Macros for Cutscene Data (#63)
* Added additional (potentially unused) fields to macros, now builds OK * Ran formatter, attempted better macro formatting * Formatted unknown fields as hex, further cleanups * Rename and prefix macros, use command base macros, format cutscenes with indents * Move command macros into a new file and include it globally * Generate cutscene command macros for Bg_Toki_Swd, Cleanups * Rename CS_TEXTBOX commands to CS_TEXT, fix typo ic command_macros_base.h * Introduce CS_CMD_CONTINUE and CS_CMD_STOP * Remove apparently redundant arguments in certain commands, include the values in the macros directly * Re-add cutscene terminator destination enum values to example cutscene data * Format what should be floats as hex, Change actorAnim to actorAction * Allow floating-point representation of values in cutscene data (asm-processor hack) * Include cutscene commands only where necessary, documentation fixes * Rename actor actions to npc actions, separate player action from npc actions * Remove PlayerActionIDs for now as relevant information on it is not yet decompiled * Generate cutscene data for en_ru1, remove apparent redundancies in CS_LIGHTING and CS_PLAY/STOP/FADE_BGM commands, relax static requirement in asm-processor CutsceneData float conversion
Diffstat (limited to 'tools/asm_processor/asm_processor.py')
-rw-r--r--tools/asm_processor/asm_processor.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/tools/asm_processor/asm_processor.py b/tools/asm_processor/asm_processor.py
index 1ff25db81..50d2a91d5 100644
--- a/tools/asm_processor/asm_processor.py
+++ b/tools/asm_processor/asm_processor.py
@@ -7,6 +7,7 @@ import sys
import re
import os
from collections import namedtuple
+from io import StringIO
MAX_FN_SIZE = 100
@@ -660,6 +661,9 @@ class GlobalAsmBlock:
})
return src, fn
+def repl_float_hex(m):
+ return str(struct.unpack(">I", struct.pack(">f", float(m.group(0).strip().rstrip("f"))))[0])
+
def parse_source(f, opt, framepointer, input_enc, output_enc, print_source=None):
if opt in ['O2', 'O1']:
if framepointer:
@@ -688,6 +692,7 @@ def parse_source(f, opt, framepointer, input_enc, output_enc, print_source=None)
state = GlobalState(min_instr_count, skip_instr_count)
global_asm = None
+ is_cutscene_data = False
asm_functions = []
output_lines = []
@@ -724,15 +729,34 @@ def parse_source(f, opt, framepointer, input_enc, output_enc, print_source=None)
output_lines[-1] = ''.join(src)
asm_functions.append(fn)
global_asm = None
+ elif ((line.startswith('#include "')) and line.endswith('" EARLY')):
+ fpath = os.path.dirname(f.name)
+ fname = line[line.index(' ') + 2 : -7]
+ include_src = StringIO()
+ with open(fpath + os.path.sep + fname, encoding=input_enc) as include_file:
+ parse_source(include_file, opt, framepointer, input_enc, output_enc, include_src)
+ output_lines[-1] = include_src.getvalue()
+ include_src.write('#line ' + str(line_no) + '\n')
+ include_src.close()
else:
+ if re.compile(r"(CutsceneData (.|\n)*\[\] = {)").search(line) is not None:
+ is_cutscene_data = True
+ elif line.endswith("};"):
+ is_cutscene_data = False
+ if is_cutscene_data:
+ raw_line = re.sub(re.compile(r"[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?f"), repl_float_hex, raw_line)
output_lines[-1] = raw_line
if print_source:
- for line in output_lines:
- print_source.write(line.encode(output_enc) + b'\n')
- print_source.flush()
- if print_source != sys.stdout.buffer:
- print_source.close()
+ if isinstance(print_source, StringIO):
+ for line in output_lines:
+ print_source.write(line + '\n')
+ else:
+ for line in output_lines:
+ print_source.write(line.encode(output_enc) + b'\n')
+ print_source.flush()
+ if print_source != sys.stdout.buffer:
+ print_source.close()
return asm_functions