-- Original Mediatronix file: PicoTest.vhd
library IEEE ;
use IEEE.std_logic_1164.all ;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;

entity MPU_SYS is
 port(clk: in std_logic;
		mpu_rd: out std_logic;
		mpu_wr: out std_logic ;
		MPU_PORT: out std_logic_vector(7 downto 0);
		MPU_DBI: in std_logic_vector(7 downto 0);
		MPU_DBO: out std_logic_vector(7 downto 0);
       int_ack: OUT std_logic;
		mpu_irq: in std_logic);
end MPU_SYS ;

architecture mix of MPU_SYS is

 component kcpsm3 is
  port (	address : out std_logic_vector(9 downto 0);
			instruction : in std_logic_vector(17 downto 0);
			port_id : out std_logic_vector(7 downto 0);
			write_strobe : out std_logic;
			out_port : out std_logic_vector(7 downto 0);
			read_strobe : out std_logic;
			in_port : in std_logic_vector(7 downto 0);
			interrupt : in std_logic;
            interrupt_ack : out std_logic;
			reset : in std_logic;
			clk : in std_logic) ;
 end component ;

 component ROM_CODE_SYS
  port (	clk : in std_logic ;
			reset : out std_logic ;
			address : in std_logic_vector( 9 downto 0 ) ;
			instruction : out std_logic_vector( 17 downto 0 )) ;
 end component;
	
	signal psm_input : std_logic_vector( 7 downto 0 ) ;
	signal psm_output : std_logic_vector( 7 downto 0 ) ;
	signal psm_rd, psm_wr : std_logic ;
	signal psm_irq : std_logic ;
	signal psm_port : std_logic_vector( 7 downto 0 ) ;

	signal rom_addr : std_logic_vector( 9 downto 0 ) ;
	signal instruction : std_logic_vector( 17 downto 0 ) ;
	signal reset : std_logic ;

begin

	PSM_3 : kcpsm3
		port map (
			address => rom_addr,
			instruction => instruction,
			in_port => psm_input,
			out_port => psm_output,
			port_id => psm_port,
			read_strobe => psm_rd,
			write_strobe => psm_wr,
			interrupt => psm_irq,
         interrupt_ack => int_ack,
			reset => reset,
			clk => clk
		) ;

	ROM : ROM_CODE_SYS
        port map (
		    clk => clk,
		    reset => reset,
		    address => rom_addr,
		    instruction => instruction
		) ;

	mpu_rd <= psm_rd ;
	mpu_wr <= psm_wr ;
	MPU_PORT <= psm_port ;
	MPU_DBO <= psm_output ;
	psm_irq <= mpu_irq ;
	psm_input <= MPU_DBI ;

end mix ;
