⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 char_generator.vhd

📁 游戏玩家通过控制PS/2键盘上的方向键
💻 VHD
字号:
--------------------------------------------------------------------------------
-- Company: 
-- Engineer:
--
-- Create Date:    21:26:28 05/08/09
-- Design Name:    
-- Module Name:    char_generator - Behavioral
-- Project Name:   
-- Target Device:  
-- Tool versions:  
-- Description:
--
-- Dependencies:
-- 
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
-- 
--------------------------------------------------------------------------------

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity char_generator is
	port(
			posR, posC: in std_logic_vector(5 downto 0);
			char:in std_logic_vector(2 downto 0);
			pixel_row,pixel_col:in std_logic_vector(9 downto 0);
			RGB:out std_logic_vector (2 downto 0)
	);
end char_generator;

architecture Behavioral of char_generator is
------------------------------------------------------------------------
-- A representation of a door
------------------------------------------------------------------------
component rom_door_char is
	port(line, col : in std_logic_vector(3 downto 0); 
			color : out std_logic_vector(2 downto 0)
	);
end component rom_door_char;
------------------------------------------------------------------------
-- A representation of an empty spot(black on vga)
------------------------------------------------------------------------
component rom_empty_char is
	port(line, col : in std_logic_vector(3 downto 0); 
			color : out std_logic_vector(2 downto 0)
	);
end component rom_empty_char;
------------------------------------------------------------------------
-- A representation of wall
------------------------------------------------------------------------
component rom_wall_char is
	port(line, col : in std_logic_vector(3 downto 0); 
			color : out std_logic_vector(2 downto 0)
	);
end component rom_wall_char;
------------------------------------------------------------------------
-- A representation of the actual player(a happy face on vga)
------------------------------------------------------------------------
component rom_human_char is
	port(line, col : in std_logic_vector(3 downto 0); 
			color : out std_logic_vector(2 downto 0)
	);
end component rom_human_char;
------------------------------------------------------------------------
-- The mux
------------------------------------------------------------------------
component mux8_1_3bits is
	port(a,b,c,d,e,f,g,h:in std_logic_vector(2 downto 0);
			s:in std_logic_vector(2 downto 0);
			o:out std_logic_vector(2 downto 0)
	);
end component mux8_1_3bits;

signal p_r_mod8,p_c_mod8:std_logic_vector(3 downto 0);
signal s_mux,empty_out,full_out:std_logic_vector(2 downto 0);
signal people_out,door_out:std_logic_vector(2 downto 0);

begin
		empty : rom_empty_char 
			port map (line=>p_r_mod8, col=>p_c_mod8, color=>empty_out);

		wall : rom_wall_char 
			port map (line=>p_r_mod8, col=>p_c_mod8, color=>full_out);

		human : rom_human_char 
			port map (line=>p_r_mod8, col=>p_c_mod8, color=>people_out);
		
		door : rom_door_char 
			port map (line=>p_r_mod8, col=>p_c_mod8, color=>door_out);
		
		mux : mux8_1_3bits port map (a=>empty_out, b=>full_out, 
			c=>door_out, d=>people_out, e=>"000", 
			f=>"000", g=>"000", h=>"000", s=>s_mux, o=>RGB
		);
		process (pixel_row,pixel_col)
		variable p_r_div8,p_c_div8:std_logic_vector(6 downto 0);
		begin
------------------------------------------------------------------------
-- Because each character is 16x16 pixels, the current pixel 
-- in a character is determined by (pixel_row mod 16, pixel_col mod 16)
------------------------------------------------------------------------
			p_r_mod8 <= 
				conv_std_logic_vector(conv_integer(pixel_row) mod 16,4);
			p_c_mod8 <= 
				conv_std_logic_vector(conv_integer(pixel_col) mod 16,4);
			p_r_div8 := 
				conv_std_logic_vector(conv_integer(pixel_row) / 16,7);
			p_c_div8 := 
				conv_std_logic_vector(conv_integer(pixel_col) / 16,7);
------------------------------------------------------------------------
-- if posR, posC (the current position of the player) corespond 
-- to the current pixel position, than the rom_human_char is 
-- selected on mux
------------------------------------------------------------------------
			if ((p_r_div8=posR) and (p_c_div8=posC)) then s_mux<="011";
			else s_mux<=char;
			end if;
		end process;
end Behavioral;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -