OSDN Git Service

b766fcf19ed07efa1daed4b7fbcbea0a2ed7a70f
[motonesfpga/motonesfpga.git] / de1_nes / mem / prg_rom.vhd
1 library ieee;
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;
5 use std.textio.all;
6
7 --asyncronous rom
8 entity prg_rom is 
9     generic (abus_size : integer := 15; dbus_size : integer := 8);
10     port (  ce_n            : in std_logic;     --active low.
11             addr            : in std_logic_vector (abus_size - 1 downto 0);
12             data            : out std_logic_vector (dbus_size - 1 downto 0)
13         );
14 end prg_rom;
15
16 architecture rtl of prg_rom is
17
18 --32k ROM
19 subtype rom_data is std_logic_vector (dbus_size -1 downto 0);
20 type rom_array is array (0 to 2**abus_size - 1) of rom_data;
21
22 --not used...
23 constant ROM_TACE : time := 100 ns;      --output enable access time
24 constant ROM_TOH : time := 10 ns;      --output hold time
25
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;
31     variable i : integer;
32     variable out_line : line;
33     variable ret : rom_array;
34     begin
35         --skip first 16 bit data(NES cardridge header part.)
36         for i in 0 to 15 loop
37             read(nes_file, read_data);
38         end loop;
39
40         for i in ret'range loop
41             read(nes_file, read_data);
42             ret(i) :=
43                 conv_std_logic_vector(character'pos(read_data), 8);
44         end loop;
45         write(out_line, string'("file load success."));
46         writeline(output, out_line);
47         return ret;
48     end rom_fill;
49
50 --itinialize with the rom_fill function.
51 constant p_rom : rom_array := rom_fill;
52
53 begin
54
55     p : process (ce_n, addr)
56     begin
57     if (ce_n = '0') then
58         data <= p_rom(conv_integer(addr));
59     else
60         data <= (others => 'Z');
61     end if;
62     end process;
63 end rtl;
64