Add a 640x480 two-colour graphics mode; start in white
The graphics memory doubles as 640x480 at a bit a pixel (port 38), four pixels to an entry, plotted by read-modify-write, in two colours from port 39 (0 transparent). BASIC gets SCREEN 0 / SCREEN 1 [,set[,clear]]; a plain fill (as every game does) returns to 320x240 and BASIC follows. The text now starts in white (SW5:4 = 00; 10 is green). The README is rewritten to stand on its own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
71fd403294
commit
bda9bb67b6
13 files changed
+2985
-2680
No files matched your search
+49
-17
@@ -24,15 +24,21 @@
|
||||
// 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
|
||||
// 30 out graphics X bits 7:0 31 out X bits 9:8, Y bit 8 (bit 2)
|
||||
// 32 out Y bits 7:0
|
||||
// 33 out plot colour at (X,Y), then X+1 in colour at (X,Y)
|
||||
// (in 640x480 mode a pixel is 0 or 1: any non-zero colour sets it)
|
||||
// 34 out fill the whole graphics screen in bit 0 = fill busy
|
||||
// (also turns the sprites off and the scroll back to 0, unless
|
||||
// bit 7 is set)
|
||||
// (also turns the sprites off, the scroll back to 0 and the
|
||||
// 320x240 mode back on, unless bit 7 is set)
|
||||
// 35 out scroll: buffer X shown at the left, bits 7:0
|
||||
// 36 out bit 0 = scroll X bit 8; bit 1 = hide the graphics in a border (4
|
||||
// columns each side, 2 rows top and bottom) to draw in unseen
|
||||
// 37 out scroll: buffer Y shown at the top (0-239)
|
||||
// 38 i/o bit 0 = 640x480 in two colours (the same memory, a bit a pixel;
|
||||
// no scrolling or border) instead of 320x240 in 16
|
||||
// 39 out 640x480 colours: bits 3:0 for a set pixel, 7:4 for a clear one
|
||||
// (0 = transparent, the text's background showing through)
|
||||
// 40 SPI flash control, 41 SPI flash data (see flash_spi.v)
|
||||
// 60 out bit 1 = stop again (NMI) after one instruction of the program
|
||||
// in why the last NMI came: 1 Pause key, 2 port 61, 3 step,
|
||||
@@ -89,6 +95,8 @@ module rv32_system #(
|
||||
output reg [8:0] scroll_x,
|
||||
output reg [7:0] scroll_y,
|
||||
output reg g_border,
|
||||
output reg g_hires, // 640x480, 1 bit a pixel
|
||||
output reg [7:0] g_cols, // its colours: {clear, set}
|
||||
// sprites, on the video clock (see sprites.v)
|
||||
input sp_go,
|
||||
input [7:0] sp_line,
|
||||
@@ -254,7 +262,10 @@ module rv32_system #(
|
||||
|
||||
// ------------------------------------------------------------ graphics
|
||||
// 76800 pixels: a 64K array and an 11264 one, so they take about 9.5 block
|
||||
// RAMs (one array would be built as 96K deep, 12 of them).
|
||||
// RAMs (one array would be built as 96K deep, 12 of them). In 640x480 mode
|
||||
// each 4-bit entry holds four pixels side by side (bit 0 the leftmost):
|
||||
// entry y*160 + x/4. A plot there reads the entry and writes it back the
|
||||
// next clock with one bit changed.
|
||||
localparam GFX_PIXELS = 320 * 240;
|
||||
(* ram_style = "block" *) reg [3:0] gfx_lo [0:65535];
|
||||
(* ram_style = "block" *) reg [3:0] gfx_hi [0:GFX_PIXELS - 65536 - 1];
|
||||
@@ -264,18 +275,31 @@ module rv32_system #(
|
||||
for (gi = 0; gi < GFX_PIXELS - 65536; gi = gi + 1) gfx_hi[gi] = 4'd0;
|
||||
end
|
||||
|
||||
reg [8:0] gx;
|
||||
reg [7:0] gy;
|
||||
reg [9:0] gx;
|
||||
reg [8:0] gy;
|
||||
reg [3:0] gfx_q_lo, gfx_q_hi, fill_c;
|
||||
reg gfx_q_sel;
|
||||
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 == 8'h33 && gx < 9'd320 && gy < 8'd240;
|
||||
wire [16:0] g_addr = fill_busy ? fill_a : gxy;
|
||||
wire g_we = fill_busy || plot;
|
||||
wire [3:0] g_wd = fill_busy ? fill_c : io_wd[3:0];
|
||||
wire [16:0] lxy = {gy[7:0], 8'd0} + {2'd0, gy[7:0], 6'd0} + {7'd0, gx}; // y*320 + x
|
||||
wire [16:0] hxy = {gy, 7'd0} + {2'd0, gy, 5'd0} + {9'd0, gx[9:2]}; // y*160 + x/4
|
||||
wire plot = io_wr && io_addr == 8'h33 &&
|
||||
(g_hires ? gx < 10'd640 && gy < 9'd480 : gx < 10'd320 && gy < 9'd240);
|
||||
reg rmw; // 640x480 plot: write the entry read last clock
|
||||
reg [16:0] rmw_a;
|
||||
reg [1:0] rmw_bit;
|
||||
reg rmw_v;
|
||||
wire [3:0] gfx_q = gfx_q_sel ? gfx_q_hi : gfx_q_lo;
|
||||
wire [3:0] rmw_wd = (gfx_q & ~(4'd1 << rmw_bit)) | ({3'd0, rmw_v} << rmw_bit);
|
||||
wire [16:0] g_addr = fill_busy ? fill_a : rmw ? rmw_a : g_hires ? hxy : lxy;
|
||||
wire g_we = fill_busy || (plot && !g_hires) || rmw;
|
||||
wire [3:0] g_wd = fill_busy ? fill_c : rmw ? rmw_wd : io_wd[3:0];
|
||||
always @(posedge clk) begin
|
||||
rmw <= plot && g_hires && !fill_busy;
|
||||
rmw_a <= hxy;
|
||||
rmw_bit <= gx[1:0];
|
||||
rmw_v <= io_wd != 8'd0;
|
||||
end
|
||||
|
||||
always @(posedge clk) begin
|
||||
if (g_we && !g_addr[16]) gfx_lo[g_addr[15:0]] <= g_wd;
|
||||
@@ -303,21 +327,28 @@ module rv32_system #(
|
||||
always @(posedge clk)
|
||||
if (rst) begin
|
||||
fill_busy <= 1'b0;
|
||||
gx <= 9'd0; gy <= 8'd0;
|
||||
gx <= 10'd0; gy <= 9'd0;
|
||||
scroll_x <= 9'd0; scroll_y <= 8'd0; g_border <= 1'b0;
|
||||
g_hires <= 1'b0; g_cols <= 8'h0F;
|
||||
end else begin
|
||||
if (io_wr) case (io_addr)
|
||||
8'h30: gx[7:0] <= io_wd;
|
||||
8'h31: gx[8] <= io_wd[0];
|
||||
8'h32: gy <= io_wd;
|
||||
8'h31: begin gx[9:8] <= io_wd[1:0]; gy[8] <= io_wd[2]; end
|
||||
8'h32: gy[7:0] <= 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];
|
||||
if (!io_wd[7]) begin scroll_x <= 9'd0; scroll_y <= 8'd0; g_border <= 1'b0; end
|
||||
fill_busy <= 1'b1; fill_a <= 17'd0;
|
||||
// in 640x480 mode a colour fills all four pixels of each entry
|
||||
fill_c <= g_hires && io_wd[7] ? {4{io_wd[3:0] != 4'd0}} : io_wd[3:0];
|
||||
if (!io_wd[7]) begin
|
||||
scroll_x <= 9'd0; scroll_y <= 8'd0; g_border <= 1'b0; g_hires <= 1'b0;
|
||||
end
|
||||
end
|
||||
8'h35: scroll_x[7:0] <= io_wd;
|
||||
8'h36: begin scroll_x[8] <= io_wd[0]; g_border <= io_wd[1]; end
|
||||
8'h37: scroll_y <= io_wd >= 8'd240 ? io_wd - 8'd240 : io_wd;
|
||||
8'h38: g_hires <= io_wd[0];
|
||||
8'h39: g_cols <= io_wd;
|
||||
default: ;
|
||||
endcase
|
||||
if (fill_busy) begin
|
||||
@@ -439,8 +470,9 @@ module rv32_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'h33: io_din = g_hires ? {7'd0, gfx_q[gx[1:0]]} : {4'd0, gfx_q};
|
||||
8'h34: io_din = {7'd0, fill_busy};
|
||||
8'h38: io_din = {7'd0, g_hires};
|
||||
8'h40: io_din = fl_ctl_q;
|
||||
8'h41: io_din = fl_dat_q;
|
||||
8'h60: io_din = {5'd0, why};
|
||||
|
||||
Reference in new issue
Block a user