huc6270: Fix some sprites not rendered

This commit is contained in:
David Hunter
2025-12-31 00:11:27 -08:00
parent a4562b4216
commit aace72f0db
4 changed files with 95 additions and 13 deletions

View File

@@ -277,7 +277,7 @@ reg SPR_FETCH_DONE;
reg SPR_FETCH_W;
reg [9:0] SPR_OUT_X;
wire SPR_CE;
wire [31:0] SPR_MAX;
wire [6:0] SPR_MAX;
reg [2:0] FETCH_DOT;
reg FETCH_CE;
wire [2:0] FDOT_CNT;
@@ -363,7 +363,7 @@ reg CLR_WE;
assign FDOT_CNT = SP64 == 1'b0 ? DOT_CNT : FETCH_DOT;
assign SPR_CE = SP64 == 1'b0 ? DCK_CE : FETCH_CE;
assign SPR_MAX = SP64 == 1'b0 ? 15 : 63;
assign SPR_MAX = SP64 == 1'b0 ? 7'd15 : 7'd63;
assign HSW_END_POS = {2'b00,HSW} + ({6'b000000,RES7M});
assign HDS_END_POS = ({2'b00,HSW}) + ({6'b000000,RES7M}) + 1 + (HDS);
assign HDISP_END_POS = ({2'b00,HSW}) + ({6'b000000,RES7M}) + 1 + (HDS) + 1 + (HDW);
@@ -1055,10 +1055,6 @@ reg CLR_WE;
//else begin
// SPR_CACHE[SPR_EVAL_CNT[5:0]].BOTTOM <= 1'b0;
//end
//SPR_EVAL_CNT <= SPR_EVAL_CNT + 1;
//if(SPR_EVAL_CNT == SPR_MAX) begin
// SPR_EVAL_FULL <= 1'b1;
//end
Sprite_r spr_cache_rhs;
spr_cache_rhs.X = SPR_X;
spr_cache_rhs.Y = SPR_Y;
@@ -1074,6 +1070,11 @@ reg CLR_WE;
spr_cache_rhs.TOP = RC_CNT == SPR_Y;
spr_cache_rhs.BOTTOM = RC_CNT == (SPR_Y + 10'(SPR_H));
SPR_CACHE[SPR_EVAL_CNT[5:0]] <= spr_cache_rhs;
SPR_EVAL_CNT <= SPR_EVAL_CNT + 1;
if(SPR_EVAL_CNT == SPR_MAX) begin
SPR_EVAL_FULL <= 1'b1;
end
end
else begin
if(`CR_IE_OC == 1'b1) begin

1
rtl/tb/.gitignore vendored
View File

@@ -1 +1,2 @@
/rombios.bin
/frames/

View File

@@ -7,6 +7,7 @@
`timescale 1us / 1ns
//`define USE_IOCTL_FOR_LOAD 1
`define SAVE_FRAMES 1
module mycore_tb;
@@ -50,6 +51,11 @@ reg [24:0] ioctl_addr;
reg [15:0] ioctl_dout;
wire ioctl_wait;
wire pce;
wire hbl, vbl;
wire vs;
wire [7:0] r, g, b;
mycore mycore
(
.clk_sys(clk_sys),
@@ -79,16 +85,16 @@ mycore mycore
.SDRAM_nRAS(SDRAM_nRAS),
.SDRAM_nWE(SDRAM_nWE),
.ce_pix(),
.ce_pix(pce),
.HBlank(),
.HBlank(hbl),
.HSync(),
.VBlank(),
.VSync(),
.VBlank(vbl),
.VSync(vs),
.R(),
.G(),
.B()
.R(r),
.G(g),
.B(b)
);
initial begin
@@ -202,16 +208,68 @@ endtask
//////////////////////////////////////////////////////////////////////
`ifdef SAVE_FRAMES
integer frame = 0;
integer fpic;
logic pice;
string fname;
initial fpic = -1;
always @(negedge vs) begin
if (fpic != -1) begin
$fclose(fpic);
fpic = -1;
`ifdef VERILATOR
$system({"python3 render2png.py ", fname, {".hex "}, fname, ".png; rm ", fname, ".hex"});
`endif
end
$display("%t: Frame %03d", $time, frame);
$sformat(fname, "frames/render-%03d", frame);
pice = 0;
if ((frame % 1) == 0) begin
fpic = $fopen({fname, ".hex"}, "w");
end
frame = frame + 1;
end
final
$fclose(fpic);
wire de = ~(hbl | vbl);
always @(posedge clk_sys) begin
if (fpic != -1 && pce) begin
if (de) begin
$fwrite(fpic, "%x", {r, g, b});
pice = 1;
end
else if (pice) begin
pice = 0;
$fwrite(fpic, "\n");
end
end
end
`endif
//////////////////////////////////////////////////////////////////////
initial #0 begin
#10 ; // wait for sdram init.
load_rombios();
$display("ROMs loaded.");
//load_file({4'h8, 21'h0}, "ram.bin", '0);
reset = 0;
end
initial @(negedge reset) #(500e3) begin
//$writememh("vram0.hex", mycore.mach.vram0.mem);
//$writememh("vram1.hex", mycore.mach.vram1.mem);
//$writememh("vce_cp.hex", mycore.mach.vce.cpram.mem);
$finish;
end

22
rtl/tb/render2png.py Normal file
View File

@@ -0,0 +1,22 @@
import sys
import re
from PIL import Image, ImageColor, ImageDraw
img = Image.new('RGB', (256, 242))
d = ImageDraw.Draw(img)
with open(sys.argv[1], "r") as fin:
y = 0
for line in fin.readlines():
for x in range(len(line)//6):
w = line[x*6:x*6+6]
if not re.match(r'[0-9a-fA-F]{6}', w):
continue
r = int(w[0:2], 16)
g = int(w[2:4], 16)
b = int(w[4:6], 16)
c = (r,g,b)
d.point((x, y), fill=c)
y = y + 1
img.save(sys.argv[2])