Skip to content
This repository has been archived by the owner on Sep 4, 2023. It is now read-only.

Commit

Permalink
Smart De-dither for composite blending
Browse files Browse the repository at this point in the history
* Smart De-dither for composite blending

* fix for the Smart De-dither

* fix overlapping status bits, leaving [45] for SNAC

Co-authored-by: sorgelig <pour.garbage@gmail.com>
  • Loading branch information
ElectronAsh and sorgelig committed May 1, 2020
1 parent 922aacc commit 911bf53
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Genesis.qsf
Expand Up @@ -13,7 +13,7 @@ set_global_assignment -name PARTITION_NETLIST_TYPE SOURCE -section_id Top
set_global_assignment -name PARTITION_FITTER_PRESERVATION_LEVEL PLACEMENT_AND_ROUTING -section_id Top
set_global_assignment -name PARTITION_COLOR 16764057 -section_id Top

set_global_assignment -name LAST_QUARTUS_VERSION "17.0.2 Standard Edition"
set_global_assignment -name LAST_QUARTUS_VERSION "17.0.0 Standard Edition"

set_global_assignment -name GENERATE_RBF_FILE ON
set_global_assignment -name PROJECT_OUTPUT_DIRECTORY output_files
Expand Down
23 changes: 19 additions & 4 deletions Genesis.sv
Expand Up @@ -177,7 +177,7 @@ assign LED_USER = cart_download | sav_pending;
// 0 1 2 3 4 5 6
// 01234567890123456789012345678901 23456789012345678901234567890123
// 0123456789ABCDEFGHIJKLMNOPQRSTUV 0123456789ABCDEFGHIJKLMNOPQRSTUV
// XXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXX
// XXXXXXXXXXXX XXXXXXXXXXXXXXXXXXX XXXXXXXXXXXXXXXXX

`include "build_id.v"
localparam CONF_STR = {
Expand All @@ -199,7 +199,7 @@ localparam CONF_STR = {
"OU,320x224 Aspect,Original,Corrected;",
"O13,Scandoubler Fx,None,HQ2x,CRT 25%,CRT 50%,CRT 75%;",
"OT,Border,No,Yes;",
"o2,Composite Blending,Off,On;",
"oEG,Composite Blending,Off,On,AutoBGA,AutoBGB,AutoBoth;",
"-;",
"OEF,Audio Filter,Model 1,Model 2,Minimal,No Filter;",
"OB,FM Chip,YM2612,YM3438;",
Expand Down Expand Up @@ -487,9 +487,24 @@ system system
.ROM_ADDR2(rom_addr2),
.ROM_DATA2(rom_data2),
.ROM_REQ2(rom_rd2),
.ROM_ACK2(rom_rdack2)
.ROM_ACK2(rom_rdack2),

.BG_LAYER_ACTIVE(BG_LAYER_ACTIVE),

.BGA_DITHER_DETECT(BGA_DITHER_DETECT),
.BGB_DITHER_DETECT(BGB_DITHER_DETECT)
);

wire BG_LAYER_ACTIVE;
wire BGA_DITHER_DETECT;
wire BGB_DITHER_DETECT;


wire cofi_enable = (status[48:46]==3'd1) || // Force on (whole screen).
(status[48:46]==3'd2 && /*BG_LAYER_ACTIVE &&*/ BGA_DITHER_DETECT) || // Auto-detect on Background Layer A.
(status[48:46]==3'd3 && /*BG_LAYER_ACTIVE &&*/ BGB_DITHER_DETECT) || // Auto-detect on Background Layer B.
(status[48:46]==3'd4 && /*BG_LAYER_ACTIVE &&*/ (BGA_DITHER_DETECT || BGB_DITHER_DETECT)); // Auto-detect on BOTH Background layers.

wire PAL = status[7];

reg new_vmode;
Expand Down Expand Up @@ -551,7 +566,7 @@ wire [7:0] red, green, blue;
cofi coffee (
.clk(clk_sys),
.pix_ce(ce_pix),
.enable(status[34]),
.enable(cofi_enable),

.hblank(hblank),
.vblank(vblank),
Expand Down
14 changes: 12 additions & 2 deletions system.sv
Expand Up @@ -123,7 +123,11 @@ module system

input EN_HIFI_PCM,
input LADDER,
input OBJ_LIMIT_HIGH
input OBJ_LIMIT_HIGH,

output BG_LAYER_ACTIVE,
output BGA_DITHER_DETECT,
output BGB_DITHER_DETECT
);

reg reset;
Expand Down Expand Up @@ -451,9 +455,15 @@ vdp vdp
.VS(VDP_vs),
.CE_PIX(CE_PIX),
.HBL(HBL),
.VBL(VBL)
.VBL(VBL),

.BG_LAYER_ACTIVE(BG_LAYER_ACTIVE),

.BGA_DITHER_DETECT(BGA_DITHER_DETECT),
.BGB_DITHER_DETECT(BGB_DITHER_DETECT)
);


// PSG 0x10-0x17 in VDP space
wire signed [10:0] PSG_SND;
jt89 psg
Expand Down
61 changes: 54 additions & 7 deletions vdp.vhd
Expand Up @@ -108,7 +108,12 @@ entity vdp is
VRAM_SPEED : in std_logic := '1'; -- 0 - full speed, 1 - FIFO throttle emulation
VSCROLL_BUG : in std_logic := '1'; -- 0 - use nicer effect, 1 - HW original
BORDER_EN : in std_logic := '1'; -- Enable border
OBJ_LIMIT_HIGH_EN : in std_logic := '0' -- Enable more sprites and pixels per line
OBJ_LIMIT_HIGH_EN : in std_logic := '0'; -- Enable more sprites and pixels per line

BG_LAYER_ACTIVE : out std_logic;

BGA_DITHER_DETECT : out std_logic;
BGB_DITHER_DETECT : out std_logic
);
end vdp;

Expand Down Expand Up @@ -441,6 +446,19 @@ type bgbc_t is (
);
signal BGBC : bgbc_t;


-- Smart De-dither signals. (ElectronAsh).
signal PRI_LEVEL : std_logic_vector(2 downto 0);

signal BGA_SHIFT_REG_0 : std_logic_vector(3 downto 0);
signal BGA_SHIFT_REG_1 : std_logic_vector(3 downto 0);
signal BGA_SHIFT_REG_2 : std_logic_vector(3 downto 0);

signal BGB_SHIFT_REG_0 : std_logic_vector(3 downto 0);
signal BGB_SHIFT_REG_1 : std_logic_vector(3 downto 0);
signal BGB_SHIFT_REG_2 : std_logic_vector(3 downto 0);


-- signal BGB_COLINFO : colinfo_t;
signal BGB_COLINFO_ADDR_A : std_logic_vector(8 downto 0);
signal BGB_COLINFO_ADDR_B : std_logic_vector(8 downto 0);
Expand Down Expand Up @@ -2594,22 +2612,48 @@ begin
end if;
end if;

if OBJ_COLINFO2_Q(3 downto 0) /= "0000" and OBJ_COLINFO2_Q(6) = '1' and
(SHI='0' or OBJ_COLINFO2_Q(5 downto 1) /= "11111") then
col := OBJ_COLINFO2_Q(5 downto 0);
-- Smart de-dither detection. (ElectronAsh).
BGA_SHIFT_REG_2 <= BGA_SHIFT_REG_1;
BGA_SHIFT_REG_1 <= BGA_SHIFT_REG_0;
BGA_SHIFT_REG_0 <= BGA_COLINFO_Q_B(3 downto 0);

BGB_SHIFT_REG_2 <= BGB_SHIFT_REG_1;
BGB_SHIFT_REG_1 <= BGB_SHIFT_REG_0;
BGB_SHIFT_REG_0 <= BGB_COLINFO_Q_B(3 downto 0);

if (BGA_SHIFT_REG_2="0000" and BGA_SHIFT_REG_1/="0000" and BGA_SHIFT_REG_0="0000" and BGA_COLINFO_Q_B(3 downto 0)/="0000") or
(BGA_SHIFT_REG_2/="0000" and BGA_SHIFT_REG_1="0000" and BGA_SHIFT_REG_0/="0000" and BGA_COLINFO_Q_B(3 downto 0)="0000") then BGA_DITHER_DETECT <= '1';
else BGA_DITHER_DETECT <= '0';
end if;

if (BGB_SHIFT_REG_2="0000" and BGB_SHIFT_REG_1/="0000" and BGB_SHIFT_REG_0="0000" and BGB_COLINFO_Q_B(3 downto 0)/="0000") or
(BGB_SHIFT_REG_2/="0000" and BGB_SHIFT_REG_1="0000" and BGB_SHIFT_REG_0/="0000" and BGB_COLINFO_Q_B(3 downto 0)="0000") then BGB_DITHER_DETECT <= '1';
else BGB_DITHER_DETECT <= '0';
end if;


-- Priority encoder for backgrounds and sprites.
if OBJ_COLINFO2_Q(3 downto 0) /= "0000" and OBJ_COLINFO2_Q(6) = '1' and (SHI='0' or OBJ_COLINFO2_Q(5 downto 1) /= "11111") then
col := OBJ_COLINFO2_Q(5 downto 0);
PRI_LEVEL <= "110";
elsif BGA_COLINFO_Q_B(3 downto 0) /= "0000" and BGA_COLINFO_Q_B(6) = '1' then
col := BGA_COLINFO_Q_B(5 downto 0);
PRI_LEVEL <= "101";
elsif BGB_COLINFO_Q_B(3 downto 0) /= "0000" and BGB_COLINFO_Q_B(6) = '1' then
col := BGB_COLINFO_Q_B(5 downto 0);
elsif OBJ_COLINFO2_Q(3 downto 0) /= "0000" and
(SHI='0' or OBJ_COLINFO2_Q(5 downto 1) /= "11111") then
col := OBJ_COLINFO2_Q(5 downto 0);
PRI_LEVEL <= "100";
elsif OBJ_COLINFO2_Q(3 downto 0) /= "0000" and (SHI='0' or OBJ_COLINFO2_Q(5 downto 1) /= "11111") then
col := OBJ_COLINFO2_Q(5 downto 0);
PRI_LEVEL <= "011";
elsif BGA_COLINFO_Q_B(3 downto 0) /= "0000" then
col := BGA_COLINFO_Q_B(5 downto 0);
PRI_LEVEL <= "010";
elsif BGB_COLINFO_Q_B(3 downto 0) /= "0000" then
col := BGB_COLINFO_Q_B(5 downto 0);
PRI_LEVEL <= "001";
else
col := BGCOL;
PRI_LEVEL <= "000";
end if;

case DBG(8 downto 7) is
Expand Down Expand Up @@ -2669,6 +2713,9 @@ begin
end if;
end process;

BG_LAYER_ACTIVE <= '1' when (PRI_LEVEL="001" or PRI_LEVEL="010" or PRI_LEVEL="100" or PRI_LEVEL="101") else '0';


----------------------------------------------------------------
-- VIDEO OUTPUT
----------------------------------------------------------------
Expand Down

1 comment on commit 911bf53

@suverman
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one :)

Please sign in to comment.