OSDN Git Service

sprite ok on the test rom.
authorastoria-d <astoria-d@mail.goo.ne.jp>
Sun, 10 Jul 2016 12:46:59 +0000 (21:46 +0900)
committerastoria-d <astoria-d@mail.goo.ne.jp>
Sun, 10 Jul 2016 12:46:59 +0000 (21:46 +0900)
de1_nes/ppu/vga_ppu.vhd
de1_nes/simulation/modelsim/de1_nes_run_msim_gate_vhdl.do
doc/mos6502-ppu.xlsx

index 75d2d73..4133873 100644 (file)
@@ -485,19 +485,30 @@ 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
+    reset_p : process (rst_n, emu_ppu_clk)\r
+    begin\r
+        if (rst_n = '0') then\r
+            io_cnt_rst_n <= '0';\r
+        else\r
+            if (rising_edge(emu_ppu_clk)) then\r
+                if (nes_x >= conv_std_logic_vector(VGA_W_MAX / 2 - 1, X_SIZE)) then io_cnt_rst_n <= '0';\r
+                else io_cnt_rst_n <= '1';\r
+                end if; \r
+            end if;\r
+        end if;\r
+    end process;\r
+\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
-           not io_cnt(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
+            'Z';\r
     rd_n <= \r
-           not io_cnt(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
@@ -509,7 +520,7 @@ begin
                 nes_y = conv_std_logic_vector(VSCAN_NEXT_START, X_SIZE)))) else\r
             'Z';\r
     al_oe_n <= \r
-           io_cnt(0) when (\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
@@ -897,42 +908,14 @@ begin
                             spr_x_we_n(conv_integer(s_oam_addr_cpy(4 downto 2))) <= '1';\r
                         end if;\r
 \r
-                        ----fetch pattern table low byte.\r
-                        if (nes_x (2 downto 0) = "101" ) then\r
-                            if (spr_attr(conv_integer(s_oam_addr_cpy(4 downto 2)))(SPRVFL) = '0') then\r
-                                vram_addr <= "0" & ppu_ctrl(PPUSPA) & \r
-                                            spr_tile_tmp(dsize - 1 downto 0) & "0" & \r
-                                            (nes_y(2 downto 0) + "001" - spr_y_tmp(2 downto 0));\r
-                            else\r
-                                --flip sprite vertically.\r
-                                vram_addr <= "0" & ppu_ctrl(PPUSPA) & \r
-                                            spr_tile_tmp(dsize - 1 downto 0) & "0" & \r
-                                            (spr_y_tmp(2 downto 0) - nes_y(2 downto 0) - "010");\r
-                            end if;\r
-                        end if;\r
-\r
+                        --pattern tbl low vale.\r
                         if (nes_x (2 downto 0) = "110" ) then\r
                             spr_ptn_l_we_n(conv_integer(s_oam_addr_cpy(4 downto 2))) <= '0';\r
                         else\r
                             spr_ptn_l_we_n(conv_integer(s_oam_addr_cpy(4 downto 2))) <= '1';\r
                         end if;\r
 \r
-                        ----fetch pattern table high byte.\r
-                        if (nes_x (2 downto 0) = "111" ) then\r
-                            if (spr_attr(conv_integer(s_oam_addr_cpy(4 downto 2)))(SPRVFL) = '0') then\r
-                                vram_addr <= "0" & ppu_ctrl(PPUSPA) & \r
-                                            spr_tile_tmp(dsize - 1 downto 0) & "0" & \r
-                                            (nes_y(2 downto 0) + "001" - spr_y_tmp(2 downto 0))\r
-                                                + "00000000001000";\r
-                            else\r
-                                --flip sprite vertically.\r
-                                vram_addr <= "0" & ppu_ctrl(PPUSPA) & \r
-                                            spr_tile_tmp(dsize - 1 downto 0) & "0"  & \r
-                                            (spr_y_tmp(2 downto 0) - nes_y(2 downto 0) - "010")\r
-                                                + "00000000001000";\r
-                            end if;\r
-                        end if;\r
-\r
+                        --pattern tbl high vale.\r
                         if (nes_x (2 downto 0) = "000") then\r
                             spr_ptn_h_we_n(conv_integer(s_oam_addr_cpy(4 downto 2))) <= '0';\r
                             s_oam_addr_cpy_ce_n <= '0';\r
@@ -982,6 +965,64 @@ begin
         end if;--if (rst_n = '0') then\r
     end process;\r
 \r
+    vaddr_p : process (rst_n, emu_ppu_clk)\r
+    begin\r
+        if (rst_n = '0') then\r
+            vram_addr <= (others => 'Z');\r
+        else\r
+            if (rising_edge(emu_ppu_clk)) then\r
+                --fetch sprite and display.\r
+                if (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))) then\r
+\r
+                    --sprite pattern fetch.\r
+                    if (nes_x > conv_std_logic_vector(HSCAN, X_SIZE) and \r
+                        nes_x <= conv_std_logic_vector(HSCAN_SPR_MAX, X_SIZE)) then\r
+                        \r
+                        ----fetch pattern table low byte.\r
+                        if (nes_x (2 downto 0) = "101" ) then\r
+                            if (spr_attr(conv_integer(s_oam_addr_cpy(4 downto 2)))(SPRVFL) = '0') then\r
+                                vram_addr <= "0" & ppu_ctrl(PPUSPA) & \r
+                                            spr_tile_tmp(dsize - 1 downto 0) & "0" & \r
+                                            (nes_y(2 downto 0) + "001" - spr_y_tmp(2 downto 0));\r
+                            else\r
+                                --flip sprite vertically.\r
+                                vram_addr <= "0" & ppu_ctrl(PPUSPA) & \r
+                                            spr_tile_tmp(dsize - 1 downto 0) & "0" & \r
+                                            (spr_y_tmp(2 downto 0) - nes_y(2 downto 0) - "010");\r
+                            end if;\r
+                        \r
+                        ----fetch pattern table high byte.\r
+                        elsif (nes_x (2 downto 0) = "111" ) then\r
+                            if (spr_attr(conv_integer(s_oam_addr_cpy(4 downto 2)))(SPRVFL) = '0') then\r
+                                vram_addr <= "0" & ppu_ctrl(PPUSPA) & \r
+                                            spr_tile_tmp(dsize - 1 downto 0) & "0" & \r
+                                            (nes_y(2 downto 0) + "001" - spr_y_tmp(2 downto 0))\r
+                                                + "00000000001000";\r
+                            else\r
+                                --flip sprite vertically.\r
+                                vram_addr <= "0" & ppu_ctrl(PPUSPA) & \r
+                                            spr_tile_tmp(dsize - 1 downto 0) & "0"  & \r
+                                            (spr_y_tmp(2 downto 0) - nes_y(2 downto 0) - "010")\r
+                                                + "00000000001000";\r
+                            end if;\r
+                        end if;\r
+\r
+                    else\r
+                        vram_addr <= (others => 'Z');\r
+                    end if; --if (nes_x > conv_std_logic_vector(HSCAN, X_SIZE) and \r
+                                --nes_x <= conv_std_logic_vector(HSCAN_SPR_MAX, X_SIZE)) then\r
+\r
+                else\r
+                    vram_addr <= (others => 'Z');\r
+                end if; --if (ppu_mask(PPUSSP) = '1') \r
+                        --(nes_y < conv_std_logic_vector(VSCAN, X_SIZE) or \r
+                        --nes_y = conv_std_logic_vector(VSCAN_NEXT_START, X_SIZE))) then\r
+            end if; --if (rising_edge(emu_ppu_clk)) then\r
+        end if;--if (rst_n = '0') then\r
+    end process;\r
+\r
 \r
     output_p : process (rst_n, emu_ppu_clk)\r
 \r
index dacbc62..f3edaca 100644 (file)
@@ -117,7 +117,7 @@ wave zoom full
 \r
 #wave zoom range 3339700 ps 5138320 ps\r
 \r
-run 850 us\r
+run 120 us\r
 #run 30 us\r
 \r
 ##wave addcursor 907923400 ps\r
index a479669..94d9cd0 100644 (file)
Binary files a/doc/mos6502-ppu.xlsx and b/doc/mos6502-ppu.xlsx differ