mirror of
https://github.com/MiSTer-devel/InputTest_MiSTer.git
synced 2026-04-19 03:04:18 +00:00
Integrate Aznable codebase
This commit is contained in:
182
sys/ascal.vhd
182
sys/ascal.vhd
@@ -151,6 +151,7 @@ ENTITY ascal IS
|
||||
o_vs : OUT std_logic; -- V sync
|
||||
o_de : OUT std_logic; -- Display Enable
|
||||
o_vbl : OUT std_logic; -- V blank
|
||||
o_brd : OUT std_logic; -- border enable
|
||||
o_ce : IN std_logic; -- Clock Enable
|
||||
o_clk : IN std_logic; -- Output clock
|
||||
|
||||
@@ -458,6 +459,7 @@ ARCHITECTURE rtl OF ascal IS
|
||||
SIGNAL o_hacc,o_hacc_ini,o_hacc_next,o_vacc,o_vacc_next,o_vacc_ini : natural RANGE 0 TO 4*OHRES-1;
|
||||
SIGNAL o_hsv,o_vsv,o_dev,o_pev,o_end : unsigned(0 TO 5);
|
||||
SIGNAL o_hsp,o_vss : std_logic;
|
||||
SIGNAL o_vcarrym,o_prim : boolean;
|
||||
SIGNAL o_read,o_read_pre : std_logic;
|
||||
SIGNAL o_readlev,o_copylev : natural RANGE 0 TO 2;
|
||||
SIGNAL o_hburst,o_hbcpt : natural RANGE 0 TO 31;
|
||||
@@ -485,6 +487,7 @@ ARCHITECTURE rtl OF ascal IS
|
||||
SIGNAL o_divstart : std_logic;
|
||||
SIGNAL o_divrun : std_logic;
|
||||
SIGNAL o_hacpt,o_vacpt : unsigned(11 DOWNTO 0);
|
||||
SIGNAL o_vacptl : unsigned(1 DOWNTO 0);
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
FUNCTION shift_ishift(shift : unsigned(0 TO 119);
|
||||
@@ -705,8 +708,10 @@ ARCHITECTURE rtl OF ascal IS
|
||||
RETURN x;
|
||||
END FUNCTION;
|
||||
|
||||
SIGNAL o_h_frac2,o_v_frac : unsigned(FRAC-1 DOWNTO 0);
|
||||
SIGNAL o_h_near_frac,o_v_near_frac : unsigned(FRAC-1 DOWNTO 0);
|
||||
SIGNAL o_h_bil_frac,o_v_bil_frac : unsigned(FRAC-1 DOWNTO 0);
|
||||
SIGNAL o_h_bil_pix,o_v_bil_pix : type_pix;
|
||||
SIGNAL o_h_near_pix,o_v_near_pix : type_pix;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
-- Nearest + Bilinear + Sharp Bilinear
|
||||
@@ -718,6 +723,7 @@ ARCHITECTURE rtl OF ascal IS
|
||||
TYPE type_bil_t IS RECORD
|
||||
r,g,b : unsigned(8+FRAC DOWNTO 0);
|
||||
END RECORD;
|
||||
|
||||
FUNCTION bil_calc(f : unsigned(FRAC-1 DOWNTO 0);
|
||||
p : arr_pix(0 TO 3)) RETURN type_bil_t IS
|
||||
VARIABLE fp,fn : unsigned(FRAC DOWNTO 0);
|
||||
@@ -725,7 +731,7 @@ ARCHITECTURE rtl OF ascal IS
|
||||
VARIABLE x : type_bil_t;
|
||||
CONSTANT Z : unsigned(FRAC-1 DOWNTO 0):=(OTHERS =>'0');
|
||||
BEGIN
|
||||
fp:='0' & f;
|
||||
fp:=('0' & f) + (Z & f(FRAC-1));
|
||||
fn:=('1' & Z) - fp;
|
||||
u:=p(2).r * fp + p(1).r * fn;
|
||||
x.r:=u;
|
||||
@@ -735,7 +741,27 @@ ARCHITECTURE rtl OF ascal IS
|
||||
x.b:=u;
|
||||
RETURN x;
|
||||
END FUNCTION;
|
||||
|
||||
FUNCTION near_calc(f : unsigned(FRAC-1 DOWNTO 0);
|
||||
p : arr_pix(0 TO 3)) RETURN type_bil_t IS
|
||||
VARIABLE fp,fn : unsigned(FRAC DOWNTO 0);
|
||||
VARIABLE u : unsigned(8+FRAC DOWNTO 0);
|
||||
VARIABLE x : type_bil_t;
|
||||
CONSTANT Z : unsigned(FRAC-1 DOWNTO 0):=(OTHERS =>'0');
|
||||
BEGIN
|
||||
IF f(FRAC-1)='0' THEN
|
||||
x.r := '0' & p(1).r & Z;
|
||||
x.g := '0' & p(1).g & Z;
|
||||
x.b := '0' & p(1).b & Z;
|
||||
ELSE
|
||||
x.r := '0' & p(2).r & Z;
|
||||
x.g := '0' & p(2).g & Z;
|
||||
x.b := '0' & p(2).b & Z;
|
||||
END IF;
|
||||
RETURN x;
|
||||
END FUNCTION;
|
||||
SIGNAL o_h_bil_t,o_v_bil_t : type_bil_t;
|
||||
SIGNAL o_h_near_t,o_v_near_t : type_bil_t;
|
||||
SIGNAL i_h_bil_t : type_bil_t;
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
@@ -1864,35 +1890,51 @@ BEGIN
|
||||
o_state<=sHSYNC;
|
||||
o_hsp<='0';
|
||||
END IF;
|
||||
o_prim<=true;
|
||||
o_vcarrym<=false;
|
||||
|
||||
--------------------------------------------------
|
||||
WHEN sHSYNC =>
|
||||
dif_v:=(o_vacc_next - 2*o_vsize + 16384) MOD 16384;
|
||||
dif_v :=(o_vacc_next - 2*o_vsize + 16384) MOD 16384;
|
||||
IF o_prim THEN
|
||||
IF dif_v>=8192 THEN
|
||||
o_vacc <=o_vacc_next;
|
||||
ELSE
|
||||
o_vacc <=dif_v;
|
||||
END IF;
|
||||
END IF;
|
||||
IF dif_v>=8192 THEN
|
||||
o_vacc <=o_vacc_next;
|
||||
o_vacc_next<=(o_vacc_next + 2*o_ivsize) MOD 8192;
|
||||
vcarry_v:=false;
|
||||
ELSE
|
||||
o_vacc <=dif_v;
|
||||
o_vacc_next<=(dif_v + 2*o_ivsize + 8192) MOD 8192;
|
||||
o_vacc_next<=dif_v;
|
||||
vcarry_v:=true;
|
||||
END IF;
|
||||
o_divstart<='1';
|
||||
|
||||
IF o_vcpt_pre2=o_vmin THEN
|
||||
o_vacc <=o_vacc_ini;
|
||||
o_vacc_next<=o_vacc_ini + 2*o_ivsize;
|
||||
o_vacpt<=x"001";
|
||||
o_vacpt <=x"001";
|
||||
o_vacptl<="01";
|
||||
vcarry_v:=false;
|
||||
END IF;
|
||||
|
||||
IF vcarry_v THEN
|
||||
o_vacpt<=o_vacpt+1;
|
||||
END IF;
|
||||
IF vcarry_v AND o_prim THEN
|
||||
o_vacptl<=o_vacptl+1;
|
||||
END IF;
|
||||
o_vcarrym <= o_vcarrym OR vcarry_v;
|
||||
o_prim <= false;
|
||||
o_hbcpt<=0; -- Clear burst counter on line
|
||||
IF (o_vpe='1' AND vcarry_v) OR o_fload>0 THEN
|
||||
o_state<=sREAD;
|
||||
ELSE
|
||||
o_state<=sDISP;
|
||||
o_divstart<=to_std_logic(NOT vcarry_v);
|
||||
IF NOT vcarry_v OR o_fload>0 THEN
|
||||
IF (o_vpe='1' AND o_vcarrym) OR o_fload>0 THEN
|
||||
o_state<=sREAD;
|
||||
ELSE
|
||||
o_state<=sDISP;
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
WHEN sREAD =>
|
||||
@@ -1942,7 +1984,7 @@ BEGIN
|
||||
o_alt<="0100";
|
||||
ELSE
|
||||
o_adrs<=to_unsigned(o_adrs_pre + (o_hbcpt * N_BURST),32);
|
||||
o_alt<=altx(o_vacpt(1 DOWNTO 0) + 1);
|
||||
o_alt<=altx(o_vacptl + 1);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
@@ -2276,33 +2318,38 @@ BEGIN
|
||||
|
||||
o_hpixq<=(o_hpix3,o_hpix2,o_hpix1,o_hpix0);
|
||||
|
||||
-- NEAREST / BILINEAR / SHARP BILINEAR ---------------
|
||||
-- NEAREST -------------------------------------------
|
||||
-- C2
|
||||
o_h_near_frac<=near_frac(o_hfrac2);
|
||||
|
||||
-- C3
|
||||
o_h_near_t<=near_calc(o_h_near_frac,o_hpixq);
|
||||
|
||||
-- C4 : Nearest
|
||||
o_h_near_pix.r<=o_h_near_t.r(7+FRAC DOWNTO FRAC);
|
||||
o_h_near_pix.g<=o_h_near_t.g(7+FRAC DOWNTO FRAC);
|
||||
o_h_near_pix.b<=o_h_near_t.b(7+FRAC DOWNTO FRAC);
|
||||
|
||||
-- BILINEAR / SHARP BILINEAR ---------------
|
||||
-- C1 : Pre-calc Sharp Bilinear
|
||||
o_h_sbil_t<=sbil_frac1(o_hfrac1);
|
||||
|
||||
-- C2 : Select
|
||||
o_h_frac2<=(OTHERS =>'0');
|
||||
CASE o_hmode(1 DOWNTO 0) IS
|
||||
WHEN "00" => -- Nearest
|
||||
IF MASK(MASK_NEAREST)='1' THEN
|
||||
o_h_frac2<=near_frac(o_hfrac2);
|
||||
END IF;
|
||||
WHEN "01" => -- Bilinear
|
||||
IF MASK(MASK_BILINEAR)='1' THEN
|
||||
o_h_frac2<=bil_frac(o_hfrac2);
|
||||
END IF;
|
||||
WHEN "10" => -- Sharp Bilinear
|
||||
IF MASK(MASK_SHARP_BILINEAR)='1' THEN
|
||||
o_h_frac2<=sbil_frac2(o_hfrac2,o_h_sbil_t);
|
||||
END IF;
|
||||
WHEN OTHERS =>
|
||||
NULL;
|
||||
END CASE;
|
||||
|
||||
o_h_bil_frac<=(OTHERS =>'0');
|
||||
IF o_hmode(0)='1' THEN -- Bilinear
|
||||
IF MASK(MASK_BILINEAR)='1' THEN
|
||||
o_h_bil_frac<=bil_frac(o_hfrac2);
|
||||
END IF;
|
||||
ELSE -- Sharp Bilinear
|
||||
IF MASK(MASK_SHARP_BILINEAR)='1' THEN
|
||||
o_h_bil_frac<=sbil_frac2(o_hfrac2,o_h_sbil_t);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
-- C3 : Opposite frac
|
||||
o_h_bil_t<=bil_calc(o_h_frac2,o_hpixq);
|
||||
o_h_bil_t<=bil_calc(o_h_bil_frac,o_hpixq);
|
||||
|
||||
-- C4 : Nearest / Bilinear / Sharp Bilinear
|
||||
-- C4 : Bilinear / Sharp Bilinear
|
||||
o_h_bil_pix.r<=bound(o_h_bil_t.r,8+FRAC);
|
||||
o_h_bil_pix.g<=bound(o_h_bil_t.g,8+FRAC);
|
||||
o_h_bil_pix.b<=bound(o_h_bil_t.b,8+FRAC);
|
||||
@@ -2340,9 +2387,12 @@ BEGIN
|
||||
o_ldw<=(x"00",x"00",x"00");
|
||||
|
||||
CASE o_hmode(2 DOWNTO 0) IS
|
||||
WHEN "000" | "001" | "010" => -- Nearest | Bilinear | Sharp Bilinear
|
||||
IF MASK(MASK_NEAREST)='1' OR
|
||||
MASK(MASK_BILINEAR)='1' OR
|
||||
WHEN "000" => -- Nearest
|
||||
IF MASK(MASK_NEAREST)='1' THEN
|
||||
o_ldw<=o_h_near_pix;
|
||||
END IF;
|
||||
WHEN "001" | "010" => -- Bilinear | Sharp Bilinear
|
||||
IF MASK(MASK_BILINEAR)='1' OR
|
||||
MASK(MASK_SHARP_BILINEAR)='1' THEN
|
||||
o_ldw<=o_h_bil_pix;
|
||||
END IF;
|
||||
@@ -2441,7 +2491,7 @@ BEGIN
|
||||
|
||||
-- CYCLE 2 -----------------------------------------
|
||||
-- Lines reordering
|
||||
CASE o_vacpt(1 DOWNTO 0) IS
|
||||
CASE o_vacptl IS
|
||||
WHEN "10" => pixq_v:=(o_ldr0,o_ldr1,o_ldr2,o_ldr3);
|
||||
WHEN "11" => pixq_v:=(o_ldr1,o_ldr2,o_ldr3,o_ldr0);
|
||||
WHEN "00" => pixq_v:=(o_ldr2,o_ldr3,o_ldr0,o_ldr1);
|
||||
@@ -2461,31 +2511,37 @@ BEGIN
|
||||
|
||||
o_vpixq1<=o_vpixq;
|
||||
|
||||
-- NEAREST / BILINEAR / SHARP BILINEAR -------------
|
||||
-- NEAREST -----------------------------------------
|
||||
-- C4
|
||||
o_v_near_frac<=near_frac(o_vfrac);
|
||||
|
||||
-- C5
|
||||
o_v_near_t<=near_calc(o_v_near_frac,o_vpixq1);
|
||||
|
||||
-- C6 : Nearest
|
||||
o_v_near_pix.r<=o_v_near_t.r(7+FRAC DOWNTO FRAC);
|
||||
o_v_near_pix.g<=o_v_near_t.g(7+FRAC DOWNTO FRAC);
|
||||
o_v_near_pix.b<=o_v_near_t.b(7+FRAC DOWNTO FRAC);
|
||||
|
||||
-- BILINEAR / SHARP BILINEAR -----------------------
|
||||
-- C3 : Pre-calc Sharp Bilinear
|
||||
o_v_sbil_t<=sbil_frac1(o_vfrac);
|
||||
|
||||
-- C4 : Select
|
||||
o_v_frac<=(OTHERS =>'0');
|
||||
CASE o_vmode(1 DOWNTO 0) IS
|
||||
WHEN "00" => -- Nearest
|
||||
IF MASK(MASK_NEAREST)='1' THEN
|
||||
o_v_frac<=near_frac(o_vfrac);
|
||||
END IF;
|
||||
WHEN "01" => -- Bilinear
|
||||
IF MASK(MASK_BILINEAR)='1' THEN
|
||||
o_v_frac<=bil_frac(o_vfrac);
|
||||
END IF;
|
||||
WHEN "10" => -- Sharp Bilinear
|
||||
IF MASK(MASK_SHARP_BILINEAR)='1' THEN
|
||||
o_v_frac<=sbil_frac2(o_vfrac,o_v_sbil_t);
|
||||
END IF;
|
||||
WHEN OTHERS => NULL;
|
||||
END CASE;
|
||||
o_v_bil_frac<=(OTHERS =>'0');
|
||||
IF o_vmode(0)='1' THEN -- Bilinear
|
||||
IF MASK(MASK_BILINEAR)='1' THEN
|
||||
o_v_bil_frac<=bil_frac(o_vfrac);
|
||||
END IF;
|
||||
ELSE -- Sharp Bilinear
|
||||
IF MASK(MASK_SHARP_BILINEAR)='1' THEN
|
||||
o_v_bil_frac<=sbil_frac2(o_vfrac,o_v_sbil_t);
|
||||
END IF;
|
||||
END IF;
|
||||
|
||||
o_v_bil_t<=bil_calc(o_v_frac,o_vpixq1);
|
||||
o_v_bil_t<=bil_calc(o_v_bil_frac,o_vpixq1);
|
||||
|
||||
-- C6 : Nearest / Bilinear / Sharp Bilinear
|
||||
-- C6 : Bilinear / Sharp Bilinear
|
||||
o_v_bil_pix.r<=bound(o_v_bil_t.r,8+FRAC);
|
||||
o_v_bil_pix.g<=bound(o_v_bil_t.g,8+FRAC);
|
||||
o_v_bil_pix.b<=bound(o_v_bil_t.b,8+FRAC);
|
||||
@@ -2524,11 +2580,17 @@ BEGIN
|
||||
o_r<=x"00";
|
||||
o_g<=x"00";
|
||||
o_b<=x"00";
|
||||
o_brd<= not o_pev(5);
|
||||
|
||||
CASE o_vmode(2 DOWNTO 0) IS
|
||||
WHEN "000" | "001" | "010" => -- Nearest | Bilinear | Sharp Bilinear
|
||||
IF MASK(MASK_NEAREST)='1' OR
|
||||
MASK(MASK_BILINEAR)='1' OR
|
||||
WHEN "000" => -- Nearest
|
||||
IF MASK(MASK_NEAREST)='1' THEN
|
||||
o_r<=o_v_near_pix.r;
|
||||
o_g<=o_v_near_pix.g;
|
||||
o_b<=o_v_near_pix.b;
|
||||
END IF;
|
||||
WHEN "001" | "010" => -- Bilinear | Sharp Bilinear
|
||||
IF MASK(MASK_BILINEAR)='1' OR
|
||||
MASK(MASK_SHARP_BILINEAR)='1' THEN
|
||||
o_r<=o_v_bil_pix.r;
|
||||
o_g<=o_v_bil_pix.g;
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
// Use buffer to access SD card. It's time-critical part.
|
||||
//
|
||||
// WIDE=1 for 16 bit file I/O
|
||||
// VDNUM 1..4
|
||||
// VDNUM 1..10
|
||||
// BLKSZ 0..7: 0 = 128, 1 = 256, 2 = 512(default), .. 7 = 16384
|
||||
//
|
||||
module hps_io #(parameter CONF_STR, CONF_STR_BRAM=1, PS2DIV=0, WIDE=0, VDNUM=1, BLKSZ=2, PS2WE=0)
|
||||
(
|
||||
input clk_sys,
|
||||
inout [45:0] HPS_BUS,
|
||||
inout [47:0] HPS_BUS,
|
||||
|
||||
// buttons up to 32
|
||||
output reg [31:0] joystick_0,
|
||||
@@ -316,7 +316,7 @@ always@(posedge clk_sys) begin : uio_block
|
||||
'h0X17,
|
||||
'h0X18: begin sd_ack <= disk[VD:0]; sdn_ack <= io_din[11:8]; end
|
||||
'h29: io_dout <= {4'hA, stflg};
|
||||
'h2B: io_dout <= 1;
|
||||
'h2B: io_dout <= {HPS_BUS[47:46],4'b0010};
|
||||
'h2F: io_dout <= 1;
|
||||
'h32: io_dout <= gamma_bus[21];
|
||||
'h36: begin io_dout <= info_n; info_n <= 0; end
|
||||
|
||||
@@ -1,144 +1,136 @@
|
||||
module shadowmask
|
||||
(
|
||||
input clk,
|
||||
input clk_sys,
|
||||
|
||||
input cmd_wr,
|
||||
input [15:0] cmd_in,
|
||||
input clk,
|
||||
input clk_sys,
|
||||
|
||||
input [23:0] din,
|
||||
input hs_in,vs_in,
|
||||
input de_in,
|
||||
input cmd_wr,
|
||||
input [15:0] cmd_in,
|
||||
|
||||
output reg [23:0] dout,
|
||||
output reg hs_out,vs_out,
|
||||
output reg de_out
|
||||
input [23:0] din,
|
||||
input hs_in,vs_in,
|
||||
input de_in,
|
||||
input brd_in,
|
||||
input enable,
|
||||
|
||||
output reg [23:0] dout,
|
||||
output reg hs_out,vs_out,
|
||||
output reg de_out
|
||||
);
|
||||
|
||||
|
||||
//These are unused right now
|
||||
parameter MaxPatternWidth = 8;
|
||||
parameter MaxPatternHeight = 4;
|
||||
|
||||
reg [3:0] hcount;
|
||||
reg [3:0] vcount;
|
||||
|
||||
reg [3:0] hmax;
|
||||
reg [3:0] vmax;
|
||||
reg [3:0] hmax2;
|
||||
reg [3:0] vmax2;
|
||||
|
||||
reg [2:0] hindex;
|
||||
reg [2:0] vindex;
|
||||
reg [2:0] hindex2;
|
||||
reg [2:0] vindex2;
|
||||
|
||||
reg mask_2x;
|
||||
reg mask_rotate;
|
||||
reg mask_enable;
|
||||
reg [4:0] hmax;
|
||||
reg [4:0] vmax;
|
||||
reg [7:0] mask_idx;
|
||||
reg mask_2x;
|
||||
reg mask_rotate;
|
||||
reg mask_enable;
|
||||
reg [10:0] mask_lut[256];
|
||||
|
||||
always @(posedge clk) begin
|
||||
reg [4:0] hcount;
|
||||
reg [4:0] vcount;
|
||||
reg [3:0] hindex;
|
||||
reg [3:0] vindex;
|
||||
reg [4:0] hmax2;
|
||||
reg [4:0] vmax2;
|
||||
reg [11:0] pcnt,pde;
|
||||
reg old_hs, old_vs, old_brd;
|
||||
reg next_v;
|
||||
|
||||
reg old_hs, old_vs;
|
||||
old_hs <= hs_in;
|
||||
old_vs <= vs_in;
|
||||
hcount <= hcount + 4'b1;
|
||||
old_hs <= hs_in;
|
||||
old_vs <= vs_in;
|
||||
old_brd<= brd_in;
|
||||
|
||||
// hcount and vcount counts pixel rows and columns
|
||||
// hindex and vindex half the value of the counters for double size patterns
|
||||
// hindex2, vindex2 swap the h and v counters for drawing rotated masks
|
||||
hindex <= mask_2x ? hcount[3:1] : hcount[2:0];
|
||||
vindex <= mask_2x ? vcount[3:1] : vcount[2:0];
|
||||
hindex2 <= mask_rotate ? vindex : hindex;
|
||||
vindex2 <= mask_rotate ? hindex : vindex;
|
||||
// hcount and vcount counts pixel rows and columns
|
||||
// hindex and vindex half the value of the counters for double size patterns
|
||||
// hindex2, vindex2 swap the h and v counters for drawing rotated masks
|
||||
hindex <= mask_2x ? hcount[4:1] : hcount[3:0];
|
||||
vindex <= mask_2x ? vcount[4:1] : vcount[3:0];
|
||||
mask_idx <= mask_rotate ? {hindex,vindex} : {vindex,hindex};
|
||||
|
||||
// hmax and vmax store these sizes
|
||||
// hmax2 and vmax2 swap the values to handle rotation
|
||||
hmax2 <= mask_rotate ? ( vmax << mask_2x ) : ( hmax << mask_2x );
|
||||
vmax2 <= mask_rotate ? ( hmax << mask_2x ) : ( vmax << mask_2x );
|
||||
// hmax and vmax store these sizes
|
||||
// hmax2 and vmax2 swap the values to handle rotation
|
||||
hmax2 <= ((mask_rotate ? vmax : hmax) << mask_2x) | mask_2x;
|
||||
vmax2 <= ((mask_rotate ? hmax : vmax) << mask_2x) | mask_2x;
|
||||
|
||||
if((old_vs && ~vs_in)) vcount <= 4'b0;
|
||||
if(old_hs && ~hs_in) begin
|
||||
vcount <= vcount + 4'b1;
|
||||
hcount <= 4'b0;
|
||||
if (vcount == (vmax2 + mask_2x)) vcount <= 4'b0;
|
||||
end
|
||||
pcnt <= pcnt+1'd1;
|
||||
if(old_brd && ~brd_in) pde <= pcnt-4'd3;
|
||||
|
||||
if (hcount == (hmax2 + mask_2x)) hcount <= 4'b0;
|
||||
hcount <= hcount+1'b1;
|
||||
if(hcount == hmax2 || pde == pcnt) hcount <= 0;
|
||||
|
||||
if(~old_brd && brd_in) next_v <= 1;
|
||||
if(old_vs && ~vs_in) vcount <= 0;
|
||||
if(old_hs && ~hs_in) begin
|
||||
vcount <= vcount + next_v;
|
||||
next_v <= 0;
|
||||
pcnt <= 0;
|
||||
if (vcount == vmax2) vcount <= 0;
|
||||
end
|
||||
end
|
||||
|
||||
wire [7:0] r,g,b;
|
||||
assign {r,g,b} = din;
|
||||
reg [4:0] r_mul, g_mul, b_mul; // 1.4 fixed point multipliers
|
||||
always @(posedge clk) begin
|
||||
reg [10:0] lut;
|
||||
|
||||
reg [23:0] d;
|
||||
lut <= mask_lut[mask_idx];
|
||||
|
||||
// Each element of mask_lut is 3 bits. 1 each for R,G,B
|
||||
// Red is 100 = 4
|
||||
// Green is 010 = 2
|
||||
// Blue is 001 = 1
|
||||
// Magenta is 101 = 5
|
||||
// Gray is 000 = 0
|
||||
// White is 111 = 7
|
||||
// Yellow is 110 = 6
|
||||
// Cyan is 011 = 3
|
||||
|
||||
// So the Pattern
|
||||
// r,r,g,g,b,b
|
||||
// r,r,g,g,b,b
|
||||
// g,b,b,r,r,g
|
||||
// g,b,b,r,r,g
|
||||
//
|
||||
// is
|
||||
// 4,4,2,2,1,1,5,3
|
||||
// 4,4,2,2,1,1,0,0,
|
||||
// 2,1,1,4,4,2,0,0
|
||||
// 2,1,1,4,4,2,0,0
|
||||
//
|
||||
// note that all rows are padded to 8 numbers although every pattern is 6 pixels wide
|
||||
// The last two entries of the top row "5,3" are the size of the mask. In this case
|
||||
// "5,3," means this pattern is 6x4 pixels.
|
||||
|
||||
|
||||
reg [2:0] mask_lut[64];
|
||||
r_mul <= 5'b10000; g_mul <= 5'b10000; b_mul <= 5'b10000; // default 100% to all channels
|
||||
if (mask_enable) begin
|
||||
r_mul <= lut[10] ? {1'b1,lut[7:4]} : {1'b0,lut[3:0]};
|
||||
g_mul <= lut[9] ? {1'b1,lut[7:4]} : {1'b0,lut[3:0]};
|
||||
b_mul <= lut[8] ? {1'b1,lut[7:4]} : {1'b0,lut[3:0]};
|
||||
end
|
||||
end
|
||||
|
||||
always @(posedge clk) begin
|
||||
reg [11:0] vid;
|
||||
reg [7:0] r1, g1, b1;
|
||||
reg [7:0] r2, g2, b2;
|
||||
reg [7:0] r3_x, g3_x, b3_x; // 6.25% + 12.5%
|
||||
reg [8:0] r3_y, g3_y, b3_y; // 25% + 50% + 100%
|
||||
reg [8:0] r4, g4, b4;
|
||||
|
||||
reg rbit, gbit, bbit;
|
||||
reg [23:0] dout1, dout2;
|
||||
reg de1,de2,vs1,vs2,hs1,hs2;
|
||||
reg [8:0] r2, g2, b2; //9 bits to handle overflow when we add to bright colors.
|
||||
reg [7:0] r3, g3, b3; //These are the final colors.
|
||||
// C1 - data input
|
||||
{r1,g1,b1} <= din;
|
||||
vid <= {vid[8:0],vs_in, hs_in, de_in};
|
||||
|
||||
{rbit,gbit, bbit} = mask_lut[{vindex2[2:0],hindex2[2:0]}];
|
||||
// C2 - relax timings
|
||||
{r2,g2,b2} <= {r1,g1,b1};
|
||||
|
||||
// I add 12.5% of the Color value and then subrtact 50% if the mask should be dark
|
||||
r2 <= r + {3'b0, r[7:3]} - (rbit ? 9'b0 : {2'b0, r[7:1]});
|
||||
g2 <= g + {3'b0, g[7:3]} - (gbit ? 9'b0 : {2'b0, g[7:1]});
|
||||
b2 <= b + {3'b0, b[7:3]} - (bbit ? 9'b0 : {2'b0, b[7:1]});
|
||||
// C3 - perform multiplications
|
||||
r3_x <= ({4{r_mul[0]}} & r2[7:4]) + ({8{r_mul[1]}} & r2[7:3]);
|
||||
r3_y <= ({6{r_mul[2]}} & r2[7:2]) + ({7{r_mul[3]}} & r2[7:1]) + ({9{r_mul[4]}} & r2[7:0]);
|
||||
g3_x <= ({4{g_mul[0]}} & g2[7:4]) + ({8{g_mul[1]}} & g2[7:3]);
|
||||
g3_y <= ({6{g_mul[2]}} & g2[7:2]) + ({7{g_mul[3]}} & g2[7:1]) + ({9{g_mul[4]}} & g2[7:0]);
|
||||
b3_x <= ({4{b_mul[0]}} & b2[7:4]) + ({8{b_mul[1]}} & b2[7:3]);
|
||||
b3_y <= ({6{b_mul[2]}} & b2[7:2]) + ({7{b_mul[3]}} & b2[7:1]) + ({9{b_mul[4]}} & b2[7:0]);
|
||||
|
||||
// Because a pixel can be brighter than 255 we have to clamp the value to 255.
|
||||
r3 <= r2[8] ? 8'd255 : r2[7:0];
|
||||
g3 <= g2[8] ? 8'd255 : g2[7:0];
|
||||
b3 <= b2[8] ? 8'd255 : b2[7:0];
|
||||
// C4 - combine results
|
||||
r4 <= r3_x + r3_y;
|
||||
g4 <= g3_x + g3_y;
|
||||
b4 <= b3_x + b3_y;
|
||||
|
||||
// I don't know how to keep the color aligned with the sync to avoid a shift.
|
||||
// This code is left over from the original hdmi scanlines code.
|
||||
dout <= ~mask_enable ? {r,g,b} : {r3 ,g3, b3};
|
||||
vs_out <= mask_enable ? vs2 : vs_in; vs2 <= vs1; vs1 <= vs_in;
|
||||
hs_out <= mask_enable ? hs2 : hs_in; hs2 <= hs1; hs1 <= hs_in;
|
||||
de_out <= mask_enable ? de2 : de_in; de2 <= de1; de1 <= de_in;
|
||||
// C5 - clamp and output
|
||||
dout <= {{8{r4[8]}} | r4[7:0], {8{g4[8]}} | g4[7:0], {8{b4[8]}} | b4[7:0]};
|
||||
{vs_out,hs_out,de_out} <= vid[11:9];
|
||||
end
|
||||
|
||||
// 000_000_000_000_000_
|
||||
// clock in mask commands
|
||||
always @(posedge clk_sys) begin
|
||||
if (cmd_wr) begin
|
||||
case(cmd_in[15:13])
|
||||
3'b000: {mask_rotate, mask_2x, mask_enable} <= cmd_in[2:0];
|
||||
3'b001: vmax <= cmd_in[3:0];
|
||||
3'b010: hmax <= cmd_in[3:0];
|
||||
3'b011: mask_lut[cmd_in[9:4]] <= cmd_in[2:0];
|
||||
endcase
|
||||
end
|
||||
reg m_enable;
|
||||
reg [7:0] idx;
|
||||
|
||||
if (cmd_wr) begin
|
||||
case(cmd_in[15:13])
|
||||
3'b000: begin {m_enable, mask_rotate, mask_2x} <= cmd_in[3:1]; idx <= 0; end
|
||||
3'b001: vmax <= cmd_in[3:0];
|
||||
3'b010: hmax <= cmd_in[3:0];
|
||||
3'b011: begin mask_lut[idx] <= cmd_in[10:0]; idx <= idx + 1'd1; end
|
||||
endcase
|
||||
end
|
||||
|
||||
mask_enable <= m_enable & enable;
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
||||
@@ -295,7 +295,7 @@ reg [31:0] cfg_custom_p2;
|
||||
reg [4:0] vol_att;
|
||||
initial vol_att = 5'b11111;
|
||||
|
||||
reg [6:0] coef_addr;
|
||||
reg [8:0] coef_addr;
|
||||
reg [8:0] coef_data;
|
||||
reg coef_wr = 0;
|
||||
|
||||
@@ -335,7 +335,10 @@ always@(posedge clk_sys) begin
|
||||
|
||||
old_strobe <= io_strobe;
|
||||
coef_wr <= 0;
|
||||
|
||||
`ifndef MISTER_DEBUG_NOHDMI
|
||||
shadowmask_wr <= 0;
|
||||
`endif
|
||||
|
||||
if(~io_uio) begin
|
||||
has_cmd <= 0;
|
||||
@@ -364,6 +367,7 @@ always@(posedge clk_sys) begin
|
||||
end
|
||||
end
|
||||
else begin
|
||||
cnt <= cnt + 1'd1;
|
||||
if(cmd == 1) begin
|
||||
cfg <= io_din;
|
||||
cfg_set <= 1;
|
||||
@@ -371,7 +375,6 @@ always@(posedge clk_sys) begin
|
||||
end
|
||||
if(cmd == 'h20) begin
|
||||
cfg_set <= 0;
|
||||
cnt <= cnt + 1'd1;
|
||||
if(cnt<8) begin
|
||||
case(cnt[2:0])
|
||||
0: if(WIDTH != io_din[11:0]) WIDTH <= io_din[11:0];
|
||||
@@ -403,7 +406,6 @@ always@(posedge clk_sys) begin
|
||||
end
|
||||
end
|
||||
if(cmd == 'h2F) begin
|
||||
cnt <= cnt + 1'd1;
|
||||
case(cnt[3:0])
|
||||
0: {LFB_EN,LFB_FLT,LFB_FMT} <= {io_din[15], io_din[14], io_din[5:0]};
|
||||
1: LFB_BASE[15:0] <= io_din[15:0];
|
||||
@@ -420,12 +422,14 @@ always@(posedge clk_sys) begin
|
||||
if(cmd == 'h25) {led_overtake, led_state} <= io_din;
|
||||
if(cmd == 'h26) vol_att <= io_din[4:0];
|
||||
if(cmd == 'h27) VSET <= io_din[11:0];
|
||||
if(cmd == 'h2A) {coef_wr,coef_addr,coef_data} <= {1'b1,io_din};
|
||||
if(cmd == 'h2A) begin
|
||||
if(cnt[0]) {coef_wr,coef_data} <= {1'b1,io_din[8:0]};
|
||||
else coef_addr <= io_din[8:0];
|
||||
end
|
||||
if(cmd == 'h2B) scaler_flt <= io_din[2:0];
|
||||
if(cmd == 'h37) {FREESCALE,HSET} <= {io_din[15],io_din[11:0]};
|
||||
if(cmd == 'h38) vs_line <= io_din[11:0];
|
||||
if(cmd == 'h39) begin
|
||||
cnt <= cnt + 1'd1;
|
||||
case(cnt[3:0])
|
||||
0: acx_att <= io_din[4:0];
|
||||
1: aflt_rate[15:0] <= io_din;
|
||||
@@ -445,7 +449,6 @@ always@(posedge clk_sys) begin
|
||||
endcase
|
||||
end
|
||||
if(cmd == 'h3A) begin
|
||||
cnt <= cnt + 1'd1;
|
||||
case(cnt[3:0])
|
||||
0: arc1x <= io_din[12:0];
|
||||
1: arc1y <= io_din[12:0];
|
||||
@@ -453,7 +456,9 @@ always@(posedge clk_sys) begin
|
||||
3: arc2y <= io_din[12:0];
|
||||
endcase
|
||||
end
|
||||
`ifndef MISTER_DEBUG_NOHDMI
|
||||
if(cmd == 'h3E) {shadowmask_wr,shadowmask_data} <= {1'b1, io_din};
|
||||
`endif
|
||||
end
|
||||
end
|
||||
|
||||
@@ -620,7 +625,7 @@ wire [15:0] vbuf_byteenable;
|
||||
wire vbuf_write;
|
||||
|
||||
wire [23:0] hdmi_data;
|
||||
wire hdmi_vs, hdmi_hs, hdmi_de, hdmi_vbl;
|
||||
wire hdmi_vs, hdmi_hs, hdmi_de, hdmi_vbl, hdmi_brd;
|
||||
wire freeze;
|
||||
|
||||
`ifndef MISTER_DEBUG_NOHDMI
|
||||
@@ -636,6 +641,7 @@ ascal
|
||||
.PALETTE2("false"),
|
||||
`endif
|
||||
`endif
|
||||
.FRAC(6),
|
||||
.N_DW(128),
|
||||
.N_AW(28)
|
||||
)
|
||||
@@ -669,6 +675,7 @@ ascal
|
||||
.o_vs (hdmi_vs),
|
||||
.o_de (hdmi_de),
|
||||
.o_vbl (hdmi_vbl),
|
||||
.o_brd (hdmi_brd),
|
||||
.o_lltune (lltune),
|
||||
.htotal (WIDTH + HFP + HBP + HS),
|
||||
.hsstart (WIDTH + HFP),
|
||||
@@ -1051,36 +1058,18 @@ cyclonev_hps_interface_peripheral_i2c hdmi_i2c
|
||||
);
|
||||
|
||||
`ifndef MISTER_DEBUG_NOHDMI
|
||||
wire [23:0] hdmi_data_sl;
|
||||
wire hdmi_de_sl, hdmi_vs_sl, hdmi_hs_sl;
|
||||
|
||||
`ifdef MISTER_FB
|
||||
reg dis_output;
|
||||
always @(posedge clk_hdmi) begin
|
||||
reg dis;
|
||||
dis <= fb_force_blank;
|
||||
dis <= fb_force_blank & ~LFB_EN;
|
||||
dis_output <= dis;
|
||||
end
|
||||
`else
|
||||
wire dis_output = 0;
|
||||
`endif
|
||||
|
||||
scanlines #(1) HDMI_scanlines
|
||||
(
|
||||
.clk(clk_hdmi),
|
||||
|
||||
.scanlines(scanlines),
|
||||
.din(dis_output ? 24'd0 : hdmi_data),
|
||||
.hs_in(hdmi_hs),
|
||||
.vs_in(hdmi_vs),
|
||||
.de_in(hdmi_de),
|
||||
|
||||
.dout(hdmi_data_sl),
|
||||
.hs_out(hdmi_hs_sl),
|
||||
.vs_out(hdmi_vs_sl),
|
||||
.de_out(hdmi_de_sl)
|
||||
);
|
||||
|
||||
wire [23:0] hdmi_data_mask;
|
||||
wire hdmi_de_mask, hdmi_vs_mask, hdmi_hs_mask;
|
||||
|
||||
@@ -1095,11 +1084,13 @@ shadowmask HDMI_shadowmask
|
||||
.cmd_wr(shadowmask_wr),
|
||||
.cmd_in(shadowmask_data),
|
||||
|
||||
.din(hdmi_data_sl),
|
||||
.hs_in(hdmi_hs_sl),
|
||||
.vs_in(hdmi_vs_sl),
|
||||
.de_in(hdmi_de_sl),
|
||||
|
||||
.din(dis_output ? 24'd0 : hdmi_data),
|
||||
.hs_in(hdmi_hs),
|
||||
.vs_in(hdmi_vs),
|
||||
.de_in(hdmi_de),
|
||||
.brd_in(hdmi_brd),
|
||||
.enable(~LFB_EN),
|
||||
|
||||
.dout(hdmi_data_mask),
|
||||
.hs_out(hdmi_hs_mask),
|
||||
.vs_out(hdmi_vs_mask),
|
||||
@@ -1489,12 +1480,12 @@ wire [6:0] user_out, user_in;
|
||||
|
||||
assign clk_ihdmi= clk_vid;
|
||||
assign ce_hpix = ce_pix;
|
||||
assign hr_out = r_out;
|
||||
assign hg_out = g_out;
|
||||
assign hb_out = b_out;
|
||||
assign hhs_fix = hs_fix;
|
||||
assign hvs_fix = vs_fix;
|
||||
assign hde_emu = de_emu;
|
||||
assign hr_out = vga_data_sl[23:16];
|
||||
assign hg_out = vga_data_sl[15:8];
|
||||
assign hb_out = vga_data_sl[7:0];
|
||||
assign hhs_fix = vga_hs_sl;
|
||||
assign hvs_fix = vga_vs_sl;
|
||||
assign hde_emu = vga_de_sl;
|
||||
|
||||
wire uart_dtr;
|
||||
wire uart_dsr;
|
||||
@@ -1535,7 +1526,7 @@ emu emu
|
||||
(
|
||||
.CLK_50M(FPGA_CLK2_50),
|
||||
.RESET(reset),
|
||||
.HPS_BUS({f1, HDMI_TX_VS,
|
||||
.HPS_BUS({scanlines,f1, HDMI_TX_VS,
|
||||
clk_100m, clk_ihdmi,
|
||||
ce_hpix, hde_emu, hhs_fix, hvs_fix,
|
||||
io_wait, clk_sys, io_fpga, io_uio, io_strobe, io_wide, io_din, io_dout}),
|
||||
|
||||
Reference in New Issue
Block a user