Skip to content

Commit

Permalink
Update sys
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeS11 committed Mar 10, 2023
1 parent 06220ba commit 32a22c4
Show file tree
Hide file tree
Showing 14 changed files with 3,594 additions and 2,918 deletions.
10 changes: 8 additions & 2 deletions Arcade-Defender.sv
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module emu
input RESET,

//Must be passed to hps_io module
inout [45:0] HPS_BUS,
inout [48:0] HPS_BUS,

//Base video clock. Usually equals to CLK_SYS.
output CLK_VIDEO,
Expand All @@ -52,13 +52,14 @@ module emu
output VGA_F1,
output [1:0] VGA_SL,
output VGA_SCALER, // Force VGA scaler
output VGA_DISABLE, // analog out is off

input [11:0] HDMI_WIDTH,
input [11:0] HDMI_HEIGHT,
output HDMI_FREEZE,

`ifdef MISTER_FB
// Use framebuffer in DDRAM (USE_FB=1 in qsf)
// Use framebuffer in DDRAM
// FB_FORMAT:
// [2:0] : 011=8bpp(palette) 100=16bpp 101=24bpp 110=32bpp
// [3] : 0=16bits 565 1=16bits 1555
Expand Down Expand Up @@ -189,6 +190,7 @@ assign LED_POWER = 0;
assign BUTTONS = 0;
assign FB_FORCE_BLANK = '0;
assign HDMI_FREEZE = 0;
assign VGA_DISABLE = 0;

wire [1:0] ar = status[17:16];

Expand Down Expand Up @@ -264,6 +266,7 @@ hps_io #(.CONF_STR(CONF_STR)) hps_io
.forced_scandoubler(forced_scandoubler),
.gamma_bus(gamma_bus),
.direct_video(direct_video),
.video_rotated(video_rotated),

.ioctl_download(ioctl_download),
.ioctl_upload(ioctl_upload),
Expand Down Expand Up @@ -463,6 +466,9 @@ always @(posedge clk_48) begin
ce_pix <= !div;
end

wire flip = 0;
wire video_rotated;

screen_rotate screen_rotate (.*);

arcade_video #(306,8) arcade_video
Expand Down
64 changes: 43 additions & 21 deletions sys/arcade_video.v
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,17 @@ module screen_rotate

input rotate_ccw,
input no_rotate,

output FB_EN,
output [4:0] FB_FORMAT,
output [11:0] FB_WIDTH,
output [11:0] FB_HEIGHT,
output [31:0] FB_BASE,
output [13:0] FB_STRIDE,
input FB_VBL,
input FB_LL,
input flip,
output video_rotated,

output FB_EN,
output [4:0] FB_FORMAT,
output reg [11:0] FB_WIDTH,
output reg [11:0] FB_HEIGHT,
output [31:0] FB_BASE,
output [13:0] FB_STRIDE,
input FB_VBL,
input FB_LL,

output DDRAM_CLK,
input DDRAM_BUSY,
Expand All @@ -196,6 +198,8 @@ module screen_rotate

parameter MEM_BASE = 7'b0010010; // buffer at 0x24000000, 3x8MB

reg do_flip;

assign DDRAM_CLK = CLK_VIDEO;
assign DDRAM_BURSTCNT = 1;
assign DDRAM_ADDR = {MEM_BASE, i_fb, ram_addr[22:3]};
Expand All @@ -207,8 +211,6 @@ assign DDRAM_RD = 0;
assign FB_EN = fb_en[2];
assign FB_FORMAT = 5'b00110;
assign FB_BASE = {MEM_BASE,o_fb,23'd0};
assign FB_WIDTH = vsz;
assign FB_HEIGHT = hsz;
assign FB_STRIDE = stride;

function [1:0] buf_next;
Expand All @@ -220,6 +222,19 @@ function [1:0] buf_next;
end
endfunction

assign video_rotated = ~no_rotate;

always @(posedge CLK_VIDEO) begin
do_flip <= no_rotate && flip;
if( do_flip ) begin
FB_WIDTH <= hsz;
FB_HEIGHT <= vsz;
end else begin
FB_WIDTH <= vsz;
FB_HEIGHT <= hsz;
end
end

reg [1:0] i_fb,o_fb;
always @(posedge CLK_VIDEO) begin
reg old_vbl,old_vs;
Expand Down Expand Up @@ -251,20 +266,23 @@ always @(posedge CLK_VIDEO) begin
if(CE_PIXEL) begin
old_vs <= VGA_VS;
old_de <= VGA_DE;

hcnt <= hcnt + 1'd1;
if(~old_de & VGA_DE) begin
hcnt <= 1;
vcnt <= vcnt + 1'd1;
end
if(old_de & ~VGA_DE) hsz <= hcnt;
if(old_de & ~VGA_DE) begin
hsz <= hcnt;
if( do_flip ) bwidth <= hcnt + 2'd3;
end
if(~old_vs & VGA_VS) begin
vsz <= vcnt;
bwidth <= vcnt + 2'd3;
if( !do_flip ) bwidth <= vcnt + 2'd3;
vcnt <= 0;
fb_en <= {fb_en[1:0], ~no_rotate};
fb_en <= {fb_en[1:0], ~no_rotate | flip};
end
if(old_vs & ~VGA_VS) bufsize <= hsz * stride;
if(old_vs & ~VGA_VS) bufsize <= (do_flip ? vsz : hsz ) * stride;
end
end

Expand All @@ -278,21 +296,25 @@ always @(posedge CLK_VIDEO) begin
reg old_vs, old_de;

ram_wr <= 0;
if(CE_PIXEL) begin
if(CE_PIXEL && FB_EN) begin
old_vs <= VGA_VS;
old_de <= VGA_DE;

if(~old_vs & VGA_VS) begin
next_addr <= rotate_ccw ? (bufsize - stride) : {vsz-1'd1, 2'b00};
next_addr <=
do_flip ? bufsize-3'd4 :
rotate_ccw ? (bufsize - stride) : {vsz-1'd1, 2'b00};
hcnt <= rotate_ccw ? 3'd4 : {vsz-2'd2, 2'b00};
end
if(VGA_DE) begin
ram_wr <= 1;
ram_data <= {VGA_B,VGA_G,VGA_R};
ram_data <= {8'd0,VGA_B,VGA_G,VGA_R};
ram_addr <= next_addr;
next_addr <= rotate_ccw ? (next_addr - stride) : (next_addr + stride);
next_addr <=
do_flip ? next_addr-3'd4 :
rotate_ccw ? (next_addr - stride) : (next_addr + stride);
end
if(old_de & ~VGA_DE) begin
if(old_de & ~VGA_DE & ~do_flip) begin
next_addr <= rotate_ccw ? (bufsize - stride + hcnt) : hcnt;
hcnt <= rotate_ccw ? (hcnt + 3'd4) : (hcnt - 3'd4);
end
Expand Down
Loading

0 comments on commit 32a22c4

Please sign in to comment.