BASIC graphics: 320x240 16-colour layer, manual and demo
- z80_system: dual-clock graphics RAM behind ports 30h-34h (X/Y, plot with auto-increment, read-back, hardware fill); text_display overlays it under the text, colour 0 transparent. - BASIC: CLS COLOR PLOT LINE RECT FILL CIRCLE POINT, LOCATE and INK; faster keyword tokenizing. - docs/basic-manual.md (+ PDF via docs/build-manual.sh). - basic/examples/graphics-demo.bas and tools/send-bas.py to load programs over the serial port. - Simulation checks drawing and saves a frame; the emulator models the graphics and timer ports and can stop when BASIC waits for input. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
59d5e617f2
commit
dc7c7c22c5
14 files changed
+5205
-4141
No files matched your search
+14
-1
@@ -35,6 +35,9 @@ class Z80:
|
||||
self.inp = bytearray(inp)
|
||||
self.out = out if out is not None else bytearray()
|
||||
self.rom_top = 0
|
||||
self.count = 0
|
||||
self.idle = 0
|
||||
self.last_poll = 0
|
||||
|
||||
# ------------------------------------------------------------- helpers
|
||||
def rd(self, a):
|
||||
@@ -78,9 +81,16 @@ class Z80:
|
||||
def io_in(self, port):
|
||||
p = port & 0xFF
|
||||
if p == 0:
|
||||
if not self.inp: # back-to-back polls: waiting for a key
|
||||
self.idle = self.idle + 1 if self.count - self.last_poll < 30 else 0
|
||||
self.last_poll = self.count
|
||||
return (1 if self.inp else 0) | 2
|
||||
if p == 1:
|
||||
return self.inp.pop(0) if self.inp else 0
|
||||
if 0x10 <= p <= 0x13: # ~3 clocks per instruction at 90 MHz
|
||||
return (self.count * 3 // 90000) >> (8 * (p - 0x10)) & 0xFF
|
||||
if p in (0x33, 0x34): # graphics: nothing drawn, never busy
|
||||
return 0
|
||||
return 0xFF
|
||||
|
||||
def io_out(self, port, v):
|
||||
@@ -525,16 +535,19 @@ def main():
|
||||
ap.add_argument("--trace", help="write a register trace here")
|
||||
ap.add_argument("--max", type=int, default=10_000_000, help="instruction limit")
|
||||
ap.add_argument("--rom-top", type=lambda s: int(s, 0), default=0)
|
||||
ap.add_argument("--stop-idle", action="store_true",
|
||||
help="stop once the input is used up and the program waits for a key")
|
||||
a = ap.parse_args()
|
||||
inp = open(a.input, "rb").read() if a.input else b""
|
||||
cpu = Z80(open(a.image, "rb").read(), inp)
|
||||
cpu.rom_top = a.rom_top
|
||||
tr = open(a.trace, "w") if a.trace else None
|
||||
n = 0
|
||||
while not cpu.halted and n < a.max:
|
||||
while not cpu.halted and n < a.max and not (a.stop_idle and cpu.idle > 100):
|
||||
if tr: tr.write(fmt(cpu.state()) + "\n")
|
||||
cpu.step()
|
||||
n += 1
|
||||
cpu.count = n
|
||||
sys.stdout.write(cpu.out.decode("latin-1"))
|
||||
if tr:
|
||||
open(a.trace.replace("trace", "mem"), "w").write("".join("%02x\n" % v for v in cpu.m[32768:]))
|
||||
|
||||
Reference in new issue
Block a user