library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity objecttracker is
	Port (
    		RESET_in	  : in  std_logic; -- Reset (active high)
		CLK_in	  : in  std_logic; -- Clock

		);
end objecttracker;


architecture Behavioral of objecttracker is


   --RAM, 12 bits x 256
   component image 
	port (
	addr: IN std_logic_VECTOR(7 downto 0);
	clk: IN std_logic;
	din: IN std_logic_VECTOR(11 downto 0);
	dout: OUT std_logic_VECTOR(11 downto 0);
	we: IN std_logic);
   end component;

   signal sclk_rw	: std_logic;


   type sclk_status_type is (read, write);
   signal sclk_status: sclk_status_type;




begin

   --Connect up the ram-bank that memorizes which
   --colour has occured the most
   RAMIMAGE1: image port map(
	addr => latched_colour(7 downto 0),
	clk => sclk,
	din => colour_count_in,
	dout => colour_count_out,
	we => sclk_rw);

	
	sclk_rw <= '1' when sclk_status = write else '0';

	process(SCLK)
	begin
	if rising_edge(SCLK) then
		if (sclk_status = read) then
			latched_colour_count <= colour_count_out;
			--latch current colour
			latched_colour <= colour_data;
		--else
		--	latched_colour <= latched_colour;
		--	latched_colour_count <= latched_colour_count;
		end if;
	end if;	
	end process;	

	--read the number of times it has occured
	process
	begin
	if falling_edge(SCLK) then
		if (sclk_status = read) then
			sclk_status <= write;
			colour_count_in <= latched_colour_count + 1;
		else
			sclk_status <= read;
		end if;
	end if;

	--increment that number by one


