OSDN Git Service

update test data
[motonesfpga/motonesfpga.git] / de1_nes / dummy-mos6502.vhd
1 library ieee;
2 use ieee.std_logic_1164.all;
3
4 entity mos6502 is 
5     generic (   dsize : integer := 8;
6                 asize : integer :=16
7             );
8     port (  
9     signal dbg_instruction  : out std_logic_vector(7 downto 0);
10     signal dbg_int_d_bus    : out std_logic_vector(7 downto 0);
11     signal dbg_exec_cycle   : out std_logic_vector (5 downto 0);
12     signal dbg_ea_carry     : out std_logic;
13
14 --    signal dbg_index_bus    : out std_logic_vector(7 downto 0);
15 --    signal dbg_acc_bus      : out std_logic_vector(7 downto 0);
16     signal dbg_status       : out std_logic_vector(7 downto 0);
17     signal dbg_pcl, dbg_pch, dbg_sp, dbg_x, dbg_y, dbg_acc       : out std_logic_vector(7 downto 0);
18     signal dbg_dec_oe_n    : out std_logic;
19     signal dbg_dec_val     : out std_logic_vector (7 downto 0);
20     signal dbg_int_dbus    : out std_logic_vector (7 downto 0);
21 --    signal dbg_status_val    : out std_logic_vector (7 downto 0);
22     signal dbg_stat_we_n    : out std_logic;
23     signal dbg_idl_h, dbg_idl_l, dbg_dbb_r, dbg_dbb_w    : out std_logic_vector (7 downto 0);
24
25             input_clk   : in std_logic; --phi0 input pin.
26             rdy         : in std_logic;
27             rst_n       : in std_logic;
28             irq_n       : in std_logic;
29             nmi_n       : in std_logic;
30             dbe         : in std_logic;
31             r_nw        : out std_logic;
32             phi1        : out std_logic;
33             phi2        : out std_logic;
34             addr        : out std_logic_vector ( asize - 1 downto 0);
35             d_io        : inout std_logic_vector ( dsize - 1 downto 0)
36     );
37 end mos6502;
38
39 architecture rtl of mos6502 is
40
41
42 begin
43     phi1 <= input_clk;\r
44     phi2 <= not input_clk;\r
45
46     --set ppu value...\r
47     set_ppu_p : process (input_clk, rst_n)\r
48     use ieee.std_logic_arith.conv_std_logic_vector;\r
49 \r
50     variable init_step_cnt, plt_step_cnt, \r
51             nt_step_cnt, spr_step_cnt, enable_ppu_step_cnt : integer;\r
52     variable init_done : std_logic;\r
53     variable global_step_cnt : integer;\r
54     variable cpu_cnt : integer;\r
55     constant cpu_io_multi : integer := 4; --io happens every 4 cpu cycle.\r
56 \r
57 procedure io_out (ad: in integer; dt : in integer) is\r
58 begin\r
59     r_nw <= '0';\r
60     addr <= conv_std_logic_vector(ad, 16);\r
61     d_io <= conv_std_logic_vector(dt, 8);\r
62 end;\r
63 procedure io_brk is\r
64 begin\r
65     addr <= (others => 'Z');\r
66     d_io <= (others => 'Z');\r
67     r_nw <= '1';\r
68 end;\r
69 \r
70     begin\r
71         if (rst_n = '0') then\r
72             \r
73             r_nw <= 'Z';\r
74             addr <= (others => 'Z');\r
75             d_io <= (others => 'Z');\r
76             \r
77             init_done := '0';\r
78             global_step_cnt := 0;\r
79             init_step_cnt := 0;\r
80             plt_step_cnt := 0;\r
81             nt_step_cnt := 0;\r
82             spr_step_cnt := 0;\r
83             enable_ppu_step_cnt := 0;\r
84             cpu_cnt := 0;\r
85 \r
86         elsif (rising_edge(input_clk)) then\r
87             cpu_cnt := cpu_cnt + 1;\r
88 \r
89             if (init_done = '0') then\r
90                 if (global_step_cnt = 0) then\r
91                     --step0.0 = init ppu.\r
92                     if (init_step_cnt = 0 * cpu_io_multi) then\r
93                         --PPUCTRL=00\r
94                         io_out(16#2000#, 16#00#);\r
95                     elsif (init_step_cnt = 1 * cpu_io_multi) then\r
96                         --PPUMASK=00\r
97                         io_out(16#2001#, 16#00#);\r
98                     else\r
99                         io_brk;\r
100                         if (init_step_cnt > 2 * cpu_io_multi) then\r
101                             global_step_cnt := global_step_cnt + 1;\r
102                         end if;\r
103                     end if;\r
104                     init_step_cnt := init_step_cnt + 1;\r
105                 elsif (global_step_cnt = 1) then\r
106                     --step0.1 = palette set.\r
107 --palettes:\r
108 --;;;bg palette\r
109 --      .byte   $0f, $00, $10, $20\r
110 --      .byte   $0f, $04, $14, $24\r
111 --      .byte   $0f, $08, $18, $28\r
112 --      .byte   $0f, $0c, $1c, $2c\r
113 --;;;spr palette\r
114 --      .byte   $0f, $00, $10, $20\r
115 --      .byte   $0f, $06, $16, $26\r
116 --      .byte   $0f, $08, $18, $28\r
117 --      .byte   $0f, $0a, $1a, $2a\r
118                     \r
119                     \r
120                     if (plt_step_cnt = 0 * cpu_io_multi) then\r
121                         --set vram addr 3f00\r
122                         io_out(16#2006#, 16#3f#);\r
123                     elsif (plt_step_cnt = 1 * cpu_io_multi) then\r
124                         io_out(16#2006#, 16#00#);\r
125                     \r
126                     elsif (plt_step_cnt = 2 * cpu_io_multi) then\r
127                         --set palette bg data\r
128                         io_out(16#2007#, 16#11#);\r
129                     elsif (plt_step_cnt = 3 * cpu_io_multi) then\r
130                         io_out(16#2007#, 16#01#);\r
131                     elsif (plt_step_cnt = 4 * cpu_io_multi) then\r
132                         io_out(16#2007#, 16#03#);\r
133                     elsif (plt_step_cnt = 5 * cpu_io_multi) then\r
134                         io_out(16#2007#, 16#13#);\r
135 \r
136                     elsif (plt_step_cnt = 6 * cpu_io_multi) then\r
137                         io_out(16#2007#, 16#0f#);\r
138                     elsif (plt_step_cnt = 7 * cpu_io_multi) then\r
139                         io_out(16#2007#, 16#04#);\r
140                     elsif (plt_step_cnt = 8 * cpu_io_multi) then\r
141                         io_out(16#2007#, 16#14#);\r
142                     elsif (plt_step_cnt = 9 * cpu_io_multi) then\r
143                         io_out(16#2007#, 16#24#);\r
144  \r
145                     elsif (plt_step_cnt = 10 * cpu_io_multi) then\r
146                         io_out(16#2007#, 16#0f#);\r
147                     elsif (plt_step_cnt = 11 * cpu_io_multi) then\r
148                         io_out(16#2007#, 16#08#);\r
149                     elsif (plt_step_cnt = 12 * cpu_io_multi) then\r
150                         io_out(16#2007#, 16#18#);\r
151                     elsif (plt_step_cnt = 13 * cpu_io_multi) then\r
152                         io_out(16#2007#, 16#28#);\r
153  \r
154                     elsif (plt_step_cnt = 14 * cpu_io_multi) then\r
155                         io_out(16#2007#, 16#05#);\r
156                     elsif (plt_step_cnt = 15 * cpu_io_multi) then\r
157                         io_out(16#2007#, 16#0c#);\r
158                     elsif (plt_step_cnt = 16 * cpu_io_multi) then\r
159                         io_out(16#2007#, 16#1c#);\r
160                     elsif (plt_step_cnt = 17 * cpu_io_multi) then\r
161                         io_out(16#2007#, 16#2c#);\r
162 \r
163                      elsif (plt_step_cnt = 18 * cpu_io_multi) then\r
164                         --below is sprite pallete\r
165                         io_out(16#2007#, 16#00#);\r
166                     elsif (plt_step_cnt = 19 * cpu_io_multi) then\r
167                         io_out(16#2007#, 16#24#);\r
168                     elsif (plt_step_cnt = 20 * cpu_io_multi) then\r
169                         io_out(16#2007#, 16#1b#);\r
170                     elsif (plt_step_cnt = 21 * cpu_io_multi) then\r
171                         io_out(16#2007#, 16#11#);\r
172 \r
173                     elsif (plt_step_cnt = 22 * cpu_io_multi) then\r
174                         io_out(16#2007#, 16#00#);\r
175                     elsif (plt_step_cnt = 23 * cpu_io_multi) then\r
176                         io_out(16#2007#, 16#32#);\r
177                     elsif (plt_step_cnt = 24 * cpu_io_multi) then\r
178                         io_out(16#2007#, 16#16#);\r
179                     elsif (plt_step_cnt = 25 * cpu_io_multi) then\r
180                         io_out(16#2007#, 16#20#);\r
181 \r
182                     elsif (plt_step_cnt = 26 * cpu_io_multi) then\r
183                         io_out(16#2007#, 16#00#);\r
184                     elsif (plt_step_cnt = 27 * cpu_io_multi) then\r
185                         io_out(16#2007#, 16#26#);\r
186                     elsif (plt_step_cnt = 28 * cpu_io_multi) then\r
187                         io_out(16#2007#, 16#01#);\r
188                     elsif (plt_step_cnt = 29 * cpu_io_multi) then\r
189                         io_out(16#2007#, 16#31#);\r
190 \r
191                     else\r
192                         io_brk;\r
193                         if (plt_step_cnt > 30 * cpu_io_multi) then\r
194                             global_step_cnt := global_step_cnt + 1;\r
195                         end if;\r
196                     end if;\r
197                     plt_step_cnt := plt_step_cnt + 1;\r
198                     \r
199                 elsif (global_step_cnt = 2) then\r
200                     --step1 = name table set.\r
201                     if (nt_step_cnt = 0 * cpu_io_multi) then\r
202                         --set vram addr 2005 (first row, 6th col)\r
203                         io_out(16#2006#, 16#20#);\r
204                     elsif (nt_step_cnt = 1 * cpu_io_multi) then\r
205                         io_out(16#2006#, 16#06#);\r
206                     elsif (nt_step_cnt = 2 * cpu_io_multi) then\r
207                         --set name tbl data\r
208                         --0x44, 45, 45 = DEE\r
209                         io_out(16#2007#, 16#44#);\r
210                     elsif (nt_step_cnt = 3 * cpu_io_multi) then\r
211                         io_out(16#2007#, 16#45#);\r
212                     elsif (nt_step_cnt = 4 * cpu_io_multi) then\r
213                         io_out(16#2007#, 16#45#);\r
214 \r
215                     elsif (nt_step_cnt = 5 * cpu_io_multi) then\r
216                         --set vram addr 21d1\r
217                         io_out(16#2006#, 16#21#);\r
218                     elsif (nt_step_cnt = 6 * cpu_io_multi) then\r
219                         io_out(16#2006#, 16#E6#);\r
220                     elsif (nt_step_cnt = 7 * cpu_io_multi) then\r
221                         --msg=DEE TEST !!!\r
222                         io_out(16#2007#, 16#44#);\r
223                     elsif (nt_step_cnt = 8 * cpu_io_multi) then\r
224                         io_out(16#2007#, 16#45#);\r
225                     elsif (nt_step_cnt = 9 * cpu_io_multi) then\r
226                         io_out(16#2007#, 16#45#);\r
227                     elsif (nt_step_cnt = 10 * cpu_io_multi) then\r
228                         io_out(16#2007#, 16#00#);\r
229                     elsif (nt_step_cnt = 11 * cpu_io_multi) then\r
230                         io_out(16#2007#, 16#54#);\r
231                     elsif (nt_step_cnt = 12 * cpu_io_multi) then\r
232                         io_out(16#2007#, 16#45#);\r
233                     elsif (nt_step_cnt = 13 * cpu_io_multi) then\r
234                         io_out(16#2007#, 16#53#);\r
235                     elsif (nt_step_cnt = 14 * cpu_io_multi) then\r
236                         io_out(16#2007#, 16#54#);\r
237                     elsif (nt_step_cnt = 15 * cpu_io_multi) then\r
238                         io_out(16#2007#, 16#21#);\r
239 \r
240                     elsif (nt_step_cnt = 16 * cpu_io_multi) then\r
241                         --set vram addr 23c1 (attribute)\r
242                         io_out(16#2006#, 16#23#);\r
243                     elsif (nt_step_cnt = 17 * cpu_io_multi) then\r
244                         io_out(16#2006#, 16#c1#);\r
245                     elsif (nt_step_cnt = 18 * cpu_io_multi) then\r
246                                                                 --attr=11011000\r
247                         io_out(16#2007#, 16#d8#);\r
248 \r
249 \r
250                     \r
251                     --display test pattern\r
252                     elsif (nt_step_cnt = 19 * cpu_io_multi) then\r
253                         io_out(16#2006#, 16#20#);\r
254                     elsif (nt_step_cnt = 20 * cpu_io_multi) then\r
255                         io_out(16#2006#, 16#20#);\r
256                     \r
257                     elsif (nt_step_cnt = 21 * cpu_io_multi) then\r
258                         io_out(16#2007#, 16#01#);\r
259                     elsif (nt_step_cnt = 22 * cpu_io_multi) then\r
260                         io_out(16#2007#, 16#02#);\r
261                     elsif (nt_step_cnt = 23 * cpu_io_multi) then\r
262                         io_out(16#2007#, 16#03#);\r
263                     elsif (nt_step_cnt = 24 * cpu_io_multi) then\r
264                         io_out(16#2007#, 16#04#);\r
265                     elsif (nt_step_cnt = 25 * cpu_io_multi) then\r
266                         io_out(16#2007#, 16#05#);\r
267                     elsif (nt_step_cnt = 26 * cpu_io_multi) then\r
268                         io_out(16#2007#, 16#06#);\r
269                     elsif (nt_step_cnt = 27 * cpu_io_multi) then\r
270                         io_out(16#2007#, 16#07#);\r
271                     elsif (nt_step_cnt = 28 * cpu_io_multi) then\r
272                         io_out(16#2007#, 16#08#);\r
273                     elsif (nt_step_cnt = 29 * cpu_io_multi) then\r
274                         io_out(16#2007#, 16#09#);\r
275                     elsif (nt_step_cnt = 30 * cpu_io_multi) then\r
276                         io_out(16#2007#, 16#0a#);\r
277                     elsif (nt_step_cnt = 31 * cpu_io_multi) then\r
278                         io_out(16#2007#, 16#0b#);\r
279                     elsif (nt_step_cnt = 32 * cpu_io_multi) then\r
280                         io_out(16#2007#, 16#0c#);\r
281                     elsif (nt_step_cnt = 33 * cpu_io_multi) then\r
282                         io_out(16#2007#, 16#0d#);\r
283                     elsif (nt_step_cnt = 34 * cpu_io_multi) then\r
284                         io_out(16#2007#, 16#0e#);\r
285                     elsif (nt_step_cnt = 35 * cpu_io_multi) then\r
286                         io_out(16#2007#, 16#0f#);\r
287                     elsif (nt_step_cnt = 36 * cpu_io_multi) then\r
288                         io_out(16#2007#, 16#01#);\r
289 \r
290                     elsif (nt_step_cnt = 37 * cpu_io_multi) then\r
291                         io_out(16#2006#, 16#20#);\r
292                     elsif (nt_step_cnt = 38 * cpu_io_multi) then\r
293                         io_out(16#2006#, 16#40#);\r
294                     \r
295                     elsif (nt_step_cnt = 39 * cpu_io_multi) then\r
296                         io_out(16#2007#, 16#11#);\r
297                     elsif (nt_step_cnt = 40 * cpu_io_multi) then\r
298                         io_out(16#2007#, 16#12#);\r
299                     elsif (nt_step_cnt = 41 * cpu_io_multi) then\r
300                         io_out(16#2007#, 16#13#);\r
301                     elsif (nt_step_cnt = 42 * cpu_io_multi) then\r
302                         io_out(16#2007#, 16#14#);\r
303                     elsif (nt_step_cnt = 43 * cpu_io_multi) then\r
304                         io_out(16#2007#, 16#15#);\r
305                     elsif (nt_step_cnt = 44 * cpu_io_multi) then\r
306                         io_out(16#2007#, 16#16#);\r
307                     elsif (nt_step_cnt = 45 * cpu_io_multi) then\r
308                         io_out(16#2007#, 16#17#);\r
309                     elsif (nt_step_cnt = 46 * cpu_io_multi) then\r
310                         io_out(16#2007#, 16#18#);\r
311                     elsif (nt_step_cnt = 47 * cpu_io_multi) then\r
312                         io_out(16#2007#, 16#19#);\r
313                     elsif (nt_step_cnt = 48 * cpu_io_multi) then\r
314                         io_out(16#2007#, 16#1a#);\r
315                     elsif (nt_step_cnt = 49 * cpu_io_multi) then\r
316                         io_out(16#2007#, 16#1b#);\r
317                     elsif (nt_step_cnt = 50 * cpu_io_multi) then\r
318                         io_out(16#2007#, 16#1c#);\r
319                     elsif (nt_step_cnt = 51 * cpu_io_multi) then\r
320                         io_out(16#2007#, 16#1d#);\r
321                     elsif (nt_step_cnt = 52 * cpu_io_multi) then\r
322                         io_out(16#2007#, 16#1e#);\r
323                     elsif (nt_step_cnt = 53 * cpu_io_multi) then\r
324                         io_out(16#2007#, 16#1f#);\r
325                     elsif (nt_step_cnt = 54 * cpu_io_multi) then\r
326                         io_out(16#2007#, 16#11#);\r
327 \r
328 \r
329                     else\r
330                         io_brk;\r
331                         if (nt_step_cnt > 54 * cpu_io_multi) then\r
332                             global_step_cnt := global_step_cnt + 1;\r
333                         end if;\r
334                     end if;\r
335                     \r
336                     nt_step_cnt := nt_step_cnt + 1;\r
337                     \r
338                 elsif (global_step_cnt = 3) then\r
339                     --step2 = sprite set.\r
340                     if (spr_step_cnt = 0) then\r
341                         --set sprite addr=00 (first sprite)\r
342                         io_out(16#2003#, 16#00#);\r
343                     elsif (spr_step_cnt = 1 * cpu_io_multi) then\r
344                         --set sprite data: y=02\r
345                         io_out(16#2004#, 16#02#);\r
346                     elsif (spr_step_cnt = 2 * cpu_io_multi) then\r
347                         --tile=0x4d (ascii 'M')\r
348                         io_out(16#2004#, 16#4d#);\r
349                     elsif (spr_step_cnt = 3 * cpu_io_multi) then\r
350                         --set sprite attr=03 (palette 03)\r
351                         io_out(16#2004#, 16#03#);\r
352                     elsif (spr_step_cnt = 4 * cpu_io_multi) then\r
353                         --set sprite data: x=100\r
354                         io_out(16#2004#, 16#64#);\r
355 \r
356                     elsif (spr_step_cnt = 5 * cpu_io_multi) then\r
357                         --set sprite data: y=50\r
358                         io_out(16#2004#, 16#32#);\r
359                     elsif (spr_step_cnt = 6 * cpu_io_multi) then\r
360                         --tile=0x4d (ascii 'O')\r
361                         io_out(16#2004#, 16#4f#);\r
362                     elsif (spr_step_cnt = 7 * cpu_io_multi) then\r
363                         --set sprite attr=01\r
364                         io_out(16#2004#, 16#01#);\r
365                     elsif (spr_step_cnt = 8 * cpu_io_multi) then\r
366                         --set sprite data: x=30\r
367                         io_out(16#2004#, 16#1e#);\r
368 \r
369                     elsif (spr_step_cnt = 9 * cpu_io_multi) then\r
370                         --set sprite data: y=60\r
371                         io_out(16#2004#, 60);\r
372                     elsif (spr_step_cnt = 10 * cpu_io_multi) then\r
373                         --tile=0x4d (ascii 'P')\r
374                         io_out(16#2004#, 16#50#);\r
375                     elsif (spr_step_cnt = 11 * cpu_io_multi) then\r
376                         --set sprite attr=01\r
377                         io_out(16#2004#, 16#01#);\r
378                     elsif (spr_step_cnt = 12 * cpu_io_multi) then\r
379                         --set sprite data: x=33\r
380                         io_out(16#2004#, 16#21#);\r
381 \r
382                     elsif (spr_step_cnt = 13 * cpu_io_multi) then\r
383                         --set sprite data: y=61\r
384                         io_out(16#2004#, 16#3d#);\r
385                     elsif (spr_step_cnt = 14 * cpu_io_multi) then\r
386                         --tile=0x4d (ascii 'Q')\r
387                         io_out(16#2004#, 16#51#);\r
388                     elsif (spr_step_cnt = 15 * cpu_io_multi) then\r
389                         --set sprite attr=02\r
390                         io_out(16#2004#, 16#02#);\r
391                     elsif (spr_step_cnt = 16 * cpu_io_multi) then\r
392                         --set sprite data: x=45\r
393                         io_out(16#2004#, 45);\r
394 \r
395                     else\r
396                         io_brk;\r
397                         if (spr_step_cnt > 17 * cpu_io_multi) then\r
398                             global_step_cnt := global_step_cnt + 1;\r
399                         end if;\r
400                     end if;\r
401                     spr_step_cnt := spr_step_cnt + 1;\r
402 \r
403                 elsif (global_step_cnt = 4) then\r
404                     --final step = enable ppu.\r
405                     if (enable_ppu_step_cnt = 0) then\r
406                         --show bg\r
407                         --PPUMASK=1e (show bg and sprite)\r
408                         --PPUMASK=0e (show bg only)\r
409                         io_out(16#2001#, 16#1e#);\r
410                     elsif (enable_ppu_step_cnt = 1 * cpu_io_multi) then\r
411                         --enable nmi\r
412                         --PPUCTRL=80\r
413                         io_out(16#2000#, 16#80#);\r
414                     else\r
415                         io_brk;\r
416                         if (enable_ppu_step_cnt > 2 * cpu_io_multi) then\r
417                             global_step_cnt := global_step_cnt + 1;\r
418                         end if;\r
419                     end if;\r
420                     enable_ppu_step_cnt := enable_ppu_step_cnt + 1;\r
421 \r
422                 else\r
423                     io_brk;\r
424                     init_done := '1';\r
425                 end if;\r
426             end if;--if (init_done = '0') then\r
427         end if; --if (rst_n = '0') then\r
428     end process;
429
430 end rtl;
431
432 \r
433 \r
434 \r
435 \r
436 \r
437 -----------dummy prg rom\r
438 library ieee;\r
439 use ieee.std_logic_1164.all;\r
440 entity prg_rom is \r
441     generic (abus_size : integer := 15; dbus_size : integer := 8);\r
442     port (\r
443             clk             : in std_logic;\r
444             ce_n            : in std_logic;     --active low.\r
445             addr            : in std_logic_vector (abus_size - 1 downto 0);\r
446             data            : out std_logic_vector (dbus_size - 1 downto 0)\r
447         );\r
448 end prg_rom;\r
449 architecture rtl of prg_rom is\r
450 begin\r
451     data <= (others => 'Z');\r
452 end rtl;\r
453 \r