basic loading and saving

This commit is contained in:
Joppe Blondel
2026-10-10 12:34:48 +02:00
parent 6374a070ea
commit 7d7ab196c3
2 changed files with 340 additions and 169 deletions
+9 -4
View File
@@ -10,7 +10,9 @@ from pathlib import Path
BLOCK_SIZE = 128
TYPE_RAW = 0
TYPE_HEADER = 1
TYPE_BINARY = 1
TYPE_BAS_PROG = 2
TYPE_BAS_ARR = 3
def crc16(data: bytes) -> int:
"""Calculate CRC-16/CCITT-FALSE."""
@@ -107,9 +109,12 @@ class PulseWriter:
def header(pulses: PulseWriter, path:Path) -> None:
fname = path.name
fsize = os.path.getsize(path)
data = struct.pack("<H", math.ceil(fsize/BLOCK_SIZE)) + fname.encode()[:32].ljust(32, b' ')
pulses.block(TYPE_HEADER, data)
pulses.block(TYPE_HEADER, data)
data = (
struct.pack("<HH", math.ceil(fsize/BLOCK_SIZE), fsize)
+ fname.encode()[:32].ljust(32, b' ')
)
pulses.block(TYPE_BINARY, data)
pulses.block(TYPE_BINARY, data)
def raw(pulses: PulseWriter, data:bytes) -> None:
pulses.block(TYPE_RAW, data)