-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassm.py
144 lines (124 loc) · 5.56 KB
/
assm.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Run this script with XAS99 to assemble all files
# See https://endlos99.github.io/xdt99/
#
# If you can't run powershell scripts research this command locally:
# Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
import os, glob
from itertools import chain
#Functions
WORK_FOLDER = "./Fiad/"
def get_work_file(filename):
return WORK_FOLDER + filename
def get_unlinked_string(include_membuf, object_files):
unlinked_files = []
for object_file in object_files:
unlinked_files.append(get_work_file(object_file + ".obj.temp"))
# These can't be the first files in the list because the first byte is not the program start
# These can't be at the end, because the main program gets auto-split into smaller pieces
if include_membuf == True:
unlinked_files.insert(1, "MEMBUF.noheader.obj")
unlinked_files.insert(2, "ARRAY.noheader.obj")
return " ".join(unlinked_files)
def link_test_files(linked_file, include_membuf, object_files):
unlinked_files_string = get_unlinked_string(include_membuf, object_files)
link_command_1 = "xas99.py -l {source} -o {output}"
link_command_2 = link_command_1.format(source = unlinked_files_string, output = get_work_file(linked_file))
os.system(link_command_2)
def link_main_files(linked_file, include_membuf, object_files):
unlinked_files_string = get_unlinked_string(include_membuf, object_files)
link_command_1 = "xas99.py -i -a \">2000\" -l {source} -o {output}"
link_command_2 = link_command_1.format(source = unlinked_files_string, output = get_work_file(linked_file))
os.system(link_command_2)
#Assemble Src and Tests
files1 = os.scandir(".//Src")
files2 = os.scandir(".//Tests")
files = chain(files1, files2)
for file_obj in files:
print("Assembling " + file_obj.name)
list_file = get_work_file(file_obj.name.replace(".asm", ".lst"))
obj_file = get_work_file(file_obj.name.replace(".asm", ".obj.temp"))
assemble_command_1 = "xas99.py -q -S -R {source} -L {list} -o {obj}"
assemble_command_2 = assemble_command_1.format(source = file_obj.path, list = list_file, obj = obj_file)
os.system(assemble_command_2)
print("Linking Unit Test Runners")
temp_files = [ "TESTFRAM", "ACTTST", "ACT", "UTIL", "VAR", "CONST" ]
link_test_files("ACTRUN.obj", True, temp_files)
temp_files = [ "TESTFRAM", "DISPTST", "DISP", "UTIL", "POSUPD", "HEADER", "VAR", "CONST" ]
link_test_files("DISPRUN.obj", True, temp_files)
temp_files = [ "TESTFRAM", "DISPTSTA", "DISP", "UTIL", "POSUPD", "HEADER", "VAR", "CONST" ]
link_test_files("DISPARUN.obj", True, temp_files)
temp_files = [ "TESTFRAM", "INPTTST", "INPUT", "ACT", "WRAP", "UTIL", "VAR", "CONST" ]
link_test_files("INPTRUN.obj", True, temp_files)
temp_files = [ "TESTFRAM", "POSUTST", "POSUPD", "UTIL", "VAR", "CONST" ]
link_test_files("POSRUN.obj", True, temp_files)
temp_files = [ "TESTFRAM", "WRAPTST", "WRAP", "UTIL", "VAR", "CONST" ]
link_test_files("WRAPRUN.obj", True, temp_files)
print("Linking Key Buffer Test Program")
temp_files = [ "KEYTST", "KEY", "VAR", "CONST" ]
link_test_files("KEYRUN.obj", False, temp_files)
print("Linking Main Program")
temp_files = [
"MAIN",
"CONST",
"INPUT",
"WRAP",
"POSUPD",
"DISP",
"KEY",
"VDP",
"ACT",
"DSRLNK",
"MENULOGIC",
"UTIL",
"HEADER",
"VAR",
"CACHETBL",
"INIT",
"IO",
"EDTMGN",
"MENU"
]
link_main_files("EMUWRITER", True, temp_files)
#Clean up
for file in glob.glob(WORK_FOLDER + "*.lst"):
os.remove(file)
for file in glob.glob(WORK_FOLDER + "*.obj.temp"):
os.remove(file)
# Create disk image
print("Creating disk image")
disk_image = 'EmuWriter.v0.3.dsk'
os.system("xdm99.py -X sssd " + disk_image)
program_files = glob.glob(WORK_FOLDER + "EMUWRITE*")
for program_file in program_files:
if not program_file.endswith(".dsk"):
# Add the program files to disk
add_command_1 = "xdm99.py {disk_image} -a {program_file} -f PROGRAM"
add_command_2 = add_command_1.format(disk_image = disk_image, program_file = program_file)
os.system(add_command_2)
# Write-Protect the program files
protect_command_1 = "xdm99.py {disk_image} -w {program_file}"
protect_command_2 = protect_command_1.format(disk_image = disk_image, program_file = program_file.replace("./Fiad\\", ""))
os.system(protect_command_2)
# Add example documents to disk imageE
text_files = ["HANSEL", "THREELANG"]
for text_file in text_files:
remove_header1 = "xdm99.py -F Fiad/{text_file} -o TEMPFILE"
remove_header2 = remove_header1.format(text_file = text_file)
os.system(remove_header2)
add_doc_1 = "xdm99.py {disk_image} -a TEMPFILE -n {text_file} -f DIS/FIX64"
add_doc_2 = add_doc_1.format(disk_image = disk_image, text_file = text_file)
os.system(add_doc_2)
os.remove("TEMPFILE")
# Add TIFILES header to all object files
print("Adding TIFILES header")
for file in glob.glob(WORK_FOLDER + "*.obj"):
if not file.endswith(".noheader.obj"):
header_command_1 = "xdm99.py -T {object_file} -f DIS/FIX80 -o {object_file}"
header_command_2 = header_command_1.format(object_file = file)
os.system(header_command_2)
# Add TIFILES header to EMUWRITER
for program_file in program_files:
if not program_file.endswith(".dsk"):
header_command_1 = "xdm99.py -T {program_file} -f PROGRAM -o {program_file}"
header_command_2 = header_command_1.format(program_file = program_file)
os.system(header_command_2)