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