Hardware sprites: 32 x 16x16 from 64 shapes, collisions, frame counter
rtl/sprites.v draws sprites between the graphics and the text from a pair of line buffers filled one graphics line ahead. Ports 70h-77h set position, shape, flip and on/off and load shapes; 78h is a frame counter; 80h-87h report sprite-sprite and sprite-graphics collisions per frame. The graphics fill (CLS) turns sprites off unless bit 7 is set. Testbench checks pixels, priority, flip, edge clipping, collisions and CLS. Manual, README and basic/examples/sprites.bas demo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c78073320b
commit
13373244e8
9 files changed
+480
-7
No files matched your search
+21
-2
@@ -5,6 +5,7 @@
|
||||
// 132 columns: 132x64 cells of 8x16 pixels, centred (112-pixel side borders)
|
||||
// 16 colours, underline, blink, block cursor and smooth-scroll offset for the
|
||||
// scroll region. The character buffer has a 132-cell stride in both layouts.
|
||||
// Hardware sprites (sprites.v) sit between the graphics and the text.
|
||||
// A 320x240 graphics layer (each pixel 4x4, the top 960 lines, so 80-column
|
||||
// text row r still starts at graphics line 8(r-1)) shows through wherever the
|
||||
// text is background; colour 0 is transparent.
|
||||
@@ -31,6 +32,13 @@ module text_display #(
|
||||
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,
|
||||
// sprites: the line to prepare next, and the pixel on screen
|
||||
output reg sp_go,
|
||||
output reg [7:0] sp_line,
|
||||
output sp_buf,
|
||||
output [8:0] sp_x,
|
||||
output sp_on,
|
||||
input [3:0] sp_pix, // read a clock after sp_x, like gfx_pix
|
||||
output reg [3:0] red,
|
||||
output reg [3:0] green,
|
||||
output reg [3:0] blue,
|
||||
@@ -47,6 +55,9 @@ module text_display #(
|
||||
|
||||
always @(posedge clk) begin
|
||||
frame_tick <= h == 0 && v == V_VIS;
|
||||
// each graphics line is 4 scan lines; ask for the next one as it starts
|
||||
sp_go <= h == 0 && v[1:0] == 2'd0 && (v < 11'd956 || v == 11'd1064);
|
||||
sp_line <= v == 11'd1064 ? 8'd0 : v[9:2] + 1'b1;
|
||||
if (rst) begin
|
||||
h <= 0;
|
||||
v <= 0;
|
||||
@@ -79,6 +90,8 @@ module text_display #(
|
||||
reg [2:0] a_bit;
|
||||
reg a_blank, a_text, a_vis, a_cur, a_hs, a_vs, a_gon;
|
||||
reg [16:0] a_gfx;
|
||||
reg [8:0] a_spx;
|
||||
reg a_spbuf;
|
||||
always @(posedge clk) begin
|
||||
a_base <= {trow, 7'd0} + {6'd0, trow, 2'd0};
|
||||
a_col <= tcol;
|
||||
@@ -92,11 +105,16 @@ module text_display #(
|
||||
a_vs <= v >= V_VIS + V_FP && v < V_VIS + V_FP + V_SYNC;
|
||||
a_gon <= v < 960;
|
||||
a_gfx <= {v[9:2], 8'd0} + {2'd0, v[9:2], 6'd0} + {8'd0, h[10:2]};
|
||||
a_spx <= h[10:2];
|
||||
a_spbuf <= v[2];
|
||||
end
|
||||
|
||||
// ---- clock 1: character RAM and graphics reads
|
||||
assign ram_addr = a_base + {6'd0, a_col};
|
||||
assign gfx_addr = a_gfx;
|
||||
assign sp_x = a_spx;
|
||||
assign sp_buf = a_spbuf;
|
||||
assign sp_on = a_gon;
|
||||
reg [3:0] b_line;
|
||||
reg [2:0] b_bit;
|
||||
reg b_blank, b_text, b_vis, b_cur, b_hs, b_vs, b_gon;
|
||||
@@ -109,13 +127,14 @@ module text_display #(
|
||||
initial $readmemh(FONT_FILE, font);
|
||||
reg [7:0] glyph;
|
||||
reg [17:0] c_cell;
|
||||
reg [3:0] c_gfx, c_line;
|
||||
reg [3:0] c_gfx, c_spr, c_line;
|
||||
reg [2:0] c_bit;
|
||||
reg c_blank, c_text, c_vis, c_cur, c_hs, c_vs;
|
||||
always @(posedge clk) begin
|
||||
glyph <= font[{ram_data[7:0], b_line}];
|
||||
c_cell <= ram_data;
|
||||
c_gfx <= b_gon ? gfx_pix : 4'd0;
|
||||
c_spr <= sp_pix;
|
||||
{c_line, c_bit, c_blank, c_text, c_vis, c_cur, c_hs, c_vs} <=
|
||||
{b_line, b_bit, b_blank, b_text, b_vis, b_cur, b_hs, b_vs};
|
||||
end
|
||||
@@ -136,7 +155,7 @@ module text_display #(
|
||||
// ---- clock 3: colour
|
||||
wire ink = (glyph[~c_bit] | (c_cell[16] && c_line == 4'd15)) && !(c_cell[17] && frame[5]);
|
||||
wire fg = c_text && !c_blank && (ink ^ c_cur);
|
||||
wire [3:0] idx = fg ? c_cell[11:8] : c_gfx != 4'd0 ? c_gfx :
|
||||
wire [3:0] idx = fg ? c_cell[11:8] : c_spr != 4'd0 ? c_spr : c_gfx != 4'd0 ? c_gfx :
|
||||
c_blank || !c_text ? 4'd0 : c_cell[15:12];
|
||||
always @(posedge clk) begin
|
||||
{red, green, blue} <= c_vis ? palette(idx) : 12'h000;
|
||||
|
||||
Reference in new issue
Block a user