Updated scripts and added i2c upload
This commit is contained in:
parent
f22f74e3da
commit
e10c541075
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
import imageio
|
||||
import math
|
||||
|
||||
asci = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
|
||||
font = "font.png"
|
||||
|
||||
im = imageio.imread(font)
|
||||
|
||||
for c in asci:
|
||||
|
||||
base_x = (ord(c) % 16) * 16
|
||||
base_y = math.floor(ord(c)/16) * 16
|
||||
|
||||
n = 0
|
||||
for y in range(16):
|
||||
n = n << 16
|
||||
k = 0
|
||||
for x in range(16):
|
||||
d = im[base_y + y][base_x + x][0]
|
||||
k = k << 1
|
||||
if d == 255:
|
||||
k = k + 1
|
||||
|
||||
n = n + k
|
||||
|
||||
print("assign char_data[{:2}] = 256'h{:064x}; // {}".format(ord(c)-32, n, c))
|
BIN
scripts/__pycache__/mojo.cpython-39.pyc
Normal file
BIN
scripts/__pycache__/mojo.cpython-39.pyc
Normal file
Binary file not shown.
|
@ -4,9 +4,11 @@ import math
|
|||
pageSize = 128
|
||||
sectorsPerTrack = 256
|
||||
blockSize = 16384
|
||||
pagesPerBlock = 128
|
||||
maxDirs = 128
|
||||
dirBlocks = 1
|
||||
|
||||
|
||||
def addBootloader(name):
|
||||
loader = open(name, 'rb')
|
||||
b = loader.read()
|
||||
|
@ -38,14 +40,14 @@ def initDirs():
|
|||
out.write(bytearray(([0xe5] + [0x00] * 31) * maxDirs))
|
||||
|
||||
fileCounter = 0
|
||||
allocationCounter = 1
|
||||
def addFile(filename, n, t):
|
||||
global fileCounter
|
||||
global allocationCounter
|
||||
|
||||
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")
|
||||
|
||||
|
@ -55,6 +57,13 @@ def addFile(filename, n, t):
|
|||
f = open(filename, 'rb')
|
||||
b = f.read()
|
||||
|
||||
total_records = math.ceil(len(b)/pageSize)
|
||||
records = (total_records - 1) % pagesPerBlock + 1
|
||||
extends = math.ceil(total_records/pagesPerBlock)
|
||||
|
||||
if extends >= 8:
|
||||
RuntimeError("File is to big to be stored in one entry, multple entries are not implemented")
|
||||
|
||||
seekBlock(0)
|
||||
out.seek(32*fileCounter, 1)
|
||||
|
||||
|
@ -69,23 +78,32 @@ def addFile(filename, n, t):
|
|||
out.write(t.upper().encode("ascii"))
|
||||
out.write((" " * (3-len(t))).encode("ascii"))
|
||||
|
||||
# Write extend (assume no extend for now)
|
||||
out.write(bytearray(2))
|
||||
# Write extend
|
||||
# @todo This is actually wrong, as the order is EX S1 S2 with S1 being unused, however we never deal with files that big
|
||||
out.write((extends-1).to_bytes(1, byteorder='little'))
|
||||
|
||||
# Reserved byte
|
||||
out.write(bytearray(1))
|
||||
out.write(bytearray(2))
|
||||
|
||||
# Number of records (Again assuming no extends <128)
|
||||
out.write(math.ceil(len(b)/128).to_bytes(1, byteorder='little'))
|
||||
# Number of records
|
||||
|
||||
out.write(records.to_bytes(1, byteorder='little'))
|
||||
|
||||
allocationCounterOld = allocationCounter
|
||||
# We are assuming one block per file for now, so we can use fileCounter
|
||||
out.write(fileCounter.to_bytes(2, byteorder='little'))
|
||||
for i in range(extends):
|
||||
out.write(allocationCounter.to_bytes(2, byteorder='little'))
|
||||
allocationCounter += 1
|
||||
|
||||
seekBlock(fileCounter)
|
||||
seekBlock(allocationCounterOld)
|
||||
out.write(b)
|
||||
|
||||
fileCounter += 1
|
||||
|
||||
|
||||
def main():
|
||||
# @todo We need to make this configurable using the command line so we can create disk images per project
|
||||
# @todo Load the config from a file that we specify instead of hardcoding everything
|
||||
# We can probably keep the os part hardcoded as that is not something we really need to change between different projects
|
||||
global out
|
||||
out = open('../tools/disk.img', 'wb')
|
||||
|
||||
|
@ -96,7 +114,9 @@ def main():
|
|||
|
||||
addFile("../cpm/.build/MONITOR.COM", "MONITOR", "COM")
|
||||
addFile("../cpm/bin/STAT.COM", "STAT", "COM")
|
||||
addFile("../xed/.build/XED.COM", "XED", "COM")
|
||||
addFile("../cpm/bin/MBASIC.COM", "MBASIC", "COM")
|
||||
addFile("../cpm/bin/s.com", "S", "COM")
|
||||
# addFile("../xed/.build/XED.COM", "XED", "COM")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
@ -26,11 +26,10 @@ def upload_rom(filename):
|
|||
# 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
|
||||
print("Init")
|
||||
ser.write(b'#')
|
||||
time.sleep(0.002)
|
||||
ser.write(b'u')
|
||||
|
@ -38,17 +37,65 @@ def upload_rom(filename):
|
|||
ser.write(b'\n')
|
||||
time.sleep(0.002)
|
||||
|
||||
print("Target")
|
||||
ser.write([0x01])
|
||||
time.sleep(0.02)
|
||||
|
||||
print("Length")
|
||||
size = os.path.getsize(filename)
|
||||
ser.write([size & 0xFF])
|
||||
time.sleep(0.002)
|
||||
ser.write([(size >> 8) & 0xFF])
|
||||
ser.write([size & 0xFF, (size >> 8) & 0xFF])
|
||||
time.sleep(0.02)
|
||||
|
||||
print("Data")
|
||||
with open(filename, "rb") as f:
|
||||
ser.write(f.read(size))
|
||||
|
||||
while ser.out_waiting > 0:
|
||||
pass
|
||||
|
||||
print("Done")
|
||||
|
||||
ser.close()
|
||||
|
||||
else:
|
||||
print("Failed to open serial port")
|
||||
|
||||
def upload_i2c(filename):
|
||||
# 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:
|
||||
ser.write(b'\n')
|
||||
time.sleep(0.002)
|
||||
|
||||
print("Init")
|
||||
ser.write(b'#')
|
||||
time.sleep(0.002)
|
||||
ser.write(b'u')
|
||||
time.sleep(0.002)
|
||||
ser.write(b'\n')
|
||||
time.sleep(0.002)
|
||||
|
||||
print("Target")
|
||||
ser.write([0x02])
|
||||
time.sleep(0.02)
|
||||
|
||||
print("Address")
|
||||
ser.write([0x29])
|
||||
time.sleep(0.02)
|
||||
|
||||
print("Length")
|
||||
size = os.path.getsize(filename)
|
||||
ser.write([size & 0xFF, (size >> 8) & 0xFF])
|
||||
time.sleep(0.02)
|
||||
|
||||
print("Data")
|
||||
with open(filename, "rb") as f:
|
||||
for i in progressbar(range(size), "Upload: ", 40):
|
||||
byte = f.read(1)
|
||||
ser.write(byte)
|
||||
time.sleep(0.002)
|
||||
ser.write(f.read(size))
|
||||
|
||||
while ser.out_waiting > 0:
|
||||
pass
|
||||
|
||||
print("Done")
|
||||
|
||||
ser.close()
|
||||
|
||||
|
@ -110,6 +157,7 @@ def main():
|
|||
parser.add_argument("--bload", dest="bload", action="store_const", const=True, default=False, help="Upload binary to bload")
|
||||
parser.add_argument("--mojo", dest="mojo", action="store_const", const=True, default=False, help="Upload binary to mojo")
|
||||
parser.add_argument("--sd", dest="sd", action="store_const", const=True, default=False, help="Upload binary to sd card")
|
||||
parser.add_argument("--i2c", dest="i2c", action="store_const", const=True, default=False, help="Upload binary to twiboot")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
@ -121,6 +169,8 @@ def main():
|
|||
upload_mojo(args.filename)
|
||||
elif (args.sd):
|
||||
upload_sd(args.filename)
|
||||
elif (args.i2c):
|
||||
upload_i2c(args.filename)
|
||||
else:
|
||||
print("You needs to specify a target")
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# This order makes it so we can use deactive to also deactive the other additions to the path
|
||||
sudo chown tim:tim /dev/sdb
|
||||
source $(dirname $(readlink -f $0))/env/bin/activate
|
||||
PATH=$(dirname $(readlink -f $0))/arm-none-eabi/bin:$(dirname $(readlink -f $0))/microblazeel-xilinx-elf/bin:$(dirname $(readlink -f $0))/bin:/opt/Xilinx/14.7/ISE_DS/EDK/bin/lin64:$PATH
|
||||
PATH=$(dirname $(readlink -f $0))/arm-none-eabi/bin:$(dirname $(readlink -f $0))/microblazeel-xilinx-elf/bin:$(dirname $(readlink -f $0))/bin:/opt/Xilinx/14.7/ISE_DS/EDK/bin/lin64:/opt/Xilinx/14.7/ISE_DS/ISE/bin/lin64:$PATH
|
||||
|
|
Loading…
Reference in New Issue
Block a user