forked from flamewing/flamedriver-skdisasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcport.py
42 lines (37 loc) · 1.4 KB
/
cport.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import sys
import re
instrregx = r"^\s*([^\s\.:]+?)(i|q|a)?(?:\.(b|w|l|s))?\s+(?:([^,\s]+),)?([^\s]+)"
labelregx = r"^([^:]+):"
instrformats = {
"abcd": "// TODO: abcd {x},{y} was here, fix",
"add": "{y} += {x};",
"and": "{y} &= {x};",
"asl": "{y} <<= {x};",
"asr": "{y} >>= {x};",
"bcc": "// TODO: bcc {y} was here, fix",
"bcs": "// TODO: bcs {y} was here, fix",
"bvc": "// TODO: bvc {y} was here, fix",
"bvs": "// TODO: bvs {y} was here, fix",
"beq": "if (cres == 0) goto {y};",
"bne": "if (cres != 0) goto {y};",
"bge": "if ((int)cres >= 0) goto {y};",
"bgt": "if ((int)cres > 0) goto {y};",
"bhs": "if (cres >= 0) goto {y};",
"bh": "if (cres > 0) goto {y};", #supposed to be bhi, but regex breaks, works fine tho
"ble": "if ((int)cres <= 0) goto {y};",
"blt": "if ((int)cres < 0) goto {y};",
"bls": "if (cres <= 0) goto {y};",
"blo": "if (cres < 0) goto {y};",
"bm": "if (cres < 0) goto {y};",
"bpl": "if (cres >= 0) goto {y};",
"bchg": "cres |= {y} & ~(1 << {x}); {y} ^= cres;",
}
def cport(srcname: str, dstname: str):
src = open(srcname, "r")
string: list[str] = src.readlines()
dstr: str = "static unsigned char cres;\nstatic unsigned int d0".join([f", d{i+1}" for i in range(7)]).join([f", a{i}" for i in range(8)]) + ";\n\n"
src.close()
dst = open(dstname, "w")
dst.write(dstr)
dst.close()