From 91f3517b8652c6fb3086a69a355ac8aa0e1bb482 Mon Sep 17 00:00:00 2001 From: Alex Bates <16batesa@gmail.com> Date: Sat, 31 Oct 2020 00:28:23 +0000 Subject: [PATCH] parse ASCII structs --- tools/disasm_map.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/disasm_map.py b/tools/disasm_map.py index 970d462d96..6e68c556b4 100755 --- a/tools/disasm_map.py +++ b/tools/disasm_map.py @@ -3,7 +3,9 @@ import sys import os import yaml +import json from struct import unpack + from disasm_script import disassemble as disassemble_script def disassemble(bytes, offset, midx, symbol_map = {}, map_name = "map"): @@ -57,6 +59,15 @@ def disassemble(bytes, offset, midx, symbol_map = {}, map_name = "map"): out += f" .tattle = {tattle:X},\n" out += f"}};\n" + elif struct["type"] == "ASCII": + string_data = bytes.read(struct["length"]).decode("ascii") + + # strip null terminator(s) + while string_data[-1] == "\0": + string_data = string_data[:-1] + + string_literal = json.dumps(string_data) + out += f"const char M({struct['name']})[] = {string_literal};" else: # unknown type of struct out += f"s32 M({name})[] = {{" for i in range(0, struct["length"], 4):