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:
brad ArantandClaude Opus 5.5 committed 2026-11-27 21:09:43 -08:00
1 parent 59d5e617f2
commit dc7c7c22c5
14 files changed
+5205 -4141

No files matched your search

+51 -1
View File
@@ -9,7 +9,11 @@
// 01 in key (clears bit 0) out byte to the terminal
// 10 in millisecond counter bits 7:0; reading it latches bits 31:8 for 11-13
// 20 out 7-segment display, right two digits 21 out left two digits
// 30 out graphics X bits 7:0 31 out X bit 8 32 out Y
// 33 out plot colour at (X,Y), then X+1 in colour at (X,Y)
// 34 out fill the whole graphics screen in bit 0 = fill busy
//
// Graphics are 320x240 in 16 colours (0 = transparent), shown over the text.
// Writes below ROM_TOP are ignored so a crashed program cannot damage BASIC.
module z80_system #(
parameter MEM_FILE = "basic.mem",
@@ -27,7 +31,11 @@ module z80_system #(
output reg [7:0] tx_data,
input tx_ack,
output reg [15:0] seg_val,
output halted
output halted,
// graphics layer read port, on the video clock
input vclk,
input [16:0] gfx_vaddr,
output reg [3:0] gfx_vpix
);
wire [15:0] ma, io_addr;
wire we, io_rd, io_wr;
@@ -57,6 +65,46 @@ module z80_system #(
wire rx_avail = rx_req_s[1] != rx_ack;
wire tx_ready = tx_ack_s[1] == tx_req;
// ------------------------------------------------------------ graphics
localparam GFX_PIXELS = 320 * 240;
(* ram_style = "block" *) reg [3:0] gfx [0:GFX_PIXELS - 1];
integer gi;
initial for (gi = 0; gi < GFX_PIXELS; gi = gi + 1) gfx[gi] = 4'd0;
reg [8:0] gx;
reg [7:0] gy;
reg [3:0] gfx_q, fill_c;
reg [16:0] fill_a;
reg fill_busy;
wire [16:0] gxy = {gy, 8'd0} + {2'd0, gy, 6'd0} + {8'd0, gx};
wire plot = io_wr && io_addr[7:0] == 8'h33 && gx < 9'd320 && gy < 8'd240;
wire [16:0] g_addr = fill_busy ? fill_a : gxy;
always @(posedge clk) begin
if (fill_busy || plot) gfx[g_addr] <= fill_busy ? fill_c : io_wd[3:0];
gfx_q <= gfx[g_addr];
end
always @(posedge vclk) gfx_vpix <= gfx[gfx_vaddr];
always @(posedge clk)
if (rst) begin
fill_busy <= 1'b0;
gx <= 9'd0; gy <= 8'd0;
end else begin
if (io_wr) case (io_addr[7:0])
8'h30: gx[7:0] <= io_wd;
8'h31: gx[8] <= io_wd[0];
8'h32: gy <= io_wd;
8'h33: gx <= gx + 1'b1;
8'h34: begin fill_busy <= 1'b1; fill_a <= 17'd0; fill_c <= io_wd[3:0]; end
default: ;
endcase
if (fill_busy) begin
fill_a <= fill_a + 1'b1;
if (fill_a == GFX_PIXELS - 1) fill_busy <= 1'b0;
end
end
// millisecond timer
localparam MS_DIV = CPU_HZ / 1000;
reg [31:0] ms, ms_latch;
@@ -76,6 +124,8 @@ module z80_system #(
8'h11: io_din = ms_latch[15:8];
8'h12: io_din = ms_latch[23:16];
8'h13: io_din = ms_latch[31:24];
8'h33: io_din = {4'd0, gfx_q};
8'h34: io_din = {7'd0, fill_busy};
default: io_din = 8'hFF;
endcase