OpenCores
URL https://opencores.org/ocsvn/am9080_cpu_based_on_microcoded_am29xx_bit-slices/am9080_cpu_based_on_microcoded_am29xx_bit-slices/trunk

Subversion Repositories am9080_cpu_based_on_microcoded_am29xx_bit-slices

[/] [am9080_cpu_based_on_microcoded_am29xx_bit-slices/] [trunk/] [hexfilerom.vhd] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 zpekic
----------------------------------------------------------------------------------
2
-- Company: 
3
-- Engineer: 
4
-- 
5
-- Create Date:    11:56:00 11/12/2017 
6
-- Design Name: 
7
-- Module Name:    hexfilerom - Behavioral 
8
-- Project Name: 
9
-- Target Devices: 
10
-- Tool versions: 
11
-- Description: 
12
--
13
-- Dependencies: 
14
--
15
-- Revision: 
16
-- Revision 0.01 - File Created
17
-- Additional Comments: 
18
--
19
----------------------------------------------------------------------------------
20
library IEEE;
21
use IEEE.STD_LOGIC_1164.ALL;
22
use STD.textio.all;
23
use ieee.std_logic_textio.all;
24
 
25
-- Uncomment the following library declaration if using
26
-- arithmetic functions with Signed or Unsigned values
27
use IEEE.NUMERIC_STD.ALL;
28
 
29
-- Uncomment the following library declaration if instantiating
30
-- any Xilinx primitives in this code.
31
--library UNISIM;
32
--use UNISIM.VComponents.all;
33
 
34
entity hexfilerom is
35
         generic (
36
                filename: string := "";
37
                address_size: positive := 8;
38
                default_value: STD_LOGIC_VECTOR(7 downto 0) := X"FF");
39
    Port (
40
                          D : out  STD_LOGIC_VECTOR (7 downto 0);
41
           A : in  STD_LOGIC_VECTOR ((address_size - 1) downto 0);
42
           nRead : in  STD_LOGIC;
43
           nSelect : in  STD_LOGIC);
44
end hexfilerom;
45
 
46
architecture Behavioral of hexfilerom is
47
 
48
COMPONENT rom4kx8
49
  PORT (
50
    clka : IN STD_LOGIC;
51
    addra : IN STD_LOGIC_VECTOR(11 DOWNTO 0);
52
    douta : OUT STD_LOGIC_VECTOR(7 DOWNTO 0)
53
  );
54
END COMPONENT;
55
 
56
type bytememory is array(0 to (2 ** address_size) - 1) of std_logic_vector(7 downto 0);
57
 
58
impure function init_inlinememory(depth: in integer; default_value: std_logic_vector(7 downto 0)) return bytememory is
59
variable temp_mem : bytememory;
60
variable i: integer range 0 to (depth - 1);
61
variable location: std_logic_vector(7 downto 0);
62
 
63
begin
64
        -- fill with default value
65
        for i in 0 to depth - 1 loop
66
                location := std_logic_vector(to_unsigned(i, 8));
67
                case location is
68
                        ------- RST0 @ 0x00 --------
69
                        when X"00" =>
70
                                temp_mem(i) := X"F3"; -- DI
71
                        when X"01" =>
72
                                temp_mem(i) := X"21"; -- LXI H, 0x0000
73
                        when X"02" =>
74
                                temp_mem(i) := X"00";
75
                        when X"03" =>
76
                                temp_mem(i) := X"00";
77
                        when X"04" =>
78
                                temp_mem(i) := X"2B"; -- DCX H
79
                        when X"05" =>
80
                                temp_mem(i) := X"F9"; -- SPHL
81
                        when X"06" =>
82
                                temp_mem(i) := X"FB"; -- EI
83
                        when X"07" =>
84
                                temp_mem(i) := X"00"; -- NOP
85
                        when X"08" =>
86
                                temp_mem(i) := X"AF"; -- XRA A
87
                        when X"09" =>
88
                                temp_mem(i) := X"37"; -- STC
89
                        when X"0A" =>
90
                                temp_mem(i) := X"76"; -- HLT ; interrupt is needed to go further
91
                        when X"0B" =>
92
                                temp_mem(i) := X"01"; -- DeadLoop: LXI B, 0x0D20; set C to ASCII space
93
                        when X"0C" =>
94
                                temp_mem(i) := X"20";
95
                        when X"0D" =>
96
                                temp_mem(i) := X"0D";
97
                        when X"0E" =>
98
                                temp_mem(i) := X"79"; -- SendNextChar: MOV A, C
99
                        when X"0F" =>
100
                                temp_mem(i) := X"D3"; -- OUT 0x00; send char
101
                        when X"10" =>
102
                                temp_mem(i) := X"00";
103
                        when X"11" =>
104
                                temp_mem(i) := X"FE"; -- CPI 07FH; end of printable chars reached?
105
                        when X"12" =>
106
                                temp_mem(i) := X"7F";
107
                        when X"13" =>
108
                                temp_mem(i) := X"F2"; -- JP NextLine
109
                        when X"14" =>
110
                                temp_mem(i) := X"1A";
111
                        when X"15" =>
112
                                temp_mem(i) := X"00";
113
                        when X"16" =>
114
                                temp_mem(i) := X"0C"; -- INR C
115
                        when X"17" =>
116
                                temp_mem(i) := X"C3"; -- JMP SendNextChar
117
                        when X"18" =>
118
                                temp_mem(i) := X"0E";
119
                        when X"19" =>
120
                                temp_mem(i) := X"00";
121
                        when X"1A" =>
122
                                temp_mem(i) := X"78"; -- NextLine: MOV A, B
123
                        when X"1B" =>
124
                                temp_mem(i) := X"D3"; -- OUT 0x00; send char
125
                        when X"1C" =>
126
                                temp_mem(i) := X"00";
127
                        when X"1D" =>
128
                                temp_mem(i) := X"EE"; -- XRI A, 00000110B 
129
                        when X"1E" =>
130
                                temp_mem(i) := X"06";
131
                        when X"1F" =>
132
                                temp_mem(i) := X"D3"; -- OUT 0x00; send char
133
                        when X"20" =>
134
                                temp_mem(i) := X"00";
135
                        when X"21" =>
136
                                temp_mem(i) := X"C3"; -- JMP DeadLoop
137
                        when X"22" =>
138
                                temp_mem(i) := X"0B";
139
                        when X"23" =>
140
                                temp_mem(i) := X"00";
141
                        when X"24" =>
142
                                temp_mem(i) := X"00";
143
                        when X"25" =>
144
                                temp_mem(i) := X"00";
145
                        when X"26" =>
146
                                temp_mem(i) := X"00";
147
                        when X"27" =>
148
                                temp_mem(i) := X"00";
149
                        ------- RST5 @ 0x28 --------
150
                        when X"28" =>
151
                                temp_mem(i) := X"C3"; -- JMP RST7
152
                        when X"29" =>
153
                                temp_mem(i) := X"38";
154
                        when X"2A" =>
155
                                temp_mem(i) := X"00";
156
                        ------- RST6 @ 0x30 --------
157
                        when X"30" =>
158
                                temp_mem(i) := X"C3"; -- JMP RST7
159
                        when X"31" =>
160
                                temp_mem(i) := X"38";
161
                        when X"32" =>
162
                                temp_mem(i) := X"00";
163
                        ------- RST7 @ 0x38 --------
164
                        when X"38" =>
165
                                temp_mem(i) := X"F3"; -- DI
166
                        when X"39" =>
167
                                temp_mem(i) := X"F5"; -- PUSH PSW
168
                        when X"3A" =>
169
                                temp_mem(i) := X"E5"; -- PUSH H
170
                        when X"3B" =>
171
                                temp_mem(i) := X"3E"; -- MVI A, '*'
172
                        when X"3C" =>
173
                                temp_mem(i) := X"2A";
174
                        when X"3D" =>
175
                                temp_mem(i) := X"D3"; -- OUT 00H
176
                        when X"3E" =>
177
                                temp_mem(i) := X"00";
178
                        when X"3F" =>
179
                                temp_mem(i) := X"E1"; -- POP H
180
                        when X"40" =>
181
                                temp_mem(i) := X"F1"; -- POP PSW
182
                        when X"41" =>
183
                                temp_mem(i) := X"FB"; -- RETI: EI 
184
                        when X"42" =>
185
                                temp_mem(i) := X"C9"; -- RET
186
                        when X"43" =>
187
                                temp_mem(i) := X"00"; -- NOP
188
                        -----------------------------
189
                when others =>
190
                        temp_mem(i) := default_value;
191
                end case;
192
        end loop;
193
 
194
   return temp_mem;
195
 
196
end init_inlinememory;
197
 
198
impure function init_filememory(file_name : in string; depth: in integer; default_value: std_logic_vector(7 downto 0)) return bytememory is
199
variable temp_mem : bytememory;
200
variable i, addr_start, addr_end: integer range 0 to (depth - 1);
201
variable location: std_logic_vector(7 downto 0);
202
file input_file : text open read_mode is file_name;
203
variable input_line : line;
204
variable line_current: integer := 0;
205
variable address: std_logic_vector(15 downto 0);
206
variable byte_count, record_type, byte_value: std_logic_vector(7 downto 0);
207
variable firstChar: character;
208
variable count: integer;
209
variable isOk: boolean;
210
 
211
begin
212
        -- fill with default value
213
        for i in 0 to depth - 1 loop
214
                        temp_mem(i) := default_value;
215
        end loop;
216
 
217
         -- parse the file for the data
218
         -- format described here: https://en.wikipedia.org/wiki/Intel_HEX
219
         assert false report file_name & ": loading up to " & integer'image(depth) & " bytes." severity note;
220
         loop
221
                line_current := line_current + 1;
222
      readline (input_file, input_line);
223
                exit when endfile(input_file); --till the end of file is reached continue.
224
 
225
                read(input_line, firstChar);
226
                if (firstChar = ':') then
227
                        hread(input_line, byte_count);
228
                        hread(input_line, address);
229
                        hread(input_line, record_type);
230
                        case record_type is
231
                                when X"00" => -- DATA
232
                                        count := to_integer(unsigned(byte_count));
233
                                        if (count > 0) then
234
                                                addr_start := to_integer(unsigned(address));
235
                                                addr_end := addr_start + to_integer(unsigned(byte_count)) - 1;
236
                                                report file_name & ": parsing line " & integer'image(line_current) & " for " & integer'image(count) & " bytes at address " & integer'image(addr_start) severity note;
237
                                                for i in addr_start to addr_end loop
238
                                                        hread(input_line, byte_value);
239
                                                        if (i < depth) then
240
                                                                temp_mem(i) := byte_value;
241
                                                        else
242
                                                                report file_name & ": line " & integer'image(line_current) & " data beyond memory capacity ignored" severity note;
243
                                                        end if;
244
                                                end loop;
245
                                        else
246
                                                report file_name  & ": line " & integer'image(line_current) & " has no data" severity note;
247
                                        end if;
248
                                when X"01" => -- EOF
249
                                        report file_name & ": line " & integer'image(line_current) & " eof record type detected" severity note;
250
                                        exit;
251
                                when others =>
252
                                        report file_name & ": line " & integer'image(line_current) & " unsupported record type detected" severity failure;
253
                        end case;
254
                else
255
                        report file_name & ": line " & integer'image(line_current) & " does not start with ':' " severity failure;
256
                end if;
257
        end loop; -- next line in file
258
 
259
        file_close(input_file);
260
 
261
   return temp_mem;
262
 
263
end init_filememory;
264
 
265
signal rom: bytememory := init_filememory(filename, 2 ** address_size, default_value);
266
--signal rom: bytememory := init_inlinememory(2 ** address_size, default_value);
267
attribute ram_style: string;
268
attribute ram_style of rom: signal is "block";
269
 
270
begin
271
        D <= rom(to_integer(unsigned(A))) when (nRead = '0' and nSelect = '0') else "ZZZZZZZZ";
272
end Behavioral;
273
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.