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 v_addr : in std_logic_vector (13 downto 0);
115 v_data : in std_logic_vector (7 downto 0);
116 nt_v_mirror : in std_logic;
117 pt_ce_n : out std_logic;
118 nt0_ce_n : out std_logic;
119 nt1_ce_n : out std_logic
124 generic (abus_size : integer := 13; dbus_size : integer := 8);
125 port ( ce_n : in std_logic; --active low.
126 addr : in std_logic_vector (abus_size - 1 downto 0);
127 data : out std_logic_vector (dbus_size - 1 downto 0);
128 nt_v_mirror : out std_logic
136 port ( c : in std_logic;
138 d : in std_logic_vector(dsize - 1 downto 0);
139 q : out std_logic_vector(dsize - 1 downto 0)
144 port ( clk : in std_logic;
146 rst_n : in std_logic;
147 r_nw : inout std_logic;
148 cpu_addr : inout std_logic_vector (15 downto 0);
149 cpu_d : inout std_logic_vector (7 downto 0);
154 constant data_size : integer := 8;
155 constant addr_size : integer := 16;
156 constant vram_size14 : integer := 14;
158 constant ram_2k : integer := 11; --2k = 11 bit width.
159 constant rom_32k : integer := 15; --32k = 15 bit width.
160 constant vram_1k : integer := 10; --1k = 10 bit width.
161 constant chr_rom_8k : integer := 13; --32k = 15 bit width.
163 signal cpu_clk : std_logic;
164 signal ppu_clk : std_logic;
165 signal mem_clk : std_logic;
166 signal vga_out_clk : std_logic;
168 signal rdy, irq_n, nmi_n, dbe, r_nw : std_logic;
169 signal phi1, phi2 : std_logic;
170 signal addr : std_logic_vector( addr_size - 1 downto 0);
171 signal d_io : std_logic_vector( data_size - 1 downto 0);
173 signal rom_ce_n : std_logic;
174 signal ram_ce_n : std_logic;
175 signal ram_oe_n : std_logic;
176 signal ppu_ce_n : std_logic;
177 signal apu_ce_n : std_logic;
179 signal rd_n : std_logic;
180 signal wr_n : std_logic;
181 signal ale : std_logic;
182 signal vram_ad : std_logic_vector (7 downto 0);
183 signal vram_a : std_logic_vector (13 downto 8);
184 signal v_addr : std_logic_vector (13 downto 0);
185 signal nt_v_mirror : std_logic;
186 signal pt_ce_n : std_logic;
187 signal nt0_ce_n : std_logic;
188 signal nt1_ce_n : std_logic;
194 vga_clk <= vga_out_clk;
196 --ppu/cpu clock generator
197 clock_inst : clock_divider port map
198 (base_clk, rst_n, cpu_clk, ppu_clk, mem_clk, vga_out_clk);
200 --mos 6502 cpu instance
201 cpu_inst : mos6502 generic map (data_size, addr_size)
202 port map (cpu_clk, rdy, rst_n, irq_n, nmi_n, dbe, r_nw,
203 phi1, phi2, addr, d_io);
205 addr_dec_inst : address_decoder generic map (addr_size, data_size)
206 port map (phi2, mem_clk, r_nw, addr, d_io, rom_ce_n, ram_ce_n, ppu_ce_n, apu_ce_n);
208 --main ROM/RAM instance
209 prg_rom_inst : prg_rom generic map (rom_32k, data_size)
210 port map (mem_clk, rom_ce_n, addr(rom_32k - 1 downto 0), d_io);
212 ram_oe_n <= not R_nW;
213 prg_ram_inst : ram generic map (ram_2k, data_size)
214 port map (ram_ce_n, ram_oe_n, R_nW, addr(ram_2k - 1 downto 0), d_io);
218 port map (ppu_clk, ppu_ce_n, rst_n, r_nw, addr(2 downto 0), d_io,
219 nmi_n, rd_n, wr_n, ale, vram_ad, vram_a,
220 vga_out_clk, h_sync_n, v_sync_n, r, g, b);
222 ppu_addr_decoder : v_address_decoder generic map (vram_size14, data_size)
223 port map (ppu_clk, rd_n, wr_n, ale, v_addr, vram_ad,
224 nt_v_mirror, pt_ce_n, nt0_ce_n, nt1_ce_n);
226 ---VRAM/CHR ROM instances
227 v_addr (13 downto 8) <= vram_a;
229 --transparent d-latch
230 latch_inst : ls373 generic map (data_size)
231 port map(ale, '0', vram_ad, v_addr(7 downto 0));
233 vchr_rom : chr_rom generic map (chr_rom_8k, data_size)
234 port map (pt_ce_n, v_addr(chr_rom_8k - 1 downto 0), vram_ad, nt_v_mirror);
236 --name table/attr table
237 vram_nt0 : ram generic map (vram_1k, data_size)
238 port map (nt0_ce_n, rd_n, wr_n, v_addr(vram_1k - 1 downto 0), vram_ad);
240 vram_nt1 : ram generic map (vram_1k, data_size)
241 port map (nt1_ce_n, rd_n, wr_n, v_addr(vram_1k - 1 downto 0), vram_ad);
245 port map (cpu_clk, apu_ce_n, rst_n, r_nw, addr, d_io, rdy);