---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- The Marienbad Game -- EE 552 Project -- Group Members: Koziar, Kory -- McDermott, Ashley -- Stangeland, Duane -- -- File : Display.vhd ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- Display.vhd module has three purposes, to control the constant display -- across the top, control the display of the game pieces and the display -- of the mouse cursor. Display uses three components, HV_Time, Buttons -- and Mouse. Display routes the necessary siganls to Project.vhd to -- display the results on the VGA monitor. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- library ieee; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.all; use IEEE.STD_LOGIC_UNSIGNED.all; use work.my_constants.all; LIBRARY lpm; use lpm.lpm_components.ALL; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- The entity display contains four inputs and five outputs, which are -- described below. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- entity Display is port( signal PB1 : in std_logic; -- Push Button 1 signal PB2 : in std_logic; -- Push Button 2 signal Clock : in std_logic; -- System Clock signal MouseData : in std_logic; -- Data from the mouse signal Red : out std_logic; -- Red for VGA signal Green : out std_logic; -- Green for VGA signal Blue : out std_logic; -- Blue for VGA signal Horiz_sync : out std_logic; -- Horizontal for VGA signal Vert_sync : out std_logic -- Vertical for VGA ); end Display; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- architecture behavior of Display is ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- HV_Time is the component which creates the synchronized signals for the -- horizontal and vertical diplay on the VGA monitor. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- component HV_Time port( signal Clock : in std_logic; signal Power_On : in std_logic; signal Horiz_sync : out std_logic; signal Vert_sync : out std_logic; signal Video_on_H : out std_logic; signal Video_on_V : out std_logic; signal Pixel_Col_Count : buffer std_logic_vector(5 Downto 0); signal Pixel_Row_Count : buffer std_logic_vector(5 Downto 0); signal Col_Address : buffer std_logic_vector(5 Downto 0); signal Row_Address : buffer std_logic_vector(5 Downto 0) ); end component; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- Mouse is the component which calculates the movement of the mouse and -- set the data necessary for the display of the mouse in its proper -- location. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- component mouse port( signal Clock : in std_logic; signal MouseData : in std_logic; signal Power_On : in std_logic; signal Computer_Play : in std_logic; signal PointerX : out std_logic_vector(6 downto 0); signal PointerY : out std_logic_vector(6 downto 0); signal Player : buffer std_logic; signal MouseX : buffer std_logic_vector(6 downto 0); signal MouseY : buffer std_logic_vector(6 downto 0) ); end component; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- Buttons provide the reset and player vs. computer signals to the reset -- of the project modules. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- component Buttons port( signal Clock : in std_logic; signal Power_On : in std_logic; signal PB1 : in std_logic; signal PB2 : in std_logic; signal Reset_Ready : out std_logic; signal Computer : out std_logic ); end component; ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- Used to reset the system is start up conditions signal Reset_Ready : std_logic; -- PB1 and been press and latched -- Used for the diferent colors displayed on the VGA monitor. signal Video_On_H : std_logic; -- Video horizontal signal on signal Video_On_V : std_logic; -- Video vertical signal on signal Player : std_logic; -- Whos turn signal Red_Data : std_logic; -- Used for mixing the color red signal Green_Data : std_logic; -- Used for mixing the color green signal Blue_Data : std_logic; -- Used for mixing the color blue signal Power_on : std_logic; -- Used for resetting the system signal Rev_video : std_logic; -- Used for coloring signal rom_mux_output : std_logic; -- Used for coloring signal Mouse_color : std_logic; -- Used to display the mouse signal video_on : std_logic; -- Used for coloring -- Used for determining where or not the computer vs player mode. signal Computer_Play : std_logic; signal Computer : std_logic; -- The following signals are used for the locations of where the mouse is and also -- where the last selection had been made. signal MouseX : std_logic_vector(6 downto 0); signal MouseY : std_logic_vector(6 downto 0); signal pointerX : std_logic_vector(6 downto 0); signal pointerY : std_logic_vector(6 downto 0); -- The following signals are used for the display of the characters shown on the -- monintor. signal rom_address : std_logic_vector(8 Downto 0); signal rom_data : std_logic_vector(7 Downto 0); -- signal sum_address : std_logic_vector(6 Downto 0); -- signal format_address : std_logic_vector(6 downto 0); signal col_address : std_logic_vector(5 Downto 0); signal row_address : std_logic_vector(5 Downto 0); signal pixel_col_count : std_logic_vector(5 Downto 0); signal pixel_row_count : std_logic_vector(5 Downto 0); -- signal format_data : std_logic_vector(5 downto 0); begin ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- The following is the defining the use of the mif file and the port map -- which links the file to dispaly. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- tiny_char_gen_rom: lpm_rom GENERIC MAP ( lpm_widthad => 9, lpm_numwords => "512", lpm_outdata => "UNREGISTERED", lpm_address_control => "UNREGISTERED", lpm_file => "tcgrom.mif", lpm_width => 8) PORT MAP (address=> rom_address,q=> rom_data); ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- Linking the necessary timing signals to the display module. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- Timing : HV_Time port map ( Clock => Clock, Power_On => Power_On, Horiz_sync => Horiz_Sync, Vert_sync => Vert_Sync, Video_on_H => Video_On_H, Video_on_V => Video_On_V, Pixel_Col_Count => Pixel_Col_Count, Pixel_Row_Count => Pixel_Row_Count, Col_Address => Col_Address, Row_Address => Row_Address ); ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- Linking the Mouse module to the display module. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- Move_Mouse : Mouse port map( Clock => Clock, MouseData => MouseData, Power_On => Power_On, PointerX => PointerX, PointerY => PointerY, MouseX => MouseX, MouseY => MouseY, Player => Player, Computer_Play => Computer_Play ); ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- Linking buttons.vhd to the display module. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- Button_Pressed : Buttons port map( Clock => Clock, Power_On => Power_On, Reset_Ready => Reset_Ready, Computer => Computer, PB1 => PB1, PB2 => PB2 ); ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- The following signals are used for the purpose of creating different -- colors for different areas of the screen, as well as making different -- characters different colors. Red_Data <= ( not (rom_mux_output xor Rev_video) or Mouse_Color ); Green_Data <= not (rom_mux_output); Blue_Data <= '1' and not(Mouse_Color); -- The following assignments is how the mif file is accessed and a -- particular character is drawn to the screen. -- Each character in the mif file consists of three octal numbers. -- The first two are constant for any one character. -- The lower three bits of the rom_address, being assigned here is how -- each of the different lines are drawn to the screen. rom_address(2 Downto 0) <= pixel_row_count(3 Downto 1); rom_mux_output <= rom_data ( (CONV_INTEGER(NOT pixel_col_count(3 downto 1)))); -- Mixing the colors for the display. Red <= Red_Data and video_on; Green <= Green_Data and video_on; Blue <= Blue_Data and video_on; video_on <= video_on_H and video_on_V; -- format_address(1 Downto 0) <= Col_address(1 Downto 0); -- format_address(6 Downto 2) <= Row_address(4 Downto 0); ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- -- The following process, VIDEO_DISPLAY_DATA, controlls what is printed to -- the screen and where on the screen it printed. ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- VIDEO_DISPLAY_DATA: process begin wait until (clock'event) and (clock='1'); -- If reset or intial turn on has occurred if Power_On = '0' then Mouse_Color <= '0'; Computer_Play <= '0'; Power_On <= '1'; -- If PB1 has been pressed then reset the system. elsif (Reset_Ready = '1') then Power_On <= '0'; -- If PB2 has been pressed the computer becomes player 2. elsif (Computer = '1') then Computer_Play <= '1'; end if; -- Creates a different color for the top border of the game -- screen. If (row_address <= "000010") Then rev_video <= '1'; ELSE rev_video <= '0'; End if; -- Creates the border on the sides of the game playing area. -- row_address(0)='0' makes every other line in the game board a blank line. If (row_address(0)='0') or (col_address < "000010") or (col_address >"100110") Then rom_address(8 Downto 3) <= "100000"; Else -- Checks to see what row is being printed to the screen of the monitor. case row_address(4 downto 1) is -- When on the first row, the area where player 1 and player 2 are displayed, -- print the following information. when Row0 => -- Checking to see if there are pieces still remaining on the game board. -- LastX points to the last column on the board. -- LastY points to the last row on the board. if ((PointerX(5 downto 0) < LastX) or (PointerY(4 downto 1) < LastY)) then -- BLANK if (col_address(5 downto 0) <= "000010") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"40"); -- P elsif (col_address = "000011" or col_address = "011001") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"20"); -- L elsif (col_address = "000100" or col_address = "011010") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"14"); -- A elsif (col_address = "000101" or col_address = "011011") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"01"); -- Y elsif (col_address = "000110" or col_address = "011100") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"31"); -- E elsif (col_address = "000111" or col_address = "011101") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"05"); -- R elsif (col_address = "001000" or col_address = "011110") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"22"); -- 1 elsif (col_address = "001001") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"61"); -- 2 elsif (col_address = "011111") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"62"); -- PLAYER 1 TURN elsif (col_address = "001010" and Player = '0') then rom_address(8 Downto 3) <=To_Stdlogicvector(O"37"); -- PLAYER 2 TURN elsif (col_address = "100000" and Player = '1') then rom_address(8 Downto 3) <=To_Stdlogicvector(O"37"); -- SHOWS IF THE COMPUTER IS PLAYING -- C elsif (col_address = "010111" and Player = '1' and Computer_Play = '1') then rom_address(8 Downto 3) <=To_Stdlogicvector(O"03"); -- _ elsif (col_address = "011000" and Player = '1' and Computer_Play = '1') then rom_address(8 Downto 3) <=To_Stdlogicvector(O"63"); -- BLANKS else rom_address(8 Downto 3) <=To_Stdlogicvector(O"40"); end if; -- THERE IS A WINNER else -- BLANKS if (col_address(5 downto 0) < "001001") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"40"); -- 1 elsif (col_address = "001001" AND Player = '1') then rom_address(8 Downto 3) <=To_Stdlogicvector(O"61"); -- 2 elsif(col_address = "001001" AND Player = '0') then rom_address(8 Downto 3) <=To_Stdlogicvector(O"62"); -- w elsif (col_address = "001100") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"27"); -- I elsif (col_address = "001101") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"11"); -- N elsif (col_address = "001110") then rom_address(8 Downto 3) <=To_Stdlogicvector(O"16"); -- BLANKS else rom_address(8 Downto 3) <=To_Stdlogicvector(O"40"); end if; end if; ---------------------------------------------------------------------------- -- Game Playing Board ---------------------------------------------------------------------------- WHEN others => -- Puts in the white space where pebbles have already been taken. if ( (Col_address(5 downto 0) <= PointerX(5 downto 0) ) and ( Row_address(4 downto 1) <= PointerY(4 downto 1) ) ) then rom_address(8 Downto 3) <=To_Stdlogicvector(O"40"); -- Prints the pebble character on the screen. else rom_address(8 Downto 3) <=To_Stdlogicvector(O"77"); end if; -- Necessary overwrite. if (Row_address(4 downto 1) < PointerY(4 downto 1)) then rom_address(8 Downto 3) <=To_Stdlogicvector(O"40"); end if; ------------------------------------------------------------------------------ -- DISPLAYS THE MOUSE ------------------------------------------------------------------------------ -- When the print location equal the mouse location print the mouse -- pointer. Change the color of that location to give the mouse a -- distinct color. if ((MouseX(5 downto 0) = Col_address(5 downto 0)) and (MouseY(5 downto 1) = Row_address(5 downto 1))) then Mouse_Color <= '1'; rom_address(8 Downto 3) <=To_Stdlogicvector(O"76"); else Mouse_Color <= '0'; end if; end CASE; -- Prints blank characters. if ((Col_Address = "000001") or (Col_Address = "100110")) or (Row_Address > "11111") or (Row_Address < "00001") Then Rom_Address(8 Downto 3) <= To_Stdlogicvector(O"40"); end if; end if; end process VIDEO_DISPLAY_DATA; end behavior;