-- ### -------------------------------------------------------------- ###
-- #									#
-- # file	: dlxm_dec.vbe						#
-- # date	: Mar 29 1993						#
-- # version	: v0.1							#
-- # author	: Pirouz BAZARGAN SABET					#
-- # descr.	: data flow description of an address decoder for DLXp.	#
-- #									#
-- ### -------------------------------------------------------------- ###

entity dlxm_dec is

port (
   ck          : in    bit                         ;	-- external clock
   dlx_dadr    : in    bit_vector (31 downto 0)    ;	-- data address
   rw          : in    bit                         ;	-- read write
   byte        : in    bit_vector ( 0     to 3)    ;	-- valid bytes
   sel_romu_n  : out   bit                         ;	-- user rom
   sel_ramu_n  : out   bit_vector ( 0     to 3)    ;	-- user ram
   sel_roms_n  : out   bit                         ;	-- system rom
   sel_rams_n  : out   bit_vector ( 0     to 3)    ;	-- system ram
   sel_timer_n : out   bit                         ;	-- timer
   vdd         : in    bit                         ;	--
   vss         : in    bit				--
  );

end dlxm_dec;

architecture FUNCTIONAL of dlxm_dec is

  signal rams    : bit;					-- select system ram
  signal ramu    : bit;					-- select user ram
  signal roms    : bit;					-- select system rom
  signal romu    : bit;					-- select user rom
  signal timer   : bit;					-- select system timer
  signal dly0_ck : bit;					-- delayed clock
  signal dly1_ck : bit;					-- delayed clock
  signal dly2_ck : bit;					-- delayed clock
  signal dly3_ck : bit;					-- delayed clock
  signal dly4_ck : bit;					-- delayed clock
  signal dly5_ck : bit;					-- delayed clock
  signal dlyd_ck : bit;					-- delayed clock

begin

  dly0_ck      <= ck;
  dly1_ck      <= dly0_ck;
  dly2_ck      <= dly1_ck;
  dly3_ck      <= dly2_ck;
  dly4_ck      <= dly3_ck;
  dly5_ck      <= dly4_ck;
  dlyd_ck      <= dly5_ck;

	-- ### ------------------------------------------------------ ###
	-- #   select on board user/system ram-rom depending on data	#
	-- # addresses :						#
	-- #								#
	-- #     0000_0000 - user ram					#
	-- #     0000_00FF - user ram					#
	-- #								#
	-- #     0000_0100 - off board ram extension			#
	-- #     7FFF_FEFF - off board ram extension			#
	-- #								#
	-- #     7FFF_FF00 - user rom					#
	-- #     7FFF_FFFF - user rom					#
	-- #								#
	-- #     8000_0000 - system ram					#
	-- #     8000_00FF - system ram					#
	-- #								#
	-- #     8000_0100 - system timer				#
	-- #     8000_01FF - system timer				#
	-- #								#
	-- #     8000_0200 - off board ram extension			#
	-- #     FFFF_FFFF - off board ram extension			#
	-- #								#
	-- #     FFFF_FF00 - system rom					#
	-- #     FFFF_FFFF - system rom					#
	-- ### ------------------------------------------------------ ###

  with dlx_dadr (31 downto 8) select
  ramu  <= '1' when X"0000_00",
           '0' when others;

  with dlx_dadr (31 downto 8) select
  romu  <= '1' when X"7FFF_FF",
           '0' when others;

  with dlx_dadr (31 downto 8) select
  rams  <= '1' when X"8000_00",
           '0' when others;

  with dlx_dadr (31 downto 8) select
  timer  <= '1' when X"8000_01",
            '0' when others;

  with dlx_dadr (31 downto 8) select
  roms  <= '1' when X"FFFF_FF",
           '0' when others;

	-- ### ------------------------------------------------------ ###
	-- #   assign outputs						#
	-- #     - effective selection of ram chips (on high level of	#
	-- #       clock to avoid conflicts)				#
	-- #     - effective selection of rom chips			#
	-- #     - effective selection of timer				#
	-- ### ------------------------------------------------------ ###

  sel_ramu_n (0) <= not (ramu  and ck and byte (0));
  sel_ramu_n (1) <= not (ramu  and ck and byte (1));
  sel_ramu_n (2) <= not (ramu  and ck and byte (2));
  sel_ramu_n (3) <= not (ramu  and ck and byte (3));

  sel_rams_n (0) <= not (rams  and ck and byte (0));
  sel_rams_n (1) <= not (rams  and ck and byte (1));
  sel_rams_n (2) <= not (rams  and ck and byte (2));
  sel_rams_n (3) <= not (rams  and ck and byte (3));

  sel_timer_n    <= not (timer and ck);

  sel_romu_n     <= not (romu  and ck);
  sel_roms_n     <= not (roms  and ck);

end FUNCTIONAL;
