aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorRangi <remy.oukaour+rangi42@gmail.com>2022-09-18 23:59:03 -0400
committerRangi <remy.oukaour+rangi42@gmail.com>2022-09-18 23:59:03 -0400
commitfa7d76f39ef2ca94f1b4a1ba01039f748664f523 (patch)
tree0ff9751bb44db26fffe7c8f376c4a5c56d99386b /tools
parentUpdate and add more tool scripts (diff)
downloadpokeyellow-fa7d76f39ef2ca94f1b4a1ba01039f748664f523.tar.gz
pokeyellow-fa7d76f39ef2ca94f1b4a1ba01039f748664f523.tar.xz
pokeyellow-fa7d76f39ef2ca94f1b4a1ba01039f748664f523.zip
Fix tools/unnamed.py and add tools/consts.py
Diffstat (limited to 'tools')
-rwxr-xr-xtools/consts.py56
-rwxr-xr-xtools/unnamed.py4
2 files changed, 58 insertions, 2 deletions
diff --git a/tools/consts.py b/tools/consts.py
new file mode 100755
index 00000000..37c85951
--- /dev/null
+++ b/tools/consts.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+
+"""
+Usage: python consts.py constants/some_constants.asm
+
+View numeric values of `const`ants.
+"""
+
+import sys
+import re
+
+const_value = 0
+const_inc = 1
+
+def asm_int(s):
+ base = {'$': 16, '&': 8, '%': 2}.get(s[0], 10)
+ return int(s if base == 10 else s[1:], base)
+
+def print_const(s, v):
+ print(f'{s} == {v} == ${v:x}')
+
+def parse_for_constants(line):
+ global const_value, const_inc
+ if not (m := re.match(r'^\s+([A-Za-z_][A-Za-z0-9_@#]*)(?:\s+([^;\\n]+))?', line)):
+ return
+ macro, rest = m.groups()
+ args = [arg.strip() for arg in rest.split(',')] if rest else []
+ if args and not args[-1]:
+ args = args[:-1]
+ if macro == 'const_def':
+ const_value = asm_int(args[0]) if len(args) >= 1 else 0
+ const_inc = asm_int(args[1]) if len(args) >= 2 else 1
+ elif macro == 'const':
+ print_const(args[0], const_value)
+ const_value += const_inc
+ elif macro == 'shift_const':
+ print_const(args[0], 1 << const_value)
+ print_const(args[0] + '_F', const_value)
+ const_value += const_inc
+ elif macro == 'const_skip':
+ const_value += const_inc * (asm_int(args[0]) if len(args) >= 1 else 1)
+ elif macro == 'const_next':
+ const_value = asm_int(args[0])
+
+def main():
+ if len(sys.argv) < 2:
+ print(f'Usage: {sys.argv[0]} constants/some_constants.asm', file=sys.stderr)
+ sys.exit(1)
+ for filename in sys.argv[1:]:
+ with open(filename, 'r', encoding='utf-8') as file:
+ for line in file:
+ parse_for_constants(line)
+
+if __name__ == '__main__':
+ main()
diff --git a/tools/unnamed.py b/tools/unnamed.py
index 265f1452..9dcf5cb3 100755
--- a/tools/unnamed.py
+++ b/tools/unnamed.py
@@ -48,8 +48,8 @@ objects = None
if args.rootdir:
for line in subprocess.Popen(['make', '-C', args.rootdir, '-s', '-p', 'DEBUG=1'],
stdout=subprocess.PIPE).stdout.read().decode().split('\n'):
- if line.startswith('pokered_obj := '):
- objects = line[19:].strip().split()
+ if line.startswith('pokered_obj :='):
+ objects = line[len('pokered_obj :='):].strip().split()
break
else:
print('Error: Object files not found!', file=sys.stderr)