2 use ieee.std_logic_1164.all;
3 use ieee.std_logic_unsigned.conv_integer;
4 use ieee.std_logic_arith.conv_std_logic_vector;
6 use work.motonesfpga_common.all;
10 generic (abus_size : integer := 13; dbus_size : integer := 8);
13 ce_n : in std_logic; --active low.
14 addr : in std_logic_vector (abus_size - 1 downto 0);
15 data : out std_logic_vector (dbus_size - 1 downto 0);
16 nt_v_mirror : out std_logic
20 architecture rtl of chr_rom is
23 subtype rom_data is std_logic_vector (dbus_size -1 downto 0);
24 type rom_array is array (0 to 2**abus_size - 1) of rom_data;
26 --function is called only once at the array initialize.
27 function rom_fill return rom_array is
28 type binary_file is file of character;
29 FILE nes_file : binary_file OPEN read_mode IS "rom-file.nes" ;
30 variable read_data : character;
32 variable ret : rom_array;
34 --skip first 16 bit data(NES cardridge header part.)
36 read(nes_file, read_data);
38 --skip program ROM part
39 for i in 0 to 16#8000# - 1 loop
40 read(nes_file, read_data);
43 for i in ret'range loop
44 read(nes_file, read_data);
46 conv_std_logic_vector(character'pos(read_data), 8);
48 d_print("chr rom file load success.");
52 function vmirror return std_logic is
53 type binary_file is file of character;
54 FILE nes_file : binary_file OPEN read_mode IS "rom-file.nes" ;
55 variable read_data : character;
57 variable ret : std_logic_vector(7 downto 0);
59 --read NES cardridge header part
61 read(nes_file, read_data);
64 conv_std_logic_vector(character'pos(read_data), 8);
67 d_print("nes header read ok.");
71 --for GHDL environment
72 --itinialize with the rom_fill function.
73 --signal p_rom : rom_array := rom_fill;
75 --for Quartus II environment
76 signal p_rom : rom_array;
77 attribute ram_init_file : string;
78 attribute ram_init_file of p_rom : signal is "sample1-chr.hex";
82 --nt_v_mirror <= vmirror;
87 if (rising_edge(clk)) then
89 data <= p_rom(conv_integer(addr));
91 data <= (others => 'Z');