2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_unsigned.conv_integer;
6 -- MOTO NES FPGA On GHDL Simulation Environment Virtual Cuicuit Board
7 -- All of the components are assembled and instanciated on this board.
12 base_clk : in std_logic;
14 joypad1 : in std_logic_vector(7 downto 0);
15 joypad2 : in std_logic_vector(7 downto 0);
16 vga_clk : out std_logic;
17 h_sync_n : out std_logic;
18 v_sync_n : out std_logic;
19 r : out std_logic_vector(3 downto 0);
20 g : out std_logic_vector(3 downto 0);
21 b : out std_logic_vector(3 downto 0)
25 architecture rtl of motones_sim is
27 generic ( dsize : integer := 8;
30 port ( input_clk : in std_logic; --phi0 input pin.
39 addr : out std_logic_vector ( asize - 1 downto 0);
40 d_io : inout std_logic_vector ( dsize - 1 downto 0)
44 component clock_divider
45 port ( base_clk : in std_logic;
46 reset_n : in std_logic;
47 cpu_clk : out std_logic;
48 ppu_clk : out std_logic;
49 mem_clk : out std_logic;
50 vga_clk : out std_logic
54 component address_decoder
55 generic (abus_size : integer := 16; dbus_size : integer := 8);
56 port ( phi2 : in std_logic;
57 mem_clk : in std_logic;
59 addr : in std_logic_vector (abus_size - 1 downto 0);
60 d_io : in std_logic_vector (dbus_size - 1 downto 0);
61 rom_ce_n : out std_logic;
62 ram_ce_n : out std_logic;
63 ppu_ce_n : out std_logic;
64 apu_ce_n : out std_logic
69 generic (abus_size : integer := 16; dbus_size : integer := 8);
70 port ( ce_n, oe_n, we_n : in std_logic; --select pin active low.
71 addr : in std_logic_vector (abus_size - 1 downto 0);
72 d_io : inout std_logic_vector (dbus_size - 1 downto 0)
77 generic (abus_size : integer := 15; dbus_size : integer := 8);
80 ce_n : in std_logic; --active low.
81 addr : in std_logic_vector (abus_size - 1 downto 0);
82 data : out std_logic_vector (dbus_size - 1 downto 0)
87 port ( clk : in std_logic;
91 cpu_addr : in std_logic_vector (2 downto 0);
92 cpu_d : inout std_logic_vector (7 downto 0);
93 vblank_n : out std_logic;
97 vram_ad : inout std_logic_vector (7 downto 0);
98 vram_a : out std_logic_vector (13 downto 8);
99 vga_clk : in std_logic;
100 h_sync_n : out std_logic;
101 v_sync_n : out std_logic;
102 r : out std_logic_vector(3 downto 0);
103 g : out std_logic_vector(3 downto 0);
104 b : out std_logic_vector(3 downto 0)
108 component v_address_decoder
109 generic (abus_size : integer := 14; dbus_size : integer := 8);
110 port ( clk : in std_logic;
114 vram_ad : inout std_logic_vector (7 downto 0);
115 vram_a : in std_logic_vector (13 downto 8)
120 port ( clk : in std_logic;
122 rst_n : in std_logic;
123 r_nw : inout std_logic;
124 cpu_addr : inout std_logic_vector (15 downto 0);
125 cpu_d : inout std_logic_vector (7 downto 0);
130 constant data_size : integer := 8;
131 constant addr_size : integer := 16;
132 constant size14 : integer := 14;
134 constant ram_2k : integer := 11; --2k = 11 bit width.
135 constant rom_32k : integer := 15; --32k = 15 bit width.
138 signal cpu_clk : std_logic;
139 signal ppu_clk : std_logic;
140 signal mem_clk : std_logic;
141 signal vga_out_clk : std_logic;
143 signal rdy, irq_n, nmi_n, dbe, r_nw : std_logic;
144 signal phi1, phi2 : std_logic;
145 signal addr : std_logic_vector( addr_size - 1 downto 0);
146 signal d_io : std_logic_vector( data_size - 1 downto 0);
148 signal rom_ce_n : std_logic;
149 signal ram_ce_n : std_logic;
150 signal ram_oe_n : std_logic;
151 signal ppu_ce_n : std_logic;
152 signal apu_ce_n : std_logic;
153 signal rd_n : std_logic;
154 signal wr_n : std_logic;
155 signal ale : std_logic;
156 signal vram_ad : std_logic_vector (7 downto 0);
157 signal vram_a : std_logic_vector (13 downto 8);
162 vga_clk <= vga_out_clk;
164 --ppu/cpu clock generator
165 clock_inst : clock_divider port map
166 (base_clk, rst_n, cpu_clk, ppu_clk, mem_clk, vga_out_clk);
168 --mos 6502 cpu instance
169 cpu_inst : mos6502 generic map (data_size, addr_size)
170 port map (cpu_clk, rdy, rst_n, irq_n, nmi_n, dbe, r_nw,
171 phi1, phi2, addr, d_io);
173 addr_dec_inst : address_decoder generic map (addr_size, data_size)
174 port map (phi2, mem_clk, r_nw, addr, d_io, rom_ce_n, ram_ce_n, ppu_ce_n, apu_ce_n);
176 --main ROM/RAM instance
177 prg_rom_inst : prg_rom generic map (rom_32k, data_size)
178 port map (mem_clk, rom_ce_n, addr(rom_32k - 1 downto 0), d_io);
180 ram_oe_n <= not R_nW;
181 prg_ram_inst : ram generic map (ram_2k, data_size)
182 port map (ram_ce_n, ram_oe_n, R_nW, addr(ram_2k - 1 downto 0), d_io);
186 port map (ppu_clk, ppu_ce_n, rst_n, r_nw, addr(2 downto 0), d_io,
187 nmi_n, rd_n, wr_n, ale, vram_ad, vram_a,
188 vga_out_clk, h_sync_n, v_sync_n, r, g, b);
190 ppu_addr_decoder : v_address_decoder generic map (size14, data_size)
191 port map (ppu_clk, rd_n, wr_n, ale, vram_ad, vram_a);
194 port map (cpu_clk, apu_ce_n, rst_n, r_nw, addr, d_io, rdy);