Files
T
brad ArantandClaude Opus 5.5 5930b958b4 Basys 3 RISC-V computer
The Basys 3 Z-80 computer with the Z-80 replaced by an RV32IM processor
written from scratch (rtl/rv32_cpu.v): multi-cycle, 90 MHz, CSRs and
traps, interrupts, two hardware triggers and a resumable NMI for the
monitor. Passes riscv-tests rv32ui/um/mi.

rv32_system.v keeps all the Z-80 machine's peripherals, with I/O port N
at FFFFFF00h + N, 80 KB of RAM with BASIC preloaded, and a 32 KB monitor
ROM. BASIC, the five games and the monitor (with an RV32 disassembler,
assembler, breakpoints and single step) are ported to RISC-V GCC. Python
emulator and tests in tools/; full-system simulation in sim/.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 18:09:18 -08:00

135 lines
4.1 KiB
Python

#!/usr/bin/env python3
"""Make data.h for warden.c: the sprite shapes and the planet's mountains.
Shapes are 16 rows of 16 hex digits, one colour per pixel (0 is see-through).
The planet is 1,280 pixels round; the mountains are a height for every column,
made by midpoint displacement so that they join up where the world wraps.
"""
import random
import sys
SHIP = ["0" * 16] * 5 + [
"0F00000000000000",
"0FF0000066000000",
"BFFFFFF666600000",
"BFFFFFFFFFFFFF00",
"0CCCCCCCCCCCC000",
"0FF0000000000000",
"0F00000000000000",
] + ["0" * 16] * 4
LANDER = ["0" * 16] * 3 + [
"00000BBBBBB00000",
"0000BBBBBBBB0000",
"000AAAAAAAAAA000",
"00AA2AA2AA2AAA00",
"00AAAAAAAAAAAA00",
"000AAAAAAAAAA000",
"0000A00AA00A0000",
"000A000AA000A000",
"00A0000AA0000A00",
] + ["0" * 16] * 4
MUTANT = ["0" * 16] * 2 + [
"0000D00000D00000",
"00000D000D000000",
"000DDDDDDDDD0000",
"00DDAADDDAADD000",
"0DDDAADDDAADDD00",
"00DDDDDDDDDDD000",
"000D0D0D0D0D0000",
"00D0D0D0D0D0D000",
] + ["0" * 16] * 6
BOMBER = ["0" * 16] * 4 + [
"0000CCCCCCCC0000",
"0000C444444C0000",
"0000C4EEEE4C0000",
"0000C4EEEE4C0000",
"0000C444444C0000",
"0000CCCCCCCC0000",
] + ["0" * 16] * 6
MINE = ["0" * 16] * 6 + [
"0000000990000000",
"000000999F000000",
"000000F999000000",
"0000000990000000",
] + ["0" * 16] * 6
HUMAN = ["0" * 16] * 6 + [
"0000000FF0000000",
"0000000FF0000000",
"000000DDDD000000",
"00000D0DD0D00000",
"0000000DD0000000",
"0000000CC0000000",
"000000C00C000000",
"000000C00C000000",
] + ["0" * 16] * 2
LASER = ["0" * 16] * 8 + ["BFFFFFFFFFFFFFFB"] + ["0" * 16] * 7
SHOT = ["0" * 16] * 7 + ["0000000F90000000", "00000009F0000000"] + ["0" * 16] * 7
def burst(seed, cols, size):
import math
r = random.Random(seed)
img = [["0"] * 16 for _ in range(16)]
for _ in range(90):
a = r.uniform(0, 2 * math.pi)
d = r.uniform(0, size)
x, y = int(8 + d * math.cos(a)), int(8 + d * math.sin(a))
if 0 <= x < 16 and 0 <= y < 16:
img[y][x] = cols[0] if d < size / 3 else cols[1] if d < 2 * size / 3 else cols[2]
return ["".join(row) for row in img]
BOOM1 = burst(7, "FB9", 5)
BOOM2 = burst(9, "B91", 7.5)
SHIPBOOM = burst(11, "FFB", 7.9)
SHAPES = [("S_SHIP", SHIP), ("S_LANDER", LANDER), ("S_MUTANT", MUTANT), ("S_BOMBER", BOMBER),
("S_MINE", MINE), ("S_HUMAN", HUMAN), ("S_LASER", LASER), ("S_SHOT", SHOT),
("S_BOOM1", BOOM1), ("S_BOOM2", BOOM2), ("S_SHIPBOOM", SHIPBOOM)]
WORLD = 1280
def mountains():
r = random.Random(2084)
n = WORLD
h = [0.0] * n
step = 256 # 1280 = 5 x 256, so halving reaches every column
for i in range(0, n, step):
h[i] = r.uniform(150, 205)
amp = 48.0
while step > 1:
half = step // 2
for i in range(0, n, step):
a, b = h[i], h[(i + step) % n]
h[i + half] = (a + b) / 2 + r.uniform(-amp, amp)
step = half
amp *= 0.62
assert all(v > 0 for v in h), "a column was missed"
return [max(118, min(222, int(v))) for v in h]
def main(out):
L = ["/* made by gen.py - edit that instead */", ""]
for i, (name, img) in enumerate(SHAPES):
assert len(img) == 16 and all(len(row) == 16 for row in img), name
L.append("#define %s %d" % (name, i))
L.append("#define N_SHAPES %d" % len(SHAPES))
L.append("#define WORLD %d" % WORLD)
L.append("static const u8 shape_data[N_SHAPES * 128] = {")
for name, img in SHAPES:
b = [int(row[x], 16) << 4 | int(row[x + 1], 16) for row in img for x in range(0, 16, 2)]
L.append(" " + ",".join(str(v) for v in b) + ", /* %s */" % name)
L.append("};")
m = mountains()
L.append("static const u8 mountain[WORLD] = {")
for k in range(0, WORLD, 32):
L.append(" " + ",".join(str(v) for v in m[k:k + 32]) + ",")
L.append("};")
open(out, "w").write("\n".join(L) + "\n")
print("data.h: %d shapes, mountains %d-%d" % (len(SHAPES), min(m), max(m)))
if __name__ == "__main__":
main(sys.argv[1] if len(sys.argv) > 1 else "data.h")