aboutsummaryrefslogtreecommitdiff
path: root/basys3/basys3.srcs/ppu_comp.vhd
blob: 30b161cf534469df004615374f01b727cfffdb5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
library ieee;
use ieee.std_logic_1164.all;
use work.ppu_consts.all;

entity ppu_comp is port (
	OE : in std_logic; -- global output enable (screen active)
	FG_HIT : in std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0); -- foreground hit array
	BG_EN : out std_logic; -- background enable output
	FG_EN : out std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0)); -- foreground enable output
end ppu_comp;

architecture Behavioral of ppu_comp is
	signal FG_HIT_EMPTY : std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0) := (others => '0');
	signal TMP_BG_EN : std_logic; -- background enable output
	signal TMP_FG_EN : std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0); -- foreground enable output
begin
	BG_EN <= TMP_BG_EN and OE;
	FG_EN <= TMP_FG_EN and OE;

	process (FG_HIT)
		variable HIT : boolean := false;
	begin
		-- check if FG_HIT is not empty
		if FG_HIT /= FG_HIT_EMPTY then
			TMP_BG_EN <= '0';
			for i in 0 to PPU_FG_SPRITE_COUNT-1 loop
				-- if FG_HIT is the first one then enable it
				if(FG_HIT(i) = '1' and HIT = false) then
					TMP_FG_EN(i) <= '1';
					HIT := true;
				else
					-- make rest low
					TMP_FG_EN(i) <= '0';
				end if;
			end loop;
			HIT := false;
		else
			TMP_BG_EN <= '1';
			TMP_FG_EN <= (others => '0');
		end if;
	end process;
end Behavioral;