Skip to content
Snippets Groups Projects
Commit 140e076a authored by vagle's avatar vagle
Browse files

Final version

parent 094df1d7
No related branches found
No related tags found
No related merge requests found
---------------------------------------------------------------------------------- ----------------------------------------------------------------------------------
-- Company: -- Company:
-- Engineer: -- Engineer: Mlinkó Péter, Vági Levente
-- --
-- Create Date: 12/10/2018 01:49:49 PM -- Create Date: 12/10/2018 01:49:49 PM
-- Design Name: -- Design Name:
-- Module Name: game_of_life - Behavioral -- Module Name: game_of_life - Behavioral
-- Project Name: -- Project Name: FPGA grand project
-- Target Devices: -- Target Devices:
-- Tool Versions: -- Tool Versions:
-- Description: -- Description:
...@@ -33,7 +33,7 @@ use IEEE.NUMERIC_STD.ALL; ...@@ -33,7 +33,7 @@ use IEEE.NUMERIC_STD.ALL;
entity game_of_life is entity game_of_life is
generic (cell_number : positive := 32); 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 switch_mode : in STD_LOGIC; -- 0: editor, 1: simulation
move_left : in STD_LOGIC; -- cursor's move left button move_left : in STD_LOGIC; -- cursor's move left button
move_right : in STD_LOGIC; -- cursor's move right 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); ...@@ -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 shift_register_middle : std_logic_vector(0 to cell_number+1);
signal actual_register : std_logic_vector(0 to 0); 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 : std_logic_vector(0 to 8);
signal neighbours_count : unsigned(3 downto 0); signal neighbours_count : unsigned(3 downto 0);
signal frame_counter : unsigned(6 downto 0); signal frame_counter : unsigned(6 downto 0);
...@@ -116,7 +112,6 @@ clk_gen_25MHz : clk_wiz_0 ...@@ -116,7 +112,6 @@ clk_gen_25MHz : clk_wiz_0
); );
options : process(clk_25MHz,locked) options : process(clk_25MHz,locked)
--variable neighbour_cnt : unsigned(3 downto 0) := (others=>'0');
begin begin
if locked = '0' then if locked = '0' then
horizontal_counter <= (others => '0'); horizontal_counter <= (others => '0');
...@@ -131,8 +126,6 @@ begin ...@@ -131,8 +126,6 @@ begin
neighbours_count <= (others => '0'); neighbours_count <= (others => '0');
frame_counter <= (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_x <= (others => '0');
cursor_pos_y <= (others => '0'); cursor_pos_y <= (others => '0');
prev_move_left <= move_left; prev_move_left <= move_left;
...@@ -166,59 +159,23 @@ begin ...@@ -166,59 +159,23 @@ begin
-- handle shift registers -- 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+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); 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) /= 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; 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 <= 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); 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)); 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 else
shift_register_middle <= shift_register_middle(1 to cell_number+1) & actual_register; 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 <= 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); 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; end if;
if vertical_counter(9 downto 3) >= 2 and horizontal_counter(9 downto 3) >= 2 then 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 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'; 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 ...@@ -250,19 +207,15 @@ begin
-- moving with cursor -- moving with cursor
if switch_mode = '0' then 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 /= 0 then
--if prev_move_left = '0' and move_left = '1' and cursor_pos_x /= 8 then
cursor_pos_x <= cursor_pos_x - 8; cursor_pos_x <= cursor_pos_x - 8;
end if; 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-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; cursor_pos_x <= cursor_pos_x + 8;
end if; 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 /= 0 then
--if prev_move_up = '0' and move_up = '1' and cursor_pos_y /= 8 then
cursor_pos_y <= cursor_pos_y - 8; cursor_pos_y <= cursor_pos_y - 8;
end if; 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-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; cursor_pos_y <= cursor_pos_y + 8;
end if; end if;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment