-----------------------------------------\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
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
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
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