-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.py
More file actions
44 lines (35 loc) · 1.24 KB
/
Utils.py
File metadata and controls
44 lines (35 loc) · 1.24 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
import sys
addressingModeNames = ["INDIRECT_Y_ENCODING", "INDIRECT_X_ENCODING", "ABSOLUTE_Y_ENCODING", "ABSOLUTE_X_ENCODING",
"ABSOLUTE_ENCODING", "ZEROPAGE_X_ENCODING", "ZEROPAGE_ENCODING", "IMMEDIATE_ENCODING",
"RELATIVE_ENCODING", "ACCUMULATOR_ENCODING", "INDIRECT_ENCODING", "ZEROPAGE_Y_ENCODING" ]
def writeDataToFile(data, outputFileName):
f = open(outputFileName, "wb")
f.write(data)
def exitWithError(fmt, *error):
print(fmt % error)
sys.exit()
def addressingModeString(addressingMode):
if addressingMode == 0:
return "IMPLIED_ENCODING"
return addressingModeNames[addressingModeIndex(addressingMode) - 1]
# expects a string number with the format $<hex number>. examples: $FF, $80, $C87F
def numForString(numStr, enforceType):
# must be explicit about number
if (numStr[0] == '$' or enforceType == "hex") and enforceType != "binary":
try:
value = int(numStr[1::], 16)
return (True, value)
except ValueError as verr:
return (False, 0)
elif numStr[0] == '%' or enforceType == "binary":
try:
value = int(numStr[1::], 2)
return (True, value)
except ValueError as verr:
return (False, 0)
else:
try:
value = int(numStr, 10)
return (True, value)
except ValueError as verr:
return (False, 0)