Skip to content

Commit

Permalink
Par sprites (#695)
Browse files Browse the repository at this point in the history
simson: sprite scaling implemented for Parodius
  • Loading branch information
rp-jt committed Jun 3, 2024
1 parent f3a8cfa commit 1bb5cb0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
47 changes: 30 additions & 17 deletions cores/simson/hdl/jt053246.sv
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ module jt053246( // sprite logic
output reg vflip,
output reg [ 8:0] hpos,
output [ 3:0] ysub,
output reg [ 9:0] hzoom,
output reg [11:0] hzoom,
output reg hz_keep,

// base video
Expand Down Expand Up @@ -79,7 +79,8 @@ localparam [2:0] REG_XOFF = 0, // X offset
REG_CFG = 2; // interrupt control, ROM read

reg [18:0] yz_add;
reg [ 9:0] vzoom, y, y2, x, ydiff, ydiff_b, xadj, yadj, ywrap, yw0;
reg [11:0] vzoom;
reg [ 9:0] y, y2, x, ydiff, ydiff_b, xadj, yadj, ywrap, yw0;
reg [ 8:0] vlatch, ymove, full_h, vscl, hscl, full_w;
reg [ 7:0] scan_obj; // max 256 objects
reg [ 3:0] size;
Expand All @@ -96,7 +97,8 @@ wire [ 7:0] cfg;
wire [ 1:0] nx_mir, hsz, vsz;
wire dma_wel, dma_weh, dma_trig, last_obj, vb_rd,
cpu_bsy, ghf, gvf, mode8, dma_en, flicker;
reg [ 8:0] zoffset[0:255];
reg [ 8:0] zoffset [0:255];
reg [ 3:0] pzoffset[0:15 ];

assign ghf = cfg[0]; // global flip
assign gvf = cfg[1];
Expand All @@ -117,12 +119,12 @@ always @(negedge clk) cen2 <= ~cen2;
always @(posedge clk) begin
xadj <= xoffset - (k44_en ? 10'd108 : 10'd61);
yadj <= yoffset + (k44_en ? 10'h10f : {5'o10, simson, 4'hf} ); // 10'h11f for Simpsons, 10'h10f for Vendetta (and Parodius)
vscl <= zoffset[ vzoom[7:0] ];
hscl <= zoffset[ hzoom[7:0] ];
vscl <= k44_en? red_offset(vzoom, zoffset,pzoffset): zoffset[ vzoom[7:0] ];
hscl <= k44_en? red_offset(hzoom, zoffset,pzoffset): zoffset[ hzoom[7:0] ];
/* verilator lint_off WIDTH */
yz_add <= vzoom*ydiff_b; // vzoom < 10'h40 enlarge, >10'h40 reduce
// opposite to the one in Aliens, which always
// shrunk for non-zero zoom values
yz_add <= vzoom[9:0]*ydiff_b; // vzoom < 10'h40 enlarge, >10'h40 reduce
// opposite to the one in Aliens, which always
// shrunk for non-zero zoom values
/* verilator lint_on WIDTH */
yw0 = y + yadj;
ywrap = yw0 > 10'h200 ? yw0+10'h121 : yw0;
Expand All @@ -137,6 +139,16 @@ function [8:0] zmove( input [1:0] sz, input[8:0] scl );
endcase
endfunction

function [8:0] red_offset( input [11:0] zoom, input [ 8:0] offset1 [0:255], input [3:0] offset2[0:15]);
case( zoom[11:8] )
0: red_offset = offset1 [zoom[7:0]];
1: red_offset = {5'b0,offset2 [zoom[7:4]]};
2: red_offset = 9'd3;
4,3: red_offset = 9'd2;
default: red_offset = 9'd1;
endcase
endfunction

always @* begin
ymove = zmove( vsz, vscl );
y2 = y + {1'b0,ymove};
Expand Down Expand Up @@ -233,14 +245,11 @@ always @(posedge clk, posedge rst) begin
2: begin
x <= x - xadj;
y <= ywrap;
vzoom <= scan_even[9:0];
hzoom <= sq ? scan_even[9:0] : scan_odd[9:0];
if( k44_en ) begin //
if(scan_odd>16'h3ff) hzoom <= 10'h3ff;
if(scan_even>16'h3ff) begin
vzoom <= 10'h3ff;
if( sq ) hzoom <= 10'h3ff;
end
vzoom <= scan_even[11:0];
hzoom <= sq ? scan_even[11:0] : scan_odd[11:0];
if( !k44_en) begin
vzoom[11:10] <= 0;
hzoom[11:10] <= 0;
end
end
3: begin
Expand Down Expand Up @@ -274,7 +283,7 @@ always @(posedge clk, posedge rst) begin
if( (!dr_start && !dr_busy) || !inzone ) begin
{code[4],code[2],code[0]} <= hcode + hsum;
if( hstep==0 ) begin
hpos <= x[8:0] - zmove( hsz, hscl );
hpos <= x[8:0] - zmove( hsz, hscl ) - 9'b1;
end else begin
hpos <= hpos + 9'h10;
hz_keep <= 1;
Expand Down Expand Up @@ -367,6 +376,10 @@ jtframe_dual_ram16 #(.AW(10)) u_odd( // 10:0 -> 2kB
.q1 ( scan_odd )
);

initial pzoffset ='{
8, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4, 4, 4, 4
};

initial zoffset ='{ // octal count
511, 511, 511, 511, 511, 410, 341, 293, // 0- 7
256, 228, 205, 186, 171, 158, 146, 137, // 10- 17
Expand Down
4 changes: 2 additions & 2 deletions cores/simson/hdl/jtsimson_obj.v
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ wire [ 9:0] attr; // OC pins
wire hflip, vflip, hz_keep, pre_cs;
wire [ 8:0] hpos;
wire [ 3:0] ysub;
wire [ 9:0] hzoom;
wire [11:0] hzoom;
wire [31:0] sorted;
wire pen15;

Expand Down Expand Up @@ -174,7 +174,7 @@ jt053246 u_scan( // sprite logic

jtframe_objdraw #(
.CW(16),.PW(4+10+2),.LATCH(1),.SWAPH(1),
.ZW(10),.ZI(6),.ZENLARGE(1),
.ZW(12),.ZI(6),.ZENLARGE(1),
.FLIP_OFFSET(9'h12),.KEEP_OLD(1)
) u_draw(
.rst ( rst ),
Expand Down

0 comments on commit 1bb5cb0

Please sign in to comment.