OSDN Git Service

work update
authorastoria-d <astoria-d@mail.goo.ne.jp>
Sat, 9 Jul 2016 17:12:12 +0000 (02:12 +0900)
committerastoria-d <astoria-d@mail.goo.ne.jp>
Sat, 9 Jul 2016 17:12:12 +0000 (02:12 +0900)
de1_nes/de1_nes.vhd
de1_nes/dummy-mos6502.vhd
de1_nes/ppu/vga_ppu.vhd
de1_nes/simulation/modelsim/de1_nes_run_msim_gate_vhdl.do
doc/mos6502-ppu.xlsx

index 77f0401..4d4bfd3 100644 (file)
@@ -478,8 +478,6 @@ begin
     dbg_vram_a  <= vram_a ;\r
 \r
     dbg_sp(7 downto 6) <= dbg_ppu_clk_cnt;\r
-    dbg_sp(5 downto 0) <= v_addr (13 downto 8);\r
-    dbg_x <= v_addr (7 downto 0);\r
 \r
     dbg_nmi <= nmi_n;\r
 --    nmi_n <= dummy_nmi;\r
index 38a360f..a12baa5 100644 (file)
@@ -58,6 +58,8 @@ begin
     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
     r_nw <= '0';\r
@@ -90,6 +92,7 @@ end;
             nmi_step_cnt := 0;\r
             nmi_oam_x := 0;\r
             nmi_scl_y := 200;\r
+            ref_cnt := 0;\r
 \r
         elsif (rising_edge(input_clk)) then\r
 \r
@@ -267,7 +270,7 @@ end;
                             io_out(16#2003#, 16#00#);\r
                         elsif (spr_step_cnt = 1 * cpu_io_multi) then\r
                             --set sprite data: y=02\r
-                            io_out(16#2004#, 16#13#);\r
+                            io_out(16#2004#, 16#01#);\r
                         elsif (spr_step_cnt = 2 * cpu_io_multi) then\r
                             --tile=0x4d (ascii 'M')\r
                             io_out(16#2004#, 16#4d#);\r
@@ -419,12 +422,15 @@ end;
                                 --scroll y++\r
 --                                io_out(16#2005#, nmi_scl_y);\r
                             else\r
-                                nmi_oam_x := nmi_oam_x + 1;\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 > 3 * 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
index e60f634..75d2d73 100644 (file)
@@ -216,7 +216,9 @@ signal nes_y        : std_logic_vector (8 downto 0);
 ------- render instance ----------------\r
 \r
 --vram i/o\r
-signal io_oe_n          : std_logic;\r
+signal io_cnt_rst_n     : std_logic;\r
+signal io_cnt           : std_logic_vector(0 downto 0);\r
+signal al_oe_n          : std_logic;\r
 signal ah_oe_n          : std_logic;\r
 \r
 --bg prefetch position (scroll + 16 cycle ahead of current pos)\r
@@ -275,7 +277,6 @@ signal s_oam_data           : std_logic_vector (dsize - 1 downto 0);
 \r
 signal p_oam_cnt_res_n  : std_logic;\r
 signal p_oam_cnt_ce_n   : std_logic;\r
-signal p_oam_cnt_wrap_n : std_logic;\r
 signal p_oam_cnt        : std_logic_vector (dsize - 1 downto 0);\r
 signal p_oam_addr_in    : std_logic_vector (dsize - 1 downto 0);\r
 signal oam_ev_status    : std_logic_vector (2 downto 0);\r
@@ -484,26 +485,31 @@ begin
     -----------------------------------------\r
     ---vram access signals\r
     -----------------------------------------\r
+    io_cnt_rst_n <= '0' when nes_x = conv_std_logic_vector(VGA_W_MAX / 2, X_SIZE) else \r
+                    '1';\r
+    io_cnt_inst : counter_register generic map (1, 1)\r
+            port map (emu_ppu_clk, io_cnt_rst_n, '0', '1', (others => '0'), io_cnt);\r
+\r
     ale <= \r
-           nes_x(0) when (\r
+           not io_cnt(0) when (\r
                 ((ppu_mask(PPUSBG) = '1' or ppu_mask(PPUSSP) = '1') and\r
                 (nes_y < conv_std_logic_vector(VSCAN, X_SIZE) or \r
                 nes_y = conv_std_logic_vector(VSCAN_NEXT_START, X_SIZE)))) else\r
            'Z';\r
     rd_n <= \r
-           nes_x(0) when (\r
+           not io_cnt(0) when (\r
                 ((ppu_mask(PPUSBG) = '1' or ppu_mask(PPUSSP) = '1') and\r
                 (nes_y < conv_std_logic_vector(VSCAN, X_SIZE) or \r
                 nes_y = conv_std_logic_vector(VSCAN_NEXT_START, X_SIZE)))) else\r
             'Z';\r
     wr_n <= \r
-            '0' when (\r
+            '1' when (\r
                 ((ppu_mask(PPUSBG) = '1' or ppu_mask(PPUSSP) = '1') and\r
                 (nes_y < conv_std_logic_vector(VSCAN, X_SIZE) or \r
                 nes_y = conv_std_logic_vector(VSCAN_NEXT_START, X_SIZE)))) else\r
             'Z';\r
-    io_oe_n <= \r
-           not nes_x(0) when (\r
+    al_oe_n <= \r
+           io_cnt(0) when (\r
                 ((ppu_mask(PPUSBG) = '1' or ppu_mask(PPUSSP) = '1') and\r
                 (nes_y < conv_std_logic_vector(VSCAN, X_SIZE) or \r
                 nes_y = conv_std_logic_vector(VSCAN_NEXT_START, X_SIZE)))) else\r
@@ -516,6 +522,14 @@ begin
             '1';\r
     v_bus_busy_n <= ah_oe_n;\r
 \r
+    -----------------------------------------\r
+    --vram i/o\r
+    -----------------------------------------\r
+    vram_io_buf : tri_state_buffer generic map (dsize)\r
+            port map (al_oe_n, vram_addr(dsize - 1 downto 0), vram_ad);\r
+\r
+    vram_a_buf : tri_state_buffer generic map (6)\r
+            port map (ah_oe_n, vram_addr(asize - 1 downto dsize), vram_a);\r
 \r
     -----------------------------------------\r
     ---primary oam implementation...\r
@@ -616,15 +630,6 @@ begin
     end generate;\r
 \r
     -----------------------------------------\r
-    --vram i/o\r
-    -----------------------------------------\r
-    vram_io_buf : tri_state_buffer generic map (dsize)\r
-            port map (io_oe_n, vram_addr(dsize - 1 downto 0), vram_ad);\r
-\r
-    vram_a_buf : tri_state_buffer generic map (6)\r
-            port map (ah_oe_n, vram_addr(asize - 1 downto dsize), vram_a);\r
-\r
-    -----------------------------------------\r
     ---palette ram\r
     -----------------------------------------\r
     r_n <= not r_nw;\r
@@ -727,7 +732,6 @@ begin
             p_oam_cnt_res_n <= '1';\r
             p_oam_cnt_ce_n <= '1';\r
             s_oam_cnt_ce_n <= '1';\r
-            p_oam_cnt_wrap_n <= '1';\r
             oam_ev_status <= EV_STAT_COMP;\r
             p_oam_addr_in <= (others => 'Z');\r
 \r
@@ -766,7 +770,6 @@ begin
                         p_oam_cnt_res_n <= '0';\r
                         p_oam_cnt_ce_n <= '1';\r
                         s_oam_cnt_ce_n <= '1';\r
-                        p_oam_cnt_wrap_n <= '1';\r
                         oam_ev_status <= EV_STAT_COMP;\r
 \r
                     --sprite evaluation and secondary oam copy.\r
@@ -774,16 +777,9 @@ begin
                             nes_x <= conv_std_logic_vector(HSCAN, X_SIZE)) then\r
                         p_oam_cnt_res_n <= '1';\r
 \r
-                        --TODO: sprite evaluation is simplified!!\r
-                        --not complying the original NES spec at\r
-                        --http://wiki.nesdev.com/w/index.php/PPU_sprite_evaluation\r
-                        --e.g., when overflow happens, it just ignore subsequent entry.\r
-                        if (p_oam_cnt = "00000000" and nes_x > conv_std_logic_vector(192, X_SIZE)) then\r
-                            p_oam_cnt_wrap_n <= '0';\r
-                        end if;\r
-\r
                         --odd cycle copy from primary oam\r
                         if (nes_x(0) = '1') then\r
+                            s_oam_w_n <= '1';\r
                             if (oam_ev_status = EV_STAT_COMP) then\r
                                 p_oam_addr_in <= p_oam_cnt;\r
                                 p_oam_cnt_ce_n <= '1';\r
@@ -804,44 +800,52 @@ begin
                         else\r
                         --even cycle copy to secondary oam (if y is in range.)\r
                             s_oam_r_n <= '1';\r
-                            if (p_oam_cnt_wrap_n <= '1') then\r
-                                s_oam_w_n <= '0';\r
-                            else\r
-                                s_oam_w_n <= '1';\r
-                            end if;\r
-                            s_oam_addr <= s_oam_cnt;\r
-                            s_oam_data <= p_oam_data;\r
 \r
-                            if (oam_ev_status = EV_STAT_COMP) then\r
-                                --check y range.\r
-                                if (nes_y < "000000110" and p_oam_data <= nes_y + "000000001") or \r
-                                    (nes_y >= "000000110" and p_oam_data <= nes_y + "000000001" and \r
-                                             p_oam_data >= nes_y - "000000110") then\r
-                                    oam_ev_status <= EV_STAT_CP1;\r
-                                    s_oam_cnt_ce_n <= '0';\r
-                                    --copy remaining oam entry.\r
-                                    p_oam_cnt_ce_n <= '1';\r
-                                    \r
-                                    --check sprite 0 is used.\r
-                                    if (p_oam_cnt = "00000000") then\r
-                                        sprite0_evaluated <= '1';\r
+                            --TODO: sprite evaluation is simplified!!\r
+                            --not complying the original NES spec at\r
+                            --http://wiki.nesdev.com/w/index.php/PPU_sprite_evaluation\r
+                            --e.g., when overflow happens, it just ignore subsequent entry.\r
+                            if (s_oam_cnt = "00000" and nes_x > conv_std_logic_vector(HSCAN_OAM_EVA_START + 2, X_SIZE)) then\r
+                                s_oam_cnt_ce_n <= '1';\r
+                                s_oam_w_n <= '1';\r
+                                s_oam_addr <= (others => 'Z');\r
+                                s_oam_data <= (others => 'Z');\r
+                            else\r
+                                s_oam_w_n <= '0';\r
+                                s_oam_addr <= s_oam_cnt;\r
+                                s_oam_data <= p_oam_data;\r
+\r
+                                if (oam_ev_status = EV_STAT_COMP) then\r
+                                    --check y range.\r
+                                    if (nes_y < "000000110" and p_oam_data <= nes_y + "000000001") or \r
+                                        (nes_y >= "000000110" and p_oam_data <= nes_y + "000000001" and \r
+                                                 p_oam_data >= nes_y - "000000110") then\r
+                                        oam_ev_status <= EV_STAT_CP1;\r
+                                        s_oam_cnt_ce_n <= '0';\r
+                                        --copy remaining oam entry.\r
+                                        p_oam_cnt_ce_n <= '1';\r
+                                        \r
+                                        --check sprite 0 is used.\r
+                                        if (p_oam_cnt = "00000000") then\r
+                                            sprite0_evaluated <= '1';\r
+                                        end if;\r
+                                    else\r
+                                        --goto next entry\r
+                                        p_oam_cnt_ce_n <= '0';\r
                                     end if;\r
-                                else\r
-                                    --goto next entry\r
+                                elsif (oam_ev_status = EV_STAT_CP1) then\r
+                                    s_oam_cnt_ce_n <= '0';\r
+                                    oam_ev_status <= EV_STAT_CP2;\r
+                                elsif (oam_ev_status = EV_STAT_CP2) then\r
+                                    s_oam_cnt_ce_n <= '0';\r
+                                    oam_ev_status <= EV_STAT_CP3;\r
+                                elsif (oam_ev_status = EV_STAT_CP3) then\r
+                                    s_oam_cnt_ce_n <= '0';\r
+                                elsif (oam_ev_status = EV_STAT_PRE_COMP) then\r
+                                    oam_ev_status <= EV_STAT_COMP;\r
+                                    s_oam_cnt_ce_n <= '0';\r
                                     p_oam_cnt_ce_n <= '0';\r
                                 end if;\r
-                            elsif (oam_ev_status = EV_STAT_CP1) then\r
-                                s_oam_cnt_ce_n <= '0';\r
-                                oam_ev_status <= EV_STAT_CP2;\r
-                            elsif (oam_ev_status = EV_STAT_CP2) then\r
-                                s_oam_cnt_ce_n <= '0';\r
-                                oam_ev_status <= EV_STAT_CP3;\r
-                            elsif (oam_ev_status = EV_STAT_CP3) then\r
-                                s_oam_cnt_ce_n <= '0';\r
-                            elsif (oam_ev_status = EV_STAT_PRE_COMP) then\r
-                                oam_ev_status <= EV_STAT_COMP;\r
-                                s_oam_cnt_ce_n <= '0';\r
-                                p_oam_cnt_ce_n <= '0';\r
                             end if;\r
                         end if;--if (nes_x(0) = '1') then\r
 \r
@@ -944,7 +948,7 @@ begin
                     elsif (nes_x > conv_std_logic_vector(HSCAN_SPR_MAX, X_SIZE)) then\r
                         --clear last write enable.\r
                         spr_ptn_h_we_n <= "11111111";\r
-                    end if;--if (nes_x /= "000000000" and nes_x <= conv_std_logic_vector(HSCAN_OAM_EVA_START, X_SIZE))\r
+                    end if;--if (nes_x <= conv_std_logic_vector(HSCAN_OAM_EVA_START, X_SIZE))\r
 \r
                     --display sprite.\r
                     if ((nes_x < conv_std_logic_vector(HSCAN, X_SIZE)) and\r
index f092f50..dacbc62 100644 (file)
@@ -81,7 +81,8 @@ add wave -label rd_n sim:/testbench_motones_sim/sim_board/dbg_ppu_scrl_x(1)
 add wave -label wr_n sim:/testbench_motones_sim/sim_board/dbg_ppu_scrl_x(2)\r
 #add wave -label nt0_ce_n sim:/testbench_motones_sim/sim_board/dbg_ppu_scrl_x(3)\r
 \r
-add wave  -radix hex -label v_addr {sim:/testbench_motones_sim/sim_board/dbg_sp(5 downto 0)}\r
+add wave  -radix hex -label v_addr  {sim:/testbench_motones_sim/sim_board/dbg_vram_a(13 downto 8) & \r
+                                     sim:/testbench_motones_sim/sim_board/dbg_vram_ad(7 downto 0)}\r
 add wave  -radix hex -label vram_ad sim:/testbench_motones_sim/sim_board/dbg_vram_ad\r
 \r
 #add wave -label plt_ce_n sim:/testbench_motones_sim/sim_board/dbg_ppu_scrl_y(5)\r
@@ -116,8 +117,8 @@ wave zoom full
 \r
 #wave zoom range 3339700 ps 5138320 ps\r
 \r
-run 100 us\r
-run 30 us\r
+run 850 us\r
+#run 30 us\r
 \r
 ##wave addcursor 907923400 ps\r
 \r
index 1c5ea64..a479669 100644 (file)
Binary files a/doc/mos6502-ppu.xlsx and b/doc/mos6502-ppu.xlsx differ