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
@@ -268,12 +268,15 @@ module basys3_terminal #(
|
||||
always @(posedge clk) ztx_req_s <= {ztx_req_s[0], ztx_req};
|
||||
|
||||
wire [15:0] z80_seg;
|
||||
wire [16:0] gfx_addr;
|
||||
wire [3:0] gfx_pix;
|
||||
|
||||
z80_system #(.MEM_FILE(MEM_FILE), .CPU_HZ(CPU_HZ)) z80 (
|
||||
.clk(cpu_clk), .rst(cpu_rst_s[2]),
|
||||
.rx_req(zrx_req), .rx_data(zrx_data), .rx_ack(zrx_ack),
|
||||
.tx_req(ztx_req), .tx_data(ztx_data), .tx_ack(ztx_ack),
|
||||
.seg_val(z80_seg), .halted()
|
||||
.seg_val(z80_seg), .halted(),
|
||||
.vclk(clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix)
|
||||
);
|
||||
|
||||
// terminal input: Z-80 output or received bytes, local echo, banner
|
||||
@@ -358,7 +361,7 @@ module basys3_terminal #(
|
||||
text_display #(.FONT_FILE(FONT_FILE)) video (
|
||||
.clk(clk), .rst(rst), .cur_row(cur_row), .cur_col(cur_col), .cur_vis(cur_vis),
|
||||
.stop(stop), .sbot(sbot), .sm_on(sm_on), .sm_dir(sm_dir), .sm_off(sm_off),
|
||||
.ram_addr(v_addr), .ram_data(v_data),
|
||||
.ram_addr(v_addr), .ram_data(v_data), .gfx_addr(gfx_addr), .gfx_pix(gfx_pix),
|
||||
.red(vgaRed), .green(vgaGreen), .blue(vgaBlue), .hsync(Hsync), .vsync(Vsync),
|
||||
.frame_tick(frame_tick)
|
||||
);
|
||||
|
||||
+8
-1
@@ -2,6 +2,8 @@
|
||||
|
||||
// 640x480 @ 60 Hz VGA text display: 80x30 cells of 8x16 pixels, 16 colours,
|
||||
// underline, blink, block cursor and smooth-scroll offset for the scroll region.
|
||||
// A 320x240 graphics layer (each pixel 2x2) shows through wherever the text is
|
||||
// background; graphics colour 0 is transparent.
|
||||
// Runs on the 100 MHz clock with a 25 MHz pixel enable. After each pixel tick:
|
||||
// clock 1 scanline values registered (row base address, glyph line)
|
||||
// clock 2 character RAM read
|
||||
@@ -23,6 +25,8 @@ module text_display #(
|
||||
input [4:0] sm_off, // pixels the region has moved
|
||||
output [11:0] ram_addr,
|
||||
input [17:0] ram_data, // {blink, underline, bg, fg, code}
|
||||
output [16:0] gfx_addr, // graphics pixel, read a clock later
|
||||
input [3:0] gfx_pix,
|
||||
output reg [3:0] red,
|
||||
output reg [3:0] green,
|
||||
output reg [3:0] blue,
|
||||
@@ -75,6 +79,7 @@ module text_display #(
|
||||
|
||||
wire [6:0] tcol = h[9:3];
|
||||
assign ram_addr = row_base + {5'b0, tcol};
|
||||
assign gfx_addr = {v[8:1], 8'd0} + {2'd0, v[8:1], 6'd0} + {8'd0, h[9:1]};
|
||||
|
||||
reg [7:0] font [0:4095];
|
||||
reg [7:0] glyph;
|
||||
@@ -97,7 +102,9 @@ module text_display #(
|
||||
wire visible = h < H_VIS && v < V_VIS;
|
||||
wire cursor = cur_vis && frame[5] && tcol == cur_col && srow == cur_row;
|
||||
wire ink = (glyph[~h[2:0]] | (ram_data[16] && line == 4'd15)) && !(ram_data[17] && frame[5]);
|
||||
wire [3:0] idx = blank_line ? 4'd0 : (ink ^ cursor) ? ram_data[11:8] : ram_data[15:12];
|
||||
wire fg = !blank_line && (ink ^ cursor);
|
||||
wire [3:0] idx = fg ? ram_data[11:8] : gfx_pix != 4'd0 ? gfx_pix :
|
||||
blank_line ? 4'd0 : ram_data[15:12];
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (tick) begin
|
||||
|
||||
+51
-1
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user