aboutsummaryrefslogtreecommitdiff
path: root/basys3/basys3.srcs/ppu_pceg.vhd
blob: a491244ef0c687ee291c5fe617560229943bc082 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
library ieee;
use ieee.std_logic_1164.all;
use work.ppu_consts.all;
use work.ppu_pceg_consts.all;

entity ppu_pceg is port(
	CLK : in std_logic; -- system clock
	RESET : in std_logic; -- async reset
	SPRITE_BG : out ppu_sprite_bg_pl_state := PL_BG_IDLE; -- sprite info fetch + sprite pixel fetch
	SPRITE_FG : out ppu_sprite_fg_pl_state := PL_FG_IDLE; -- sprite pixel fetch
	SPRITE_FG_HIT : out ppu_sprite_fg_hit_pl_state := PL_HIT_INACCURATE; -- foreground hit accuracy
	DISPCTL_BWEN : out std_logic := '0'); -- display controller scanline buffer write enable
end ppu_pceg;

architecture Behavioral of ppu_pceg is
	signal CLK_IDX_T : natural range 0 to PPU_PCEG_TOTAL_STAGES+1 := 0;
begin
	process(CLK, RESET)
		variable CLK_IDX : natural range 0 to PPU_PCEG_TOTAL_STAGES+1 := 0;
	begin
		if RESET = '1' then
			CLK_IDX := 0;

			SPRITE_BG <= PL_BG_IDLE;
			SPRITE_FG <= PL_FG_IDLE;
			DISPCTL_BWEN <= '0';
		elsif falling_edge(CLK) then
			-- increment clock counter
			CLK_IDX := CLK_IDX + 1;
			if CLK_IDX = PPU_PCEG_TOTAL_STAGES then
				CLK_IDX := 0;
			end if;

			CLK_IDX_T <= CLK_IDX;

			case CLK_IDX is
				when 0 =>
					SPRITE_BG <= PL_BG_IDLE;
					SPRITE_FG <= PL_FG_IDLE;
					SPRITE_FG_HIT <= PL_HIT_INACCURATE;
				when 1 =>
					SPRITE_BG <= PL_BG_BAM_ADDR;
					SPRITE_FG <= PL_FG_TMM_ADDR;
				when 2 =>
					SPRITE_BG <= PL_BG_BAM_DATA;
					SPRITE_FG <= PL_FG_TMM_DATA;
				when 3 =>
					SPRITE_BG <= PL_BG_IDLE;
					SPRITE_FG <= PL_FG_IDLE;
					SPRITE_FG_HIT <= PL_HIT_ACCURATE;
				when 4 => null;
				when 5 => null;
				when 6 =>
					SPRITE_BG <= PL_BG_TMM_ADDR;
				when 7 =>
					SPRITE_BG <= PL_BG_TMM_DATA;
				when 8 =>
					SPRITE_BG <= PL_BG_IDLE;
				when 9 => null;
				when 10 => null;
				when 11 =>
					DISPCTL_BWEN <= '1';
				when 12 => null;
				when 13 =>
					DISPCTL_BWEN <= '0';
				when others => null;
			end case;
		end if;
	end process;
end Behavioral;