📄 target.vhd
字号:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity target is
Port ( clk : in std_logic;
reset : in std_logic;
hcnt : in std_logic_vector(10 downto 0);
vcnt : in std_logic_vector(9 downto 0);
mouse_x : in std_logic_vector(9 downto 0);
ballx : in std_logic_vector(9 downto 0);
bally : in std_logic_vector(9 downto 0);
hit_target : out std_logic;
targetrgb : out std_logic_vector(7 downto 0));
end target;
architecture Behavioral of target is
signal movclk,sampclk : std_logic;
signal sampcnt : std_logic_vector(5 downto 0);
signal hit : std_logic;
signal rgbout : std_logic_vector(7 downto 0);
signal loc,mov_x,tempmov : std_logic_vector(9 downto 0);
begin
movclk <= vcnt(9);
sampclk <= sampcnt(5);
sampcount: process(movclk,reset)
begin
if reset='1' then
sampcnt <= "000000";
elsif (movclk'event and movclk='1') then
sampcnt <= sampcnt + '1';
end if;
end process;
drawtarget: process(clk)
begin
if (clk'event and clk='1') then
if ((hcnt>=(loc-9)) and (hcnt<=(loc+9))) and ((vcnt>=20) and (vcnt<=29)) then
rgbout <= "00111111";
else
rgbout <= "00000000";
end if;
end if;
end process;
movable: process(movclk,reset)
begin
if reset='1' then
loc <= (others=>'0');
elsif (movclk'event and movclk='1') then
loc <= loc + mov_x;
--if loc>=770 then
-- loc <= "1100000001";
--elsif loc<=29 then
-- loc <= "0000011100";
--end if;
end if;
end process;
sampspeed: process(sampclk,reset)
begin
if reset='1' then
tempmov <= "0000000001";
elsif (sampclk'event and sampclk='1') then
tempmov <= mouse_x;
end if;
end process;
detectmov: process(movclk,reset)
begin
if reset='1' then
mov_x <= "0000000001";
elsif (movclk'event and movclk='1') then
if (loc>=770) or (loc<=29) then
mov_x <= not tempmov + "0000000001";
else
mov_x <= tempmov;
end if;
end if;
end process;
detecthit: process(movclk,reset)
begin
if reset='1' then
hit <= '0';
elsif (movclk'event and movclk='1') then
if (bally<=33) then
if (ballx>=(loc-9)) and (ballx<=(loc+9)) then
hit <= '1';
else
hit <= '0';
end if;
else
hit <= '0';
end if;
end if;
end process;
hit_target <= hit;
targetrgb <= rgbout;
end Behavioral;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -