-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsp1asm.py
More file actions
99 lines (90 loc) · 2.71 KB
/
Copy pathsp1asm.py
File metadata and controls
99 lines (90 loc) · 2.71 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
print("\033c")
print("SP1 ASSEMBLER || (C)2023 723179\n")
def lenHex(funcLength):
funcOutput = hex(funcLength)[2:]
while len(funcOutput) < 2:
funcOutput = "0" + funcOutput
if len(funcOutput) > 2:
print("\nERROR: LENGTH\n")
raise SystemExit(0)
return funcOutput
#define some default variables
##does it print the location of every jump point?
jpPrint = False
# get input and choose output filename
with open(input("File input name? "), "r", encoding="utf-8") as f:
file = f.read()
fileIn = file.splitlines()
length = len(str(len(file))) + 1
outName = input("File output name? ")
while 1 == 1:
arg = input("Extra Arguments? ")
if arg == "":
break
if arg[0] in ["l","j"]:
#if the automatic get-length thing breaks the program, here's an option to fix it preemptively
if arg[0] == "l":
length = int(arg[1:])
elif arg[0] == "j":
if arg[1] == "0":
jpPrint = False
else:
jpPrint = True
else:
print("Syntax Error")
## Variables
currentPos = 0
# jump point lists
jpName = []
jpPos = []
#loop through once to find where jump points are
for i in range(len(fileIn)):
item = fileIn[i].lstrip()
if len(item) > 0:
if item[0] == "j":
jpName.append(item[1:])
jpPos.append(currentPos + 1)
if jpPrint:
print("JP: " + item[1:] + " :" + str(currentPos + 1))
else:
if item[0] in ["=", "g", ">", "<"]:
currentPos += (4 + length)
elif item[0] in ["@"]:
currentPos += (2 + length)
elif item[0] == "#":
pass
else:
currentPos += len(item)
output = ""
for i in range(len(fileIn)):
item = fileIn[i].lstrip()
if len(item) > 0:
if item[0] == "j":
pass
elif item[0] in ["=","g", ">", "<", "@"]:
if item[0] == "g":
output += "06"
elif item[0] == "=":
output += "20"
elif item[0] == ">":
output += "21"
elif item[0] == "<":
output += "22"
output += lenHex(length)
tempOut = str(jpPos[jpName.index(item[1:])])
while len(tempOut) < length:
tempOut = "0" + tempOut
output += tempOut
elif item[0] == "#":
pass
elif item[2:4] == "##":
output += item[0:2]
output += lenHex(len(item[4:]))
output += item[4:]
else:
output += item
if outName == "":
print(output)
else:
with open(outName, "w", encoding="utf-8") as o:
o.write(output)