Moved some of the script to tools
This commit is contained in:
parent
b76107938a
commit
7fe2758af7
99
build.py
99
build.py
|
@ -1,99 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
import math
|
|
||||||
|
|
||||||
pageSize = 128
|
|
||||||
sectorsPerTrack = 256
|
|
||||||
blockSize = 16384
|
|
||||||
maxDirs = 128
|
|
||||||
dirBlocks = 1
|
|
||||||
|
|
||||||
out = open('.build/disk.img', 'wb')
|
|
||||||
|
|
||||||
def addBootloader(name):
|
|
||||||
loader = open(name, 'rb')
|
|
||||||
b = loader.read()
|
|
||||||
|
|
||||||
if len(b) > pageSize:
|
|
||||||
raise RuntimeError("Bootloader binary cannot be larger than one page")
|
|
||||||
|
|
||||||
out.seek(0)
|
|
||||||
out.write(b)
|
|
||||||
|
|
||||||
def addOS(cpmName, biosName):
|
|
||||||
cpm = open(cpmName, 'rb')
|
|
||||||
bios = open(biosName, 'rb')
|
|
||||||
|
|
||||||
b = cpm.read()
|
|
||||||
out.seek(pageSize)
|
|
||||||
out.write(b)
|
|
||||||
|
|
||||||
b = bios.read()
|
|
||||||
out.seek(pageSize + 0x1600)
|
|
||||||
out.write(b)
|
|
||||||
|
|
||||||
def seekBlock(i):
|
|
||||||
# Blocks start at track 1, sector 0
|
|
||||||
out.seek(pageSize*sectorsPerTrack + i*blockSize)
|
|
||||||
|
|
||||||
def initDirs():
|
|
||||||
seekBlock(0)
|
|
||||||
out.write(bytearray(([0xe5] + [0x00] * 31) * maxDirs))
|
|
||||||
|
|
||||||
fileCounter = 0
|
|
||||||
def addFile(filename, n, t):
|
|
||||||
global fileCounter
|
|
||||||
|
|
||||||
if fileCounter > maxDirs:
|
|
||||||
raise RuntimeError("Max dir entries has been reached")
|
|
||||||
|
|
||||||
fileCounter += 1
|
|
||||||
|
|
||||||
if len(n) > 8:
|
|
||||||
raise RuntimeError("Filename cannot be longer than 8")
|
|
||||||
|
|
||||||
if len(t) > 3:
|
|
||||||
raise RuntimeError("Filetype cannot be longer than 3")
|
|
||||||
|
|
||||||
f = open(filename, 'rb')
|
|
||||||
b = f.read()
|
|
||||||
|
|
||||||
seekBlock(0)
|
|
||||||
out.seek(32*fileCounter, 1)
|
|
||||||
|
|
||||||
# Write user (assume 0 for now)
|
|
||||||
out.write(bytearray(1))
|
|
||||||
|
|
||||||
# Write the name
|
|
||||||
out.write(n.upper().encode("ascii"))
|
|
||||||
out.write((" " * (8-len(n))).encode("ascii"))
|
|
||||||
|
|
||||||
# Write the type
|
|
||||||
out.write(t.upper().encode("ascii"))
|
|
||||||
out.write((" " * (3-len(t))).encode("ascii"))
|
|
||||||
|
|
||||||
# Write extend (assume no extend for now)
|
|
||||||
out.write(bytearray(2))
|
|
||||||
|
|
||||||
# Reserved byte
|
|
||||||
out.write(bytearray(1))
|
|
||||||
|
|
||||||
# Number of records (Again assuming no extends <128)
|
|
||||||
out.write(math.ceil(len(b)/128).to_bytes(1, byteorder='little'))
|
|
||||||
|
|
||||||
# We are assuming one block per file for now, so we can use fileCounter
|
|
||||||
out.write(fileCounter.to_bytes(2, byteorder='little'))
|
|
||||||
|
|
||||||
seekBlock(fileCounter)
|
|
||||||
out.write(b)
|
|
||||||
|
|
||||||
|
|
||||||
addBootloader('.build/loader.bin')
|
|
||||||
addOS('.build/cpm22.bin', '.build/bios.bin')
|
|
||||||
|
|
||||||
initDirs()
|
|
||||||
|
|
||||||
addFile(".build/MONITOR.COM", "MONITOR", "COM")
|
|
||||||
addFile("bin/STAT.COM", "STAT", "COM")
|
|
||||||
addFile("../qe/.build/test.com", "test", "COM")
|
|
||||||
addFile("../qe/.build/qe.com", "qe", "COM")
|
|
||||||
addFile("../xed/.build/xed.com", "xed", "COM")
|
|
58
upload.py
58
upload.py
|
@ -1,58 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
import serial
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
|
|
||||||
def progressbar(it, prefix="", size=60, file=sys.stdout):
|
|
||||||
count = len(it)
|
|
||||||
def show(j):
|
|
||||||
x = int(size*j/count)
|
|
||||||
file.write("%s[%s%s] %i/%i\r" % (prefix, "#"*x, "."*(size-x), j, count))
|
|
||||||
file.flush()
|
|
||||||
show(0)
|
|
||||||
for i, item in enumerate(it):
|
|
||||||
yield item
|
|
||||||
show(i+1)
|
|
||||||
file.write("\n")
|
|
||||||
file.flush()
|
|
||||||
|
|
||||||
def main():
|
|
||||||
if len(sys.argv) == 2:
|
|
||||||
# ser = serial.Serial("COM3", timeout=1, write_timeout=1)
|
|
||||||
ser = serial.Serial("/dev/ttyUSB0", timeout=1, write_timeout=1, baudrate=115200)
|
|
||||||
if ser.is_open:
|
|
||||||
# Clear out any existing input
|
|
||||||
ser.write(b'\n')
|
|
||||||
time.sleep(0.002)
|
|
||||||
|
|
||||||
# Send the upload command
|
|
||||||
ser.write(b'#')
|
|
||||||
time.sleep(0.002)
|
|
||||||
ser.write(b'u')
|
|
||||||
time.sleep(0.002)
|
|
||||||
ser.write(b'\n')
|
|
||||||
time.sleep(0.002)
|
|
||||||
|
|
||||||
path = sys.argv[1]
|
|
||||||
size = os.path.getsize(path)
|
|
||||||
ser.write([size & 0xFF])
|
|
||||||
time.sleep(0.002)
|
|
||||||
ser.write([(size >> 8) & 0xFF])
|
|
||||||
time.sleep(0.002)
|
|
||||||
|
|
||||||
with open(path, "rb") as f:
|
|
||||||
for i in progressbar(range(size), "Upload: ", 40):
|
|
||||||
byte = f.read(1)
|
|
||||||
ser.write(byte)
|
|
||||||
time.sleep(0.002)
|
|
||||||
|
|
||||||
ser.close()
|
|
||||||
|
|
||||||
else:
|
|
||||||
print("Failed to open serial port")
|
|
||||||
else:
|
|
||||||
print("Please provide file to upload")
|
|
||||||
|
|
||||||
if "__main__":
|
|
||||||
main()
|
|
|
@ -1,49 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
import serial
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
|
|
||||||
def progressbar(it, prefix="", size=60, file=sys.stdout):
|
|
||||||
count = len(it)
|
|
||||||
def show(j):
|
|
||||||
x = int(size*j/count)
|
|
||||||
file.write("%s[%s%s] %i/%i\r" % (prefix, "#"*x, "."*(size-x), j, count))
|
|
||||||
file.flush()
|
|
||||||
show(0)
|
|
||||||
for i, item in enumerate(it):
|
|
||||||
yield item
|
|
||||||
show(i+1)
|
|
||||||
file.write("\n")
|
|
||||||
file.flush()
|
|
||||||
|
|
||||||
def main():
|
|
||||||
if len(sys.argv) == 2:
|
|
||||||
# ser = serial.Serial("COM3", timeout=1, write_timeout=1)
|
|
||||||
ser = serial.Serial("/dev/ttyUSB0", timeout=1, write_timeout=1, baudrate=115200)
|
|
||||||
if ser.is_open:
|
|
||||||
path = sys.argv[1]
|
|
||||||
size = os.path.getsize(path)
|
|
||||||
|
|
||||||
with open(path, "rb") as f:
|
|
||||||
for i in progressbar(range(size), "Upload: ", 40):
|
|
||||||
byte = f.read(1)
|
|
||||||
ser.write(byte)
|
|
||||||
|
|
||||||
if byte == b'#':
|
|
||||||
time.sleep(0.002)
|
|
||||||
ser.write(b'#')
|
|
||||||
time.sleep(0.002)
|
|
||||||
ser.write(b'\n')
|
|
||||||
|
|
||||||
time.sleep(0.002)
|
|
||||||
|
|
||||||
ser.close()
|
|
||||||
|
|
||||||
else:
|
|
||||||
print("Failed to open serial port")
|
|
||||||
else:
|
|
||||||
print("Please provide file to upload")
|
|
||||||
|
|
||||||
if "__main__":
|
|
||||||
main()
|
|
Loading…
Reference in New Issue
Block a user