OSDN Git Service

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