OSDN Git Service

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