sound chips added to pld file and added sn76489 test

This commit is contained in:
Joppe Blondel
2026-10-17 13:30:54 +02:00
parent 55012d8b7b
commit ebf409745d
20 changed files with 2972 additions and 264 deletions
+20 -8
View File
@@ -106,11 +106,10 @@ class PulseWriter:
self.bytes(struct.pack("<H", crc16(block_data)))
self.byte(0x00) # Make sure the last byte has its last edge
def header(pulses: PulseWriter, path:Path) -> None:
def header(pulses: PulseWriter, path:Path, file_size: int) -> None:
fname = path.name
fsize = os.path.getsize(path)
data = (
struct.pack("<HH", math.ceil(fsize/BLOCK_SIZE), fsize)
struct.pack("<HH", math.ceil(file_size/BLOCK_SIZE), file_size)
+ fname.encode()[:32].ljust(32, b' ')
)
pulses.block(TYPE_BINARY, data)
@@ -126,6 +125,12 @@ def main() -> None:
)
parser.add_argument("input", type=Path, help="input file to encode")
parser.add_argument("output", type=Path, help="output WAV file")
parser.add_argument(
"--max-size",
type=int,
metavar="BYTES",
help="encode at most this many bytes from the input file",
)
parser.add_argument("--sample-rate", type=int, default=48_000)
parser.add_argument(
"--t-short",
@@ -152,6 +157,13 @@ def main() -> None:
parser.error("--t-short must be less than --t-long")
if not 0.0 <= args.amplitude <= 1.0:
parser.error("--amplitude must be between 0 and 1")
if args.max_size is not None and args.max_size < 0:
parser.error("--max-size must not be negative")
input_size = os.path.getsize(args.input)
encoded_size = (
input_size if args.max_size is None else min(input_size, args.max_size)
)
try:
pulses = PulseWriter(
@@ -165,14 +177,14 @@ def main() -> None:
# create header block
pulses.space(5.0)
header(pulses, args.input)
header(pulses, args.input, encoded_size)
pulses.space(1.0)
with open(args.input, "rb") as f:
while True:
data = f.read(BLOCK_SIZE)
if not len(data):
break
remaining = encoded_size
while remaining:
data = f.read(min(BLOCK_SIZE, remaining))
raw(pulses, data)
remaining -= len(data)
pulses.space(1.0)
with wave.open(str(args.output), "wb") as wav: