OSDN Git Service

03d06e86257e953b166009ef50587104d959dc50
[motonesfpga/motonesfpga.git] / de0_cv_nes / dummy-mos6502.vhd
1 library ieee;\r
2 use ieee.std_logic_1164.all;\r
3 \r
4 entity mos6502 is \r
5     port (  \r
6             pi_rst_n       : in std_logic;\r
7             pi_base_clk         : in std_logic;\r
8             pi_cpu_en       : in std_logic_vector (7 downto 0);\r
9             pi_rdy         : in std_logic;\r
10             pi_irq_n       : in std_logic;\r
11             pi_nmi_n       : in std_logic;\r
12             po_oe_n        : out std_logic;\r
13             po_we_n        : out std_logic;\r
14             po_addr        : out std_logic_vector ( 15 downto 0);\r
15             pio_d_io       : inout std_logic_vector ( 7 downto 0);\r
16 \r
17             --for debugging..\r
18             po_dbg_cnt     : out std_logic_vector (63 downto 0);\r
19             po_exc_cnt     : out std_logic_vector (63 downto 0)\r
20     );\r
21 end mos6502;\r
22 \r
23 architecture rtl of mos6502 is\r
24 \r
25 signal reg_oe_n     : std_logic;\r
26 signal reg_we_n     : std_logic;\r
27 signal reg_addr     : std_logic_vector ( 15 downto 0);\r
28 signal reg_d_in     : std_logic_vector ( 7 downto 0);\r
29 signal reg_d_out    : std_logic_vector ( 7 downto 0);\r
30 \r
31 signal dummy_ad     : std_logic_vector (12 downto 0) := "0000000000000";\r
32 signal dummy_cnt    : integer := 0;\r
33 \r
34 begin\r
35 \r
36     po_oe_n     <= reg_oe_n;\r
37     po_we_n     <= reg_we_n;\r
38     po_addr     <= reg_addr;\r
39     pio_d_io    <= reg_d_out;\r
40     reg_d_in    <= pio_d_io;\r
41 \r
42     --set ppu value...\r
43     set_ppu_p : process (pi_base_clk, pi_rst_n)\r
44     use ieee.std_logic_arith.conv_std_logic_vector;\r
45 \r
46     variable init_step_cnt, plt_step_cnt, \r
47             nt_step_cnt, spr_step_cnt, dma_step_cnt, scl_step_cnt, \r
48             enable_ppu_step_cnt, nmi_step_cnt : integer;\r
49     variable init_done : std_logic;\r
50     variable global_step_cnt : integer;\r
51     constant cpu_io_multi : integer := 3; --io happens every 4 cpu cycle.\r
52     variable i, j : integer;\r
53     variable ch : integer := 16#41# ;\r
54     variable nmi_oam_x : integer range 0 to 255;\r
55     variable nmi_scl_y : integer range 0 to 255;\r
56 \r
57     variable ref_cnt : integer range 0 to 120;\r
58 \r
59 procedure io_out (ad: in integer; dt : in integer) is\r
60 begin\r
61     reg_oe_n <= '1';\r
62     reg_we_n <= '0';\r
63     reg_addr <= conv_std_logic_vector(ad, 16);\r
64     reg_d_out <= conv_std_logic_vector(dt, 8);\r
65 end;\r
66 \r
67 procedure io_brk is\r
68 use ieee.std_logic_unsigned.all;\r
69 begin\r
70     --fake ram read/write to emulate dummy i/o.\r
71 --    reg_addr <= "000" & dummy_ad;\r
72 --    dummy_ad <= dummy_ad + 1;\r
73 --    if (dummy_cnt = 0) then\r
74 --        reg_d_out <= (others => 'Z');\r
75 --        reg_oe_n <= '1';\r
76 --        reg_we_n <= '1';\r
77 --        dummy_cnt <= 1;\r
78 --    else\r
79 --        reg_d_out <= dummy_ad(7 downto 0);\r
80 --        reg_oe_n <= '1';\r
81 --        reg_we_n <= '1';\r
82 --        dummy_cnt <= 0;\r
83 --    end if;\r
84     reg_d_out <= (others => 'Z');\r
85     reg_oe_n <= 'Z';\r
86     reg_we_n <= 'Z';\r
87 end;\r
88 \r
89 procedure io_read (ad: in integer) is\r
90 begin\r
91     reg_oe_n <= '0';\r
92     reg_we_n <= '1';\r
93     reg_addr <= conv_std_logic_vector(ad, 16);\r
94     reg_d_out <= (others => 'Z');\r
95 end;\r
96 \r
97     begin\r
98         if (pi_rst_n = '0') then\r
99             \r
100             reg_oe_n <= '1';\r
101             reg_we_n <= '1';\r
102             reg_addr <= (others => 'Z');\r
103             reg_d_out <= (others => 'Z');\r
104             \r
105             init_done := '0';\r
106             global_step_cnt := 0;\r
107             init_step_cnt := 0;\r
108             plt_step_cnt := 0;\r
109             nt_step_cnt := 0;\r
110             spr_step_cnt := 0;\r
111             dma_step_cnt := 0;\r
112             scl_step_cnt := 0;\r
113             enable_ppu_step_cnt := 0;\r
114             nmi_step_cnt := 0;\r
115             nmi_oam_x := 0;\r
116             nmi_scl_y := 200;\r
117             ref_cnt := 0;\r
118 \r
119         elsif (rising_edge(pi_base_clk)) then\r
120             if (pi_cpu_en(0) = '1') then\r
121             if (pi_rdy = '1') then\r
122                 if (init_done = '0') then\r
123                     if (global_step_cnt = 0) then\r
124                         --step0.0 = init ppu.\r
125                         if (init_step_cnt = 0 * cpu_io_multi) then\r
126                             --PPUCTRL=01 for test...\r
127                             io_out(16#2000#, 16#01#);\r
128                         elsif (init_step_cnt = 1 * cpu_io_multi) then\r
129                             --PPUMASK=02\r
130                             io_out(16#2001#, 16#02#);\r
131                         elsif (init_step_cnt = 2 * cpu_io_multi) then\r
132                             --PPUCTRL=00\r
133                             io_out(16#2000#, 16#00#);\r
134                         elsif (init_step_cnt = 3 * cpu_io_multi) then\r
135                             --PPUMASK=00\r
136                             io_out(16#2001#, 16#00#);\r
137                         elsif (init_step_cnt = 4 * cpu_io_multi) then\r
138                             --ppuaddr\r
139                             io_out(16#2006#, 16#02#);\r
140                         elsif (init_step_cnt = 5 * cpu_io_multi) then\r
141                             io_out(16#2006#, 16#40#);\r
142                         elsif (init_step_cnt = 6 * cpu_io_multi) then\r
143                             --scroll\r
144                             io_out(16#2005#, 16#21#);\r
145                         elsif (init_step_cnt = 7 * cpu_io_multi) then\r
146                             io_out(16#2005#, 16#5#);\r
147 \r
148                         elsif (init_step_cnt = 8 * cpu_io_multi) then\r
149                             --vram read test.\r
150                             io_out(16#2006#, 16#1e#);\r
151                         elsif (init_step_cnt = 9 * cpu_io_multi) then\r
152                             --vram read test.\r
153                             io_out(16#2006#, 16#c0#);\r
154                         elsif (init_step_cnt = 10 * cpu_io_multi) then\r
155                             --vram read test.\r
156                             io_out(16#2007#, 10);\r
157                         elsif (init_step_cnt = 11 * cpu_io_multi) then\r
158                             io_read(16#2007#);\r
159                         elsif (init_step_cnt = 12 * cpu_io_multi) then\r
160                             io_read(16#2007#);\r
161 \r
162                         else\r
163                             io_read(16#00#);\r
164                             if (init_step_cnt > 13 * cpu_io_multi) then\r
165                                 global_step_cnt := global_step_cnt + 1;\r
166                             end if;\r
167                         end if;\r
168                         init_step_cnt := init_step_cnt + 1;\r
169                     elsif (global_step_cnt = 1) then\r
170                         --step0.1 = palette set.\r
171     --palettes:\r
172     --;;;bg palette\r
173     --  .byte   $0f, $00, $10, $20\r
174     --  .byte   $0f, $04, $14, $24\r
175     --  .byte   $0f, $08, $18, $28\r
176     --  .byte   $0f, $0c, $1c, $2c\r
177     --;;;spr palette\r
178     --  .byte   $0f, $00, $10, $20\r
179     --  .byte   $0f, $06, $16, $26\r
180     --  .byte   $0f, $08, $18, $28\r
181     --  .byte   $0f, $0a, $1a, $2a\r
182                         \r
183                         \r
184                         if (plt_step_cnt = 0 * cpu_io_multi) then\r
185                             --set vram addr 3f00\r
186                             io_out(16#2006#, 16#3f#);\r
187                         elsif (plt_step_cnt = 1 * cpu_io_multi) then\r
188                             io_out(16#2006#, 16#00#);\r
189                         \r
190                         elsif (plt_step_cnt = 2 * cpu_io_multi) then\r
191                             --set palette bg data\r
192                             io_out(16#2007#, 16#11#);\r
193                         elsif (plt_step_cnt = 3 * cpu_io_multi) then\r
194                             io_out(16#2007#, 16#01#);\r
195                         elsif (plt_step_cnt = 4 * cpu_io_multi) then\r
196                             io_out(16#2007#, 16#03#);\r
197                         elsif (plt_step_cnt = 5 * cpu_io_multi) then\r
198                             io_out(16#2007#, 16#13#);\r
199 \r
200                         elsif (plt_step_cnt = 6 * cpu_io_multi) then\r
201                             io_out(16#2007#, 16#0f#);\r
202                         elsif (plt_step_cnt = 7 * cpu_io_multi) then\r
203                             io_out(16#2007#, 16#04#);\r
204                         elsif (plt_step_cnt = 8 * cpu_io_multi) then\r
205                             io_out(16#2007#, 16#14#);\r
206                         elsif (plt_step_cnt = 9 * cpu_io_multi) then\r
207                             io_out(16#2007#, 16#24#);\r
208      \r
209                         elsif (plt_step_cnt = 10 * cpu_io_multi) then\r
210                             io_out(16#2007#, 16#0f#);\r
211                         elsif (plt_step_cnt = 11 * cpu_io_multi) then\r
212                             io_out(16#2007#, 16#08#);\r
213                         elsif (plt_step_cnt = 12 * cpu_io_multi) then\r
214                             io_out(16#2007#, 16#18#);\r
215                         elsif (plt_step_cnt = 13 * cpu_io_multi) then\r
216                             io_out(16#2007#, 16#28#);\r
217      \r
218                         elsif (plt_step_cnt = 14 * cpu_io_multi) then\r
219                             io_out(16#2007#, 16#05#);\r
220                         elsif (plt_step_cnt = 15 * cpu_io_multi) then\r
221                             io_out(16#2007#, 16#0c#);\r
222                         elsif (plt_step_cnt = 16 * cpu_io_multi) then\r
223                             io_out(16#2007#, 16#1c#);\r
224                         elsif (plt_step_cnt = 17 * cpu_io_multi) then\r
225                             io_out(16#2007#, 16#2c#);\r
226 \r
227                          elsif (plt_step_cnt = 18 * cpu_io_multi) then\r
228                             --below is sprite pallete\r
229                             io_out(16#2007#, 16#00#);\r
230                         elsif (plt_step_cnt = 19 * cpu_io_multi) then\r
231                             io_out(16#2007#, 16#24#);\r
232                         elsif (plt_step_cnt = 20 * cpu_io_multi) then\r
233                             io_out(16#2007#, 16#1b#);\r
234                         elsif (plt_step_cnt = 21 * cpu_io_multi) then\r
235                             io_out(16#2007#, 16#11#);\r
236 \r
237                         elsif (plt_step_cnt = 22 * cpu_io_multi) then\r
238                             io_out(16#2007#, 16#00#);\r
239                         elsif (plt_step_cnt = 23 * cpu_io_multi) then\r
240                             io_out(16#2007#, 16#32#);\r
241                         elsif (plt_step_cnt = 24 * cpu_io_multi) then\r
242                             io_out(16#2007#, 16#16#);\r
243                         elsif (plt_step_cnt = 25 * cpu_io_multi) then\r
244                             io_out(16#2007#, 16#20#);\r
245 \r
246                         elsif (plt_step_cnt = 26 * cpu_io_multi) then\r
247                             io_out(16#2007#, 16#00#);\r
248                         elsif (plt_step_cnt = 27 * cpu_io_multi) then\r
249                             io_out(16#2007#, 16#26#);\r
250                         elsif (plt_step_cnt = 28 * cpu_io_multi) then\r
251                             io_out(16#2007#, 16#01#);\r
252                         elsif (plt_step_cnt = 29 * cpu_io_multi) then\r
253                             io_out(16#2007#, 16#31#);\r
254 \r
255                         else\r
256                             io_read(16#00#);\r
257                             if (plt_step_cnt > 30 * cpu_io_multi) then\r
258                                 global_step_cnt := global_step_cnt + 1;\r
259                             end if;\r
260                         end if;\r
261                         plt_step_cnt := plt_step_cnt + 1;\r
262                         \r
263                     elsif (global_step_cnt = 2) then\r
264                         --step1 = name table set.\r
265                         if (nt_step_cnt = 0 * cpu_io_multi) then\r
266                             --set vram addr 2005 (2nd row, 6th col)\r
267                             io_out(16#2006#, 16#20#);\r
268                         elsif (nt_step_cnt = 1 * cpu_io_multi) then\r
269                             io_out(16#2006#, 16#26#);\r
270                         elsif (nt_step_cnt = 2 * cpu_io_multi) then\r
271                             --set name tbl data\r
272                             --0x44, 45, 45 = DEM\r
273                             io_out(16#2007#, 16#44#);\r
274                         elsif (nt_step_cnt = 3 * cpu_io_multi) then\r
275                             io_out(16#2007#, 16#45#);\r
276                         elsif (nt_step_cnt = 4 * cpu_io_multi) then\r
277                             io_out(16#2007#, 16#4d#);\r
278 \r
279 \r
280                         elsif (nt_step_cnt = 5 * cpu_io_multi) then\r
281                             io_out(16#2006#, 16#20#);\r
282                         elsif (nt_step_cnt = 6 * cpu_io_multi) then\r
283                             io_out(16#2006#, 16#2a#);\r
284                         elsif (nt_step_cnt = 7 * cpu_io_multi) then\r
285                             io_out(16#2007#, 16#44#);\r
286 \r
287                         elsif (nt_step_cnt = 8 * cpu_io_multi) then\r
288                             io_out(16#2006#, 16#24#);\r
289                         elsif (nt_step_cnt = 9 * cpu_io_multi) then\r
290                             io_out(16#2006#, 16#43#);\r
291                         elsif (nt_step_cnt = 10 * cpu_io_multi) then\r
292                             io_out(16#2007#, 16#6d#);\r
293                         elsif (nt_step_cnt = 11 * cpu_io_multi) then\r
294                             io_out(16#2007#, 16#6f#);\r
295                         elsif (nt_step_cnt = 12 * cpu_io_multi) then\r
296                             io_out(16#2007#, 16#74#);\r
297                         elsif (nt_step_cnt = 13 * cpu_io_multi) then\r
298                             io_out(16#2007#, 16#6f#);\r
299                             \r
300                         elsif (nt_step_cnt = 14 * cpu_io_multi) then\r
301                             io_out(16#2006#, 16#2e#);\r
302                         elsif (nt_step_cnt = 15 * cpu_io_multi) then\r
303                             io_out(16#2006#, 16#93#);\r
304                         elsif (nt_step_cnt = 16 * cpu_io_multi) then\r
305                             io_out(16#2007#, 16#59#);\r
306 \r
307                         elsif (nt_step_cnt = 17 * cpu_io_multi) then\r
308                             io_out(16#2007#, 16#00#);\r
309 \r
310                         else\r
311                             io_read(16#00#);\r
312                             if (nt_step_cnt > 4 * cpu_io_multi) then\r
313                                 global_step_cnt := global_step_cnt + 1;\r
314                             end if;\r
315                         end if;\r
316                         \r
317                         nt_step_cnt := nt_step_cnt + 1;\r
318                         \r
319                     elsif (global_step_cnt = 3) then\r
320                         --step2 = sprite set.\r
321                         if (spr_step_cnt = 0) then\r
322                             --set sprite addr=00 (first sprite)\r
323                             io_out(16#2003#, 16#00#);\r
324                         \r
325                         elsif (spr_step_cnt = 1 * cpu_io_multi) then\r
326                             --set sprite data: y=02\r
327                             io_out(16#2004#, 16#05#);\r
328                         elsif (spr_step_cnt = 2 * cpu_io_multi) then\r
329                             --tile=0x4d (ascii 'O')\r
330                             io_out(16#2004#, 16#4f#);\r
331                         elsif (spr_step_cnt = 3 * cpu_io_multi) then\r
332                             --set sprite attr=01 (palette 01)\r
333                             io_out(16#2004#, 16#01#);\r
334                         elsif (spr_step_cnt = 4 * cpu_io_multi) then\r
335                             --set sprite data: x=60\r
336                             io_out(16#2004#, 16#3c#);\r
337 \r
338                         elsif (spr_step_cnt = 5 * cpu_io_multi) then\r
339                             --set sprite data: y=50\r
340                             io_out(16#2004#, 1);\r
341                         elsif (spr_step_cnt = 6 * cpu_io_multi) then\r
342                             --tile=0x4f (ascii 'M')\r
343                             io_out(16#2004#, 16#4d#);\r
344                         elsif (spr_step_cnt = 7 * cpu_io_multi) then\r
345                             --set sprite attr=02\r
346                             io_out(16#2004#, 16#02#);\r
347                         elsif (spr_step_cnt = 8 * cpu_io_multi) then\r
348                             --set sprite data: x=100\r
349                             io_out(16#2004#, 16#64#);\r
350 \r
351 --                        elsif (spr_step_cnt = 9 * cpu_io_multi) then\r
352 --                            --set sprite data: y=60\r
353 --                            io_out(16#2004#, 60);\r
354 --                        elsif (spr_step_cnt = 10 * cpu_io_multi) then\r
355 --                            --tile=0x4d (ascii 'P')\r
356 --                            io_out(16#2004#, 16#50#);\r
357 --                        elsif (spr_step_cnt = 11 * cpu_io_multi) then\r
358 --                            --set sprite attr=01\r
359 --                            io_out(16#2004#, 16#01#);\r
360 --                        elsif (spr_step_cnt = 12 * cpu_io_multi) then\r
361 --                            --set sprite data: x=33\r
362 --                            io_out(16#2004#, 16#21#);\r
363 --\r
364 --                        elsif (spr_step_cnt = 13 * cpu_io_multi) then\r
365 --                            --set sprite data: y=61\r
366 --                            io_out(16#2004#, 16#3d#);\r
367 --                        elsif (spr_step_cnt = 14 * cpu_io_multi) then\r
368 --                            --tile=0x4d (ascii 'Q')\r
369 --                            io_out(16#2004#, 16#51#);\r
370 --                        elsif (spr_step_cnt = 15 * cpu_io_multi) then\r
371 --                            --set sprite attr=02\r
372 --                            io_out(16#2004#, 16#02#);\r
373 --                        elsif (spr_step_cnt = 16 * cpu_io_multi) then\r
374 --                            --set sprite data: x=45\r
375 --                            io_out(16#2004#, 45);\r
376 \r
377                         else\r
378                             io_read(16#00#);\r
379                             if (spr_step_cnt > 8 * cpu_io_multi) then\r
380                                 global_step_cnt := global_step_cnt + 2;\r
381                             end if;\r
382                         end if;\r
383                         spr_step_cnt := spr_step_cnt + 1;\r
384 \r
385                     elsif (global_step_cnt = 4) then\r
386                         --step3 = dma set.\r
387 --                        for i in 0 to 64 loop\r
388 --                            j := i * 4;\r
389 --                            if (ch = 16#5b#) then\r
390 --                                ch := 16#41#;\r
391 --                            else\r
392 --                                ch := 16#41# + i;\r
393 --                            end if;\r
394 --\r
395 --                            --if (i < 64) then\r
396 --                            if (i < 10) then\r
397 --                                --set dma value on the ram.\r
398 --                                if    (dma_step_cnt = (0 + j) * cpu_io_multi) then\r
399 --                                    io_out(16#0200# + j, i);\r
400 --                                elsif (dma_step_cnt = (1 + j) * cpu_io_multi) then\r
401 --                                    io_out(16#0201# + j, ch);\r
402 --                                elsif (dma_step_cnt = (2 + j) * cpu_io_multi) then\r
403 --                                    io_out(16#0202# + j, 16#01#);\r
404 --                                elsif (dma_step_cnt = (3 + j) * cpu_io_multi) then\r
405 --                                    io_out(16#0203# + j, j);\r
406 --                                elsif (dma_step_cnt = (0 + j) * cpu_io_multi + 1) or\r
407 --                                        (dma_step_cnt = (1 + j) * cpu_io_multi + 1) or\r
408 --                                        (dma_step_cnt = (2 + j) * cpu_io_multi + 1) or\r
409 --                                        (dma_step_cnt = (3 + j) * cpu_io_multi + 1) then\r
410 --                                    io_read(16#00#);\r
411 --                                end if;\r
412 --                            else\r
413 --                                if    (dma_step_cnt = (0 + j) * cpu_io_multi) then\r
414 --                                    --start dma\r
415 --                                    io_out(16#4014#, 16#02#);\r
416 --                                elsif (dma_step_cnt = (0 + j) * cpu_io_multi + 1) then\r
417 --                                    io_read(16#00#);\r
418 --                                elsif (dma_step_cnt = (0 + j) * cpu_io_multi + 2) then\r
419                                     io_read(16#00#);\r
420                                     global_step_cnt := global_step_cnt + 1;\r
421 --                                end if;\r
422 --                            end if;\r
423 --                        end loop;\r
424 --                        \r
425 --                        dma_step_cnt := dma_step_cnt + 1;\r
426 \r
427                     elsif (global_step_cnt = 5) then\r
428                         --step4 = scroll test and ppu reg read test.\r
429                         if (scl_step_cnt = 123) then\r
430                             --x scroll pos=5\r
431                             io_out(16#2005#, 5);\r
432                         elsif (scl_step_cnt = 1 * cpu_io_multi) then\r
433                             --y scroll pos=9\r
434                             io_out(16#2005#, 9);\r
435 \r
436                         elsif (scl_step_cnt = 2 * cpu_io_multi) then\r
437                             --read status reg.\r
438                             io_read(16#2002#);\r
439 \r
440                         elsif (scl_step_cnt = 3 * cpu_io_multi) then\r
441                             --read vram nt0.\r
442                             io_out(16#2006#, 16#20#);\r
443 \r
444                         elsif (scl_step_cnt = 4 * cpu_io_multi) then\r
445                             io_out(16#2006#, 16#03#);\r
446 \r
447                         elsif (scl_step_cnt = 5 * cpu_io_multi) then\r
448                             io_read(16#2007#);\r
449 \r
450                         elsif (scl_step_cnt = 6 * cpu_io_multi) then\r
451                             --pattern tbl.\r
452                             io_out(16#2006#, 16#04#);\r
453 \r
454                         elsif (scl_step_cnt = 7 * cpu_io_multi) then\r
455                             io_out(16#2006#, 16#d1#);\r
456 \r
457                         elsif (scl_step_cnt = 8 * cpu_io_multi) then\r
458                             io_read(16#2007#);\r
459 \r
460                         elsif (scl_step_cnt = 9 * cpu_io_multi) then\r
461                             --attr tbl.\r
462                             io_out(16#2006#, 16#23#);\r
463 \r
464                         elsif (scl_step_cnt = 10 * cpu_io_multi) then\r
465                             io_out(16#2006#, 16#c0#);\r
466 \r
467                         elsif (scl_step_cnt = 11 * cpu_io_multi) then\r
468                             --set attr first.\r
469                             io_out(16#2007#, 16#5a#);\r
470 \r
471                         elsif (scl_step_cnt = 12 * cpu_io_multi) then\r
472                             io_out(16#2006#, 16#23#);\r
473 \r
474                         elsif (scl_step_cnt = 13 * cpu_io_multi) then\r
475                             io_out(16#2006#, 16#c0#);\r
476 \r
477                         elsif (scl_step_cnt = 14 * cpu_io_multi) then\r
478                             io_read(16#2007#);\r
479 \r
480                         elsif (scl_step_cnt = 15 * cpu_io_multi) then\r
481                             --read palette tbl.\r
482                             io_out(16#2006#, 16#3f#);\r
483 \r
484                         elsif (scl_step_cnt = 16 * cpu_io_multi) then\r
485                             io_out(16#2006#, 16#11#);\r
486 \r
487                         elsif (scl_step_cnt = 17 * cpu_io_multi) then\r
488                             io_read(16#2007#);\r
489 \r
490                         else\r
491                             io_read(16#00#);\r
492                             if (scl_step_cnt > 17 * cpu_io_multi) then\r
493                                 global_step_cnt := global_step_cnt + 1;\r
494                             end if;\r
495                         end if;\r
496                         scl_step_cnt := scl_step_cnt + 1;\r
497 \r
498                     elsif (global_step_cnt = 6) then\r
499                         --final step = enable ppu.\r
500                         if (enable_ppu_step_cnt = 0 * cpu_io_multi) then\r
501                             --show bg\r
502                             --PPUMASK=1e (show bg and sprite)\r
503                             --PPUMASK=0e (show bg only)\r
504                             io_out(16#2001#, 16#1e#);\r
505                         elsif (enable_ppu_step_cnt = 1 * cpu_io_multi) then\r
506                             --enable nmi\r
507                             --PPUCTRL=80\r
508                             io_out(16#2000#, 16#80#);\r
509                         else\r
510                             io_read(16#00#);\r
511                             if (enable_ppu_step_cnt > 1 * cpu_io_multi) then\r
512                                 --skip nmi test at this momemnt..\r
513                                 global_step_cnt := global_step_cnt + 1;\r
514                             end if;\r
515                         end if;\r
516                         enable_ppu_step_cnt := enable_ppu_step_cnt + 1;\r
517 \r
518                     elsif (global_step_cnt = 7) then\r
519                         ----nmi tests.....\r
520                         if (pi_nmi_n = '0') then\r
521 \r
522                             if (nmi_step_cnt = 0 * cpu_io_multi) then\r
523                                 --set sprite addr=00 (first sprite)\r
524                                 io_out(16#2003#, 16#03#);\r
525                             elsif (nmi_step_cnt = 1 * cpu_io_multi) then\r
526                                 --set sprite data: x=100\r
527                                 io_out(16#2004#, nmi_oam_x);\r
528                             elsif (nmi_step_cnt = 2 * cpu_io_multi) then\r
529                                 --scroll x=0\r
530                                 io_out(16#2005#, nmi_scl_y);\r
531                             elsif (nmi_step_cnt = 3 * cpu_io_multi) then\r
532                                 --scroll y++\r
533                                 io_out(16#2005#, nmi_scl_y);\r
534                             elsif (nmi_step_cnt = 4 * cpu_io_multi) then\r
535                                 --set sprite addr=00 (first sprite)\r
536                                 io_out(16#2003#, 16#04#);\r
537                             elsif (nmi_step_cnt = 5 * cpu_io_multi) then\r
538                                 --set sprite data: x=100\r
539                                 io_out(16#2004#, nmi_oam_x);\r
540                             else\r
541                                 if (ref_cnt = 0) then\r
542                                     nmi_oam_x := nmi_oam_x + 1;\r
543                                 end if;\r
544                                 if (nmi_step_cnt mod 10 = 0) then\r
545                                     nmi_scl_y := nmi_scl_y + 1;\r
546                                 end if;\r
547                                 io_read(16#00#);\r
548                                 if (nmi_step_cnt > 5 * cpu_io_multi) then\r
549                                     ref_cnt := ref_cnt + 1;\r
550                                     global_step_cnt := global_step_cnt + 1;\r
551                                 end if;\r
552                             end if;\r
553                             nmi_step_cnt := nmi_step_cnt + 1;\r
554                         end if;\r
555                     elsif (global_step_cnt = 8) then\r
556                         ----back to nmi tests.....\r
557                         if (pi_nmi_n = '1') then\r
558                             nmi_step_cnt := 0;\r
559                             global_step_cnt := global_step_cnt - 1;\r
560                         end if;\r
561                     else\r
562                         io_read(16#00#);\r
563                         init_done := '1';\r
564                     end if;\r
565                 else\r
566                     io_read(16#00#);\r
567                 end if;--if (init_done = '0') then\r
568             else\r
569                 io_brk;\r
570             end if;--if (rdy = '1') then\r
571             end if;--if (pi_cpu_en(0) = '1') then\r
572         end if; --if (rst_n = '0') then\r
573     end process;\r
574 \r
575 end rtl;\r
576 \r
577 \r
578 \r
579 \r
580 \r
581 -----------dummy prg rom\r
582 library ieee;\r
583 use ieee.std_logic_1164.all;\r
584 entity prg_rom is \r
585     port (\r
586             pi_base_clk         : in std_logic;\r
587             pi_ce_n         : in std_logic;\r
588             pi_oe_n         : in std_logic;\r
589             pi_addr         : in std_logic_vector (14 downto 0);\r
590             po_data         : out std_logic_vector (7 downto 0)\r
591         );\r
592 end prg_rom;\r
593 architecture rtl of prg_rom is\r
594 begin\r
595     p_read : process (pi_base_clk)\r
596     begin\r
597         if (rising_edge(pi_base_clk)) then\r
598             if (pi_ce_n = '0') then\r
599                 ---dummy data.\r
600                 po_data <= "00110011";\r
601             else\r
602                 po_data <= (others => 'Z');\r
603             end if;\r
604         end if;\r
605     end process;\r
606 \r
607 end rtl;\r
608 \r