library IEEE; use IEEE.std_logic_1164.all; use IEEE.numeric_std.all; entity COUNT_TOP is port( JA:inout std_logic_vector(1 downto 0); JB:in std_logic_vector(3 downto 0); btnL,btnR,btnC:in std_logic; clk:in std_logic); end entity COUNT_TOP; architecture COUNT_TOP of COUNT_TOP is component scale_clock is port(clk:in std_logic; clk12k:out std_logic); end component scale_clock; component COUNT_TYPE is port( INPUT: in std_logic_vector(1 downto 0); CLK:in std_logic; COUNT_UP,COUNT_DN: out std_logic); end component COUNT_TYPE; component COUNT_8B is port( RESET,CLK:in std_logic; UP,DN:in std_logic; COUNT:out std_logic_vector(7 downto 0); SIGN:out std_logic); end component COUNT_8B; component BYTEPACKET is port( Xsign,Ysign:in std_logic; LBTN,RBTN:in std_logic; state_byte:out std_logic_vector(7 downto 0)); end component BYTEPACKET; component PS2Manager is port( clk,clk12khz,reset:in std_logic; --one clk for the internal operation of the device and another to output on PS2C out_message,finished:in std_logic; --if a new message needs to be sent to the host then out_message='1' in_message:out std_logic; --flag the new recieved message data_out:in std_logic_vector(7 downto 0); --data to be sent to Host data_in:out std_logic_vector(7 downto 0); -- data to recieve by device PS2D,PS2C:inout std_logic ); end component PS2Manager; component message_manager is port(in_message,clk12khz,clk:in std_logic;--flag for incoming message from host data_in,xbyte,ybyte,statebyte:in std_logic_vector(7 downto 0); data_out:out std_logic_vector(7 downto 0); finish,out_message:out std_logic); end component message_manager; signal CUPX,CUPY,CDNX,CDNY,xsgn,ysgn,fin,out_flag,in_msg,clk12khz:std_logic; signal countx,county,PSstate,out_msg,in_data:std_logic_vector(7 downto 0); begin Clock:scale_clock port map(clk=>clk, clk12k=>clk12khz); INX: COUNT_TYPE port map( INPUT=>JB(1 downto 0), COUNT_UP=>CUPX, COUNT_DN=>CDNX, CLK=>clk); INY: COUNT_TYPE port map( INPUT=>JB(3 downto 2), COUNT_UP=>CUPY, COUNT_DN=>CDNY, CLK=>clk); XCOUNT: COUNT_8B port map( RESET=>btnC, CLK=>clk, UP=>CUPX, DN=>CDNX, COUNT=>countx(7 downto 0), SIGN=>xsgn); YCOUNT: COUNT_8B port map( RESET=>btnC, CLK=>clk, UP=>CUPY, DN=>CDNY, COUNT=>county(7 downto 0), SIGN=>ysgn); BYTES: BYTEPACKET port map( Xsign=>xsgn, Ysign=>ysgn, LBTN=>btnL, RBTN=>btnR, state_byte=>PSstate); PS2Interface: PS2Manager port map( clk=>clk, clk12khz=>clk12khz, reset=>btnC, out_message=>out_flag, finished=>fin, in_message=>in_msg, data_out=>out_msg, data_in=>in_data, PS2D=>JA(1), PS2C=>JA(0)); Message: message_manager port map(clk=>clk, in_message=>in_msg, out_message=>out_flag, clk12khz=>clk12khz, data_in=>in_data, xbyte=>countx, ybyte=>county, statebyte=>PSstate, data_out=>out_msg, finish=>fin); end architecture COUNT_TOP;