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

📄 hicolvga.vhd

📁 VHDL Checkers Implementation by Ibrahim Elbouchikhi Amir Nader-Tehrani
💻 VHD
📖 第 1 页 / 共 2 页
字号:
					presGameState <= init;
					show1 <= '1';
				when win2 =>								--A move to this state is made if player two wins the game
					presGameState <= init;
					show2 <= '1';
				when others => 
					presGameState <= init;
			end case;
		end if;

end process;



--process(presGameState)
--	begin
--		case presGameState is
--			when init =>
--				resetGame <= '1';
--
--			when player1 =>
--				canMove <= '1';
--				won1 <= '0';
--			when stDelay1 =>
--				count <= "0000";
--				canMove<='0';
--			when player2 =>
--				canMove <= '1';
--				won2 <= '0';
--			when stDelay2 =>
--				count <= "0000";
--				canMove<='0';
--			when win1 => 
--				show1 <= '1';
--			when win2 =>
--				show2 <= '1';
--			when others => null;
--		end case;
--end process;

process(clk,resetVGA)

variable  xloc , yloc : integer;      -- The value of the location recieved from user as integer
variable  move : std_logic_vector(3 downto 0); --direction of the move result of cancatination of recieved signals						
variable other , self : std_logic_vector(1 downto 0);		--Indicates which color is the current player and which the opponent 

begin


	playerout <= player;
	moveout <= canMove;						--indicates to the board if pushbottoms are working or if stuck
	if resetVGA = '0' then

	counter1 <= "000"; -- initialize the players
	counter2 <= "000";

	for i in 0 to 3 loop -- initialize the board
		for j in 0 to 3 loop
			if (i+j) mod 2 = 0 then
				Board(i*4+j) <= "00"; -- means Green
			else 
			   Board(i*4+j) <= "01"; -- means Yellow
			end if;
		end loop;
	end loop;
	
	-- initialize the pins
	Board(1) <= "10";
	Board(9) <= "10";
	Board(12) <= "11";
	Board(14) <= "11";

	
	elsif clk'event and clk='1' then

	if player = '0' then   --Using the player input from the board indicate the values of the self and other
		other := "11";
		self := "10";
	elsif player = '1' then
		other := "10";
		self := "11";
	end if;
   
	xloc := CONV_INTEGER(x&"00");    --multiply the X location by four and set Xloc
	yloc := CONV_INTEGER(y);			--Set Yloc from input from the board
	move := NW & NE & SW & SE;			--cancatinate direction from the board to create move
	whereto<= count;

	if not (move="1111") and canMove = '1' and count = "0000" then --Check to see if a move should be allowed
		
		Board(xloc+yloc) <= "01";				-- If a move is to be made clear position of the pin that needs to be moved
	if Board(xloc+yloc) = "10" or Board(xloc+yloc) = "11" then
		case move is		--Determine which set of rules should be applied for this move 
			when "0111" =>			-- Move to the direction of NW
					if Board(xloc+yloc-5) = other then
						Board(xloc+yloc-10) <= self;
						Board(xloc+yloc-5) <= "01";
	 				   if player='0' then
							counter1<=counter1+1;
						else
							counter2<=counter2+1;
						end if;
					elsif Board(xloc+yloc-5) = "01" then
						Board(xloc+yloc-5) <= self;
					end if;
					count<=count+1;

			when "1011" =>		-- Move to the direction of NE
					if Board(xloc+yloc-3) = other then
						Board(xloc+yloc-6) <= self;
						Board(xloc+yloc-3) <= "01";
						if player='0' then
							counter1<=counter1+1;
						else
							counter2<=counter2+1;
						end if;
					elsIf Board(xloc+yloc-3) = "01" then
					  	Board(xloc+yloc-3) <= self; 
					end if;
					count<=count+1;

			when "1101" =>		-- Move to the direction of SW
					if Board(xloc+yloc+3) = other then
						Board(xloc+yloc+6) <= self;
						Board(xloc+yloc+3) <= "01";
 					   if player='0' then
							counter1<=counter1+1;
						else
							counter2<=counter2+1;
						end if;
					elsif Board(xloc+yloc+3) = "01" then
						Board(xloc+yloc+3) <= self;
					end if;
					count<=count+1;

			when "1110" =>		---- Move to the direction of SE
					if Board(xloc+yloc+5) = other then
						 Board(xloc+yloc+10) <= self;
						 Board(xloc+yloc+5) <= "01";
						 if player='0' then
							counter1<=counter1+1;
						 else
							counter2<=counter2+1;
						 end if;
					elsif Board(xloc+yloc+5) = "01" then
						 Board(xloc+yloc+5) <= self;
					end if;
					count<=count+1;
			when others => null;

			end case;
		end if;
	end if;
end if;

end process;


process(clk, resetVGA)

variable  row : integer := 0;
variable  col : integer := 0;
variable  h , v : integer := 0;
variable  even : boolean := true;

begin
	if resetVGA = '0' then
		pixelData(14 downto 10) <= (others => '0');
	elsif clk'event and clk = '1' then
	
	h := CONV_INTEGER(hloc);
	v := CONV_INTEGER(vloc);
	row := v/64;
	col := h/64;

	if ( ((row+col) mod 2) = 0 ) then
		even:=True;
	else
		even:=False;
	end if;
	
	--currentColor <= Board(row)(col);
	currentColor <= Board(row*4+col);


	--try for moving a pin from a certain location to one on adjacent cells
	if counter1=pinnums or counter2=pinnums then
			if counter1=pinnums then
				pixelData(14 downto 0) <= "111110000000000";
			elsif counter2=pinnums then
				pixelData(14 downto 0) <= "001100110011001"; 
			end if;
	else
			
		case currentColor is

			when "00" => pixelData(14 downto 0) <= "000001111100000"; -- case Green Background
			when "01" => pixelData(14 downto 0) <= "001100110011001";  -- case Yellow Background
			when "10" => 
					if ( (v-(row*64+32))*(v-(row*64+32)) + (h-(col*64+32))*(h-(col*64+32)) < 256 ) then
						pixelData(14 downto 0) <= "111110000000000"; -- case player two - black
					elsif ( even ) then
						pixelData(14 downto 0) <= "000001111100000"; -- case Green Background
					else 
			  			pixelData(14 downto 0) <= "001100110011001";  -- case Yellow Background
					end if;

			when "11" =>
					if ( (v-(row*64+32))*(v-(row*64+32)) + (h-(col*64+32))*(h-(col*64+32)) < 256 ) then
						pixelData(14 downto 0) <= "000000000011111"; -- case player two - black
					elsif ( even ) then
						pixelData(14 downto 0) <= "000001111100000"; -- case Green Background
					else 
			  			pixelData(14 downto 0) <= "001100110011001";  -- case Yellow Background
					end if;

			when others =>
					h := CONV_INTEGER(hloc);
					v := CONV_INTEGER(vloc);
					row := v/64;
					col := h/64;

					if ( ((row+col) mod 2) = 0 ) then
						even:=True;
					else
						even:=False;
					end if;
					if even then
						pixelData(14 downto 0) <= "000001111100000"; -- means Green
				 	else 
			  			pixelData(14 downto 0) <= "001100110011001"; -- means Yellow
					end if;
		end case;
	end if;
end if;
end process;

-- handle dual-edged clock to give correct data to the RAMDAC
pixel <= pixelData(7 downto 0) when clk = '1' else pixelData(15 downto 8);

-- only start VGA after RAMDAC has been programmed
resetVGA <= rstn and startVGA;

-- pass the outputs out
hsync <= hsyncINT;
vsync <= vsyncINT;

-- Provide 50MHz pixel clock
pixelclk <= clk;

-- turn off the ethernet outputs and the right SRAM bank to avoid contention on the lines
triste <= '1';
rramce <= '1';

end vga_arch;

⌨️ 快捷键说明

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