---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- The Marienbad Game -- EE 552 Project -- Group Members: Koziar, Kory -- McDermott, Ashley -- Stangeland, Duane -- -- File : Mouse.vhd ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- This VHDL code is used to link the mouse to the rest of the project. -- The functionality this module provides is provides two essential -- operations. First, indicates to other files when the left mouse button -- is pressed. Secondly, it provides valid X and Y coordinates of a mouse -- pointer. The mouse X and Y coordinates are not permitted to leave the -- gameboard, and thus only valid coordinates are produced. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- library ieee; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.all; use IEEE.STD_LOGIC_UNSIGNED.all; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- The entity mouse contains four inputs, two outputs and three buffered -- signals. They are described below. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- entity mouse is port( signal Clock : in std_logic; --system clock, 25.175MHz signal MouseData : in std_logic; --data from the ps2 mouse port signal Power_On : in std_logic; --reset signal signal Computer_Play : in std_logic; signal PointerX : out std_logic_vector(6 downto 0); --X position of last piece taken signal PointerY : out std_logic_vector(6 downto 0); --Y position of last piece taken signal Player : buffer std_logic; --player1=0, player2=1 signal MouseX : buffer std_logic_vector(6 downto 0); --current X position of mouse signal MouseY : buffer std_logic_vector(6 downto 0) --current Y position of mouse ); end mouse; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- architecture behavior of mouse is ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- The Gd_Move is the component that checks the moves that a player may -- make to see if it is a legal move. In the case of the computers turn, -- Gd_Move calculates the move for the computer. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- component Gd_Move port( signal Power_On : in std_logic; --Reset signal signal MouseL : in std_logic; --Left mouse button signal MouseX : in std_logic_vector(6 downto 0); --Mouse x-position signal MouseY : in std_logic_vector(6 downto 0); --Mouse y-position signal Computer_Play : in std_logic; --Against computer=1, player/player=0 signal PointerX : out std_logic_vector(6 downto 0); --Last x-location signal PointerY : out std_logic_vector(6 downto 0); --Last y-location signal Player : buffer std_logic --Whos turn ); end component; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- signal IncommingDataDetected : std_logic; --Set, when start bit of packet found signal MouseL : std_logic; --Left mouse button signal data : std_logic_vector(29 downto 0); --Data from the mouse data packet signal Counter1 : integer range 0 to 32000; --Division of the clock signal Counter2 : integer range 0 to 29; --Number of bits captured begin ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- Linking the signals between Mouse.vhd and Gd_Move.vhd ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- Checking_Move : Gd_Move port map( Power_On => Power_On, MouseL => MouseL, Player => Player, Computer_Play => Computer_Play, MouseX => MouseX, MouseY => MouseY, PointerX => PointerX, PointerY => PointerY ); ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- MouseDetect detects data from the mouse and reacts to the data producing -- new MouseX, MouseY, PointerX, PointerY, and MouseL values. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- MouseDetect : process (Clock) begin if Power_On = '0' then MouseL <= '0'; --mouse button not pressed IncommingDataDetected <= '0'; --data not detected Counter1 <= 0 ; --start frequency division counter from beginning Counter2 <= 0 ; --no bits have been received MouseX <= "0000010"; --place mouse initially in 2nd column MouseY <= "0000011"; --place mouse initially in 3rd row else if (Clock='1' and Clock'Event) then if(IncommingDataDetected='0' and MouseData='1') then --if new data packet starting IncommingDataDetected <= '1'; --signal to counters "start" Counter1 <= 0; --reinitialize clock divider Counter2 <= 0; --reinitialize loop counter elsif (IncommingDataDetected='1') then --if data packet arriving Counter1 <= Counter1 + 1; --clock frequency divider if (Counter1=10070) then --400us @ 25.154MHz data(Counter2) <= not MouseData; --Capture inverted data from the mouse packet elsif (Counter1=20140) then --800us @ 25.154MHz Counter1 <= 0; --reinitialize clock divider Counter2 <= Counter2+1; --increment loop counter if(Counter2=28) then --have all bits been received? IncommingDataDetected <= '0'; --yes, all packets received Counter1 <= 0; --reinitialize clock divider Counter2 <= 0; --reinitialize loop counter if ( data(17 downto 14) /= "0" ) then --most significant 4 bits X movement --provides a minimum movement threshold ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- Was there movement in the negaitive X direction? If so, then check if -- moving to left would cause mouse to cross the game board edge, -- if movement to the left is ok then decrement the mouse current X -- position. Else was there movement in the positve X direction? If so, -- check right scrren edge, if mouse cursor will not pass the right edge of -- game board then increment the X mouse location 1 to the right. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- if ( (data(1) = '1') and ((MouseX - "0000001") > "0000001" ) )then MouseX <= MouseX - "0000001"; elsif ( (data(1) = '0') and ((MouseX + "0000001") < "0100110") ) then MouseX <= MouseX + "0000001"; end if; end if; if ( data(27 downto 25) /= "0" ) then --most significant 4 bits Y movement --provides a minimum movement threshold ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- Was there any movement in the negative Y direction? If yes, would -- moving the mouse cursor down a line cause the mouse cursor to leave the -- gameboard? If the move down is ok decrement the mouse Y location. Else, -- was there any movement in the positive Y direction? If yes, would -- moving the mouse cursor up aline cause the mouse cursor to leave the -- gameboard? If the moove up is ok increment the mouse Y location. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- if ( (data(3) = '1') and ((MouseY - "0000010") > "0000001" ) )then MouseY <= MouseY - "0000010"; elsif ( (data(3) = '0') and ((MouseY + "0000010") < "0011111") ) then MouseY <= MouseY + "0000010"; end if; end if; MouseL <= data(6); --latch data from the left mouse button end if; end if; end if; end if; end if; end process MouseDetect; end behavior;