OSDN Git Service

cpu source and ppu stub added.
authorastoria-d@fc <astoria-d@fc>
Thu, 15 Sep 2016 01:23:30 +0000 (10:23 +0900)
committerastoria-d@fc <astoria-d@fc>
Thu, 15 Sep 2016 01:23:30 +0000 (10:23 +0900)
de0_cv_nes/de0_cv_nes.qsf
de0_cv_nes/dummy-ppu.vhd [new file with mode: 0644]
de0_cv_nes/mos6502.vhd [new file with mode: 0644]

index 09f97a1..2bb50cd 100644 (file)
@@ -106,6 +106,8 @@ set_global_assignment -name VHDL_FILE dummy-ppu.vhd
 \r
 #cpu\r
 #set_global_assignment -name VHDL_FILE dummy-mos6502.vhd\r
+\r
+set_global_assignment -name VHDL_FILE mem/prg_rom.vhd\r
 set_global_assignment -name VHDL_FILE mos6502.vhd\r
 \r
 set_global_assignment -name VHDL_FILE de0_cv_nes.vhd\r
diff --git a/de0_cv_nes/dummy-ppu.vhd b/de0_cv_nes/dummy-ppu.vhd
new file mode 100644 (file)
index 0000000..9c12cba
--- /dev/null
@@ -0,0 +1,67 @@
+library ieee;\r
+use ieee.std_logic_1164.all;\r
+use ieee.std_logic_unsigned.all;\r
+\r
+entity ppu is \r
+    port (\r
+                pi_rst_n       : in std_logic;\r
+                pi_base_clk    : in std_logic;\r
+                pi_cpu_en      : in std_logic_vector (7 downto 0);\r
+                pi_ce_n        : in std_logic;\r
+                pi_r_nw        : in std_logic;\r
+                pi_cpu_addr    : in std_logic_vector (2 downto 0);\r
+                pio_cpu_d      : inout std_logic_vector (7 downto 0);\r
+\r
+                po_v_ce_n       : out std_logic;\r
+                po_v_rd_n       : out std_logic;\r
+                po_v_wr_n       : out std_logic;\r
+                po_v_addr       : out std_logic_vector (13 downto 0);\r
+                pio_v_data      : inout std_logic_vector (7 downto 0);\r
+\r
+                po_plt_ce_n     : out std_logic;\r
+                po_plt_rd_n     : out std_logic;\r
+                po_plt_wr_n     : out std_logic;\r
+                po_plt_addr     : out std_logic_vector (4 downto 0);\r
+                pio_plt_data    : inout std_logic_vector (7 downto 0);\r
+\r
+                po_spr_ce_n     : out std_logic;\r
+                po_spr_rd_n     : out std_logic;\r
+                po_spr_wr_n     : out std_logic;\r
+                po_spr_addr     : out std_logic_vector (7 downto 0);\r
+                po_spr_data     : out std_logic_vector (7 downto 0);\r
+\r
+                po_ppu_ctrl        : out std_logic_vector (7 downto 0);\r
+                po_ppu_mask        : out std_logic_vector (7 downto 0);\r
+                pi_ppu_status      : in std_logic_vector (7 downto 0);\r
+                po_ppu_scroll_x    : out std_logic_vector (7 downto 0);\r
+                po_ppu_scroll_y    : out std_logic_vector (7 downto 0)\r
+    );\r
+end ppu;\r
+\r
+architecture rtl of ppu is\r
+begin\r
+    pio_cpu_d      <= (others => 'Z');\r
+\r
+    po_v_ce_n       'Z';\r
+    po_v_rd_n       'Z';\r
+    po_v_wr_n       'Z';\r
+    po_v_addr       <= (others => 'Z');\r
+    pio_v_data      <= (others => 'Z');\r
+\r
+    po_plt_ce_n     'Z';\r
+    po_plt_rd_n     'Z';\r
+    po_plt_wr_n     'Z';\r
+    po_plt_addr     <= (others => 'Z');\r
+    pio_plt_data    <= (others => 'Z');\r
+\r
+    po_spr_ce_n     'Z';\r
+    po_spr_rd_n     'Z';\r
+    po_spr_wr_n     'Z';\r
+    po_spr_addr     <= (others => 'Z');\r
+    po_spr_data     <= (others => 'Z');\r
+\r
+    po_ppu_ctrl        <= (others => 'Z');\r
+    po_ppu_mask        <= (others => 'Z');\r
+    po_ppu_scroll_x    <= (others => 'Z');\r
+    po_ppu_scroll_y    <= (others => 'Z');\r
+end rtl;\r
diff --git a/de0_cv_nes/mos6502.vhd b/de0_cv_nes/mos6502.vhd
new file mode 100644 (file)
index 0000000..7eaf755
--- /dev/null
@@ -0,0 +1,551 @@
+library ieee;\r
+use ieee.std_logic_1164.all;\r
+\r
+entity mos6502 is \r
+    port (  \r
+            pi_rst_n       : in std_logic;\r
+            pi_base_clk        : in std_logic;\r
+            pi_cpu_en       : in std_logic_vector (7 downto 0);\r
+            pi_rdy         : in std_logic;\r
+            pi_irq_n       : in std_logic;\r
+            pi_nmi_n       : in std_logic;\r
+            po_r_nw        : out std_logic;\r
+            po_addr        : out std_logic_vector ( 15 downto 0);\r
+            pio_d_io       : inout std_logic_vector ( 7 downto 0)\r
+    );\r
+end mos6502;\r
+\r
+architecture rtl of mos6502 is\r
+\r
+signal reg_r_nw     : std_logic;\r
+signal reg_addr     : std_logic_vector ( 15 downto 0);\r
+signal reg_d_in     : std_logic_vector ( 7 downto 0);\r
+signal reg_d_out    : std_logic_vector ( 7 downto 0);\r
+\r
+signal dummy_ad     : std_logic_vector (12 downto 0) := "0000000000000";\r
+signal dummy_cnt    : integer := 0;\r
+\r
+begin\r
+\r
+    po_r_nw     <= reg_r_nw;\r
+    po_addr     <= reg_addr;\r
+    pio_d_io    <= reg_d_out;\r
+    reg_d_in    <= pio_d_io;\r
+\r
+    --set ppu value...\r
+    set_ppu_p : process (pi_base_clk, pi_rst_n)\r
+    use ieee.std_logic_arith.conv_std_logic_vector;\r
+\r
+    variable init_step_cnt, plt_step_cnt, \r
+            nt_step_cnt, spr_step_cnt, dma_step_cnt, scl_step_cnt, \r
+            enable_ppu_step_cnt, nmi_step_cnt : integer;\r
+    variable init_done : std_logic;\r
+    variable global_step_cnt : integer;\r
+    constant cpu_io_multi : integer := 3; --io happens every 4 cpu cycle.\r
+    variable i, j : integer;\r
+    variable ch : integer := 16#41# ;\r
+    variable nmi_oam_x : integer range 0 to 255;\r
+    variable nmi_scl_y : integer range 0 to 255;\r
+\r
+    variable ref_cnt : integer range 0 to 120;\r
+\r
+procedure io_out (ad: in integer; dt : in integer) is\r
+begin\r
+    reg_r_nw <= '0';\r
+    reg_addr <= conv_std_logic_vector(ad, 16);\r
+    reg_d_out <= conv_std_logic_vector(dt, 8);\r
+end;\r
+\r
+procedure io_brk is\r
+use ieee.std_logic_unsigned.all;\r
+begin\r
+    --fake ram read/write to emulate dummy i/o.\r
+    reg_addr <= "000" & dummy_ad;\r
+    dummy_ad <= dummy_ad + 1;\r
+    if (dummy_cnt = 0) then\r
+        reg_d_out <= (others => 'Z');\r
+        reg_r_nw <= '1';\r
+        dummy_cnt <= 1;\r
+    else\r
+        reg_d_out <= dummy_ad(7 downto 0);\r
+        reg_r_nw <= '0';\r
+        dummy_cnt <= 0;\r
+    end if;\r
+end;\r
+\r
+procedure io_read (ad: in integer) is\r
+begin\r
+    reg_r_nw <= '1';\r
+    reg_addr <= conv_std_logic_vector(ad, 16);\r
+    reg_d_out <= (others => 'Z');\r
+end;\r
+\r
+    begin\r
+        if (pi_rst_n = '0') then\r
+            \r
+            reg_r_nw <= 'Z';\r
+            reg_addr <= (others => 'Z');\r
+            reg_d_out <= (others => 'Z');\r
+            \r
+            init_done := '0';\r
+            global_step_cnt := 0;\r
+            init_step_cnt := 0;\r
+            plt_step_cnt := 0;\r
+            nt_step_cnt := 0;\r
+            spr_step_cnt := 0;\r
+            dma_step_cnt := 0;\r
+            scl_step_cnt := 0;\r
+            enable_ppu_step_cnt := 0;\r
+            nmi_step_cnt := 0;\r
+            nmi_oam_x := 0;\r
+            nmi_scl_y := 200;\r
+            ref_cnt := 0;\r
+\r
+        elsif (rising_edge(pi_base_clk)) then\r
+            if (pi_cpu_en(0) = '1') then\r
+            if (pi_rdy = '1') then\r
+                if (init_done = '0') then\r
+                    if (global_step_cnt = 0) then\r
+                        --step0.0 = init ppu.\r
+                        if (init_step_cnt = 0 * cpu_io_multi) then\r
+                            --PPUCTRL=01 for test...\r
+                            io_out(16#2000#, 16#01#);\r
+                        elsif (init_step_cnt = 1 * cpu_io_multi) then\r
+                            --PPUMASK=02\r
+                            io_out(16#2001#, 16#02#);\r
+                        elsif (init_step_cnt = 2 * cpu_io_multi) then\r
+                            --PPUCTRL=00\r
+                            io_out(16#2000#, 16#00#);\r
+                        elsif (init_step_cnt = 3 * cpu_io_multi) then\r
+                            --PPUMASK=00\r
+                            io_out(16#2001#, 16#00#);\r
+                        elsif (init_step_cnt = 4 * cpu_io_multi) then\r
+                            --ppuaddr\r
+                            io_out(16#2006#, 16#02#);\r
+                        elsif (init_step_cnt = 5 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#40#);\r
+                        elsif (init_step_cnt = 6 * cpu_io_multi) then\r
+                            --scroll\r
+                            io_out(16#2005#, 16#21#);\r
+                        elsif (init_step_cnt = 7 * cpu_io_multi) then\r
+                            io_out(16#2005#, 16#5#);\r
+                        else\r
+                            io_brk;\r
+                            if (init_step_cnt > 8 * cpu_io_multi) then\r
+                                global_step_cnt := global_step_cnt + 1;\r
+                            end if;\r
+                        end if;\r
+                        init_step_cnt := init_step_cnt + 1;\r
+                    elsif (global_step_cnt = 1) then\r
+                        --step0.1 = palette set.\r
+    --palettes:\r
+    --;;;bg palette\r
+    -- .byte   $0f, $00, $10, $20\r
+    -- .byte   $0f, $04, $14, $24\r
+    -- .byte   $0f, $08, $18, $28\r
+    -- .byte   $0f, $0c, $1c, $2c\r
+    --;;;spr palette\r
+    -- .byte   $0f, $00, $10, $20\r
+    -- .byte   $0f, $06, $16, $26\r
+    -- .byte   $0f, $08, $18, $28\r
+    -- .byte   $0f, $0a, $1a, $2a\r
+                        \r
+                        \r
+                        if (plt_step_cnt = 0 * cpu_io_multi) then\r
+                            --set vram addr 3f00\r
+                            io_out(16#2006#, 16#3f#);\r
+                        elsif (plt_step_cnt = 1 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#00#);\r
+                        \r
+                        elsif (plt_step_cnt = 2 * cpu_io_multi) then\r
+                            --set palette bg data\r
+                            io_out(16#2007#, 16#11#);\r
+                        elsif (plt_step_cnt = 3 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#01#);\r
+                        elsif (plt_step_cnt = 4 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#03#);\r
+                        elsif (plt_step_cnt = 5 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#13#);\r
+\r
+                        elsif (plt_step_cnt = 6 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#0f#);\r
+                        elsif (plt_step_cnt = 7 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#04#);\r
+                        elsif (plt_step_cnt = 8 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#14#);\r
+                        elsif (plt_step_cnt = 9 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#24#);\r
+     \r
+                        elsif (plt_step_cnt = 10 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#0f#);\r
+                        elsif (plt_step_cnt = 11 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#08#);\r
+                        elsif (plt_step_cnt = 12 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#18#);\r
+                        elsif (plt_step_cnt = 13 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#28#);\r
+     \r
+                        elsif (plt_step_cnt = 14 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#05#);\r
+                        elsif (plt_step_cnt = 15 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#0c#);\r
+                        elsif (plt_step_cnt = 16 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#1c#);\r
+                        elsif (plt_step_cnt = 17 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#2c#);\r
+\r
+                         elsif (plt_step_cnt = 18 * cpu_io_multi) then\r
+                            --below is sprite pallete\r
+                            io_out(16#2007#, 16#00#);\r
+                        elsif (plt_step_cnt = 19 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#24#);\r
+                        elsif (plt_step_cnt = 20 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#1b#);\r
+                        elsif (plt_step_cnt = 21 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#11#);\r
+\r
+                        elsif (plt_step_cnt = 22 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#00#);\r
+                        elsif (plt_step_cnt = 23 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#32#);\r
+                        elsif (plt_step_cnt = 24 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#16#);\r
+                        elsif (plt_step_cnt = 25 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#20#);\r
+\r
+                        elsif (plt_step_cnt = 26 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#00#);\r
+                        elsif (plt_step_cnt = 27 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#26#);\r
+                        elsif (plt_step_cnt = 28 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#01#);\r
+                        elsif (plt_step_cnt = 29 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#31#);\r
+\r
+                        else\r
+                            io_brk;\r
+                            if (plt_step_cnt > 30 * cpu_io_multi) then\r
+                                global_step_cnt := global_step_cnt + 1;\r
+                            end if;\r
+                        end if;\r
+                        plt_step_cnt := plt_step_cnt + 1;\r
+                        \r
+                    elsif (global_step_cnt = 2) then\r
+                        --step1 = name table set.\r
+                        if (nt_step_cnt = 0 * cpu_io_multi) then\r
+                            --set vram addr 2005 (first row, 6th col)\r
+                            io_out(16#2006#, 16#20#);\r
+                        elsif (nt_step_cnt = 1 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#08#);\r
+                        elsif (nt_step_cnt = 2 * cpu_io_multi) then\r
+                            --set name tbl data\r
+                            --0x44, 45, 45 = DEM\r
+                            io_out(16#2007#, 16#44#);\r
+                        elsif (nt_step_cnt = 3 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#45#);\r
+                        elsif (nt_step_cnt = 4 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#4d#);\r
+\r
+\r
+                        elsif (nt_step_cnt = 5 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#20#);\r
+                        elsif (nt_step_cnt = 6 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#2a#);\r
+                        elsif (nt_step_cnt = 7 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#44#);\r
+\r
+                        elsif (nt_step_cnt = 8 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#24#);\r
+                        elsif (nt_step_cnt = 9 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#43#);\r
+                        elsif (nt_step_cnt = 10 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#6d#);\r
+                        elsif (nt_step_cnt = 11 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#6f#);\r
+                        elsif (nt_step_cnt = 12 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#74#);\r
+                        elsif (nt_step_cnt = 13 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#6f#);\r
+                            \r
+                        elsif (nt_step_cnt = 14 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#2e#);\r
+                        elsif (nt_step_cnt = 15 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#93#);\r
+                        elsif (nt_step_cnt = 16 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#59#);\r
+\r
+                        elsif (nt_step_cnt = 17 * cpu_io_multi) then\r
+                            io_out(16#2007#, 16#00#);\r
+\r
+                        else\r
+                            io_brk;\r
+                            if (nt_step_cnt > 4 * cpu_io_multi) then\r
+                                global_step_cnt := global_step_cnt + 1;\r
+                            end if;\r
+                        end if;\r
+                        \r
+                        nt_step_cnt := nt_step_cnt + 1;\r
+                        \r
+                    elsif (global_step_cnt = 3) then\r
+                        --step2 = sprite set.\r
+                        if (spr_step_cnt = 0) then\r
+                            --set sprite addr=00 (first sprite)\r
+                            io_out(16#2003#, 16#00#);\r
+                        \r
+                        elsif (spr_step_cnt = 1 * cpu_io_multi) then\r
+                            --set sprite data: y=02\r
+                            io_out(16#2004#, 16#05#);\r
+                        elsif (spr_step_cnt = 2 * cpu_io_multi) then\r
+                            --tile=0x4d (ascii 'O')\r
+                            io_out(16#2004#, 16#4f#);\r
+                        elsif (spr_step_cnt = 3 * cpu_io_multi) then\r
+                            --set sprite attr=01 (palette 01)\r
+                            io_out(16#2004#, 16#01#);\r
+                        elsif (spr_step_cnt = 4 * cpu_io_multi) then\r
+                            --set sprite data: x=60\r
+                            io_out(16#2004#, 16#3c#);\r
+\r
+                        elsif (spr_step_cnt = 5 * cpu_io_multi) then\r
+                            --set sprite data: y=50\r
+                            io_out(16#2004#, 1);\r
+                        elsif (spr_step_cnt = 6 * cpu_io_multi) then\r
+                            --tile=0x4f (ascii 'M')\r
+                            io_out(16#2004#, 16#4d#);\r
+                        elsif (spr_step_cnt = 7 * cpu_io_multi) then\r
+                            --set sprite attr=02\r
+                            io_out(16#2004#, 16#02#);\r
+                        elsif (spr_step_cnt = 8 * cpu_io_multi) then\r
+                            --set sprite data: x=100\r
+                            io_out(16#2004#, 16#64#);\r
+\r
+                        elsif (spr_step_cnt = 9 * cpu_io_multi) then\r
+                            --set sprite data: y=60\r
+                            io_out(16#2004#, 60);\r
+                        elsif (spr_step_cnt = 10 * cpu_io_multi) then\r
+                            --tile=0x4d (ascii 'P')\r
+                            io_out(16#2004#, 16#50#);\r
+                        elsif (spr_step_cnt = 11 * cpu_io_multi) then\r
+                            --set sprite attr=01\r
+                            io_out(16#2004#, 16#01#);\r
+                        elsif (spr_step_cnt = 12 * cpu_io_multi) then\r
+                            --set sprite data: x=33\r
+                            io_out(16#2004#, 16#21#);\r
+\r
+                        elsif (spr_step_cnt = 13 * cpu_io_multi) then\r
+                            --set sprite data: y=61\r
+                            io_out(16#2004#, 16#3d#);\r
+                        elsif (spr_step_cnt = 14 * cpu_io_multi) then\r
+                            --tile=0x4d (ascii 'Q')\r
+                            io_out(16#2004#, 16#51#);\r
+                        elsif (spr_step_cnt = 15 * cpu_io_multi) then\r
+                            --set sprite attr=02\r
+                            io_out(16#2004#, 16#02#);\r
+                        elsif (spr_step_cnt = 16 * cpu_io_multi) then\r
+                            --set sprite data: x=45\r
+                            io_out(16#2004#, 45);\r
+\r
+                        else\r
+                            io_brk;\r
+                            if (spr_step_cnt > 8 * cpu_io_multi) then\r
+                                global_step_cnt := global_step_cnt + 2;\r
+                            end if;\r
+                        end if;\r
+                        spr_step_cnt := spr_step_cnt + 1;\r
+\r
+                    elsif (global_step_cnt = 4) then\r
+                        --step3 = dma set.\r
+--                        for i in 0 to 64 loop\r
+--                            j := i * 4;\r
+--                            if (ch = 16#5b#) then\r
+--                                ch := 16#41#;\r
+--                            else\r
+--                                ch := 16#41# + i;\r
+--                            end if;\r
+--\r
+--                            --if (i < 64) then\r
+--                            if (i < 10) then\r
+--                                --set dma value on the ram.\r
+--                                if    (dma_step_cnt = (0 + j) * cpu_io_multi) then\r
+--                                    io_out(16#0200# + j, i);\r
+--                                elsif (dma_step_cnt = (1 + j) * cpu_io_multi) then\r
+--                                    io_out(16#0201# + j, ch);\r
+--                                elsif (dma_step_cnt = (2 + j) * cpu_io_multi) then\r
+--                                    io_out(16#0202# + j, 16#01#);\r
+--                                elsif (dma_step_cnt = (3 + j) * cpu_io_multi) then\r
+--                                    io_out(16#0203# + j, j);\r
+--                                elsif (dma_step_cnt = (0 + j) * cpu_io_multi + 1) or\r
+--                                        (dma_step_cnt = (1 + j) * cpu_io_multi + 1) or\r
+--                                        (dma_step_cnt = (2 + j) * cpu_io_multi + 1) or\r
+--                                        (dma_step_cnt = (3 + j) * cpu_io_multi + 1) then\r
+--                                    io_brk;\r
+--                                end if;\r
+--                            else\r
+--                                if    (dma_step_cnt = (0 + j) * cpu_io_multi) then\r
+--                                    --start dma\r
+--                                    io_out(16#4014#, 16#02#);\r
+--                                elsif (dma_step_cnt = (0 + j) * cpu_io_multi + 1) then\r
+--                                    io_brk;\r
+--                                elsif (dma_step_cnt = (0 + j) * cpu_io_multi + 2) then\r
+                                    io_brk;\r
+                                    global_step_cnt := global_step_cnt + 1;\r
+--                                end if;\r
+--                            end if;\r
+--                        end loop;\r
+--                        \r
+--                        dma_step_cnt := dma_step_cnt + 1;\r
+\r
+                    elsif (global_step_cnt = 5) then\r
+                        --step4 = scroll test and ppu reg read test.\r
+                        if (scl_step_cnt = 0) then\r
+                            --x scroll pos=123\r
+                            --io_out(16#2005#, 11);\r
+                            io_out(16#2005#, 0);\r
+                        elsif (scl_step_cnt = 1 * cpu_io_multi) then\r
+                            --y scroll pos=100\r
+                            io_out(16#2005#, 0);\r
+\r
+                        elsif (scl_step_cnt = 2 * cpu_io_multi) then\r
+                            --read status reg.\r
+                            io_read(16#2002#);\r
+\r
+                        elsif (scl_step_cnt = 3 * cpu_io_multi) then\r
+                            --read vram nt0.\r
+                            io_out(16#2006#, 16#20#);\r
+\r
+                        elsif (scl_step_cnt = 4 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#03#);\r
+\r
+                        elsif (scl_step_cnt = 5 * cpu_io_multi) then\r
+                            io_read(16#2007#);\r
+\r
+                        elsif (scl_step_cnt = 6 * cpu_io_multi) then\r
+                            --pattern tbl.\r
+                            io_out(16#2006#, 16#04#);\r
+\r
+                        elsif (scl_step_cnt = 7 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#d1#);\r
+\r
+                        elsif (scl_step_cnt = 8 * cpu_io_multi) then\r
+                            io_read(16#2007#);\r
+\r
+                        elsif (scl_step_cnt = 9 * cpu_io_multi) then\r
+                            --attr tbl.\r
+                            io_out(16#2006#, 16#23#);\r
+\r
+                        elsif (scl_step_cnt = 10 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#c0#);\r
+\r
+                        elsif (scl_step_cnt = 11 * cpu_io_multi) then\r
+                            --set attr first.\r
+                            io_out(16#2007#, 16#5a#);\r
+\r
+                        elsif (scl_step_cnt = 12 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#23#);\r
+\r
+                        elsif (scl_step_cnt = 13 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#c0#);\r
+\r
+                        elsif (scl_step_cnt = 14 * cpu_io_multi) then\r
+                            io_read(16#2007#);\r
+\r
+                        elsif (scl_step_cnt = 15 * cpu_io_multi) then\r
+                            --read palette tbl.\r
+                            io_out(16#2006#, 16#3f#);\r
+\r
+                        elsif (scl_step_cnt = 16 * cpu_io_multi) then\r
+                            io_out(16#2006#, 16#11#);\r
+\r
+                        elsif (scl_step_cnt = 17 * cpu_io_multi) then\r
+                            io_read(16#2007#);\r
+\r
+                        else\r
+                            io_brk;\r
+                            if (scl_step_cnt > 17 * cpu_io_multi) then\r
+                                global_step_cnt := global_step_cnt + 1;\r
+                            end if;\r
+                        end if;\r
+                        scl_step_cnt := scl_step_cnt + 1;\r
+\r
+                    elsif (global_step_cnt = 6) then\r
+                        --final step = enable ppu.\r
+                        if (enable_ppu_step_cnt = 0 * cpu_io_multi) then\r
+                            --show bg\r
+                            --PPUMASK=1e (show bg and sprite)\r
+                            --PPUMASK=0e (show bg only)\r
+                            io_out(16#2001#, 16#1e#);\r
+                        elsif (enable_ppu_step_cnt = 1 * cpu_io_multi) then\r
+                            --enable nmi\r
+                            --PPUCTRL=80\r
+                            io_out(16#2000#, 16#80#);\r
+                        else\r
+                            io_brk;\r
+                            if (enable_ppu_step_cnt > 1 * cpu_io_multi) then\r
+                                --skip nmi test at this momemnt..\r
+                                global_step_cnt := global_step_cnt + 3;\r
+                            end if;\r
+                        end if;\r
+                        enable_ppu_step_cnt := enable_ppu_step_cnt + 1;\r
+\r
+                    elsif (global_step_cnt = 7) then\r
+                        ----nmi tests.....\r
+                        if (pi_nmi_n = '0') then\r
+\r
+                            if (nmi_step_cnt = 0 * cpu_io_multi) then\r
+                                --set sprite addr=00 (first sprite)\r
+                                io_out(16#2003#, 16#03#);\r
+                            elsif (nmi_step_cnt = 1 * cpu_io_multi) then\r
+                                --set sprite data: x=100\r
+                                io_out(16#2004#, nmi_oam_x);\r
+                            elsif (nmi_step_cnt = 2 * cpu_io_multi) then\r
+                                --scroll x=0\r
+--                                io_out(16#2005#, nmi_scl_y);\r
+                                io_brk;\r
+                            elsif (nmi_step_cnt = 3 * cpu_io_multi) then\r
+                                --scroll y++\r
+--                                io_out(16#2005#, nmi_scl_y);\r
+                                io_brk;\r
+                            elsif (nmi_step_cnt = 4 * cpu_io_multi) then\r
+                                --set sprite addr=00 (first sprite)\r
+                                io_out(16#2003#, 16#04#);\r
+                            elsif (nmi_step_cnt = 5 * cpu_io_multi) then\r
+                                --set sprite data: x=100\r
+                                io_out(16#2004#, nmi_oam_x);\r
+                            else\r
+                                if (ref_cnt = 0) then\r
+                                    nmi_oam_x := nmi_oam_x + 1;\r
+                                end if;\r
+                                if (nmi_step_cnt mod 10 = 0) then\r
+                                    nmi_scl_y := nmi_scl_y + 1;\r
+                                end if;\r
+                                io_brk;\r
+                                if (nmi_step_cnt > 5 * cpu_io_multi) then\r
+                                    ref_cnt := ref_cnt + 1;\r
+                                    global_step_cnt := global_step_cnt + 1;\r
+                                end if;\r
+                            end if;\r
+                            nmi_step_cnt := nmi_step_cnt + 1;\r
+                        end if;\r
+                    elsif (global_step_cnt = 8) then\r
+                        ----back to nmi tests.....\r
+                        if (pi_nmi_n = '1') then\r
+                            nmi_step_cnt := 0;\r
+                            global_step_cnt := global_step_cnt - 1;\r
+                        end if;\r
+                    else\r
+                        io_brk;\r
+                        init_done := '1';\r
+                    end if;\r
+                else\r
+                    io_brk;\r
+                end if;--if (init_done = '0') then\r
+            else\r
+                reg_r_nw <= 'Z';\r
+                reg_addr <= (others => 'Z');\r
+                reg_d_out <= (others => 'Z');\r
+            end if;--if (rdy = '1') then\r
+            end if;--if (pi_cpu_en(0) = '1') then\r
+        end if; --if (rst_n = '0') then\r
+    end process;\r
+\r
+end rtl;\r
+\r