Advertisement
Guest User

Untitled

a guest
Nov 28th, 2010
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 6.21 KB | None | 0 0
  1. ----------------------------------------------------------------------------------
  2. -- Company: Ladecadence.net
  3. -- Engineer: David Pello
  4. --
  5. -- Create Date:     11:35:28 11/27/2010
  6. -- Design Name:     MBC5 GameBoy Mapper Clone
  7. -- Module Name:     MBC5VHDL - Behavioral
  8. -- Project Name:
  9. -- Target Devices:  xc9536
  10. -- Tool versions:   ISE 12.1
  11. -- Description:
  12. --
  13. -- Dependencies:
  14. --
  15. -- Revision:
  16. -- Revision 0.01 - File Created
  17. -- Additional Comments:
  18. --
  19. -- This code is licensed under the terms of the GNU General Public License (GPL)
  20. -- version 2 or above; see http://www.fsf.org/licensing/licenses/gpl.html
  21. ----------------------------------------------------------------------------------
  22. library IEEE;
  23. use IEEE.STD_LOGIC_1164.ALL;
  24.  
  25. entity MBC5VHDL is
  26.     port(       not_reset   :   in      std_logic;
  27.             not_cs      :   in      std_logic;
  28.             not_wr      :   in      std_logic;
  29.             data        :   in      std_logic_vector(7 downto 0);
  30.             addr        :   in      std_logic_vector(15 downto 12);
  31.             rom_addr    :   out     std_logic_vector(22 downto 14);
  32.             ram_addr    :   out     std_logic_vector(16 downto 13);
  33.             not_ram_cs  :   out     std_logic );           
  34. end MBC5VHDL;
  35.  
  36. architecture Behavioral of MBC5VHDL is
  37.     signal ram_e_code:      std_logic;
  38.     signal ram_e_regsel:        std_logic;
  39.     signal romh_regsel:     std_logic;
  40.     signal roml_regsel:     std_logic;
  41.     signal ram_regsel:      std_logic;
  42.     signal ram_e_regsync:       std_logic;
  43.     signal roml_regsync:        std_logic;
  44.     signal romh_regsync:        std_logic;
  45.     signal ram_regsync:     std_logic;
  46.    
  47.     signal ram_e_q0:        std_logic := '0';
  48.    
  49.     signal ramq0:           std_logic := '0';
  50.     signal ramq1:           std_logic := '0';
  51.     signal ramq2:           std_logic := '0';
  52.     signal ramq3:           std_logic := '0';
  53.     signal romlq0:          std_logic := '0';
  54.     signal romlq1:          std_logic := '0';
  55.     signal romlq2:          std_logic := '0';
  56.     signal romlq3:          std_logic := '0';
  57.     signal romlq4:          std_logic := '0';
  58.     signal romlq5:          std_logic := '0';
  59.     signal romlq6:          std_logic := '0';
  60.     signal romlq7:          std_logic := '0';
  61.    
  62.     signal romhq0:          std_logic := '0';
  63.    
  64.     signal bank0map:        std_logic;
  65.    
  66. begin          
  67.         -- RAM enable   (0000h - 1FFFh)
  68.         ram_e_code <= data(3) and (not data(2)) and data(1) and (not data(0));
  69.         ram_e_regsel <= (not addr(13)) and (not addr(14));
  70.         ram_e_regsync <= ram_e_regsel and not_cs and (not not_wr);
  71.        
  72.         -- ROM high     (3000h-3FFFh)
  73.         romh_regsel <= addr(12) and addr(13) and (not addr(14));
  74.         romh_regsync <= romh_regsel and not_cs and (not not_wr);
  75.        
  76.         -- ROM low      (2000h-2FFFh)
  77.         roml_regsel <=  (not addr(12)) and addr(13) and (not addr(14));
  78.         roml_regsync <= roml_regsel and not_cs and (not not_wr);       
  79.        
  80.         -- RAM          (4000h-5FFFh)
  81.         ram_regsel <= (not addr(13)) and addr(14);
  82.         ram_regsync <= ram_regsel and not_cs and (not not_wr);
  83.        
  84.         -- REGISTERS
  85.         -- ---------
  86.        
  87.         -- RAM enable register
  88.         ram_enable:process(ram_e_regsync, not_reset) is
  89.         begin
  90.             if rising_edge(ram_e_regsync) then
  91.                 ram_e_q0 <= (ram_e_code) and not_reset;
  92.             end if;
  93.         end process ram_enable;
  94.  
  95.         -- RAM 16 register
  96.         ram16reg:process(ram_regsync, not_reset) is
  97.         begin
  98.             if rising_edge(ram_regsync) then
  99.                 ramq3 <= data(3) and not_reset;
  100.             end if;
  101.         end process ram16reg;  
  102.  
  103.         -- RAM 15 register
  104.         ram15reg:process(ram_regsync, not_reset) is
  105.         begin
  106.             if rising_edge(ram_regsync) then
  107.                 ramq2 <= data(2) and not_reset;
  108.             end if;
  109.         end process ram15reg;          
  110.  
  111.         -- RAM 14 register
  112.         ram14reg:process(ram_regsync, not_reset) is
  113.         begin
  114.             if rising_edge(ram_regsync) then
  115.                 ramq1 <= data(1) and not_reset;
  116.             end if;
  117.         end process ram14reg;
  118.  
  119.         -- RAM 13 register
  120.         ram13reg:process(ram_regsync, not_reset) is
  121.         begin
  122.             if rising_edge(ram_regsync) then
  123.                 ramq0 <= data(0) and not_reset;
  124.             end if;
  125.         end process ram13reg;
  126.  
  127.         -- ROM High registers
  128.         -- ------------------
  129.        
  130.         -- ROM 22 register
  131.         romh22reg:process(romh_regsync, not_reset) is
  132.         begin
  133.             if rising_edge(romh_regsync) then
  134.                 romhq0 <= data(0) and not_reset;
  135.             end if;
  136.         end process romh22reg;
  137.        
  138.         -- ROM Low registers
  139.         -- -----------------
  140.        
  141.         -- ROM 21 register
  142.         roml21reg:process(roml_regsync, not_reset) is
  143.         begin
  144.             if rising_edge(roml_regsync) then
  145.                 romlq7 <= data(7) and not_reset;
  146.             end if;
  147.         end process roml21reg;
  148.  
  149.         -- ROM 20 register
  150.         roml20reg:process(roml_regsync, not_reset) is
  151.         begin
  152.             if rising_edge(roml_regsync) then
  153.                 romlq6 <= data(6) and not_reset;
  154.             end if;
  155.         end process roml20reg;
  156.  
  157.         -- ROM 19 register
  158.         roml19reg:process(roml_regsync, not_reset) is
  159.         begin
  160.             if rising_edge(roml_regsync) then
  161.                 romlq5 <= data(5) and not_reset;
  162.             end if;
  163.         end process roml19reg;
  164.    
  165.         -- ROM 18 register
  166.         roml18reg:process(roml_regsync, not_reset) is
  167.         begin
  168.             if rising_edge(roml_regsync) then
  169.                 romlq4 <= data(4) and not_reset;
  170.             end if;
  171.         end process roml18reg;
  172.        
  173.         -- ROM 17 register
  174.         roml17reg:process(roml_regsync, not_reset) is
  175.         begin
  176.             if rising_edge(roml_regsync) then
  177.                 romlq3 <= data(3) and not_reset;
  178.             end if;
  179.         end process roml17reg;
  180.        
  181.         -- ROM 16 register
  182.         roml16reg:process(roml_regsync, not_reset) is
  183.         begin
  184.             if rising_edge(roml_regsync) then
  185.                 romlq2 <= data(2) and not_reset;
  186.             end if;
  187.         end process roml16reg;
  188.        
  189.         -- ROM 15 register
  190.         roml15reg:process(roml_regsync, not_reset) is
  191.         begin
  192.             if rising_edge(roml_regsync) then
  193.                 romlq1 <= data(1) and not_reset;
  194.             end if;
  195.         end process roml15reg;
  196.  
  197.         -- ROM 14 register
  198.         roml14reg:process(roml_regsync, not_reset) is
  199.         begin
  200.             if rising_edge(roml_regsync) then
  201.                 romlq0 <= data(0) and not_reset;
  202.             end if;
  203.         end process roml14reg;     
  204.        
  205.         -- Outputs
  206.         -- -------
  207.         not_ram_cs <=   not ram_e_q0;
  208.        
  209.         ram_addr(16) <= ramq3;
  210.         ram_addr(15) <= ramq2;
  211.         ram_addr(14) <= ramq1;
  212.         ram_addr(13) <= ramq0;
  213.        
  214.         rom_addr(22) <= romhq0 and addr(14);
  215.        
  216.         rom_addr(21) <= romlq7 and addr(14);
  217.         rom_addr(20) <= romlq6 and addr(14);
  218.         rom_addr(19) <= romlq5 and addr(14);
  219.         rom_addr(18) <= romlq4 and addr(14);
  220.         rom_addr(17) <= romlq3 and addr(14);
  221.         rom_addr(16) <= romlq2 and addr(14);
  222.         rom_addr(15) <= romlq1 and addr(14);
  223.         -- rom14 line is special because it has to map bank 0 correctly
  224.         bank0map <= not(romlq1 or romlq2 or romlq3 or romlq4 or romlq5 or romlq6 or romlq7);
  225.         rom_addr(14) <= (romlq0 or bank0map) and addr(14);
  226.        
  227. end architecture Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement