From 140e076a36268a41d47972d49f7d32d40fa35def Mon Sep 17 00:00:00 2001
From: vagle <vagilevente@gmail.com>
Date: Fri, 14 Dec 2018 14:51:33 +0100
Subject: [PATCH] Final version

---
 .../sources_1/new/game_of_life.vhd            | 55 ++-----------------
 1 file changed, 4 insertions(+), 51 deletions(-)

diff --git a/game_of_life_v2/game_of_life_v2.srcs/sources_1/new/game_of_life.vhd b/game_of_life_v2/game_of_life_v2.srcs/sources_1/new/game_of_life.vhd
index 86c528b..5b59080 100644
--- a/game_of_life_v2/game_of_life_v2.srcs/sources_1/new/game_of_life.vhd
+++ b/game_of_life_v2/game_of_life_v2.srcs/sources_1/new/game_of_life.vhd
@@ -1,11 +1,11 @@
 ----------------------------------------------------------------------------------
 -- Company: 
--- Engineer: 
+-- Engineer: Mlinkó Péter, Vági Levente
 -- 
 -- Create Date: 12/10/2018 01:49:49 PM
 -- Design Name: 
 -- Module Name: game_of_life - Behavioral
--- Project Name: 
+-- Project Name: FPGA grand project
 -- Target Devices: 
 -- Tool Versions: 
 -- Description: 
@@ -33,7 +33,7 @@ use IEEE.NUMERIC_STD.ALL;
 
 entity game_of_life is
     generic (cell_number : positive := 32);
-    Port ( clk : in STD_LOGIC;
+    Port ( clk : in STD_LOGIC;                             -- 100MHz clock sign
            switch_mode : in STD_LOGIC;                     -- 0: editor, 1: simulation
            move_left : in STD_LOGIC;                       -- cursor's move left button
            move_right : in STD_LOGIC;                      -- cursor's move right button
@@ -86,10 +86,6 @@ signal shift_register_top : std_logic_vector(0 to cell_number+1);
 signal shift_register_middle : std_logic_vector(0 to cell_number+1);
 signal actual_register : std_logic_vector(0 to 0);
 
---signal copy_shift_register_top : std_logic_vector(0 to cell_number-1);
---signal copy_shift_register_middle : std_logic_vector(0 to cell_number-1);
---signal copy_actual_register : std_logic_vector(0 to 0);
-
 signal neighbours : std_logic_vector(0 to 8);
 signal neighbours_count : unsigned(3 downto 0);
 signal frame_counter : unsigned(6 downto 0);
@@ -116,7 +112,6 @@ clk_gen_25MHz : clk_wiz_0
  );
 
 options : process(clk_25MHz,locked)
---variable neighbour_cnt : unsigned(3 downto 0) := (others=>'0');
 begin
     if locked = '0' then
         horizontal_counter <= (others => '0');
@@ -131,8 +126,6 @@ begin
         neighbours_count <= (others => '0');
         frame_counter <= (others => '0');
         
-        --cursor_pos_x <= to_unsigned(8,10);
-        --cursor_pos_y <= to_unsigned(8,10);
         cursor_pos_x <= (others => '0');
         cursor_pos_y <= (others => '0');
         prev_move_left <= move_left;
@@ -166,59 +159,23 @@ begin
 
             -- handle shift registers
             if switch_mode = '1' and frame_counter = 0 and horizontal_counter(2 downto 0) = 0 and horizontal_counter(9 downto 3) < cell_number+2 and vertical_counter(2 downto 0) = 0 and vertical_counter(9 downto 3) < cell_number+2 then
-            --if switch_mode = '1' and frame_counter = 0 and horizontal_counter(2 downto 0) = 0 and horizontal_counter(9 downto 3) < cell_number and vertical_counter(2 downto 0) = 0 and vertical_counter(9 downto 3) < cell_number then
                 shift_register_top <= shift_register_top(1 to cell_number+1) & shift_register_middle(0);
                 
                 if horizontal_counter(9 downto 3) /= 0 and horizontal_counter(9 downto 3) < cell_number+1 and vertical_counter(9 downto 3) /= 0 and vertical_counter(9 downto 3) < cell_number+1 then
-                --if horizontal_counter(9 downto 3) < cell_number and vertical_counter(9 downto 3) < cell_number then
-                    --copy_shift_register_top <= shift_register_top(1 to cell_number-1) & shift_register_middle(0);
                     shift_register_middle <= shift_register_middle(1 to cell_number+1) & actual_register;
-                    --copy_shift_register_middle <= shift_register_middle(1 to cell_number-1) & actual_register;
                     neighbours <= neighbours(3 to 8) & shift_register_top(0) & shift_register_middle(0) & actual_register;
                     neighbours_count <= neighbours_count - unsigned(neighbours(0 to 0)) - unsigned(neighbours(1 to 1)) - unsigned(neighbours(2 to 2)) + unsigned(shift_register_top(0 to 0)) + unsigned(shift_register_middle(0 to 0)) + unsigned(actual_register);
                     actual_register(0) <= cells(to_integer((vertical_counter(9 downto 3)-1)* to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)-1));
-                    --copy_actual_register(0) <= cells(to_integer((vertical_counter(9 downto 3))* to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)));
                 else
                     shift_register_middle <= shift_register_middle(1 to cell_number+1) & actual_register;
                     neighbours <= neighbours(3 to 8) & shift_register_top(0) & shift_register_middle(0) & actual_register;
                     
-                    -- left top corner
-                    --if horizontal_counter(9 downto 3) = 0 and vertical_counter(9 downto 3) = 0 then
-                    --    neighbours_count <= neighbours_count + unsigned(neighbours(8 to 8)) + unsigned(shift_register_middle(0 to 0)) + unsigned(actual_register);
-                    -- right top corner
-                    --elsif horizontal_counter(9 downto 3) = cell_number-1 and vertical_counter(9 downto 3) = 0 then
-                    --    neighbours_count <= neighbours_count - unsigned(neighbours(1 to 1)) - unsigned(neighbours(2 to 2));
-                    -- left bottom corner
-                    --elsif horizontal_counter(9 downto 3) = 0 and vertical_counter(9 downto 3) = cell_number-1 then
-                    --    neighbours_count <= neighbours_count - unsigned(neighbours(0 to 0)) - unsigned(neighbours(1 to 1)) - unsigned(neighbours(2 to 2)) - unsigned(neighbours(3 to 3)) - unsigned(neighbours(4 to 4)) - unsigned(neighbours(5 to 5)) + unsigned(neighbours(6 to 6)) + unsigned(neighbours(7 to 7)) + unsigned(neighbours(8 to 8)) + unsigned(shift_register_top(0 to 0)) + unsigned(shift_register_middle(0 to 0));
-                    -- right bottom corner
-                    --elsif horizontal_counter(9 downto 3) = cell_number-1 and vertical_counter(9 downto 3) = cell_number-1 then
-                    --    neighbours_count <= neighbours_count - unsigned(neighbours(0 to 0)) - unsigned(neighbours(1 to 1));
-                    -- top edge
-                    --elsif vertical_counter(9 downto 3) = 0 then
-                    --    neighbours_count <= neighbours_count - unsigned(neighbours(1 to 1)) - unsigned(neighbours(2 to 2)) + unsigned(shift_register_middle(0 to 0)) + unsigned(actual_register);
-                    -- left edge
-                    --elsif horizontal_counter(9 downto 3) = 0 then
-                    --    neighbours_count <= neighbours_count - unsigned(neighbours(0 to 0)) - unsigned(neighbours(1 to 1)) - unsigned(neighbours(2 to 2)) - unsigned(neighbours(3 to 3)) - unsigned(neighbours(4 to 4)) - unsigned(neighbours(5 to 5)) + unsigned(neighbours(6 to 6)) + unsigned(neighbours(7 to 7)) + unsigned(neighbours(8 to 8)) + unsigned(shift_register_top(0 to 0)) + unsigned(shift_register_middle(0 to 0)) + unsigned(actual_register);
-                    -- right edge
-                    --elsif horizontal_counter(9 downto 3) = cell_number-1 then
-                    --    neighbours_count <= neighbours_count - unsigned(neighbours(0 to 0)) - unsigned(neighbours(1 to 1)) - unsigned(neighbours(2 to 2));
-                    -- bottom edge
-                    --elsif vertical_counter(9 downto 3) = cell_number-1 then
-                    --    neighbours_count <= neighbours_count - unsigned(neighbours(0 to 0)) - unsigned(neighbours(1 to 1)) + unsigned(shift_register_top(0 to 0)) + unsigned(shift_register_middle(0 to 0));
-                    --end if;
                     
                     neighbours_count <= neighbours_count - unsigned(neighbours(0 to 0)) - unsigned(neighbours(1 to 1)) - unsigned(neighbours(2 to 2)) + unsigned(shift_register_top(0 to 0)) + unsigned(shift_register_middle(0 to 0)) + unsigned(actual_register);
-                    actual_register(0) <= '0';--cells(to_integer((vertical_counter(9 downto 3))* to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)));
+                    actual_register(0) <= '0';
                 end if;
                 
                 if vertical_counter(9 downto 3) >= 2 and horizontal_counter(9 downto 3) >= 2 then
-                    --neighbour_cnt := (others=>'0');
-                    --for i in 0 to 8 loop
-                    --    if (neighbours(i)) = '1' then
-                            --neighbour_cnt := neighbour_cnt+1;
-                    --    end if;
-                    --end loop;
                     
                     if horizontal_counter(9 downto 3) = 0 or horizontal_counter(9 downto 3) = cell_number+1 or vertical_counter(9 downto 3) = 0 or vertical_counter(9 downto 3) = cell_number+1 then
                         cells(to_integer((vertical_counter(9 downto 3)-2) * to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)-4)) <= '0';
@@ -250,19 +207,15 @@ begin
             -- moving with cursor
             if switch_mode = '0' then
                 if prev_move_left = '0' and move_left = '1' and cursor_pos_x /= 0 then
-                --if prev_move_left = '0' and move_left = '1' and cursor_pos_x /= 8 then
                     cursor_pos_x <= cursor_pos_x - 8;
                 end if;
                 if prev_move_right = '0' and move_right = '1' and cursor_pos_x /= (cell_number-1)*8 then
-                --if prev_move_right = '0' and move_right = '1' and cursor_pos_x /= (cell_number-2)*8 then
                     cursor_pos_x <= cursor_pos_x + 8;
                 end if;
                 if prev_move_up = '0' and move_up = '1' and cursor_pos_y /= 0 then
-                --if prev_move_up = '0' and move_up = '1' and cursor_pos_y /= 8 then
                     cursor_pos_y <= cursor_pos_y - 8;
                 end if;
                 if prev_move_down = '0' and move_down = '1' and cursor_pos_y /= (cell_number-1)*8 then
-                --if prev_move_down = '0' and move_down = '1' and cursor_pos_y /= (cell_number-2)*8 then
                     cursor_pos_y <= cursor_pos_y + 8;
                 end if;
                 
-- 
GitLab