From d2eb1cf5055a19f3e276ce737428b06332de63b3 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 20 Feb 2023 11:23:30 +0100 Subject: rename .vhdl to .vhd --- style.md | 1 + 1 file changed, 1 insertion(+) (limited to 'style.md') diff --git a/style.md b/style.md index 7e6b9b6..3cbe9b8 100644 --- a/style.md +++ b/style.md @@ -50,4 +50,5 @@ before formatting as a failsafe. - use lower case keywords - testbench name is the component name with `_tb` as suffix - vhdl filename is the same as the component name +- vhdl files should end in the `.vhd` file extension, not `.vhdl` -- cgit v1.2.3 From e608ff1230b1db80cb4d68e513fb05fc92774bdc Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 20 Feb 2023 12:39:43 +0100 Subject: update code style --- basys3/basys3.srcs/apu.vhd | 32 +-- basys3/basys3.srcs/apu_note_to_frequency.vhd | 6 +- basys3/basys3.srcs/apu_note_to_frequency_tb.vhd | 14 +- basys3/basys3.srcs/ppu.vhd | 266 ++++++++++++------------ basys3/basys3.srcs/ppu_addr_dec.vhd | 30 +-- basys3/basys3.srcs/ppu_addr_dec_tb.vhd | 60 +++--- basys3/basys3.srcs/ppu_consts.vhd | 38 ++-- basys3/basys3.srcs/ppu_pceg.vhd | 16 +- basys3/basys3.srcs/ppu_pceg_tb.vhd | 24 +-- style.md | 1 + 10 files changed, 244 insertions(+), 243 deletions(-) (limited to 'style.md') diff --git a/basys3/basys3.srcs/apu.vhd b/basys3/basys3.srcs/apu.vhd index 4a594ab..1fff1e8 100644 --- a/basys3/basys3.srcs/apu.vhd +++ b/basys3/basys3.srcs/apu.vhd @@ -3,29 +3,29 @@ use ieee.std_logic_1164.all; --use ieee.numeric_std.all; entity apu is port( - CLK100: in std_logic; -- system clock - RESET: in std_logic; -- global (async) system reset - DATA: in std_logic_vector(15 downto 0); - SOUND: out std_logic); + CLK100 : in std_logic; -- system clock + RESET : in std_logic; -- global (async) system reset + DATA : in std_logic_vector(15 downto 0); + SOUND : out std_logic); - -- EN: in std_logic; -- PPU VRAM enable (enable ADDR and DATA tri-state drivers) - -- WEN: in std_logic; -- PPU VRAM write enable - -- ADDR: in std_logic_vector(15 downto 0); -- PPU VRAM ADDR - -- R,G,B: out std_logic_vector(3 downto 0); - -- NVSYNC, NHSYNC: out std_logic; -- native VGA out - -- TVSYNC, TVBLANK, THSYNC, THBLANK: out std_logic); -- tiny VGA out + -- EN : in std_logic; -- PPU VRAM enable (enable ADDR and DATA tri-state drivers) + -- WEN : in std_logic; -- PPU VRAM write enable + -- ADDR : in std_logic_vector(15 downto 0); -- PPU VRAM ADDR + -- R,G,B : out std_logic_vector(3 downto 0); + -- NVSYNC, NHSYNC : out std_logic; -- native VGA out + -- TVSYNC, TVBLANK, THSYNC, THBLANK : out std_logic); -- tiny VGA out end apu; architecture Behavioral of apu is component apu_note_to_frequency port( - data: in std_logic_vector(7 downto 0); - freq: out std_logic_vector(7 downto 0)); --frequency + data : in std_logic_vector(7 downto 0); + freq : out std_logic_vector(7 downto 0)); --frequency end component; component apu_LUT_reader port( - clk: in std_logic; - rst: in std_logic; - wave: in std_logic_vector(1 downto 0); - level: out std_logic_vector(7 downto 0)); + clk : in std_logic; + rst : in std_logic; + wave : in std_logic_vector(1 downto 0); + level : out std_logic_vector(7 downto 0)); end component; begin diff --git a/basys3/basys3.srcs/apu_note_to_frequency.vhd b/basys3/basys3.srcs/apu_note_to_frequency.vhd index 7e02c75..1e47b8e 100644 --- a/basys3/basys3.srcs/apu_note_to_frequency.vhd +++ b/basys3/basys3.srcs/apu_note_to_frequency.vhd @@ -10,9 +10,9 @@ entity apu_note_to_frequency is port ( end entity; architecture Behavioral of apu_note_to_frequency is - signal buff_small: std_logic_vector(7 downto 0) := (others => '0'); - signal buff: std_logic_vector(15 downto 0) := (others => '0'); - signal shift: integer; + signal buff_small : std_logic_vector(7 downto 0) := (others => '0'); + signal buff : std_logic_vector(15 downto 0) := (others => '0'); + signal shift : integer; begin shift <= to_integer(unsigned(data(2 downto 0))); buff_small <= diff --git a/basys3/basys3.srcs/apu_note_to_frequency_tb.vhd b/basys3/basys3.srcs/apu_note_to_frequency_tb.vhd index 6814c1f..f48a40c 100644 --- a/basys3/basys3.srcs/apu_note_to_frequency_tb.vhd +++ b/basys3/basys3.srcs/apu_note_to_frequency_tb.vhd @@ -10,20 +10,20 @@ end entity; architecture Behavioral of apu_note_to_frequency_tb is component apu_note_to_frequency is port( - data: in std_logic_vector(7 downto 0); - freq: out std_logic_vector(11 downto 0)); -- frequency + data : in std_logic_vector(7 downto 0); + freq : out std_logic_vector(11 downto 0)); -- frequency end component; - signal data: std_logic_vector(7 downto 0) := (others => '0'); - signal freq: std_logic_vector(11 downto 0) := (others => '0'); + signal data : std_logic_vector(7 downto 0) := (others => '0'); + signal freq : std_logic_vector(11 downto 0) := (others => '0'); - signal ok: boolean := false; + signal ok : boolean := false; begin - uut: apu_note_to_frequency port map( + uut : apu_note_to_frequency port map( data => data, freq => freq); - tb: process + tb : process begin for i in 0 to 255 loop data <= std_logic_vector(to_unsigned(i, 8)); diff --git a/basys3/basys3.srcs/ppu.vhd b/basys3/basys3.srcs/ppu.vhd index 663f3ab..acf546f 100644 --- a/basys3/basys3.srcs/ppu.vhd +++ b/basys3/basys3.srcs/ppu.vhd @@ -6,184 +6,184 @@ use ieee.std_logic_1164.all; use work.ppu_consts.all; entity ppu is port( - CLK100: in std_logic; -- system clock - RESET: in std_logic; -- global (async) system reset - EN: in std_logic; -- PPU VRAM enable (enable ADDR and DATA tri-state drivers) - WEN: in std_logic; -- PPU VRAM write enable - ADDR: in std_logic_vector(PPU_RAM_BUS_ADDR_WIDTH-1 downto 0); -- PPU VRAM ADDR - DATA: in std_logic_vector(PPU_RAM_BUS_DATA_WIDTH-1 downto 0); - R,G,B: out std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); - NVSYNC, NHSYNC: out std_logic; -- native VGA out - TVSYNC, TVBLANK, THSYNC, THBLANK: out std_logic); -- tiny VGA out + CLK100 : in std_logic; -- system clock + RESET : in std_logic; -- global (async) system reset + EN : in std_logic; -- PPU VRAM enable (enable ADDR and DATA tri-state drivers) + WEN : in std_logic; -- PPU VRAM write enable + ADDR : in std_logic_vector(PPU_RAM_BUS_ADDR_WIDTH-1 downto 0); -- PPU VRAM ADDR + DATA : in std_logic_vector(PPU_RAM_BUS_DATA_WIDTH-1 downto 0); + R,G,B : out std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); + NVSYNC, NHSYNC : out std_logic; -- native VGA out + TVSYNC, TVBLANK, THSYNC, THBLANK : out std_logic); -- tiny VGA out end ppu; architecture Behavioral of ppu is component ppu_pceg port( -- pipeline clock edge generator - CLK: in std_logic; -- system clock - RESET: in std_logic; -- async reset - SPRITE: out std_logic; -- sprite info fetch + sprite pixel fetch - COMP_PAL: out std_logic; -- compositor + palette lookup - DONE: out std_logic); -- last pipeline stage done + CLK : in std_logic; -- system clock + RESET : in std_logic; -- async reset + SPRITE : out std_logic; -- sprite info fetch + sprite pixel fetch + COMP_PAL : out std_logic; -- compositor + palette lookup + DONE : out std_logic); -- last pipeline stage done end component; component ppu_addr_dec port( -- pipeline clock edge generator - WEN: in std_logic; -- EXT write enable + WEN : in std_logic; -- EXT write enable TMM_WEN, BAM_WEN, FAM_WEN, PAL_WEN, - AUX_WEN: out std_logic; -- write enable MUX - EN: in std_logic; -- EXT *ADDR enable (switch *AO to ADDR instead of *AI) - ADDR: in std_logic_vector(PPU_RAM_BUS_ADDR_WIDTH-1 downto 0); -- address in - TMM_AI: in std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); - BAM_AI: in std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); - FAM_AI: in std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); - PAL_AI: in std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); - AUX_AI: in std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); - TMM_AO: out std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); - BAM_AO: out std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); - FAM_AO: out std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); - PAL_AO: out std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); - AUX_AO: out std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0)); + AUX_WEN : out std_logic; -- write enable MUX + EN : in std_logic; -- EXT *ADDR enable (switch *AO to ADDR instead of *AI) + ADDR : in std_logic_vector(PPU_RAM_BUS_ADDR_WIDTH-1 downto 0); -- address in + TMM_AI : in std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); + BAM_AI : in std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); + FAM_AI : in std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); + PAL_AI : in std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); + AUX_AI : in std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); + TMM_AO : out std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); + BAM_AO : out std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); + FAM_AO : out std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); + PAL_AO : out std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); + AUX_AO : out std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0)); end component; component ppu_bam port( -- BAM block memory - clka: in std_logic; - rsta: in std_logic; - wea: in std_logic_vector(0 downto 0); - addra: in std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); - dina: in std_logic_vector(PPU_BAM_DATA_WIDTH-1 downto 0); - douta: out std_logic_vector(PPU_BAM_DATA_WIDTH-1 downto 0); - rsta_busy: out std_logic); + clka : in std_logic; + rsta : in std_logic; + wea : in std_logic_vector(0 downto 0); + addra : in std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); + dina : in std_logic_vector(PPU_BAM_DATA_WIDTH-1 downto 0); + douta : out std_logic_vector(PPU_BAM_DATA_WIDTH-1 downto 0); + rsta_busy : out std_logic); end component; component ppu_tmm port( -- TMM block memory - clka: in std_logic; - rsta: in std_logic; - wea: in std_logic_vector(0 downto 0); - addra: in std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); - dina: in std_logic_vector(PPU_TMM_DATA_WIDTH-1 downto 0); - douta: out std_logic_vector(PPU_TMM_DATA_WIDTH-1 downto 0); - rsta_busy: out std_logic); + clka : in std_logic; + rsta : in std_logic; + wea : in std_logic_vector(0 downto 0); + addra : in std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); + dina : in std_logic_vector(PPU_TMM_DATA_WIDTH-1 downto 0); + douta : out std_logic_vector(PPU_TMM_DATA_WIDTH-1 downto 0); + rsta_busy : out std_logic); end component; component ppu_aux port( - CLK: in std_logic; -- system clock - RESET: in std_logic; -- reset memory + CLK : in std_logic; -- system clock + RESET : in std_logic; -- reset memory -- internal memory block (AUX) - AUX_WEN: in std_logic; -- VRAM AUX write enable - AUX_ADDR: in std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); -- VRAM AUX address - AUX_DATA: in std_logic_vector(PPU_AUX_DATA_WIDTH-1 downto 0); -- VRAM AUX data + AUX_WEN : in std_logic; -- VRAM AUX write enable + AUX_ADDR : in std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); -- VRAM AUX address + AUX_DATA : in std_logic_vector(PPU_AUX_DATA_WIDTH-1 downto 0); -- VRAM AUX data -- aux outputs - BG_SHIFT_X: out std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); - BG_SHIFT_Y: out std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); - FG_FETCH: out std_logic); + BG_SHIFT_X : out std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); + BG_SHIFT_Y : out std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); + FG_FETCH : out std_logic); end component; component ppu_sprite_bg port( -- background sprite -- inputs - CLK: in std_logic; -- system clock - RESET: in std_logic; -- reset clock counter - OE: in std_logic; -- output enable (of CIDX) - X: in std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x - Y: in std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y + CLK : in std_logic; -- system clock + RESET : in std_logic; -- reset clock counter + OE : in std_logic; -- output enable (of CIDX) + X : in std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x + Y : in std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y -- aux inputs - BG_SHIFT_X: in std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); - BG_SHIFT_Y: in std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); + BG_SHIFT_X : in std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); + BG_SHIFT_Y : in std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- used memory blocks - BAM_ADDR: out std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); - BAM_DATA: in std_logic_vector(PPU_BAM_DATA_WIDTH-1 downto 0); - TMM_ADDR: out std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); - TMM_DATA: in std_logic_vector(PPU_TMM_DATA_WIDTH-1 downto 0); + BAM_ADDR : out std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); + BAM_DATA : in std_logic_vector(PPU_BAM_DATA_WIDTH-1 downto 0); + TMM_ADDR : out std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); + TMM_DATA : in std_logic_vector(PPU_TMM_DATA_WIDTH-1 downto 0); -- outputs - CIDX: out std_logic_vector(PPU_PALETTE_CIDX_WIDTH-1 downto 0)); -- output color + CIDX : out std_logic_vector(PPU_PALETTE_CIDX_WIDTH-1 downto 0)); -- output color end component; component ppu_sprite_fg port( -- foreground sprite -- inputs - CLK: in std_logic; -- system clock - RESET: in std_logic; -- reset internal memory and clock counters - OE: in std_logic; -- output enable (of CIDX) - X: in std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x - Y: in std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y - FETCH: in std_logic; -- fetch sprite data from TMM (TODO: generic map, set foreground sprite component index) + CLK : in std_logic; -- system clock + RESET : in std_logic; -- reset internal memory and clock counters + OE : in std_logic; -- output enable (of CIDX) + X : in std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x + Y : in std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y + FETCH : in std_logic; -- fetch sprite data from TMM (TODO : generic map, set foreground sprite component index) -- internal memory block (FAM) - FAM_WEN: in std_logic; -- VRAM FAM write enable - FAM_ADDR: in std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); -- VRAM fam address - FAM_DATA: in std_logic_vector(PPU_FAM_DATA_WIDTH-1 downto 0); -- VRAM fam data + FAM_WEN : in std_logic; -- VRAM FAM write enable + FAM_ADDR : in std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); -- VRAM fam address + FAM_DATA : in std_logic_vector(PPU_FAM_DATA_WIDTH-1 downto 0); -- VRAM fam data -- used memory blocks - TMM_ADDR: out std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); - TMM_DATA: in std_logic_vector(PPU_TMM_DATA_WIDTH-1 downto 0); + TMM_ADDR : out std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); + TMM_DATA : in std_logic_vector(PPU_TMM_DATA_WIDTH-1 downto 0); -- outputs - CIDX: out std_logic_vector(PPU_PALETTE_CIDX_WIDTH-1 downto 0); -- output color - HIT: out std_logic); -- current pixel is not transparent + CIDX : out std_logic_vector(PPU_PALETTE_CIDX_WIDTH-1 downto 0); -- output color + HIT : out std_logic); -- current pixel is not transparent end component; component ppu_comp port( -- compositor - FG_HIT: in std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0); - BG_EN: out std_logic; - FG_EN: out std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0)); + FG_HIT : in std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0); + BG_EN : out std_logic; + FG_EN : out std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0)); end component; component ppu_plut port( -- palette lookup table - CLK: in std_logic; -- system clock - CIDX: in std_logic_vector(PPU_PALETTE_CIDX_WIDTH-1 downto 0); -- color in - RESET: in std_logic; + CLK : in std_logic; -- system clock + CIDX : in std_logic_vector(PPU_PALETTE_CIDX_WIDTH-1 downto 0); -- color in + RESET : in std_logic; -- internal memory block (AUX) - PAL_WEN: in std_logic; -- VRAM PAL write enable - PAL_ADDR: in std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); -- VRAM PAL address - PAL_DATA: in std_logic_vector(PPU_PAL_DATA_WIDTH-1 downto 0); -- VRAM PAL data + PAL_WEN : in std_logic; -- VRAM PAL write enable + PAL_ADDR : in std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); -- VRAM PAL address + PAL_DATA : in std_logic_vector(PPU_PAL_DATA_WIDTH-1 downto 0); -- VRAM PAL data - R,G,B: out std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0)); -- VGA color out + R,G,B : out std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0)); -- VGA color out end component; component ppu_vga_tiny port( -- tiny vga signal generator - CLK: in std_logic; -- system clock - RESET: in std_logic; + CLK : in std_logic; -- system clock + RESET : in std_logic; - X: out std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x - Y: out std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y + X : out std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x + Y : out std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y VSYNC, VBLANK, - HSYNC, HBLANK: out std_logic); -- VGA sync outputs + HSYNC, HBLANK : out std_logic); -- VGA sync outputs end component; component ppu_vga_native port( -- native vga signal generator (upscaler) - CLK: in std_logic; -- system clock - RESET: in std_logic; + CLK : in std_logic; -- system clock + RESET : in std_logic; - X: in std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x - Y: in std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y - PREADY: in std_logic; -- current pixel ready (pixel color is stable) - RI,GI,BI: in std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- VGA color in + X : in std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x + Y : in std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y + PREADY : in std_logic; -- current pixel ready (pixel color is stable) + RI,GI,BI : in std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- VGA color in - RO,GO,BO: out std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- VGA color out - VSYNC, HSYNC: out std_logic); -- VGA sync outputs + RO,GO,BO : out std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- VGA color out + VSYNC, HSYNC : out std_logic); -- VGA sync outputs end component; -- signals - signal SYSCLK, SYSRST: std_logic; -- system clock and reset - signal PL_SPRITE, PL_COMP_PAL, PL_DONE: std_logic; -- pipeline stages - signal TMM_WEN, BAM_WEN, FAM_WEN, PAL_WEN, AUX_WEN: std_logic; - signal TMM_AI, TMM_AO: std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); - signal BAM_AI, BAM_AO: std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); - signal FAM_AI, FAM_AO: std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); - signal PAL_AI, PAL_AO: std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); - signal AUX_AI, AUX_AO: std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); - signal TMM_DO: std_logic_vector(PPU_TMM_DATA_WIDTH-1 downto 0); - signal BAM_DO: std_logic_vector(PPU_BAM_DATA_WIDTH-1 downto 0); - signal FAM_DO: std_logic_vector(PPU_FAM_DATA_WIDTH-1 downto 0); - signal PAL_DO: std_logic_vector(PPU_PAL_DATA_WIDTH-1 downto 0); - signal AUX_DO: std_logic_vector(PPU_AUX_DATA_WIDTH-1 downto 0); - signal CIDX: std_logic_vector(PPU_PALETTE_CIDX_WIDTH-1 downto 0); - signal BG_EN: std_logic; - signal FG_EN, FG_HIT: std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0); - signal X: std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x - signal Y: std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y - signal UR,UG,UB: std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- unstable RGB (to be buffered) - signal SR,SG,SB: std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- stable RGB (buffered until PL_COMP_PAL) - signal BG_SHIFT_X: std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); - signal BG_SHIFT_Y: std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); - signal FG_FETCH: std_logic; + signal SYSCLK, SYSRST : std_logic; -- system clock and reset + signal PL_SPRITE, PL_COMP_PAL, PL_DONE : std_logic; -- pipeline stages + signal TMM_WEN, BAM_WEN, FAM_WEN, PAL_WEN, AUX_WEN : std_logic; + signal TMM_AI, TMM_AO : std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); + signal BAM_AI, BAM_AO : std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); + signal FAM_AI, FAM_AO : std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); + signal PAL_AI, PAL_AO : std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); + signal AUX_AI, AUX_AO : std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); + signal TMM_DO : std_logic_vector(PPU_TMM_DATA_WIDTH-1 downto 0); + signal BAM_DO : std_logic_vector(PPU_BAM_DATA_WIDTH-1 downto 0); + signal FAM_DO : std_logic_vector(PPU_FAM_DATA_WIDTH-1 downto 0); + signal PAL_DO : std_logic_vector(PPU_PAL_DATA_WIDTH-1 downto 0); + signal AUX_DO : std_logic_vector(PPU_AUX_DATA_WIDTH-1 downto 0); + signal CIDX : std_logic_vector(PPU_PALETTE_CIDX_WIDTH-1 downto 0); + signal BG_EN : std_logic; + signal FG_EN, FG_HIT : std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0); + signal X : std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x + signal Y : std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y + signal UR,UG,UB : std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- unstable RGB (to be buffered) + signal SR,SG,SB : std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- stable RGB (buffered until PL_COMP_PAL) + signal BG_SHIFT_X : std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); + signal BG_SHIFT_Y : std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); + signal FG_FETCH : std_logic; begin SYSCLK <= CLK100; SYSRST <= RESET; @@ -197,14 +197,14 @@ begin FAM_AI <= (others => '0'); PAL_AI <= (others => '0'); - pipeline_clock_edge_generator: component ppu_pceg port map( + pipeline_clock_edge_generator : component ppu_pceg port map( CLK => SYSCLK, RESET => SYSRST, SPRITE => PL_SPRITE, COMP_PAL => PL_COMP_PAL, DONE => PL_DONE); - address_decoder: component ppu_addr_dec port map( + address_decoder : component ppu_addr_dec port map( EN => EN, WEN => WEN, ADDR => ADDR, @@ -224,7 +224,7 @@ begin PAL_WEN => PAL_WEN, AUX_WEN => AUX_WEN); - background_attribute_memory: component ppu_bam port map( + background_attribute_memory : component ppu_bam port map( clka => SYSCLK, rsta => SYSRST, wea => (others => BAM_WEN), @@ -232,7 +232,7 @@ begin dina => DATA(PPU_BAM_DATA_WIDTH-1 downto 0), douta => BAM_DO, rsta_busy => open); - tilemap_memory: component ppu_tmm port map( + tilemap_memory : component ppu_tmm port map( clka => SYSCLK, rsta => SYSRST, wea => (others => TMM_WEN), @@ -241,7 +241,7 @@ begin douta => TMM_DO, rsta_busy => open); - aux: component ppu_aux port map( + aux : component ppu_aux port map( CLK => SYSCLK, RESET => SYSRST, AUX_WEN => AUX_WEN, @@ -251,7 +251,7 @@ begin BG_SHIFT_Y => BG_SHIFT_Y, FG_FETCH => FG_FETCH); - background_sprite: component ppu_sprite_bg port map( + background_sprite : component ppu_sprite_bg port map( CLK => PL_SPRITE, RESET => SYSRST, OE => BG_EN, @@ -265,8 +265,8 @@ begin TMM_DATA => TMM_DO, CIDX => CIDX); - foreground_sprites: for FG_IDX in 0 to PPU_FG_SPRITE_COUNT-1 generate - foreground_sprite: component ppu_sprite_fg port map( + foreground_sprites : for FG_IDX in 0 to PPU_FG_SPRITE_COUNT-1 generate + foreground_sprite : component ppu_sprite_fg port map( CLK => PL_SPRITE, RESET => SYSRST, OE => FG_EN(FG_IDX), @@ -282,12 +282,12 @@ begin HIT => FG_HIT(FG_IDX)); end generate; - compositor: component ppu_comp port map( -- compositor + compositor : component ppu_comp port map( -- compositor FG_HIT => FG_HIT, BG_EN => BG_EN, FG_EN => FG_EN); - palette_lookup: component ppu_plut port map( -- palette lookup table + palette_lookup : component ppu_plut port map( -- palette lookup table CLK => SYSCLK, CIDX => CIDX, RESET => SYSRST, @@ -312,7 +312,7 @@ begin end if; end process; - tiny_vga_signal_generator: component ppu_vga_tiny port map( -- tiny vga signal generator + tiny_vga_signal_generator : component ppu_vga_tiny port map( -- tiny vga signal generator CLK => SYSCLK, RESET => SYSRST, X => X, @@ -322,7 +322,7 @@ begin HSYNC => THSYNC, HBLANK => THBLANK); - native_vga_signal_generator: component ppu_vga_native port map( -- native vga signal generator (upscaler) + native_vga_signal_generator : component ppu_vga_native port map( -- native vga signal generator (upscaler) CLK => SYSCLK, RESET => SYSRST, X => X, diff --git a/basys3/basys3.srcs/ppu_addr_dec.vhd b/basys3/basys3.srcs/ppu_addr_dec.vhd index 28c22fc..df83964 100644 --- a/basys3/basys3.srcs/ppu_addr_dec.vhd +++ b/basys3/basys3.srcs/ppu_addr_dec.vhd @@ -5,28 +5,28 @@ use ieee.std_logic_1164.all; use work.ppu_consts.all; entity ppu_addr_dec is port( - EN: in std_logic; -- EXT *ADDR enable (switch *AO to ADDR instead of *AI) - WEN: in std_logic; -- EXT write enable + EN : in std_logic; -- EXT *ADDR enable (switch *AO to ADDR instead of *AI) + WEN : in std_logic; -- EXT write enable TMM_WEN, BAM_WEN, FAM_WEN, PAL_WEN, - AUX_WEN: out std_logic; -- write enable MUX - ADDR: in std_logic_vector(PPU_RAM_BUS_ADDR_WIDTH-1 downto 0); -- address in - TMM_AI: in std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); - BAM_AI: in std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); - FAM_AI: in std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); - PAL_AI: in std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); - AUX_AI: in std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); - TMM_AO: out std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); - BAM_AO: out std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); - FAM_AO: out std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); - PAL_AO: out std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); - AUX_AO: out std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0)); + AUX_WEN : out std_logic; -- write enable MUX + ADDR : in std_logic_vector(PPU_RAM_BUS_ADDR_WIDTH-1 downto 0); -- address in + TMM_AI : in std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); + BAM_AI : in std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); + FAM_AI : in std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); + PAL_AI : in std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); + AUX_AI : in std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); + TMM_AO : out std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); + BAM_AO : out std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); + FAM_AO : out std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); + PAL_AO : out std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); + AUX_AO : out std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0)); end ppu_addr_dec; architecture Behavioral of ppu_addr_dec is - signal TMM_RANGE, BAM_RANGE, FAM_RANGE, PAL_RANGE, AUX_RANGE: std_logic := '0'; -- ADDR in range of memory area + signal TMM_RANGE, BAM_RANGE, FAM_RANGE, PAL_RANGE, AUX_RANGE : std_logic := '0'; -- ADDR in range of memory area begin -- address MUX TMM_AO <= ADDR(PPU_TMM_ADDR_WIDTH-1 downto 0) when EN = '1' else TMM_AI; diff --git a/basys3/basys3.srcs/ppu_addr_dec_tb.vhd b/basys3/basys3.srcs/ppu_addr_dec_tb.vhd index 5c7119d..f31ee67 100644 --- a/basys3/basys3.srcs/ppu_addr_dec_tb.vhd +++ b/basys3/basys3.srcs/ppu_addr_dec_tb.vhd @@ -12,41 +12,41 @@ end ppu_addr_dec_tb; architecture behavioral of ppu_addr_dec_tb is component ppu_addr_dec port( - EN: in std_logic; -- EXT *ADDR enable (switch *AO to ADDR instead of *AI) - WEN: in std_logic; -- EXT write enable + EN : in std_logic; -- EXT *ADDR enable (switch *AO to ADDR instead of *AI) + WEN : in std_logic; -- EXT write enable TMM_WEN, BAM_WEN, FAM_WEN, PAL_WEN, - AUX_WEN: out std_logic; -- write enable MUX - ADDR: in std_logic_vector(PPU_RAM_BUS_ADDR_WIDTH-1 downto 0); -- address in - TMM_AI: in std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); - BAM_AI: in std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); - FAM_AI: in std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); - PAL_AI: in std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); - AUX_AI: in std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); - TMM_AO: out std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); - BAM_AO: out std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); - FAM_AO: out std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); - PAL_AO: out std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); - AUX_AO: out std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0)); + AUX_WEN : out std_logic; -- write enable MUX + ADDR : in std_logic_vector(PPU_RAM_BUS_ADDR_WIDTH-1 downto 0); -- address in + TMM_AI : in std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); + BAM_AI : in std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); + FAM_AI : in std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); + PAL_AI : in std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); + AUX_AI : in std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); + TMM_AO : out std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); + BAM_AO : out std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); + FAM_AO : out std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); + PAL_AO : out std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); + AUX_AO : out std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0)); end component; - signal EN: std_logic; - signal WEN: std_logic; - signal TMM_WEN, BAM_WEN, FAM_WEN, PAL_WEN, AUX_WEN: std_logic; - signal ADDR: std_logic_vector(PPU_RAM_BUS_ADDR_WIDTH-1 downto 0); - signal TMM_AI: std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); - signal BAM_AI: std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); - signal FAM_AI: std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); - signal PAL_AI: std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); - signal AUX_AI: std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); - signal TMM_AO: std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); - signal BAM_AO: std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); - signal FAM_AO: std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); - signal PAL_AO: std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); - signal AUX_AO: std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); + signal EN : std_logic; + signal WEN : std_logic; + signal TMM_WEN, BAM_WEN, FAM_WEN, PAL_WEN, AUX_WEN : std_logic; + signal ADDR : std_logic_vector(PPU_RAM_BUS_ADDR_WIDTH-1 downto 0); + signal TMM_AI : std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); + signal BAM_AI : std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); + signal FAM_AI : std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); + signal PAL_AI : std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); + signal AUX_AI : std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); + signal TMM_AO : std_logic_vector(PPU_TMM_ADDR_WIDTH-1 downto 0); + signal BAM_AO : std_logic_vector(PPU_BAM_ADDR_WIDTH-1 downto 0); + signal FAM_AO : std_logic_vector(PPU_FAM_ADDR_WIDTH-1 downto 0); + signal PAL_AO : std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); + signal AUX_AO : std_logic_vector(PPU_AUX_ADDR_WIDTH-1 downto 0); begin - uut: ppu_addr_dec port map( + uut : ppu_addr_dec port map( EN => EN, WEN => WEN, TMM_WEN => TMM_WEN, @@ -75,7 +75,7 @@ begin PAL_AI <= (others => '0'); AUX_AI <= (others => '0'); - tb: process + tb : process begin for i in 0 to 65535 loop ADDR <= std_logic_vector(to_unsigned(i,16)); diff --git a/basys3/basys3.srcs/ppu_consts.vhd b/basys3/basys3.srcs/ppu_consts.vhd index c063586..3e7d46d 100644 --- a/basys3/basys3.srcs/ppu_consts.vhd +++ b/basys3/basys3.srcs/ppu_consts.vhd @@ -1,22 +1,22 @@ package ppu_consts is - constant PPU_RAM_BUS_ADDR_WIDTH: natural := 16; -- RAM bus address width - constant PPU_RAM_BUS_DATA_WIDTH: natural := 16; -- RAM bus data width - constant PPU_FG_SPRITE_COUNT: natural := 128; -- amount of foreground sprites - constant PPU_COLOR_OUTPUT_DEPTH: natural := 4; -- VGA output channel depth - constant PPU_PALETTE_IDX_WIDTH: natural := 3; -- palette index width (within sprite) - constant PPU_PALETTE_WIDTH: natural := 3; -- palette index width (palette table) - constant PPU_PALETTE_CIDX_WIDTH: natural := PPU_PALETTE_IDX_WIDTH + PPU_PALETTE_WIDTH; -- global palette index width - constant PPU_TMM_ADDR_WIDTH: natural := 16; - constant PPU_TMM_DATA_WIDTH: natural := 16; - constant PPU_BAM_ADDR_WIDTH: natural := 11; - constant PPU_BAM_DATA_WIDTH: natural := 15; - constant PPU_FAM_ADDR_WIDTH: natural := 8; - constant PPU_FAM_DATA_WIDTH: natural := 16; - constant PPU_PAL_ADDR_WIDTH: natural := 6; - constant PPU_PAL_DATA_WIDTH: natural := 12; - constant PPU_AUX_ADDR_WIDTH: natural := 2; - constant PPU_AUX_DATA_WIDTH: natural := 16; - constant PPU_POS_H_WIDTH: natural := 9; -- amount of bits for horizontal screen offset - constant PPU_POS_V_WIDTH: natural := 8; -- amount of bits for vertical screen offset + constant PPU_RAM_BUS_ADDR_WIDTH : natural := 16; -- RAM bus address width + constant PPU_RAM_BUS_DATA_WIDTH : natural := 16; -- RAM bus data width + constant PPU_FG_SPRITE_COUNT : natural := 128; -- amount of foreground sprites + constant PPU_COLOR_OUTPUT_DEPTH : natural := 4; -- VGA output channel depth + constant PPU_PALETTE_IDX_WIDTH : natural := 3; -- palette index width (within sprite) + constant PPU_PALETTE_WIDTH : natural := 3; -- palette index width (palette table) + constant PPU_PALETTE_CIDX_WIDTH : natural := PPU_PALETTE_IDX_WIDTH + PPU_PALETTE_WIDTH; -- global palette index width + constant PPU_TMM_ADDR_WIDTH : natural := 16; + constant PPU_TMM_DATA_WIDTH : natural := 16; + constant PPU_BAM_ADDR_WIDTH : natural := 11; + constant PPU_BAM_DATA_WIDTH : natural := 15; + constant PPU_FAM_ADDR_WIDTH : natural := 8; + constant PPU_FAM_DATA_WIDTH : natural := 16; + constant PPU_PAL_ADDR_WIDTH : natural := 6; + constant PPU_PAL_DATA_WIDTH : natural := 12; + constant PPU_AUX_ADDR_WIDTH : natural := 2; + constant PPU_AUX_DATA_WIDTH : natural := 16; + constant PPU_POS_H_WIDTH : natural := 9; -- amount of bits for horizontal screen offset + constant PPU_POS_V_WIDTH : natural := 8; -- amount of bits for vertical screen offset end package ppu_consts; diff --git a/basys3/basys3.srcs/ppu_pceg.vhd b/basys3/basys3.srcs/ppu_pceg.vhd index 9675e5b..1aaeee4 100644 --- a/basys3/basys3.srcs/ppu_pceg.vhd +++ b/basys3/basys3.srcs/ppu_pceg.vhd @@ -3,18 +3,18 @@ use ieee.std_logic_1164.all; --use ieee.numeric_std.all; entity ppu_pceg is port( - CLK: in std_logic; -- system clock - RESET: in std_logic; -- async reset - SPRITE: out std_logic; -- sprite info fetch + sprite pixel fetch - COMP_PAL: out std_logic; -- compositor + palette lookup - DONE: out std_logic); -- last pipeline stage done + CLK : in std_logic; -- system clock + RESET : in std_logic; -- async reset + SPRITE : out std_logic; -- sprite info fetch + sprite pixel fetch + COMP_PAL : out std_logic; -- compositor + palette lookup + DONE : out std_logic); -- last pipeline stage done end ppu_pceg; architecture Behavioral of ppu_pceg is - constant PPU_PL_TOTAL_STAGES: natural := 14; + constant PPU_PL_TOTAL_STAGES : natural := 14; type states is (PL_SPRITE, PL_COMP_PAL, PL_DONE); - signal state: states := PL_SPRITE; + signal state : states := PL_SPRITE; begin -- output drivers SPRITE <= CLK when RESET = '0' and state = PL_SPRITE else '0'; @@ -22,7 +22,7 @@ begin DONE <= '1' when RESET = '0' and state = PL_DONE else '0'; process(CLK, RESET) - variable CLK_IDX: natural range 0 to PPU_PL_TOTAL_STAGES+1 := 0; + variable CLK_IDX : natural range 0 to PPU_PL_TOTAL_STAGES+1 := 0; begin if RESET = '1' then state <= PL_SPRITE; diff --git a/basys3/basys3.srcs/ppu_pceg_tb.vhd b/basys3/basys3.srcs/ppu_pceg_tb.vhd index 137d4b4..719ec06 100644 --- a/basys3/basys3.srcs/ppu_pceg_tb.vhd +++ b/basys3/basys3.srcs/ppu_pceg_tb.vhd @@ -10,27 +10,27 @@ end ppu_pceg_tb; architecture behavioral of ppu_pceg_tb is component ppu_pceg port( - CLK: in std_logic; -- system clock - RESET: in std_logic; -- async reset - SPRITE: out std_logic; -- sprite info fetch + sprite pixel fetch - COMP_PAL: out std_logic; -- compositor + palette lookup - DONE: out std_logic); -- last pipeline stage done + CLK : in std_logic; -- system clock + RESET : in std_logic; -- async reset + SPRITE : out std_logic; -- sprite info fetch + sprite pixel fetch + COMP_PAL : out std_logic; -- compositor + palette lookup + DONE : out std_logic); -- last pipeline stage done end component; - signal CLK: std_logic := '0'; - signal RESET: std_logic := '0'; - signal SPRITE: std_logic; - signal COMP_PAL: std_logic; - signal DONE: std_logic; + signal CLK : std_logic := '0'; + signal RESET : std_logic := '0'; + signal SPRITE : std_logic; + signal COMP_PAL : std_logic; + signal DONE : std_logic; begin - uut: ppu_pceg port map( + uut : ppu_pceg port map( CLK => CLK, RESET => RESET, SPRITE => SPRITE, COMP_PAL => COMP_PAL, DONE => DONE); - tb: process + tb : process begin for i in 0 to 32 loop if i > 20 then diff --git a/style.md b/style.md index 3cbe9b8..4a65ed3 100644 --- a/style.md +++ b/style.md @@ -51,4 +51,5 @@ before formatting as a failsafe. - testbench name is the component name with `_tb` as suffix - vhdl filename is the same as the component name - vhdl files should end in the `.vhd` file extension, not `.vhdl` +- use spaces around the colon used for setting the type of signal definitions -- cgit v1.2.3 From 14a1c464c27206bff847fd46d3d5594b30f53af9 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 24 Feb 2023 12:49:20 +0100 Subject: update style guide and format code --- basys3/basys3.srcs/ppu_comp.vhd | 89 +++++--------- basys3/basys3.srcs/ppu_comp_tb.vhd | 60 +++++----- basys3/basys3.srcs/ppu_plut.vhd | 104 ++++++---------- basys3/basys3.srcs/ppu_vga_native.vhd | 200 +++++++++++++------------------ basys3/basys3.srcs/ppu_vga_native_tb.vhd | 179 ++++++++++++--------------- basys3/basys3.srcs/ppu_vga_tiny.vhd | 156 ++++++++++-------------- style.md | 29 ++++- 7 files changed, 346 insertions(+), 471 deletions(-) (limited to 'style.md') diff --git a/basys3/basys3.srcs/ppu_comp.vhd b/basys3/basys3.srcs/ppu_comp.vhd index 1ea315e..e79738f 100644 --- a/basys3/basys3.srcs/ppu_comp.vhd +++ b/basys3/basys3.srcs/ppu_comp.vhd @@ -1,67 +1,36 @@ ----------------------------------------------------------------------------------- --- Company: --- Engineer: --- --- Create Date: 23.02.2023 10:31:25 --- Design Name: --- Module Name: ppu_comp - Behavioral --- Project Name: --- Target Devices: --- Tool Versions: --- Description: --- --- Dependencies: --- --- Revision: --- Revision 0.01 - File Created --- Additional Comments: --- ----------------------------------------------------------------------------------- - - -library IEEE; -use IEEE.STD_LOGIC_1164.ALL; +library ieee; +use ieee.std_logic_1164.all; use work.ppu_consts.all; --- Uncomment the following library declaration if using --- arithmetic functions with Signed or Unsigned values ---use IEEE.NUMERIC_STD.ALL; - --- Uncomment the following library declaration if instantiating --- any Xilinx leaf cells in this code. ---library UNISIM; ---use UNISIM.VComponents.all; -entity ppu_comp is - Port ( - FG_HIT: in std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0); - BG_EN: out std_logic; - FG_EN: out std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0)); - +entity ppu_comp is port ( + FG_HIT : in std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0); + BG_EN : out std_logic; + FG_EN : out std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0)); 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 FG_HIT_EMPTY : std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0) := (others => '0'); begin - process (FG_HIT) - variable HIT : BOOLEAN := FALSE; - begin - -- check if fg_hit is not empty - if FG_HIT /= FG_HIT_Empty then - 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 - FG_EN(I) <= '1'; - HIT := TRUE; - ELSE - -- make rest low - FG_EN(I) <= '0'; - END IF; - END LOOP; - HIT := FALSE; - else - BG_EN <= '1'; - FG_EN <= (others => '0'); - end if; - end process; + process (FG_HIT) + variable HIT : boolean := false; + begin + -- check if FG_HIT is not empty + if FG_HIT /= FG_HIT_EMPTY then + 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 + FG_EN(i) <= '1'; + HIT := true; + else + -- make rest low + FG_EN(i) <= '0'; + end if; + end loop; + HIT := false; + else + BG_EN <= '1'; + FG_EN <= (others => '0'); + end if; + end process; end Behavioral; diff --git a/basys3/basys3.srcs/ppu_comp_tb.vhd b/basys3/basys3.srcs/ppu_comp_tb.vhd index e8f6893..be4c2e3 100644 --- a/basys3/basys3.srcs/ppu_comp_tb.vhd +++ b/basys3/basys3.srcs/ppu_comp_tb.vhd @@ -8,37 +8,33 @@ entity ppu_comp_tb is end ppu_comp_tb; architecture behavioral of ppu_comp_tb is -COMPONENT ppu_comp - port ( - FG_HIT: in std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0); - BG_EN: out std_logic; - FG_EN: out std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0)); -end component; - -signal FG_HIT: std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0) := (others => '0'); -signal BG_EN: std_logic := '0'; -signal FG_EN: std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0) := (others => '0'); + component ppu_comp port ( + FG_HIT : in std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0); + BG_EN : out std_logic; + FG_EN : out std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0)); + end component; + signal FG_HIT : std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0) := (others => '0'); + signal BG_EN : std_logic := '0'; + signal FG_EN : std_logic_vector(PPU_FG_SPRITE_COUNT-1 downto 0) := (others => '0'); begin -UUT : ppu_comp port map ( -FG_HIT => FG_HIT, -BG_EN => BG_EN, -FG_EN => FG_EN -); - TB : PROCESS - BEGIN - FG_HIT <= (OTHERS => '0'); - wait for 1 ps; - FG_HIT(6) <= '1'; - FG_HIT(5) <= '1'; - FG_HIT(100) <= '1'; - wait for 1 ps; - - FG_HIT(0) <= '1'; - wait for 1 ps; - FG_HIT <= (OTHERS => '0'); - wait for 1 ps; - - - wait; - END PROCESS; + uut : ppu_comp port map ( + FG_HIT => FG_HIT, + BG_EN => BG_EN, + FG_EN => FG_EN + ); + tb : process + begin + FG_HIT <= (others => '0'); + wait for 1 ps; + FG_HIT(6) <= '1'; + FG_HIT(5) <= '1'; + FG_HIT(100) <= '1'; + wait for 1 ps; + + FG_HIT(0) <= '1'; + wait for 1 ps; + FG_HIT <= (others => '0'); + wait for 1 ps; + wait; + end process; end Behavioral; diff --git a/basys3/basys3.srcs/ppu_plut.vhd b/basys3/basys3.srcs/ppu_plut.vhd index d03da1f..d2e132e 100644 --- a/basys3/basys3.srcs/ppu_plut.vhd +++ b/basys3/basys3.srcs/ppu_plut.vhd @@ -1,48 +1,20 @@ ----------------------------------------------------------------------------------- --- Company: --- Engineer: --- --- Create Date: 23.02.2023 11:03:27 --- Design Name: --- Module Name: ppu_plut - Behavioral --- Project Name: --- Target Devices: --- Tool Versions: --- Description: --- --- Dependencies: --- --- Revision: --- Revision 0.01 - File Created --- Additional Comments: --- ----------------------------------------------------------------------------------- - - -library IEEE; -use IEEE.STD_LOGIC_1164.ALL; +library ieee; +use ieee.std_logic_1164.all; use work.ppu_consts.all; --- Uncomment the following library declaration if using --- arithmetic functions with Signed or Unsigned values -use IEEE.NUMERIC_STD.ALL; +use ieee.numeric_std.all; use ieee.std_logic_unsigned.all; --- Uncomment the following library declaration if instantiating --- any Xilinx leaf cells in this code. ---library UNISIM; ---use UNISIM.VComponents.all; -entity ppu_plut is - Port ( - CLK: in std_logic; -- system clock - CIDX: in std_logic_vector(PPU_PALETTE_CIDX_WIDTH-1 downto 0); -- color in - RESET: in std_logic; +entity ppu_plut is port ( + CLK : in std_logic; -- system clock + CIDX : in std_logic_vector(PPU_PALETTE_CIDX_WIDTH-1 downto 0); -- color in + RESET : in std_logic; + + -- internal memory block (AUX) + PAL_WEN : in std_logic; -- VRAM PAL write enable + PAL_ADDR : in std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); -- VRAM PAL address + PAL_DATA : in std_logic_vector(PPU_PAL_DATA_WIDTH-1 downto 0); -- VRAM PAL data - -- internal memory block (AUX) - PAL_WEN: in std_logic; -- VRAM PAL write enable - PAL_ADDR: in std_logic_vector(PPU_PAL_ADDR_WIDTH-1 downto 0); -- VRAM PAL address - PAL_DATA: in std_logic_vector(PPU_PAL_DATA_WIDTH-1 downto 0); -- VRAM PAL data - - R,G,B: out std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0)); -- VGA color out + R,G,B : out std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0)); -- VGA color out end ppu_plut; architecture Behavioral of ppu_plut is @@ -61,8 +33,8 @@ architecture Behavioral of ppu_plut is REG : out std_logic_vector((ADDR_RANGE*DATA_W)-1 downto 0)); -- exposed register output end component; - SIGNAL PLUT : std_logic_vector((64 * PPU_PAL_DATA_WIDTH)-1 downto 0) := (others => '0'); - SIGNAL CHECK_ZERO_CIDX : std_logic_vector(PPU_PALETTE_CIDX_WIDTH-1 downto 0) := (others => '0');-- color in + signal PLUT : std_logic_vector((64 * PPU_PAL_DATA_WIDTH)-1 downto 0) := (others => '0'); + signal CHECK_ZERO_CIDX : std_logic_vector(PPU_PALETTE_CIDX_WIDTH-1 downto 0) := (others => '0'); -- color in begin RAM : component er_ram port map( CLK => CLK, @@ -72,28 +44,26 @@ begin DATA => PAL_DATA, REG => PLUT); - - process(CLK,RESET) - VARIABLE COLOR : std_logic_vector(PPU_PAL_DATA_WIDTH-1 downto 0) := (others => '0');-- COLORS RGB IN - VARIABLE CIDX_INT : INTEGER := 0; - begin - IF(RESET = '1') THEN - PLUT <= (others => '0'); - ELSE - IF rising_edge (CLK) THEN - IF (CIDX /= CHECK_ZERO_CIDX) THEN - CIDX_INT := TO_INTEGER(UNSIGNED(CIDX)); - COLOR := PLUT((12 * CIDX_INT) + 11 DOWNTO (12*CIDX_INT)); - R <= COLOR(11 DOWNTO 8); - G <= COLOR(7 DOWNTO 4); - B <= COLOR(3 DOWNTO 0); - ELSE - R <= X"0"; - G <= X"0"; - B <= X"0"; - END IF; - END IF; - END IF; - end process; - + process(CLK, RESET) + variable COLOR : std_logic_vector(PPU_PAL_DATA_WIDTH-1 downto 0) := (others => '0'); -- COLORS RGB IN + variable CIDX_INT : integer := 0; + begin + if RESET = '1' then + PLUT <= (others => '0'); + else + if rising_edge (CLK) then + if (CIDX /= CHECK_ZERO_CIDX) then + CIDX_INT := to_integer(unsigned(CIDX)); + COLOR := PLUT((12 * CIDX_INT) + 11 downto (12*CIDX_INT)); + R <= COLOR(11 downto 8); + G <= COLOR(7 downto 4); + B <= COLOR(3 downto 0); + else + R <= x"0"; + G <= x"0"; + B <= x"0"; + end if; + end if; + end if; + end process; end Behavioral; diff --git a/basys3/basys3.srcs/ppu_vga_native.vhd b/basys3/basys3.srcs/ppu_vga_native.vhd index f5d9809..47288e9 100644 --- a/basys3/basys3.srcs/ppu_vga_native.vhd +++ b/basys3/basys3.srcs/ppu_vga_native.vhd @@ -1,125 +1,95 @@ ----------------------------------------------------------------------------------- --- Company: --- Engineer: --- --- Create Date: 22.02.2023 13:20:47 --- Design Name: --- Module Name: ppu_vga_native - Behavioral --- Project Name: --- Target Devices: --- Tool Versions: --- Description: --- --- Dependencies: --- --- Revision: --- Revision 0.01 - File Created --- Additional Comments: --- ----------------------------------------------------------------------------------- - - -library IEEE; -use IEEE.STD_LOGIC_1164.ALL; +library ieee; +use ieee.std_logic_1164.all; use work.ppu_consts.all; +use ieee.numeric_std.all; +use ieee.std_logic_unsigned.all; -use IEEE.NUMERIC_STD.ALL; -use IEEE.STD_LOGIC_UNSIGNED.ALL; +entity ppu_vga_native is port ( + CLK: in std_logic; -- system clock + RESET: in std_logic; --- Uncomment the following library declaration if instantiating --- any Xilinx leaf cells in this code. ---library UNISIM; ---use UNISIM.VComponents.all; + X: in std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x + Y: in std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y + PREADY: in std_logic; -- current pixel ready (pixel color is stable) + RI,GI,BI: in std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- VGA color in -entity ppu_vga_native is - Port ( CLK: in std_logic; -- system clock - RESET: in std_logic; - - X: in std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x - Y: in std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y - PREADY: in std_logic; -- current pixel ready (pixel color is stable) - RI,GI,BI: in std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- VGA color in - - RO,GO,BO: out std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- VGA color out - VSYNC, HSYNC: out std_logic); -- VGA sync outputs + RO,GO,BO: out std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- VGA color out + VSYNC, HSYNC: out std_logic); -- VGA sync outputs end ppu_vga_native; architecture Behavioral of ppu_vga_native is - type line_buffer is array(319 downto 0) of std_logic_vector(11 downto 0); - signal ram_x0 : line_buffer; -- buffer 0 - signal ram_x1: line_buffer; -- buffer 1 - signal hcount: STD_LOGIC_VECTOR(9 downto 0):= (others => '0'); - signal vcount: STD_LOGIC_VECTOR(9 downto 0):= (others => '0'); - signal clkCounter: STD_LOGIC_VECTOR(1 downto 0):= (others => '0'); - signal rgb_out : STD_LOGIC_VECTOR(11 downto 0):= (others => '0'); -- output colors - signal px : integer; -- conversion for hcount - signal py :integer; -- conversion for vcount - signal bufferFilledOnbuffer0 : integer; - signal bufferFilledOnbuffer1 :integer; + type line_buffer is array(319 downto 0) of std_logic_vector(11 downto 0); + signal ram_x0 : line_buffer; -- buffer 0 + signal ram_x1: line_buffer; -- buffer 1 + signal hcount: std_logic_vector(9 downto 0):= (others => '0'); + signal vcount: std_logic_vector(9 downto 0):= (others => '0'); + signal clk_counter: std_logic_vector(1 downto 0):= (others => '0'); + signal rgb_out : std_logic_vector(11 downto 0):= (others => '0'); -- output colors + signal px : integer; -- conversion for hcount + signal py :integer; -- conversion for vcount + signal buffer_filled_on_buffer0 : integer; + signal buffer_filled_on_buffer1 : integer; begin - process (clk, x, y) - variable v_x : integer ; -- integer to hold vector X - begin - if rising_edge(clk) then - clkCounter <= clkCounter + 1; - if(clkCounter = "11")then - v_x := TO_INTEGER(unsigned(x) - 72); - if(v_x >= 0 and v_x < 320 and PREADY = '1') then - if(y(0) = '0') then - ram_x0(v_x) <= RI & GI & BI; - if v_x = 319 then - bufferFilledOnbuffer0 <= TO_INTEGER(unsigned(y) - 14); - end if; - else - ram_x1(v_x) <= RI & GI & BI; - if v_x = 319 then - bufferFilledOnbuffer1 <= TO_INTEGER(unsigned(y) - 14); - end if; - end if; - end if; - -- T display(display data) - if (hcount >= 144) and (hcount < 784) and (vcount >= 31) and (vcount < 511) then - px <= TO_INTEGER(unsigned(hcount) - 144); - py <= TO_INTEGER(unsigned(vcount) - 31); - if(bufferFilledonBuffer0 = (py/2)) then - rgb_out <= ram_x0(px/2); - elsif(bufferFilledonbuffer1 = (py/2)) then - rgb_out <= ram_x1(px/2); - - else - rgb_out <= (others => '0'); - - end if; - end if; - -- pulse width - hsync <= '1'; - if hcount < 97 then - hsync <= '0'; - end if; - - vsync <= '1'; - if vcount < 3 then - vsync <= '0'; - end if; - - -- sync pulse time - hcount <= hcount + 1; - - if hcount = 800 then - vcount <= vcount + 1; - hcount <= (others => '0'); - end if; - - if vcount = 521 then - vcount <= (others => '0'); - end if; - end if; - - -- output colors - RO <= rgb_out(11 downto 8); - GO <= rgb_out(7 downto 4); - BO <= rgb_out(3 downto 0); - end if; - end process; + process (clk, x, y) + variable v_x : integer; -- integer to hold vector X + begin + if rising_edge(clk) then + clk_counter <= clk_counter + 1; + if clk_counter = "11" then + v_x := to_integer(unsigned(x) - 72); + if v_x >= 0 and v_x < 320 and PREADY = '1' then + if y(0) = '0' then + ram_x0(v_x) <= RI & GI & BI; + if v_x = 319 then + buffer_filled_on_buffer0 <= to_integer(unsigned(y) - 14); + end if; + else + ram_x1(v_x) <= RI & GI & BI; + if v_x = 319 then + buffer_filled_on_buffer1 <= to_integer(unsigned(y) - 14); + end if; + end if; + end if; + -- T display(display data) + if (hcount >= 144) and (hcount < 784) and (vcount >= 31) and (vcount < 511) then + px <= to_integer(unsigned(hcount) - 144); + py <= to_integer(unsigned(vcount) - 31); + if buffer_filled_on_buffer0 = (py/2) then + rgb_out <= ram_x0(px/2); + elsif buffer_filled_on_buffer1 = (py/2) then + rgb_out <= ram_x1(px/2); + else + rgb_out <= (others => '0'); + end if; + end if; + -- pulse width + hsync <= '1'; + if hcount < 97 then + hsync <= '0'; + end if; + + vsync <= '1'; + if vcount < 3 then + vsync <= '0'; + end if; + + -- sync pulse time + hcount <= hcount + 1; + + if hcount = 800 then + vcount <= vcount + 1; + hcount <= (others => '0'); + end if; + + if vcount = 521 then + vcount <= (others => '0'); + end if; + end if; + -- output colors + RO <= rgb_out(11 downto 8); + GO <= rgb_out(7 downto 4); + BO <= rgb_out(3 downto 0); + end if; + end process; end Behavioral; diff --git a/basys3/basys3.srcs/ppu_vga_native_tb.vhd b/basys3/basys3.srcs/ppu_vga_native_tb.vhd index 3a225d8..06061a0 100644 --- a/basys3/basys3.srcs/ppu_vga_native_tb.vhd +++ b/basys3/basys3.srcs/ppu_vga_native_tb.vhd @@ -1,116 +1,89 @@ ----------------------------------------------------------------------------------- --- Company: --- Engineer: --- --- Create Date: 22.02.2023 13:28:57 --- Design Name: --- Module Name: ppu_vga_native_tb - Behavioral --- Project Name: --- Target Devices: --- Tool Versions: --- Description: --- --- Dependencies: --- --- Revision: --- Revision 0.01 - File Created --- Additional Comments: --- ----------------------------------------------------------------------------------- - - -library IEEE; -use IEEE.STD_LOGIC_1164.ALL; +library ieee; +library unisim; +use ieee.std_logic_1164.all; use work.ppu_consts.all; - -use IEEE.NUMERIC_STD.ALL; -use IEEE.STD_LOGIC_UNSIGNED.ALL; - - --- Uncomment the following library declaration if instantiating --- any Xilinx leaf cells in this code. -library UNISIM; -use UNISIM.VComponents.all; +use ieee.numeric_std.all; +use ieee.std_logic_unsigned.all; +use unisim.vcomponents.all; entity ppu_vga_native_tb is end ppu_vga_native_tb; architecture Behavioral of ppu_vga_native_tb is -component ppu_vga_native - Port ( CLK: in std_logic; -- system clock - RESET: in std_logic; + component ppu_vga_native port ( + CLK : in std_logic; -- system clock + RESET : in std_logic; + + X : in std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x + Y : in std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y + PREADY : in std_logic; -- current pixel ready (pixel color is stable) + RI,GI,BI : in std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- VGA color in - X: in std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x - Y: in std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y - PREADY: in std_logic; -- current pixel ready (pixel color is stable) - RI,GI,BI: in std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- VGA color in - - RO,GO,BO: out std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- VGA color out - VSYNC, HSYNC: out std_logic); -- VGA sync outputs -end component; -signal clk : std_logic := '0'; -signal rst : std_logic := '0'; -signal Pready : std_logic := '0'; + RO,GO,BO : out std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0); -- VGA color out + VSYNC, HSYNC : out std_logic); -- VGA sync outputs + end component; + signal CLK : std_logic := '0'; + signal RST : std_logic := '0'; + signal PREADY : std_logic := '0'; -signal X : std_logic_vector(PPU_POS_H_WIDTH-1 downto 0) := (others => '0'); + signal X : std_logic_vector(PPU_POS_H_WIDTH-1 downto 0) := (others => '0'); + signal Y : std_logic_vector(PPU_POS_V_WIDTH-1 downto 0) := (others => '0'); -signal Xas : integer := 72; -signal Yas : integer := 14; -signal counter : std_logic_vector(1 downto 0) := (others => '0'); -signal Y : std_logic_vector(PPU_POS_V_WIDTH-1 downto 0) := (others => '0'); -signal RI,GI,BI: std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0) := (others => '0'); -- VGA color in -signal RO,GO,BO: std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0) := (others => '0'); -- VGA color out -signal VSYNC, HSYNC: std_logic := '0'; + signal RI,GI,BI : std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0) := (others => '0'); -- VGA color in + signal RO,GO,BO : std_logic_vector(PPU_COLOR_OUTPUT_DEPTH-1 downto 0) := (others => '0'); -- VGA color out + signal VSYNC, HSYNC : std_logic := '0'; + + signal Xas : integer := 72; + signal Yas : integer := 14; + signal counter : std_logic_vector(1 downto 0) := (others => '0'); begin + uut : ppu_vga_native port map( + CLK => CLK, + RESET => RST, + X => X, + Y => Y, + PREADY => PREADY, + RI => RI, + GI => GI, + BI => BI, + RO => RO, + GO => GO, + BO => BO, + VSYNC => VSYNC, + HSYNC => HSYNC + ); + + tb : process + begin + CLK <= '1'; + wait for 1 ps; + CLK <= '0'; + wait for 1 ps; + end process; -UUT : ppu_vga_native port map( - clk => clk, - reset => rst, - x => x, - y => y, - pready => pready, - ri => ri, - gi => gi, - bi => bi, - ro => ro, - go => go, - bo => bo, - vsync => vsync, - hsync => hsync -); + process(CLK) + begin + if rising_edge(CLK) then + counter <= counter + 1; + end if; - tb : process - begin - clk <= '1'; - wait for 1 ps; - clk <= '0'; - wait for 1 ps; - end process; - - - process(clk) - begin - if rising_edge(clk) then - counter <= counter + 1; - end if; - - if(counter = "11") then - pready <= '1'; - ri <= x"d"; - gi <= x"a"; - bi <= x"d"; - x <= std_logic_vector(to_unsigned(Xas, x'length)); - if (Xas = 391) then - Xas <= 72; - y <= std_logic_vector(to_unsigned(Yas, y'length)); - if (Yas = 255) then - Yas <= 14; - else - Yas <= Yas + 1; - end if; - else - Xas <= Xas + 1; - end if; - end if; - end process; + if(counter = "11") then + pready <= '1'; + ri <= x"d"; + gi <= x"a"; + bi <= x"d"; + x <= std_logic_vector(to_unsigned(Xas, x'length)); + if (Xas = 391) then + Xas <= 72; + y <= std_logic_vector(to_unsigned(Yas, y'length)); + if (Yas = 255) then + Yas <= 14; + else + Yas <= Yas + 1; + end if; + else + Xas <= Xas + 1; + end if; + end if; + end process; end Behavioral; diff --git a/basys3/basys3.srcs/ppu_vga_tiny.vhd b/basys3/basys3.srcs/ppu_vga_tiny.vhd index f47df48..0e496f6 100644 --- a/basys3/basys3.srcs/ppu_vga_tiny.vhd +++ b/basys3/basys3.srcs/ppu_vga_tiny.vhd @@ -1,103 +1,73 @@ ----------------------------------------------------------------------------------- --- Company: --- Engineer: --- --- Create Date: 22.02.2023 13:13:03 --- Design Name: --- Module Name: ppu_vga_tiny - Behavioral --- Project Name: --- Target Devices: --- Tool Versions: --- Description: --- --- Dependencies: --- --- Revision: --- Revision 0.01 - File Created --- Additional Comments: --- ----------------------------------------------------------------------------------- - - -library IEEE; -use IEEE.STD_LOGIC_1164.ALL; +library ieee; +use ieee.std_logic_1164.all; use work.ppu_consts.all; +use ieee.numeric_std.all; +use ieee.std_logic_unsigned.all; -use IEEE.NUMERIC_STD.ALL; -use IEEE.STD_LOGIC_UNSIGNED.ALL; --- Uncomment the following library declaration if instantiating --- any Xilinx leaf cells in this code. ---library UNISIM; ---use UNISIM.VComponents.all; - -entity ppu_vga_tiny is - Port ( - CLK: in std_logic; -- system clock - RESET: in std_logic; +entity ppu_vga_tiny is port ( + CLK : in std_logic; -- system clock + RESET : in std_logic; - X: out std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x - Y: out std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y - - VSYNC, VBLANK, - HSYNC, HBLANK: out std_logic); -- VGA sync outputs + X : out std_logic_vector(PPU_POS_H_WIDTH-1 downto 0); -- current screen pixel x + Y : out std_logic_vector(PPU_POS_V_WIDTH-1 downto 0); -- current screen pixel y + VSYNC, VBLANK, + HSYNC, HBLANK : out std_logic); -- VGA sync outputs end ppu_vga_tiny; architecture Behavioral of ppu_vga_tiny is - signal hcount: STD_LOGIC_VECTOR(PPU_POS_H_WIDTH-1 downto 0):= (others => '0'); - signal vcount: STD_LOGIC_VECTOR(PPU_POS_V_WIDTH-1 downto 0):= (others => '0'); - signal CLKcounter: STD_LOGIC_VECTOR(4 downto 0):= (others => '0'); - + signal hcount : std_logic_vector(PPU_POS_H_WIDTH-1 downto 0) := (others => '0'); + signal vcount : std_logic_vector(PPU_POS_V_WIDTH-1 downto 0) := (others => '0'); + signal clk_counter : std_logic_vector(4 downto 0) := (others => '0'); begin -process (CLK) -begin - if rising_edge(CLK) then - CLKcounter <= CLKcounter + 1; - if(CLKcounter > 15) then - clkCounter <= (others => '0'); - -- x,y data uit - X <= hcount; - Y <= vcount; - - --pulse width - if hcount < 32 or hcount >= 320-80 then - hsync <= '0'; - else - hsync <= '1'; - end if; - - if vcount < 8 or vcount >= 240-15 then - vsync <= '0'; - else - vsync <= '1'; - end if; - - -- Hblank and Vblank outputs - if hcount >= 320-80 then - hblank <= '1'; - else - hblank <= '0'; - end if; - - if vcount >= 240-15 then - vblank <= '1'; - else - vblank <= '0'; - end if; - - -- sync pulse time - hcount <= hcount + 1; - - if hcount = 400 then - vcount <= vcount + 1; - hcount <= (others => '0'); - end if; - - if vcount = 255 then - vcount <= (others => '0'); - end if; - end if; - end if; -end process; + process (CLK) + begin + if rising_edge(CLK) then + clk_counter <= clk_counter + 1; + if(clk_counter > 15) then + clk_counter <= (others => '0'); + -- x,y data out + X <= hcount; + Y <= vcount; + + --pulse width + if hcount < 32 or hcount >= 320-80 then + hsync <= '0'; + else + hsync <= '1'; + end if; + + if vcount < 8 or vcount >= 240-15 then + vsync <= '0'; + else + vsync <= '1'; + end if; + + -- Hblank and Vblank outputs + if hcount >= 320-80 then + hblank <= '1'; + else + hblank <= '0'; + end if; + + if vcount >= 240-15 then + vblank <= '1'; + else + vblank <= '0'; + end if; + + -- sync pulse time + hcount <= hcount + 1; + + if hcount = 400 then + vcount <= vcount + 1; + hcount <= (others => '0'); + end if; + if vcount = 255 then + vcount <= (others => '0'); + end if; + end if; + end if; + end process; end Behavioral; diff --git a/style.md b/style.md index 4a65ed3..3fe912b 100644 --- a/style.md +++ b/style.md @@ -30,12 +30,14 @@ before formatting as a failsafe. - custom typedefs are prefixed with `hh_` and suffixed with `_t` (e.g. `hh_bam_tile_t`) - library hooks that need specific symbol names are exempt from the naming conventions (e.g. `main` or `HAL_UART_MspInit`) +- names are always in English ## others - document **how to use** code using doxygen-style comments in headers - document **what code is doing** using inline comments (where applicable) - don't write redundant comments (e.g. `int c = a + b; // add a and b`) +- comments are always in English ### markdown @@ -52,4 +54,29 @@ before formatting as a failsafe. - vhdl filename is the same as the component name - vhdl files should end in the `.vhd` file extension, not `.vhdl` - use spaces around the colon used for setting the type of signal definitions - +- do not mix uppercase and lowercase in entity/component/port/signal names +- remove the default vivado file headers (large comment blocks with file info) +- add a comment to the entity definition describing what the entity does +- library import names should be lowercase +- with the exception of off by one shifts, absolutely NO magic numbers are + allowed. use existing constants if possible, or create new ones in a consts + file instead of using magic numbers. +- entities/components without a generic map should put the opening `port (` on + the same line as the `entity ... is ` line +- entities/components with a generic map should be formatted like this: + ``` + entity ... is + generic map( + NAME : type := default; + NAME : type := default) + port map( + NAME : in type; + NAME : out type); + end ...; + ``` +- port/generic maps with only one signal should be condensed into a single line +- all library declarations should be grouped together at the top of the file +- all `use` directives should be grouped together below the library + declarations +- use a space before and after the comment syntax, e.g. `variable x : integer + := 0; -- comment here` -- cgit v1.2.3