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:
brad ArantandClaude Opus 5.5 committed 2026-11-29 08:36:41 -08:00
1 parent c78073320b
commit 13373244e8
9 files changed
+480 -7

No files matched your search

+39
View File
@@ -359,6 +359,45 @@ module tb_terminal;
end
capture_frame("frame_3.ppm");
// ---- sprites: shape 0 solid colour 9, shape 1 solid 2, shape 2 left
// half 14; sprite 0 over sprite 1, sprite 2 flipped at the right edge
// over a filled strip
uart_str({"CLS:OUT 118,0:FOR I=1 TO 128:OUT 119,153:NEXT I:",
"OUT 118,1:FOR I=1 TO 128:OUT 119,34:NEXT I\015"});
uart_str({"OUT 118,2:FOR I=1 TO 16:FOR J=1 TO 4:OUT 119,238:NEXT J:",
"FOR J=1 TO 4:OUT 119,0:NEXT J:NEXT I\015"});
uart_str({"OUT 112,0:OUT 113,100:OUT 114,0:OUT 115,150:OUT 116,0:OUT 117,1:",
"OUT 112,1:OUT 113,108:OUT 114,0:OUT 115,158:OUT 116,1:OUT 117,1\015"});
uart_str({"FILL 0,200,319,239,4:OUT 112,2:OUT 113,54:OUT 114,1:OUT 115,230:",
"OUT 116,2:OUT 117,3\015"});
#40_000_000;
@(posedge vs); @(posedge vs); @(posedge vs);
uart_str("LOCATE 30,1:PRINT INP(128);INP(129);INP(132)\015");
wait_row(29, " 3 0 4");
capture_frame("frame_5.ppm");
// graphics pixel (x, y) is screen pixel (4x+2, 4y+2)
if (fb[(4*151+2)*1280 + 4*101+2] == 12'hF55 && // sprite 0
fb[(4*162+2)*1280 + 4*112+2] == 12'hF55 && // sprite 0 over sprite 1
fb[(4*170+2)*1280 + 4*120+2] == 12'h0A0 && // sprite 1
fb[(4*150+2)*1280 + 4*99+2] == 12'h000 && // beside them
fb[(4*235+2)*1280 + 4*312+2] == 12'h00A && // flipped: clear half
fb[(4*235+2)*1280 + 4*318+2] == 12'h5FF) // flipped: coloured half
$display("PASS sprites on screen");
else begin
$display("FAIL sprites on screen: %h %h %h %h %h %h",
fb[(4*151+2)*1280 + 4*101+2], fb[(4*162+2)*1280 + 4*112+2],
fb[(4*170+2)*1280 + 4*120+2], fb[(4*150+2)*1280 + 4*99+2],
fb[(4*235+2)*1280 + 4*312+2], fb[(4*235+2)*1280 + 4*318+2]);
errors = errors + 1;
end
uart_str("CLS\015");
#5_000_000;
if (dut.z80.spr.en == 32'd0) $display("PASS CLS turns sprites off");
else begin
$display("FAIL CLS left sprites on: %h", dut.z80.spr.en);
errors = errors + 1;
end
// ---- files in the flash, and the bitstream protection
uart_str({"CLS:DATE \"2026-11-28 09:30\":NEW\01510 PRINT \"SAVED\";6*7\015SAVE \"TEST1\"\015NEW\015",
"LOAD \"TEST1\"\015RUN\015DIR\015"});