You are on page 1of 34

ldhungelec

Introduction Our project is to design and implement a Tetris game by using FPGA. Tetris is a puzzle game that uses 4 square blocks joining edge to edge to form various combinations of shapes. There are 7 unique shapes. The shapes are controlled with the arrow keys from keypad or joystick. Both keypad and joystick are used to control the rotation of the shape. The reason we use both keypad and joystick as controller tool is that the players can have two options to control the game conveniently. However, we may use either keypad or joystick in our presentation to make the best effect.

Features Our project consists of a VGA display, and keypad. The VGA monitor displays the graphic images to the player. The VGA output simply displays shapes, scores, and status information. The user can press the buttons on the keypad or move the joystick to play the game. The aim is to erase rows of blocks. As the shape drops, each shape partially covers first to fourth rows. The rows are erased, when enough shapes cover first to fourth rows. To stay in the game, the players have to erase rows to make room for the dropping shape. Those are our basic features. Comparing with other Tetris games, we just simplify the score so that the player can get one point for each dropping shape. Addition options will be implemented when time allows. Those basic features that currently implemented in the VHDL code are attached in the appendix. The codes include tetrisdemo, keypad, count_xy, syncgen, synlatch, colorlatch, and tetris. The top-level design code of the basic features is tetrisdemo. Tetrisdemo includes seven

ldhungelec
components. They are keypad, count_xy, syncgen, synlatch, colorlatch, and tetris. Keypad component is to decode user inputs from the keypad and send to tetris component. The tetris component is the main game model. It controls the movement of the shape based on the keypad data and triggers the color to display on the VGA monitor. It also registers how the shape forms at the bottom of game area. The other components, count_xy, syncgen, synlatch, and colorlatch, are strongly related to VGA display. Syncgen component is to send horizontal (vga_h_sync) and vertical (vga_v_sync) synchronization to the VGA monitor. It also sends Hsync and Vsync to the count_xy component. Due to the functional complexity of the VGA, we shall not discuss the nature of the signals. Count_xy component is to use the two input signals from syncgen to generate CountX and CountY for tetris component. CountX and CountY are the pixel position counters. The top-level design code of the basic features is tetrisdemo. Tetrisdemo includes seven components. They are keypad, count_xy, syncgen, synlatch, colorlatch, and tetris. Keypad component is to decode user inputs from the keypad and send to tetris component. The tetris component is the main game model. It controls the movement of the shape based on the keypad data. tetris.vhd ------------------------------------------------------- File : tetris.vhd --- Student : Feng Gui -- new tetris.vhd -----------------------------------------------------LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.all; USE IEEE.STD_LOGIC_ARITH.all; USE IEEE.STD_LOGIC_UNSIGNED.all; LIBRARY lpm; USE lpm.lpm_components.ALL; ENTITY tetris IS PORT(clock : IN STD_LOGIC; button : IN STD_LOGIC_VECTOR(3 DOWNTO 0); timer : IN STD_LOGIC; vga_Red, vga_Green, vga_Blue : OUT BOOLEAN; countX,countY : IN STD_LOGIC_VECTOR(9 downto 0)); END tetris; ARCHITECTURE a of tetris IS -- Video Display Signals -- Signals for Video ROM Memory for Pixel Data SIGNAL rom_address: std_logic_vector(8 DOWNTO 0); SIGNAL rom_data: std_logic_vector(7 DOWNTO 0); SIGNAL col_address, row_address, con_row, con_col: std_logic_vector(5 DOWNTO 0);

ldhungelec
SIGNAL pixel_col_count, pixel_row_count: std_logic_vector(5 DOWNTO 0); SIGNAL rom_mux_output: std_logic; SIGNAL red_data,green_data, blue_data: boolean; SIGNAL in_screen, in_screen_vertical, in_screen_horizontal : BOOLEAN; SIGNAL square : STD_LOGIC_VECTOR(5 DOWNTO 0); SIGNAL shape, choice : STD_LOGIC_VECTOR(4 DOWNTO 0); SIGNAL column1, column2, column3, column4, column5, column6 : STD_LOGIC_VECTOR(5 DOWNTO 0); SIGNAL positionX1, positionX2, positionX3, positionX4 : STD_LOGIC_VECTOR(5 DOWNTO 0); SIGNAL positionY1, positionY2, positionY3, positionY4 : STD_LOGIC_VECTOR(5 DOWNTO 0); SIGNAL defaultX1, defaultX2, defaultX3, defaultX4 : STD_LOGIC_VECTOR(5 DOWNTO 0); SIGNAL defaultY1, defaultY2, defaultY3, defaultY4 : STD_LOGIC_VECTOR(5 DOWNTO 0); SIGNAL top_bound, low_bound, left_bound, right_bound : STD_LOGIC_VECTOR(5 DOWNTO 0); SIGNAL top_Y, low_Y, left_X, right_X : STD_LOGIC_VECTOR(5 DOWNTO 0); SIGNAL score1, score2, score3, score4, score5, score6 : STD_LOGIC_VECTOR(5 DOWNTO 0); SIGNAL count_timer : STD_LOGIC_VECTOR(5 DOWNTO 0); SIGNAL james : STD_LOGIC_VECTOR(3 DOWNTO 0); BEGIN load_rom : lpm_rom GENERIC MAP (lpm_widthad => 9, lpm_numwords => "512", lpm_outdata => "UNREGISTERED", lpm_address_control => "UNREGISTERED", lpm_file => "tetris_set.mif", lpm_width => 8) PORT MAP (address => rom_address, q => rom_data); square <= "100111"; --shape <= "00101"; top_bound <= "000111"; low_bound <= "010111"; left_bound <= "001000"; right_bound <= "010010"; top_Y <= "001000";

defaultY3 <= "000101". right_X <= "011101". defaultX3 <= "001111". -. defaultY1 <= "000111". column4 <= "011101".for on screen character generation rom_mux_output <= rom_data ( (CONV_INTEGER(NOT pixel_col_count(3 downto 1)))). END IF. column1 <= "011010". blue_data <= (rom_mux_output = '1'). vga_Green <= green_data and in_screen. -.B data red_data <= (rom_mux_output = '1').G. column3 <= "011100".Mux to pick off correct rom data bit from 8-bit word -. defaultX2 <= "001110". rom_address(2 Downto 0) <= pixel_row_count(3 Downto 1). defaultY2 <= "000110". column2 <= "011011". output: PROCESS(clock) BEGIN if rising_edge(clock) THEN -.draw the display area in_screen <= in_screen_horizontal AND in_screen_vertical. defaultX1 <= "001101". column5 <= "011110". vga_Blue <= blue_data and in_screen. left_X <= "011010". defaultY4 <= "000100". display_range: PROCESS(clock) BEGIN .ldhungelec low_Y <= "001011".The RGB signal pins to the VGA monitor vga_Red <= red_data and in_screen. green_data <= (rom_mux_output = '1'). END PROCESS output. defaultX4 <= "010000".local R. -.

ELSE james <= james + '1'. end process display_range. pixel_col_count <= countX(3 downto 0). IF shape <= "01101" THEN choice <= shape + "10". score1 <= "110000". positionY3 <= defaultY3. in_screen_vertical <= row_address >= "000000" AND row_address <= "011101". Vertical_position : PROCESS(timer) BEGIN IF button = "0111" THEN positionY1 <= defaultY1. score4 <= "110000". choice <= shape + '1'. score3 <= "110000". END IF. score6 <= "110000". positionY3 <= defaultY3. positionY4 <= defaultY4. ELSE choice <= "00001". END IF. positionY4 <= defaultY4. shape <= "00001". positionY2 <= defaultY2. pixel_row_count <= countY(3 downto 0). . row_address <= countY(9 downto 4). positionY2 <= defaultY2. james <= "0001". IF james = "1111" THEN james <= "0001". score2 <= "110000". score5 <= "110000".ldhungelec IF clock'event AND clock ='1' THEN col_address <= countX(9 downto 4). shape(4) <= '0'. ELSIF rising_edge(timer) THEN IF positionY1 = low_bound + 1 THEN positionY1 <= defaultY1. shape(3 DOWNTO 0) <= james(3 DOWNTO 0). in_screen_horizontal <= col_address >= "000000" AND col_address <= "100111".

'1'. ELSIF count_timer = "111111" THEN positionY1 <= positionY1 + '1'. positionX4 <= defaultX4.'1'. positionY3 <= positionY3 + '1'. positionX2 <= positionX2 .'1'. END IF. IF score2 = "111001" THEN score2 <= "110000". END PROCESS Vertical_position. positionX2 <= defaultX2. ELSIF button = "0100" THEN IF positionX1 > left_bound + 1 THEN positionX1 <= positionX1 . ELSIF score2 = "110111" THEN score2 <= "111000". IF score1 = "111001" THEN score1 <= "110000". END IF. Horizontal_position : PROCESS(button) BEGIN IF button = "0111" THEN positionX1 <= defaultX1. END IF. button) BEGIN . END IF. ELSE score2 <= score2 + '1'. END IF.'1'. positionX3 <= positionX3 .ldhungelec END IF. ELSIF score1 = "110111" THEN score1 <= "111000". END IF. positionY4 <= positionY4 + '1'. times : PROCESS(timer. END PROCESS Horizontal_position. positionX3 <= defaultX3. positionX4 <= positionX4 . positionY2 <= positionY2 + '1'. ELSE score1 <= score1 + '1'. score3 <= score3 + '1'.

x2 := x1 + '1'. END IF. ELSIF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. x4 := right_X. ELSE count_timer <= count_timer + 1. y2. y3 := y2 . ELSE rom_address(8 DOWNTO 3) <= "100010". END IF. y4 := top_Y. x2. END PROCESS times. ELSIF row_address > top_bound AND row_address < low_bound AND col_address > left_bound AND col_address < right_bound THEN CASE shape IS WHEN "00001" => IF row_address = positionY1 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. END IF.ldhungelec IF button = "0111" THEN count_timer <= (others=>'0'). y4. ELSIF row_address = positionY2 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. y3. y1 := low_Y. WHEN "00010" => IF row_address = positionY1 AND col_address = positionX1 THEN . x3 := x2 + '1'. y2 := y1 . x4 : STD_LOGIC_VECTOR(5 DOWNTO 0). x1. video_display : PROCESS(clock) VARIABLE y1. x3. ELSIF rising_edge(timer) THEN IF count_timer = "111111" THEN count_timer <= (others=>'0'). BEGIN IF rising_edge(clock) THEN IF Button = "0111" THEN rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = positionY3 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square.'1'.'1'. x1 := left_X.

WHEN "00011" => IF row_address = positionY1 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. WHEN "00101" => IF row_address = positionY1 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. . END IF. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = positionY2 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. WHEN "00100" => IF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY3 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". END IF. ELSIF row_address = positionY3 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY4 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. END IF. ELSIF row_address = positionY3 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square.ldhungelec rom_address(8 DOWNTO 3) <= square.

ELSIF row_address = positionY3 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. END IF.ldhungelec ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = positionY1 AND col_address = positionX3 THEN rom_address(8 DOWNTO 3) <= square. WHEN "01000" => IF row_address = positionY2 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". END IF. ELSIF row_address = positionY2 AND col_address = positionX3 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. END IF. WHEN "00110" => IF row_address = positionY1 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. END IF. . WHEN "01001" => IF row_address = positionY1 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = positionY2 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. WHEN "00111" => IF row_address = positionY1 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX3 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square.

ELSIF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSE . END IF.ldhungelec ELSIF row_address = positionY2 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. END IF. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = positionY1 AND col_address = positionX3 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX3 THEN rom_address(8 DOWNTO 3) <= square. END IF. WHEN "01010" => IF row_address = positionY2 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX4 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX3 THEN rom_address(8 DOWNTO 3) <= square. WHEN "01100" => IF row_address = positionY2 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY3 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. WHEN "01011" => IF row_address = positionY1 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY3 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square.

ELSIF row_address = positionY2 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX3 THEN rom_address(8 DOWNTO 3) <= square.ldhungelec rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = positionY2 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". WHEN "01111" => IF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. END IF. ELSIF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. WHEN "01110" => IF row_address = positionY3 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX3 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX1 THEN . WHEN "10000" => IF row_address = positionY3 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. END IF. WHEN "01101" => IF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = positionY2 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". END IF. END IF.

END IF. ELSIF row_address = positionY2 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". WHEN "10001" => IF row_address = positionY1 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX3 THEN rom_address(8 DOWNTO 3) <= square. .ldhungelec rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY2 AND col_address = positionX3 THEN rom_address(8 DOWNTO 3) <= square. END IF. WHEN "10010" => IF row_address = positionY3 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = positionY2 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = positionY3 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX3 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = positionY1 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square. WHEN "10011" => IF row_address = positionY2 AND col_address = positionX1 THEN rom_address(8 DOWNTO 3) <= square. END IF. ELSIF row_address = positionY3 AND col_address = positionX2 THEN rom_address(8 DOWNTO 3) <= square.

top bound col_address > left_bound AND col_address < right_bound THEN rom_address(8 DOWNTO 3) <= "100100". ELSIF col_address = right_bound AND -.bottom bound col_address > left_bound AND col_address < right_bound THEN rom_address(8 DOWNTO 3) <= "101101". ELSIF col_address = left_bound AND -. WHEN "00010" => IF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y1 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square.left bound row_address > top_bound AND row_address < low_bound THEN rom_address(8 DOWNTO 3) <= "100101". ELSIF row_address = top_bound AND -. ELSIF row_address = y1 AND col_address = x2 THEN . WHEN OTHERS => rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = low_bound AND -. ELSE rom_address(8 DOWNTO 3) <= "100010". END IF. ELSIF row_address >= top_Y AND row_address <= low_Y AND col_address >= left_X AND col_address <= right_X THEN CASE choice IS WHEN "00001" => IF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square.ldhungelec END IF.right bound row_address > top_bound AND row_address < low_bound THEN rom_address(8 DOWNTO 3) <= "100110". END CASE. ELSIF row_address = y3 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square.

ELSIF row_address = y3 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". WHEN "00100" => IF row_address = y1 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. . WHEN "00101" => IF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y3 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. END IF.ldhungelec rom_address(8 DOWNTO 3) <= square. END IF. ELSIF row_address = y2 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. WHEN "00011" => IF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. END IF. ELSIF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y3 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y4 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square.

ELSIF row_address = y1 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y1 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. END IF. WHEN "00110" => IF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010".ldhungelec END IF. . ELSIF row_address = y1 AND col_address = x3 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y2 AND col_address = x3 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y1 AND col_address = x3 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. WHEN "01000" => IF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. WHEN "01001" => IF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. END IF. END IF. WHEN "00111" => IF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y3 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square.

ELSIF row_address = y1 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y2 AND col_address = x3 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y1 AND col_address = x3 THEN rom_address(8 DOWNTO 3) <= square. WHEN "01010" => IF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. . END IF. ELSE rom_address(8 DOWNTO 3) <= "100010". END IF.ldhungelec ELSIF row_address = y3 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. END IF. ELSIF row_address = y1 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y1 AND col_address = x4 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y1 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. END IF. ELSIF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y3 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. WHEN "01011" => IF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y1 AND col_address = x3 THEN rom_address(8 DOWNTO 3) <= square. WHEN "01100" => IF row_address = y2 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square.

END IF. WHEN "01110" => IF row_address = y3 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. END IF. ELSIF row_address = y1 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square.ldhungelec WHEN "01101" => IF row_address = y1 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y2 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y3 AND col_address = x2 THEN . ELSIF row_address = y2 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y1 AND col_address = x3 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. WHEN "01111" => IF row_address = y1 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. END IF. ELSIF row_address = y2 AND col_address = x3 THEN rom_address(8 DOWNTO 3) <= square. WHEN "10000" => IF row_address = y3 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y2 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square.

ELSE rom_address(8 DOWNTO 3) <= "100010".ldhungelec rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y1 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y1 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. END IF. WHEN "10011" => IF row_address = y2 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSE rom_address(8 DOWNTO 3) <= "100010". ELSIF row_address = y2 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y1 AND col_address = x3 THEN rom_address(8 DOWNTO 3) <= square. WHEN "10010" => IF row_address = y3 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. END IF. ELSIF row_address = y3 AND col_address = x2 THEN rom_address(8 DOWNTO 3) <= square. END IF. WHEN "10001" => IF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x3 THEN rom_address(8 DOWNTO 3) <= square. . ELSIF row_address = y1 AND col_address = x1 THEN rom_address(8 DOWNTO 3) <= square. ELSIF row_address = y2 AND col_address = x3 THEN rom_address(8 DOWNTO 3) <= square. END IF.

ELSIF row_address = "001111" AND col_address= column4 THEN rom_address(8 DOWNTO 3) <= "010010".vhd --. ELSIF row_address = "010000" AND col_address= column4 THEN rom_address(8 DOWNTO 3) <= score2. ELSIF row_address = "001111" AND col_address= column3 THEN rom_address(8 DOWNTO 3) <= "001111".Student : Feng Gui --. ELSE rom_address(8 DOWNTO 3) <= "100010". END IF.vhd ------------------------------------------------------. ELSIF row_address = "010000" AND col_address= column3 THEN rom_address(8 DOWNTO 3) <= score3. END PROCESS video_display. ELSIF row_address = "001111" AND col_address= column1 THEN rom_address(8 DOWNTO 3) <= "010011".March 24 ------------------------------------------------------ . ELSIF row_address = "010000" AND col_address= column5 THEN rom_address(8 DOWNTO 3) <= score1. ELSIF row_address = "010000" AND col_address= column1 THEN rom_address(8 DOWNTO 3) <= "110000". END IF. END CASE. ELSIF row_address = "001111" AND col_address= column5 THEN rom_address(8 DOWNTO 3) <= "000101". ELSIF row_address = "010000" AND col_address= column2 THEN rom_address(8 DOWNTO 3) <= "110000". ELSIF row_address = "001111" AND col_address= column2 THEN rom_address(8 DOWNTO 3) <= "000011".File : tetrisdemo. tetrisdemo.ldhungelec WHEN OTHERS => rom_address(8 DOWNTO 3) <= "100010". END a.

END COMPONENT.all. reset: in STD_LOGIC. SIGNAL link_red_din2. signal trigger : std_logic. COMPONENT count_xy PORT(clock : in STD_LOGIC.all. END tetrisdemo. SIGNAL link_red_din1. --_vector(3 downto 0). HSync. link_green_din1. vga_h_sync. SIGNAL link_HSync. link_blue_din : BOOLEAN. databack : out std_logic_vector(3 downto 0)). link_green_din2.std_logic_arith. COMPONENT syncgen PORT(Clock : IN STD_LOGIC. link_v_din : BOOLEAN. USE ieee. vga_v_sync : OUT BOOLEAN). keyin : in std_logic_vector(3 downto 0). USE ieee. -. countX. vga_green. HSync. link_countY1 : STD_LOGIC_VECTOR(9 DOWNTO 0). . link_blue_din1 : BOOLEAN. SIGNAL link_h_din. link_blue_din2 : BOOLEAN.ldhungelec LIBRARY IEEE. link_green_din. vga_red.std_logic_1164. vga_v_sync : out BOOLEAN. signal press : std_logic. countY : out STD_LOGIC_VECTOR(9 downto 0). USE ieee.all. VSync : in BOOLEAN ).player's buttons vga_h_sync. link_countY2 : STD_LOGIC_VECTOR(9 DOWNTO 0). SIGNAL link_red_din. VSync : OUT BOOLEAN. SIGNAL link_countX. END COMPONENT. ENTITY tetrisdemo IS PORT(clock. link_VSync : BOOLEAN. SIGNAL link_countX1. SIGNAL link_countX2.std_logic_unsigned. signal keyout : std_logic_vector(3 downto 0). vga_blue: out BOOLEAN. ARCHITECTURE structure OF tetrisdemo IS SIGNAL link_timer : STD_LOGIC. timer : OUT STD_LOGIC. PB : in std_logic. link_countY : STD_LOGIC_VECTOR(9 DOWNTO 0).

clock : IN STD_LOGIC. syn_v_out : OUT BOOLEAN). vga_Red. BEGIN keytect : process begin press <= (keyout(0) or keyout(1)) or (keyout(2) or keyout(3)). COMPONENT colorlatch PORT(aclr. green_in. vga_Blue : OUT BOOLEAN.ldhungelec COMPONENT tetris PORT( clock : IN STD_LOGIC. syn_v_in : IN BOOLEAN. component keypad port( clk : IN STD_LOGIC. END COMPONENT. red_out. COMPONENT synlatch PORT(aclr. blue_in : IN BOOLEAN. vga_Green. vga_Blue : OUT BOOLEAN.External Signals row : IN STD_LOGIC_VECTOR(3 downto 0). reset : IN STD_LOGIC. button : in std_logic_vector(3 downto 0). col : OUT STD_LOGIC_VECTOR(3 downto 0)). countX. syn_h_in. syn_h_out. . reset : IN STD_LOGIC. red_in. vga_Red. COMPONENT message PORT(clock : IN STD_LOGIC. END COMPONENT. Key : OUT STD_LOGIC_VECTOR(3 downto 0). END component. vga_Green. END COMPONENT. green_out. END COMPONENT. button : IN STD_LOGIC.countY : IN STD_LOGIC_VECTOR(9 downto 0)). timer : IN STD_LOGIC. clock : IN STD_LOGIC. countX.countY : IN STD_LOGIC_VECTOR(9 downto 0)). blue_out : OUT BOOLEAN). -.

row =>keyin. button => keyout. button => keyout. red_out => vga_red. vga_green => vga_green. vga_blue => link_blue_din. -. vga_red => link_red_din2.countX => link_countX. countY => dff_countY_in). vga_blue => link_blue_din2. clock => clock. vga_v_sync => link_v_din ). countY => link_countY1). syn_v_in => link_v_din. reset => reset. vga_green => link_green_din1. countY => link_countY2). blue_out => vga_blue). use_counter: count_xy PORT MAP (clock => clock. use_colorlatch: colorlatch PORT MAP (aclr => reset. . countX => link_countX2. green_out => vga_green. --use_tetris: tetris PORT MAP -. blue_in => link_blue_din. red_in => link_red_din. VSync => link_VSync. syn_h_out => vga_h_sync. timer => link_timer. key => keyout. col=>databack). timer=>link_timer. clock => clock. use_keypad: keypad port map (clk => clock. vga_blue => vga_blue. green_in => link_green_din. use_message: message PORT MAP (clock => clock. countY => link_countY ).countX => dff_countX_in. -. end process keytect. button => PB. button => PB.vga_red => vga_red. HSync => link_HSync.vga_red => link_red_din. vga_h_sync => link_h_din.(clock => clock.ldhungelec -checking <= keyout. vga_green => link_green_din2. reset => reset. -. use_syncgen: syncgen PORT MAP (Clock => clock. vga_red => link_red_din1. use_synlatch : synlatch PORT MAP (aclr => reset. reset => reset. -. VSync => link_VSync.(clock => clock. use_tetris: tetris PORT MAP (clock => clock. syn_h_in => link_h_din. countX => link_countX. --use_message: message PORT MAP -. timer=>link_timer. countX => link_countX1. vga_green => link_green_din. HSync => link_HSync. countY => link_countY). syn_v_out => vga_v_sync). vga_blue => link_blue_din1.

when others => link_red_din <= link_red_din2. link_green_din<= link_green_din1. link_countY1 <= link_countY. link_blue_din <= link_blue_din2. --or vga_blue2. --or vga_blue2. -end if. --or link_vga_red2. link_blue_din <= link_blue_din2. link_green_din<= link_green_din2. end process choose. --or vga_red2.vhd --.vhd ------------------------------------------------------.Student : Feng Gui -- . link_countX2 <= link_countX. link_blue_din <= link_blue_din1.File : message. link_green_din<= link_green_din2. -else when '1' => link_red_din <= link_red_din2. link_countX2 <= link_countX. link_countX1 <= link_countX. link_countY2 <= link_countY. link_countY2 <= link_countY. --or vga_green2. --(press = '0') then case trigger is when '0' => link_red_din <= link_red_din1. --or vga_green2. end case. --or vga_blue2.ldhungelec choose: process(press) begin if rising_edge(press) then trigger <= trigger or press. --or vga_red2. message. --or vga_green2. end if. END structure.

signal format_address: std_logic_vector(5 DOWNTO 0). vga_Blue : OUT BOOLEAN. row_address. vga_Green. signal col_address. con_col: std_logic_vector(5 DOWNTO 0). signal pixel_col_count. countX.ldhungelec -----------------------------------------------------LIBRARY IEEE. vga_Red. con_row.green_data.countY : IN STD_LOGIC_VECTOR(9 downto 0)).ALL.Video Display Signals -. signal rom_data: std_logic_vector(7 DOWNTO 0). . button : IN STD_LOGIC. ARCHITECTURE a of message IS -.all.all.STD_LOGIC_ARITH.lpm_components. blue_data: boolean. USE IEEE. signal format_data: std_logic_vector(5 DOWNTO 0). signal rom_mux_output: std_logic.Signals for Video ROM Memory for Pixel Data signal rom_address: std_logic_vector(8 DOWNTO 0). reset : IN STD_LOGIC. pixel_row_count: std_logic_vector(5 DOWNTO 0).STD_LOGIC_1164.STD_LOGIC_UNSIGNED. USE IEEE. END message. ENTITY message IS PORT(clock. signal red_data.all. USE lpm. USE IEEE. LIBRARY lpm.

address has the value of each character or symbol stored -. --.mif contains characters and shapes we -. the function requires -.mif is represented -. -. Basically.is 8 bit wide.This is the width of the address[] port.mif.lpm_widthad => 9 -. in_screen_vertical.lpm_address_control => "UNREGISTERED" -. --.shapes stored in ROM. --. BEGIN -.and shapes will be stored in ROM.mif.by 8x8 in binary format. Also. -. the width of the q[] port -. Thus. in_screen_horizontal : BOOLEAN.mif into memory.Number of words stored in memory.lpm_file => "tetris_set.lpm_numwords => "512" -. -.mif. Depth = 512 in tetris_set.q => rom_data .will use in our project.lpm_numwords matches Depth in tetris_set.lpm_outdata => "UNREGISTERED" -.mif" -.In function lpm_rom --.Because each character in tetris_set.q[] port is unregistered. --. --.Stores file tetris_set.Width of the q[] port.file tetris_set.We can see. --.File tetris_set. and the function recommands -.We have a total of 512/8 = 64 characters and symbols in -.2^lpm_widthad = lpm_numwords => 2^9 = 512 --.lpm_width => 8 -. -.Because we have a total of 512/8 = 64 characters and -.in memory --.The address port is not registered. all the characters -.ldhungelec signal in_screen.address => rom_address -.

lpm_numwords matches Depth in tetris. -. --.and the function recommands -. --. one row at -.2^lpm_widthad = lpm_numwords --.In function lpm_rom --.a time.mif" -. lpm_outdata => "UNREGISTERED".42 appended with a 0.display on the screen. lpm_address_control => "UNREGISTERED". space.the width of 6 bit should cover the biggest address.mif.mif".of each character or symbols. this file provides -.Stores file tetris.address for character.Also. lpm_width => 8) PORT MAP (address => rom_address.q[] port is unregistered.Because the biggest address is 6x in octal number. q => rom_data).File tetris.Width of the q[] port. -.ROM address of each character to be displayed. lpm_numwords => "512".lpm_file => "tetris.lpm_address_control => "UNREGISTERED" -. --. lpm_file => "tetris_set. gives us 420 which is the ROM -.q will be assigned the 8x8 binary representation -. --.g. Of course. .mif. -. --. -. the function requires -.The address port is not registered.This is the width of the address[] port. -.lpm_widthad => 6 -. e.ldhungelec -.lpm_numwords => "38" -. -.Number of characters to be displayed on the screen. Depth = 38 in tetris_set.mif into memory.lpm_width => 8 -.lpm_outdata => "UNREGISTERED" -. Basically. -load_rom : lpm_rom GENERIC MAP (lpm_widthad => 9.We can see.mif contains string or messages we want to -. -.

-. lpm_address_control => "UNREGISTERED".is 8 bit wide.Mux to pick off correct rom data bit from 8-bit word -.draw the display area in_screen <= in_screen_horizontal AND in_screen_vertical.local R. format_data will be assigned the -.character in tetris.address => format_address -. lpm_outdata => "UNREGISTERED". green_data <= (rom_mux_output = '1').mif is represented -. --.B data red_data <= (rom_mux_output = '1').ldhungelec -.e. -.q => format_data -. Thus.The RGB signal pins to the VGA monitor . -. rom_address(2 Downto 0) <= pixel_row_count(3 Downto 1). -. blue_data <= (rom_mux_output = '1'). lpm_numwords => "63".mif -read_rom : lpm_rom GENERIC MAP (lpm_widthad => 6.by 8x8 in binary format.Because each character in tetris_set. 34 from tetris.for on screen character generation rom_mux_output <= rom_data ( (CONV_INTEGER(NOT pixel_col_count(3 downto 1)))).g 05. 21.Given an address.mif --.G.mif". lpm_file => "tetris.format_address is assigned the address value of each -.address value of each character to be displayed. the width of the q[] port -. q => format_data). output: PROCESS(clock) BEGIN if clock'EVENT AND clock= '1' THEN -. lpm_width => 6) PORT MAP (address => format_address.

pixel_col_count <= countX(3 downto 0). END IF. -.This Process Provides Character Data for Video Display -. video_display: PROCESS(clock) BEGIN IF clock'event and clock ='1' then col_address <= countX(9 downto 4). vga_Green <= green_data and in_screen.ldhungelec vga_Red <= red_data and in_screen. in_screen_vertical <= row_address >= "000000" and row_address <= "011101". end if.Address for Constant Character Data ROM format_address(4 Downto 0) <= con_col(4 Downto 0). vga_Blue <= blue_data and in_screen. if no key is pressed. format_address(5) <= con_row(0).Display process VIDEO_DISPLAY_DATA: process(clock. pixel_row_count <= countY(3 downto 0). end process video_display. row_address <= countY(9 downto 4). -. in_screen_horizontal <= col_address >= "000000" and col_address <= "100111". END PROCESS output.by generating addresses for the Character Generator ROM -.button) BEGIN IF clock'EVENT and clock = '1' THEN -.Displaying message. .using row address and col address provided by the Video -.

"001100"."001001"."001111". rom_address(8 downto 3) <= format_data. rom_address(8 downto 3) <= format_data. ELSIF col_address >= "001011" and col_address <= "011100" and row_address = "001100" AND button='1' THEN con_col <= col_address .ldhungelec IF col_address >= "010001" and col_address <= "010110" and row_address = "001001" AND button='1' THEN con_col <= col_address ."010010". rom_address(8 downto 3) <= format_data."010000". ."000101". END IF. con_row <= row_address . con_row <= row_address . rom_address(8 downto 3) <= format_data. ELSIF col_address >= "010000" and col_address <= "010111" and row_address = "010001" AND button='1' THEN con_col <= col_address + "001010". ELSIF col_address >= "010011" and col_address <= "010100" and row_address = "001111" AND button='1' THEN con_col <= col_address + "000101". con_row <= row_address . rom_address(8 downto 3) <= format_data."010100". ELSE con_row <= row_address ."010001". ELSIF col_address >= "001110" and col_address <= "011001" and row_address = "010011" AND button='1' THEN con_col <= col_address + "010100". ELSIF col_address >= "001100" and col_address <= "011011" and row_address = "010101" AND button='1' THEN con_col <= col_address + "100010"."010001". rom_address(8 downto 3) <= format_data. con_row <= row_address . IF col_address <= "010101" THEN con_row <= row_address . con_row <= row_address .

clock : IN STD_LOGIC. then display the space character. . architecture behavior of colorlatch is begin process(clock. END IF.d flip flop register --. END IF.all.vhd ------------------------------------------------------.File : colorlatch. blue_out <= ( aclr = '1').If no messages displayed. rom_address(8 downto 3) <= "100010". blue_in : IN BOOLEAN. green_out <= green_in. blue_out : OUT BOOLEAN). red_in. green_out <= ( aclr = '1'). end process.Student : Feng Gui ------------------------------------------------------library ieee. END a.std_logic_1164. green_out. colorlatch.--clock END process VIDEO_DISPLAY_DATA. ENTITY colorlatch IS port(aclr. aclr) begin if aclr = '0' then red_out <= ( aclr = '1').vhd --. ELSIF rising_edge(clock) THEN red_out <= red_in. green_in.ldhungelec ELSE -. blue_out <= blue_in. red_out. USE ieee. END colorlatch. END IF.

END synlatch.all.File : synlatch.ldhungelec end behavior.all.std_logic_arith. syn_v_out <= (aclr = '1'). use ieee. syn_h_in. clock : IN STD_LOGIC. end process. USE ieee. END IF.std_logic_1164.Student : Feng Gui -. synlatch. count_xy. syn_v_in : IN BOOLEAN. syn_h_out. countX. entity count_xy is port( clock : in std_logic.countY : out std_logic_vector(9 downto 0). architecture behavior of synlatch is begin process(clock.d flip flop register --.vhd --. use ieee.VSync : in boolean .vhd ------------------------------------------------------. aclr) begin if aclr = '0' then syn_h_out <= (aclr = '1'). syn_v_out : OUT BOOLEAN). use ieee. syn_v_out <= syn_v_in. ELSIF rising_edge(clock) THEN syn_h_out <= syn_h_in. HSync.std_logiC_unsigned. ENTITY synlatch IS port(aclr.vhd library ieee.all.all.March 19 ------------------------------------------------------library ieee. end behavior.std_logic_1164.

end count_xy.File : syncgen. use ieee. use ieee. syncgen.Synchronizatoin for countX and countY -. entity syncgen is : std_logic_vector( 9 downto 0). else countlocX <= countlocX + '1'. countY <= countlocY. architecture counting of count_xy is signal countlocX. if VSync then countlocY <= "0000000000".ldhungelec ). countX <= countlocX. end counting.all. end process. end if. use ieee. -- .std_logic_1164.all.vhd ------------------------------------------------------library ieee.std_logic_unsigned.vhd ------------------------------------------------------.all. end if. countlocY begin process(clock) begin if clock'EVENT and clock = '1' then if HSync then countlocX <= "0000000000". end if. elsif HSync then countlocY <= countlocY + '1'.std_logic_arith.

HSync.ldhungelec port ( Clock : in std_logic. vga_h_sync <= vga_HS. vga_HS <= (CounterX<96). VS. begin EnableCntY := (CounterX=40). vga_v_sync : out boolean). end if. CounterY: integer range 0 to 1023. vga_VS <= (CounterY< 2). end process. end if. if EnableCntY then if ResetCntY then CounterY <= 0. vga_HS. else CounterX <= CounterX + 1. HSync <= HS. architecture ASyncGen of syncgen is signal CounterX. VSync <= VS. if Clock'EVENT and Clock='1' then if CounterX=799 then CounterX <= 0. timer : out std_logic. HS <= (CounterX=128). else CounterY <= CounterY + 1. signal HS. . begin process(Clock) variable EnableCntY. ResetCntY := (CounterY=524). VS <= (CounterY=32) and HS. vga_VS: boolean. end syncgen. end if. ResetCntY: boolean. end if. VSync : out boolean. vga_v_sync <= vga_VS. vga_h_sync.

. end ASyncGen.ldhungelec timer<= '1' when VS.