-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.py
101 lines (77 loc) · 3.24 KB
/
build.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
import json
import sys
import subprocess
import os
import tkinter
from os import walk
from tkinter import filedialog
print("Cleaning all PRGs")
for (dir_path, dir_names, file_names) in os.walk(os.getcwd()):
for file in file_names:
if (file.endswith(".prg")):
os.remove(dir_path + "\\" + file)
no_image = False
disk_links = dict()
compiler_path = "Compiler/C64Ass.exe"
imager_path = ""
arguments_length = len(sys.argv)
argument_index = 0
while argument_index < arguments_length:
if (sys.argv[argument_index] == "-Compiler"):
print ("Compiler location overridden to " + sys.argv[argument_index + 1])
compiler_path = sys.argv[argument_index + 1]
argument_index += 1
elif (sys.argv[argument_index] == "-Imager"):
print ("Disk imager location overridden to " + sys.argv[argument_index + 1])
imager_path = sys.argv[argument_index + 1]
argument_index += 1
elif (sys.argv[argument_index] == "-NoImage"):
print ("Requested only PRG files, assuming VICE - c1541.exe is not available.")
no_image = True
argument_index += 1
if (compiler_path == ""):
print("Opening compiler target wizard...")
compiler_path = tkinter.filedialog.askopenfilename()
print(compiler_path)
if ((imager_path == "") & (no_image != True)):
print("Opening imager target wizard...")
imager_path = tkinter.filedialog.askopenfilename()
print(imager_path)
print("Compiling libraries...")
def compile_labels(path):
for (dir_path, dir_names, file_names) in os.walk(path):
for file in file_names:
if (file.endswith(".lib.asm")):
source = dir_path + file
artifact_name = source.rstrip(".lib.asm") + ".prg"
target_file_name = source.rstrip(".lib.asm") + ".asm"
artifact_to_delete = os.getcwd() + "\\" + artifact_name
subprocess.run([compiler_path, source, "-l", target_file_name, "-o", artifact_name, "-i", "W1000"])
os.remove(artifact_to_delete)
compile_labels("Library\\")
print("Compiling code...")
def compile(path):
for (dir_path, dir_names, file_names) in os.walk(path):
files_for_disk = []
for file in file_names:
if (file.endswith(".asm")):
source = dir_path + "/" + file
destination = file.rstrip(".asm")
destination += ".prg"
build_location = "Build/PRGs/" + dir_path.lstrip(path) + "/" + destination
files_for_disk.append(build_location)
subprocess.run([compiler_path, source, "-f", "CBM", "-o", build_location, "-i", "W1000"])
if (len(files_for_disk) > 0):
disk_name = dir_path.rstrip("/")
disk_links[disk_name.lstrip(path)] = files_for_disk
compile("Code/")
if not no_image:
print("Creating D64 images...")
for disk in disk_links:
print(disk + "...")
disk_path = "Build/" + disk + ".d64"
subprocess.run([imager_path, "-format", disk + ",id", "d64", disk_path])
for file in disk_links[disk]:
target_file_name = file.split(".")[0]
subprocess.run([imager_path, "-attach", disk_path, "-write", file, target_file_name.split("/")[-1]])
print("Done.")