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 6a38240a358d71cc4144dd39129b024a281ab36c..e3243536646db2d2192e97b83c0b3c6e549a0164 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 @@ -58,8 +58,8 @@ port end component; signal clk_25MHz, locked : std_logic; -signal cells : std_logic_vector(0 to cell_number-1) := (others => '0'); -signal cells_to_draw : std_logic_vector(0 to cell_number-1) := (others => '0'); +signal cells : std_logic_vector(0 to cell_number*cell_number-1) := (511 => '1', 512 => '1', 513 => '1',others => '0'); +signal cells_to_draw : std_logic_vector(0 to cell_number*cell_number-1) := (others => '0'); -- drawing period's constants constant HORIZONTAL_SYNC_PULSE : integer := 800; @@ -96,6 +96,7 @@ 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,11 +132,45 @@ begin end if; -- handle shift registers - if horizontal_counter(9 downto 3) < cell_number and vertical_counter(9 downto 3) < cell_number then + if horizontal_counter(9 downto 3) < cell_number+2 and vertical_counter(9 downto 3) < cell_number+2 then 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) & cells(to_integer(vertical_counter(9 downto 3) * to_unsigned(cell_number,8) + horizontal_counter(9 downto 3))); - neighbours <= neighbours(3 to 8) & shift_register_top(0) & shift_register_middle(0) & cells(to_integer(vertical_counter(9 downto 3) * to_unsigned(cell_number,8) + horizontal_counter(9 downto 3))); - -- TODO + + 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 + shift_register_middle <= shift_register_middle(1 to cell_number-1) & cells(to_integer((vertical_counter(9 downto 3)-1) * to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)-1)); + neighbours <= neighbours(3 to 8) & shift_register_top(0) & shift_register_middle(0) & cells(to_integer((vertical_counter(9 downto 3) -1)* to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)-1)); + else + shift_register_middle <= shift_register_middle(1 to cell_number-1) & '0'; + neighbours <= neighbours(3 to 8) & shift_register_top(0) & shift_register_middle(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 neighbours(4)='1' then + if neighbour_cnt = 3 or neighbour_cnt = 4 then + cells(to_integer((vertical_counter(9 downto 3)-1) * to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)-1)) <= '1'; + cells_to_draw(to_integer((vertical_counter(9 downto 3)-1) * to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)-1)) <= '1'; + else + cells(to_integer((vertical_counter(9 downto 3)-1) * to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)-1)) <= '0'; + cells_to_draw(to_integer((vertical_counter(9 downto 3)-1) * to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)-1)) <= '0'; + end if; + else + if neighbour_cnt = 3 then + cells(to_integer((vertical_counter(9 downto 3)-1) * to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)-1)) <= '1'; + cells_to_draw(to_integer((vertical_counter(9 downto 3)-1) * to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)-1)) <= '1'; + else + cells(to_integer((vertical_counter(9 downto 3)-1) * to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)-1)) <= '0'; + cells_to_draw(to_integer((vertical_counter(9 downto 3)-1) * to_unsigned(cell_number,8) + horizontal_counter(9 downto 3)-1)) <= '0'; + end if; + end if; + + end if; + end if; -- sign options