diff --git a/src/a2600_top_tm138k_pro.vhd b/src/a2600_top_tm138k_pro.vhd index 352daf7..289a658 100644 --- a/src/a2600_top_tm138k_pro.vhd +++ b/src/a2600_top_tm138k_pro.vhd @@ -125,6 +125,9 @@ signal system_reset : std_logic_vector(1 downto 0); signal sd_img_size : std_logic_vector(31 downto 0); signal sd_img_size_d : std_logic_vector(31 downto 0); signal sd_img_mounted : std_logic_vector(4 downto 0); +signal img_present : std_logic; +signal sc_lock : std_logic; +signal force_bs_lock : std_logic_vector(4 downto 0); signal sd_rd : std_logic_vector(4 downto 0); signal sd_wr : std_logic_vector(4 downto 0); signal sd_lba : std_logic_vector(31 downto 0); @@ -228,6 +231,7 @@ signal p_start : std_logic; signal p_select : std_logic; signal vblank_regen : std_logic; signal force_bs : std_logic_vector(4 downto 0); +signal force_bs_i : std_logic_vector(4 downto 0); signal joystick0ax : signed(7 downto 0); signal joystick0ay : signed(7 downto 0); signal joystick1ax : signed(7 downto 0); @@ -565,20 +569,24 @@ begin end process; -- paddle pins -pd1 <= not paddle_1 when port_1_sel = "0100" else +pd1 <= not paddle_1 when port_1_sel = "0100" else + not paddle_3 when port_1_sel = "0111" else joystick1_x_pos when port_1_sel = "0001" else std_logic_vector(not mx(7) & mx(6 downto 0)) when port_1_sel = "0101" else x"ff"; -pd2 <= not paddle_2 when port_1_sel = "0100" else - joystick1_y_pos(7 downto 0) when port_1_sel = "0001" else +pd2 <= not paddle_2 when port_1_sel = "0100" else + not paddle_4 when port_1_sel = "0111" else + joystick1_y_pos when port_1_sel = "0001" else std_logic_vector(not my(7) & my(6 downto 0)) when port_1_sel = "0101" else x"ff"; -pd3 <= not paddle_3 when port_2_sel = "0100" else - joystick2_x_pos(7 downto 0) when port_2_sel = "0010" else +pd3 <= not paddle_3 when port_2_sel = "0111" else + not paddle_1 when port_2_sel = "0100" else + joystick2_x_pos when port_2_sel = "0010" else std_logic_vector(not mx(7) & mx(6 downto 0)) when port_2_sel = "0101" else x"ff"; -pd4 <= not paddle_4 when port_2_sel = "0100" else - joystick2_y_pos(7 downto 0) when port_2_sel = "0010" else +pd4 <= not paddle_4 when port_2_sel = "0111" else + not paddle_2 when port_2_sel = "0100" else + joystick2_y_pos when port_2_sel = "0010" else std_logic_vector(not my(7) & my(6 downto 0)) when port_2_sel = "0101" else x"ff"; @@ -862,16 +870,35 @@ port map( enable => ioctl_wr and cart_download, cart_size => img_size_crt, data => dl_data, - force_bs => force_bs, + force_bs => force_bs_i, sc => scdetect ); +force_bs <= force_bs_i when img_present = '1' else force_bs_lock; + pal <= '1' when system_video_std(1 downto 0) = 2 else '0' when system_video_std(1 downto 0) = 1 else paldetect; sc <= '1' when system_sc(1 downto 0) = 2 else '0' when system_sc(1 downto 0) = 1 else - scdetect; + scdetect when img_present = '1' else + sc_lock; + +process(clk, pll_locked) + begin + if pll_locked = '0' then + sc_lock <= '0'; + force_bs_lock <= "00000"; + elsif rising_edge(clk) then + if sd_img_mounted(0) = '1' then + img_present <= '0' when sd_img_size = 0 else '1'; + sd_img_size_d <= sd_img_size; + elsif cart_download_d = '1' and cart_download = '0' then + sc_lock <= scdetect; + force_bs_lock <= force_bs_i; + end if; + end if; +end process; process(clk) begin diff --git a/src/a2600_top_tm60k.vhd b/src/a2600_top_tm60k.vhd index 0ceec17..7af9a41 100644 --- a/src/a2600_top_tm60k.vhd +++ b/src/a2600_top_tm60k.vhd @@ -126,6 +126,9 @@ signal system_reset : std_logic_vector(1 downto 0); signal sd_img_size : std_logic_vector(31 downto 0); signal sd_img_size_d : std_logic_vector(31 downto 0); signal sd_img_mounted : std_logic_vector(4 downto 0); +signal img_present : std_logic; +signal sc_lock : std_logic; +signal force_bs_lock : std_logic_vector(4 downto 0); signal sd_rd : std_logic_vector(4 downto 0); signal sd_wr : std_logic_vector(4 downto 0); signal sd_lba : std_logic_vector(31 downto 0); @@ -229,6 +232,7 @@ signal p_start : std_logic; signal p_select : std_logic; signal vblank_regen : std_logic; signal force_bs : std_logic_vector(4 downto 0); +signal force_bs_i : std_logic_vector(4 downto 0); signal joystick0ax : signed(7 downto 0); signal joystick0ay : signed(7 downto 0); signal joystick1ax : signed(7 downto 0); @@ -567,20 +571,24 @@ begin end process; -- paddle pins -pd1 <= not paddle_1 when port_1_sel = "0100" else +pd1 <= not paddle_1 when port_1_sel = "0100" else + not paddle_3 when port_1_sel = "0111" else joystick1_x_pos when port_1_sel = "0001" else std_logic_vector(not mx(7) & mx(6 downto 0)) when port_1_sel = "0101" else x"ff"; -pd2 <= not paddle_2 when port_1_sel = "0100" else - joystick1_y_pos(7 downto 0) when port_1_sel = "0001" else +pd2 <= not paddle_2 when port_1_sel = "0100" else + not paddle_4 when port_1_sel = "0111" else + joystick1_y_pos when port_1_sel = "0001" else std_logic_vector(not my(7) & my(6 downto 0)) when port_1_sel = "0101" else x"ff"; -pd3 <= not paddle_3 when port_2_sel = "0100" else - joystick2_x_pos(7 downto 0) when port_2_sel = "0010" else +pd3 <= not paddle_3 when port_2_sel = "0111" else + not paddle_1 when port_2_sel = "0100" else + joystick2_x_pos when port_2_sel = "0010" else std_logic_vector(not mx(7) & mx(6 downto 0)) when port_2_sel = "0101" else x"ff"; -pd4 <= not paddle_4 when port_2_sel = "0100" else - joystick2_y_pos(7 downto 0) when port_2_sel = "0010" else +pd4 <= not paddle_4 when port_2_sel = "0111" else + not paddle_2 when port_2_sel = "0100" else + joystick2_y_pos when port_2_sel = "0010" else std_logic_vector(not my(7) & my(6 downto 0)) when port_2_sel = "0101" else x"ff"; @@ -864,16 +872,35 @@ port map( enable => ioctl_wr and cart_download, cart_size => img_size_crt, data => dl_data, - force_bs => force_bs, + force_bs => force_bs_i, sc => scdetect ); +force_bs <= force_bs_i when img_present = '1' else force_bs_lock; + pal <= '1' when system_video_std(1 downto 0) = 2 else '0' when system_video_std(1 downto 0) = 1 else paldetect; sc <= '1' when system_sc(1 downto 0) = 2 else '0' when system_sc(1 downto 0) = 1 else - scdetect; + scdetect when img_present = '1' else + sc_lock; + +process(clk, pll_locked) + begin + if pll_locked = '0' then + sc_lock <= '0'; + force_bs_lock <= "00000"; + elsif rising_edge(clk) then + if sd_img_mounted(0) = '1' then + img_present <= '0' when sd_img_size = 0 else '1'; + sd_img_size_d <= sd_img_size; + elsif cart_download_d = '1' and cart_download = '0' then + sc_lock <= scdetect; + force_bs_lock <= force_bs_i; + end if; + end if; +end process; process(clk) begin diff --git a/src/a2600_top_tn20k.cst b/src/a2600_top_tn20k.cst index d6aa376..a6701f6 100644 --- a/src/a2600_top_tn20k.cst +++ b/src/a2600_top_tn20k.cst @@ -108,12 +108,12 @@ IO_LOC "ws2812" 79; IO_PORT "ws2812" PULL_MODE=DOWN IO_TYPE=LVCMOS33; // Joystick DS 2 -IO_LOC "joystick_clk" 52; -IO_PORT "joystick_clk" PULL_MODE=UP IO_TYPE=LVCMOS33; -IO_LOC "joystick_mosi" 53; -IO_PORT "joystick_mosi" PULL_MODE=UP IO_TYPE=LVCMOS33; -IO_LOC "joystick_miso" 71; -IO_PORT "joystick_miso" PULL_MODE=UP IO_TYPE=LVCMOS33; -IO_LOC "joystick_cs" 72; -IO_PORT "joystick_cs" PULL_MODE=UP IO_TYPE=LVCMOS33; +IO_LOC "ds_clk" 52; +IO_PORT "ds_clk" PULL_MODE=UP IO_TYPE=LVCMOS33; +IO_LOC "ds_mosi" 53; +IO_PORT "ds_mosi" PULL_MODE=UP IO_TYPE=LVCMOS33; +IO_LOC "ds_miso" 71; +IO_PORT "ds_miso" PULL_MODE=UP IO_TYPE=LVCMOS33; +IO_LOC "ds_cs" 72; +IO_PORT "ds_cs" PULL_MODE=UP IO_TYPE=LVCMOS33; diff --git a/src/a2600_top_tn20k.sdc b/src/a2600_top_tn20k.sdc index e6c8470..d9875a3 100644 --- a/src/a2600_top_tn20k.sdc +++ b/src/a2600_top_tn20k.sdc @@ -1,6 +1,5 @@ create_clock -name clk_27mhz -period 37.037 -waveform {0 5} [get_ports {clk_27mhz}] create_clock -name ds2_clk -period 8000 -waveform {0 5} [get_nets {gamepad/clk_spi}] -create_clock -name joymiso -period 8000 -waveform {0 20} [get_ports {joystick_miso}] create_clock -name clk -period 34.722 -waveform {0 5} [get_nets {clk}] create_clock -name clk_14 -period 70 -waveform {0 5} [get_nets {clk_14}] create_clock -name clk_cpu -period 279.408 -waveform {0 5} [get_nets {clk_cpu}] diff --git a/src/a2600_top_tn20k.vhd b/src/a2600_top_tn20k.vhd index e976f96..0a66763 100644 --- a/src/a2600_top_tn20k.vhd +++ b/src/a2600_top_tn20k.vhd @@ -34,11 +34,11 @@ entity A2600_top is sd_dat : inout std_logic_vector(3 downto 0); ws2812 : out std_logic; - -- Gamepad - joystick_clk : out std_logic; - joystick_mosi : out std_logic; - joystick_miso : inout std_logic; - joystick_cs : inout std_logic + -- Gamepad Dualshock P1 + ds_clk : out std_logic; + ds_mosi : out std_logic; + ds_miso : in std_logic; + ds_cs : out std_logic ); end; @@ -65,7 +65,8 @@ signal joyDigital : std_logic_vector(15 downto 0); signal joyNumpad : std_logic_vector(15 downto 0); signal joyMouse : std_logic_vector(15 downto 0); signal numpad : std_logic_vector(7 downto 0); -signal joyDS2 : std_logic_vector(15 downto 0); +signal joyDS2_p1 : std_logic_vector(15 downto 0); +signal joyDS2_p2 : std_logic_vector(15 downto 0); -- joystick interface signal joyA : std_logic_vector(15 downto 0); signal joyB : std_logic_vector(15 downto 0); @@ -118,6 +119,9 @@ signal system_reset : std_logic_vector(1 downto 0); signal sd_img_size : std_logic_vector(31 downto 0); signal sd_img_size_d : std_logic_vector(31 downto 0); signal sd_img_mounted : std_logic_vector(4 downto 0); +signal img_present : std_logic; +signal sc_lock : std_logic; +signal force_bs_lock : std_logic_vector(4 downto 0); signal sd_rd : std_logic_vector(4 downto 0); signal sd_wr : std_logic_vector(4 downto 0); signal sd_lba : std_logic_vector(31 downto 0); @@ -205,6 +209,7 @@ signal p_start : std_logic; signal p_select : std_logic; signal vblank_regen : std_logic; signal force_bs : std_logic_vector(4 downto 0); +signal force_bs_i : std_logic_vector(4 downto 0); signal joystick0ax : signed(7 downto 0); signal joystick0ay : signed(7 downto 0); signal joystick1ax : signed(7 downto 0); @@ -290,9 +295,6 @@ begin spi_io_clk <= m0s(3); m0s(0) <= spi_io_dout; -- M0 Dock -joystick_cs <= joystick_cs_i; -joystick_miso_i <= joystick_miso; - -- https://store.curiousinventor.com/guides/PS2/ -- https://hackaday.io/project/170365-blueretro/log/186471-playstation-playstation-2-spi-interface @@ -301,10 +303,10 @@ gamepad: entity work.dualshock2 clk => clk, rst => system_reset(0) and not pll_locked, vsync => vsync, - ds2_dat => joystick_miso_i, - ds2_cmd => joystick_mosi, - ds2_att => joystick_cs_i, - ds2_clk => joystick_clk, + ds2_dat => ds_miso, + ds2_cmd => ds_mosi, + ds2_att => ds_cs, + ds2_clk => ds_clk, ds2_ack => '0', stick_lx => paddle_1, stick_ly => paddle_2, @@ -565,9 +567,13 @@ leds(5 downto 1) <= "11111" when force_bs > 14 else "00000"; -- indicate unsuppo -- BTN_SR 9 -- BTN_SELECT 10 -- BTN_START 11 -joyDS2 <= key_rstick & key_lstick & key_r2 & key_l2 & key_start & key_select & key_r1 & key_l1 & + +-- single DS only ! 2nd port is identical to 1st one except paddle stick +joyDS2_p1 <= key_rstick & key_lstick & key_r2 & key_l2 & key_start & key_select & key_r1 & key_l1 & + key_square & key_triangle & key_cross & key_circle & key_up & key_down & key_left & key_right; +joyDS2_p2 <= key_rstick & key_lstick & key_r2 & key_l2 & key_start & key_select & key_r1 & key_l1 & key_square & key_triangle & key_cross & key_circle & key_up & key_down & key_left & key_right; -joyDigital <= not(x"FF" & "111" & io(0) & io(2) & io(1) & io(4) & io(3)); +joyDigital <= not(x"FF" & "111" & io(0) & io(2) & io(1) & io(4) & io(3)); joyUsb1 <= extra_button0 & joystick1(7 downto 4) & joystick1(3) & joystick1(2) & joystick1(1) & joystick1(0); joyUsb2 <= extra_button1 & joystick2(7 downto 4) & joystick2(3) & joystick2(2) & joystick2(1) & joystick2(0); joyNumpad <= x"00" & "000" & numpad(4) & numpad(3) & numpad(2) & numpad(1) & numpad(0); @@ -580,14 +586,17 @@ process(clk) begin if rising_edge(clk) then case port_1_sel is - when "0000" => joyA <= joyDigital; - when "0001" => joyA <= joyUsb1; - when "0010" => joyA <= joyUsb2; - when "0011" => joyA <= joyNumpad; - when "0100" => joyA <= joyDS2; - when "0101" => joyA <= joyMouse; - when "0110" => joyA <= (others => '0'); - when others => null; + when "0000" => joyA <= joyDigital;-- 0 + when "0001" => joyA <= joyUsb1; -- 1 + when "0010" => joyA <= joyUsb2; -- 2 + when "0011" => joyA <= joyNumpad; -- 3 + when "0100" => joyA <= joyDS2_p1; -- 4 + when "0101" => joyA <= joyMouse; -- 5 + when "0110" => joyA <= (others => '0'); --6 Off + when "0111" => joyA <= joyDS2_p2; -- 7 + when "1000" => joyA <= (others => '0'); -- 8 R #2 D9 PMOD + when "1001" => joyA <= (others => '0'); -- 9 R #2 D9 ALT + when others => joyA <= (others => '0'); end case; end if; end process; @@ -600,28 +609,36 @@ begin when "0001" => joyB <= joyUsb1; when "0010" => joyB <= joyUsb2; when "0011" => joyB <= joyNumpad; - when "0100" => joyB <= joyDS2; + when "0100" => joyB <= joyDS2_p1; when "0101" => joyB <= joyMouse; when "0110" => joyB <= (others => '0'); - when others => null; + when "0111" => joyB <= joyDS2_p2; + when "1000" => joyB <= (others => '0'); -- 8 R #2 D9 PMOD + when "1001" => joyB <= (others => '0'); -- 9 R #2 D9 ALT + when others => joyB <= (others => '0'); end case; end if; end process; -pd1 <= not paddle_1 when port_1_sel = "0100" else +-- paddle pins +pd1 <= not paddle_1 when port_1_sel = "0100" else + not paddle_3 when port_1_sel = "0111" else joystick1_x_pos when port_1_sel = "0001" else std_logic_vector(not mx(7) & mx(6 downto 0)) when port_1_sel = "0101" else x"ff"; -pd2 <= not paddle_2 when port_1_sel = "0100" else - joystick1_y_pos(7 downto 0) when port_1_sel = "0001" else +pd2 <= not paddle_2 when port_1_sel = "0100" else + not paddle_4 when port_1_sel = "0111" else + joystick1_y_pos when port_1_sel = "0001" else std_logic_vector(not my(7) & my(6 downto 0)) when port_1_sel = "0101" else x"ff"; -pd3 <= not paddle_3 when port_2_sel = "0100" else - joystick2_x_pos(7 downto 0) when port_2_sel = "0010" else +pd3 <= not paddle_3 when port_2_sel = "0111" else + not paddle_1 when port_2_sel = "0100" else + joystick2_x_pos when port_2_sel = "0010" else std_logic_vector(not mx(7) & mx(6 downto 0)) when port_2_sel = "0101" else x"ff"; -pd4 <= not paddle_4 when port_2_sel = "0100" else - joystick2_y_pos(7 downto 0) when port_2_sel = "0010" else +pd4 <= not paddle_4 when port_2_sel = "0111" else + not paddle_2 when port_2_sel = "0100" else + joystick2_y_pos when port_2_sel = "0010" else std_logic_vector(not my(7) & my(6 downto 0)) when port_2_sel = "0101" else x"ff"; @@ -905,16 +922,35 @@ port map( enable => ioctl_wr and cart_download, cart_size => img_size_crt, data => dl_data, - force_bs => force_bs, + force_bs => force_bs_i, sc => scdetect ); +force_bs <= force_bs_i when img_present = '1' else force_bs_lock; + pal <= '1' when system_video_std(1 downto 0) = 2 else '0' when system_video_std(1 downto 0) = 1 else paldetect; -sc <= '1' when system_sc(1 downto 0) = 2 else - '0' when system_sc(1 downto 0) = 1 else - scdetect; +sc <= '1' when system_sc(1 downto 0) = 2 else + '0' when system_sc(1 downto 0) = 1 else + scdetect when img_present = '1' else + sc_lock; + +process(clk, pll_locked) + begin + if pll_locked = '0' then + sc_lock <= '0'; + force_bs_lock <= "00000"; + elsif rising_edge(clk) then + if sd_img_mounted(0) = '1' then + img_present <= '0' when sd_img_size = 0 else '1'; + sd_img_size_d <= sd_img_size; + elsif cart_download_d = '1' and cart_download = '0' then + sc_lock <= scdetect; + force_bs_lock <= force_bs_i; + end if; + end if; +end process; process(clk) begin diff --git a/src/a2600_top_tn9k.vhd b/src/a2600_top_tn9k.vhd index 4710b0e..5b4eb2e 100644 --- a/src/a2600_top_tn9k.vhd +++ b/src/a2600_top_tn9k.vhd @@ -118,6 +118,9 @@ signal system_reset : std_logic_vector(1 downto 0); signal sd_img_size : std_logic_vector(31 downto 0); signal sd_img_size_d : std_logic_vector(31 downto 0); signal sd_img_mounted : std_logic_vector(4 downto 0); +signal img_present : std_logic; +signal sc_lock : std_logic; +signal force_bs_lock : std_logic_vector(4 downto 0); signal sd_rd : std_logic_vector(4 downto 0); signal sd_wr : std_logic_vector(4 downto 0); signal sd_lba : std_logic_vector(31 downto 0); @@ -205,6 +208,7 @@ signal p_start : std_logic; signal p_select : std_logic; signal vblank_regen : std_logic; signal force_bs : std_logic_vector(4 downto 0); +signal force_bs_i : std_logic_vector(4 downto 0); signal joystick0ax : signed(7 downto 0); signal joystick0ay : signed(7 downto 0); signal joystick1ax : signed(7 downto 0); @@ -587,7 +591,7 @@ begin when "0100" => joyA <= joyDS2; when "0101" => joyA <= joyMouse; when "0110" => joyA <= (others => '0'); - when others => null; + when others => joyA <= (others => '0'); end case; end if; end process; @@ -603,25 +607,30 @@ begin when "0100" => joyB <= joyDS2; when "0101" => joyB <= joyMouse; when "0110" => joyB <= (others => '0'); - when others => null; + when others => joyB <= (others => '0'); end case; end if; end process; -pd1 <= not paddle_1 when port_1_sel = "0100" else +-- paddle pins +pd1 <= not paddle_1 when port_1_sel = "0100" else + not paddle_3 when port_1_sel = "0111" else joystick1_x_pos when port_1_sel = "0001" else std_logic_vector(not mx(7) & mx(6 downto 0)) when port_1_sel = "0101" else x"ff"; -pd2 <= not paddle_2 when port_1_sel = "0100" else - joystick1_y_pos(7 downto 0) when port_1_sel = "0001" else +pd2 <= not paddle_2 when port_1_sel = "0100" else + not paddle_4 when port_1_sel = "0111" else + joystick1_y_pos when port_1_sel = "0001" else std_logic_vector(not my(7) & my(6 downto 0)) when port_1_sel = "0101" else x"ff"; -pd3 <= not paddle_3 when port_2_sel = "0100" else - joystick2_x_pos(7 downto 0) when port_2_sel = "0010" else +pd3 <= not paddle_3 when port_2_sel = "0111" else + not paddle_1 when port_2_sel = "0100" else + joystick2_x_pos when port_2_sel = "0010" else std_logic_vector(not mx(7) & mx(6 downto 0)) when port_2_sel = "0101" else x"ff"; -pd4 <= not paddle_4 when port_2_sel = "0100" else - joystick2_y_pos(7 downto 0) when port_2_sel = "0010" else +pd4 <= not paddle_4 when port_2_sel = "0111" else + not paddle_2 when port_2_sel = "0100" else + joystick2_y_pos when port_2_sel = "0010" else std_logic_vector(not my(7) & my(6 downto 0)) when port_2_sel = "0101" else x"ff"; @@ -905,16 +914,35 @@ port map( enable => ioctl_wr and cart_download, cart_size => img_size_crt, data => dl_data, - force_bs => force_bs, + force_bs => force_bs_i, sc => scdetect ); +force_bs <= force_bs_i when img_present = '1' else force_bs_lock; + pal <= '1' when system_video_std(1 downto 0) = 2 else '0' when system_video_std(1 downto 0) = 1 else paldetect; sc <= '1' when system_sc(1 downto 0) = 2 else '0' when system_sc(1 downto 0) = 1 else - scdetect; + scdetect when img_present = '1' else + sc_lock; + +process(clk, pll_locked) + begin + if pll_locked = '0' then + sc_lock <= '0'; + force_bs_lock <= "00000"; + elsif rising_edge(clk) then + if sd_img_mounted(0) = '1' then + img_present <= '0' when sd_img_size = 0 else '1'; + sd_img_size_d <= sd_img_size; + elsif cart_download_d = '1' and cart_download = '0' then + sc_lock <= scdetect; + force_bs_lock <= force_bs_i; + end if; + end if; +end process; process(clk) begin diff --git a/src/a2600_top_tp20k.vhd b/src/a2600_top_tp20k.vhd index aceb32e..7147c14 100644 --- a/src/a2600_top_tp20k.vhd +++ b/src/a2600_top_tp20k.vhd @@ -84,8 +84,8 @@ signal pot4 : std_logic_vector(7 downto 0); signal pd1,pd2 : std_logic_vector(7 downto 0); signal pd3,pd4 : std_logic_vector(7 downto 0); signal p1,p2,p3,p4 : std_logic_vector(7 downto 0); -signal mouse_x_pos : signed(10 downto 0); -signal mouse_y_pos : signed(10 downto 0); +signal mx : signed(8 downto 0); +signal my : signed(8 downto 0); signal pal : std_logic; signal system_video_std : std_logic_vector(1 downto 0); signal hsync : std_logic; @@ -121,6 +121,9 @@ signal system_reset : std_logic_vector(1 downto 0); signal sd_img_size : std_logic_vector(31 downto 0); signal sd_img_size_d : std_logic_vector(31 downto 0); signal sd_img_mounted : std_logic_vector(4 downto 0); +signal img_present : std_logic; +signal sc_lock : std_logic; +signal force_bs_lock : std_logic_vector(4 downto 0); signal sd_rd : std_logic_vector(4 downto 0); signal sd_wr : std_logic_vector(4 downto 0); signal sd_lba : std_logic_vector(31 downto 0); @@ -224,6 +227,7 @@ signal p_start : std_logic; signal p_select : std_logic; signal vblank_regen : std_logic; signal force_bs : std_logic_vector(4 downto 0); +signal force_bs_i : std_logic_vector(4 downto 0); signal joystick0ax : signed(7 downto 0); signal joystick0ay : signed(7 downto 0); signal joystick1ax : signed(7 downto 0); @@ -621,7 +625,7 @@ joyDigital <= not(x"FF" & "111" & io(0) & io(2) & io(1) & io(4) & io(3)); joyUsb1 <= extra_button0 & joystick1(7 downto 4) & joystick1(3) & joystick1(2) & joystick1(1) & joystick1(0); joyUsb2 <= extra_button1 & joystick2(7 downto 4) & joystick2(3) & joystick2(2) & joystick2(1) & joystick2(0); joyNumpad <= x"00" & "000" & numpad(4) & numpad(3) & numpad(2) & numpad(1) & numpad(0); -joyMouse <= x"0000"; +joyMouse <= extra_button0 & "0" & mouse_btns & "0" & "0000"; -- send external DB9 joystick port to µC db9_joy <= not ('0' & io(0) & io(2) & io(1) & io(4) & io(3)); @@ -665,30 +669,69 @@ begin end process; -- paddle pins -pd1 <= not paddle_1 when port_1_sel = "0100" else - joystick1_x_pos(7 downto 0) when port_1_sel = "0001" else +pd1 <= not paddle_1 when port_1_sel = "0100" else + not paddle_3 when port_1_sel = "0111" else + joystick1_x_pos when port_1_sel = "0001" else + std_logic_vector(not mx(7) & mx(6 downto 0)) when port_1_sel = "0101" else x"ff"; -pd2 <= not paddle_2 when port_1_sel = "0100" else - joystick1_y_pos(7 downto 0) when port_1_sel = "0001" else +pd2 <= not paddle_2 when port_1_sel = "0100" else + not paddle_4 when port_1_sel = "0111" else + joystick1_y_pos when port_1_sel = "0001" else + std_logic_vector(not my(7) & my(6 downto 0)) when port_1_sel = "0101" else x"ff"; -pd3 <= not paddle_3 when port_2_sel = "0111" else - joystick2_x_pos(7 downto 0) when port_2_sel = "0010" else +pd3 <= not paddle_3 when port_2_sel = "0111" else + not paddle_1 when port_2_sel = "0100" else + joystick2_x_pos when port_2_sel = "0010" else + std_logic_vector(not mx(7) & mx(6 downto 0)) when port_2_sel = "0101" else x"ff"; -pd4 <= not paddle_4 when port_2_sel = "0111" else - joystick2_y_pos(7 downto 0) when port_2_sel = "0010" else +pd4 <= not paddle_4 when port_2_sel = "0111" else + not paddle_2 when port_2_sel = "0100" else + joystick2_y_pos when port_2_sel = "0010" else + std_logic_vector(not my(7) & my(6 downto 0)) when port_2_sel = "0101" else x"ff"; process(clk, system_reset(0)) - variable mov_x: signed(6 downto 0); - variable mov_y: signed(6 downto 0); + variable mdx: signed(8 downto 0); + variable mdx2: signed(8 downto 0); + variable nmx: signed(8 downto 0); + variable mdy: signed(8 downto 0); + variable mdy2: signed(8 downto 0); + variable nmy: signed(8 downto 0); begin if system_reset(0) = '1' then + mx <= to_signed(0,mx'length); + my <= to_signed(0,my'length); joystick1_x_pos <= x"ff"; joystick1_y_pos <= x"ff"; joystick2_x_pos <= x"ff"; joystick2_y_pos <= x"ff"; elsif rising_edge(clk) then - if joystick_strobe = '1' then + mdx := resize(mouse_x, mdx'length); + if mdx > 10 then + mdx2:= to_signed(10,mdx2'length); + elsif mdx < -10 then + mdx2:= to_signed(-10,mdx2'length); + else + mdx2 := mdx; + end if; + nmx := mx + mdx2; + mdy := resize(mouse_y, mdy'length); + if mdy > 10 then + mdy2:= to_signed(10,mdy2'length); + elsif mouse_x < -10 then + mdy2:= to_signed(-10,mdy2'length); + else + mdy2 := mdy; + end if; + nmy := my + mdy2; + if mouse_strobe = '1' then + mx <= to_signed(-128, mx'length) when nmx < -128 + else to_signed(127, mx'length) when nmx > 127 + else nmx; + my <= to_signed(-128, my'length) when nmy < -128 + else to_signed(127, my'length) when nmy > 127 + else nmy; + elsif joystick_strobe = '1' then joystick1_x_pos <= std_logic_vector(joystick0ax(7 downto 0)); joystick1_y_pos <= std_logic_vector(joystick0ay(7 downto 0)); joystick2_x_pos <= std_logic_vector(joystick1ax(7 downto 0)); @@ -927,16 +970,35 @@ port map( enable => ioctl_wr and cart_download, cart_size => img_size_crt, data => dl_data, - force_bs => force_bs, + force_bs => force_bs_i, sc => scdetect ); +force_bs <= force_bs_i when img_present = '1' else force_bs_lock; + pal <= '1' when system_video_std(1 downto 0) = 2 else '0' when system_video_std(1 downto 0) = 1 else paldetect; sc <= '1' when system_sc(1 downto 0) = 2 else '0' when system_sc(1 downto 0) = 1 else - scdetect; + scdetect when img_present = '1' else + sc_lock; + +process(clk, pll_locked) + begin + if pll_locked = '0' then + sc_lock <= '0'; + force_bs_lock <= "00000"; + elsif rising_edge(clk) then + if sd_img_mounted(0) = '1' then + img_present <= '0' when sd_img_size = 0 else '1'; + sd_img_size_d <= sd_img_size; + elsif cart_download_d = '1' and cart_download = '0' then + sc_lock <= scdetect; + force_bs_lock <= force_bs_i; + end if; + end if; +end process; process(clk) begin diff --git a/src/a2600_top_tp25k.vhd b/src/a2600_top_tp25k.vhd index 180d456..b1a4543 100644 --- a/src/a2600_top_tp25k.vhd +++ b/src/a2600_top_tp25k.vhd @@ -57,7 +57,8 @@ signal joyDigital : std_logic_vector(15 downto 0); signal joyNumpad : std_logic_vector(15 downto 0); signal joyMouse : std_logic_vector(15 downto 0); signal numpad : std_logic_vector(7 downto 0); -signal joyDS2 : std_logic_vector(15 downto 0); +signal joyDS2_p1 : std_logic_vector(15 downto 0); +signal joyDS2_p2 : std_logic_vector(15 downto 0); -- joystick interface signal joyA : std_logic_vector(15 downto 0); signal joyB : std_logic_vector(15 downto 0); @@ -110,6 +111,9 @@ signal system_reset : std_logic_vector(1 downto 0); signal sd_img_size : std_logic_vector(31 downto 0); signal sd_img_size_d : std_logic_vector(31 downto 0); signal sd_img_mounted : std_logic_vector(4 downto 0); +signal img_present : std_logic; +signal sc_lock : std_logic; +signal force_bs_lock : std_logic_vector(4 downto 0); signal sd_rd : std_logic_vector(4 downto 0); signal sd_wr : std_logic_vector(4 downto 0); signal sd_lba : std_logic_vector(31 downto 0); @@ -180,6 +184,7 @@ signal p_start : std_logic; signal p_select : std_logic; signal vblank_regen : std_logic; signal force_bs : std_logic_vector(4 downto 0); +signal force_bs_i : std_logic_vector(4 downto 0); signal joystick0ax : signed(7 downto 0); signal joystick0ay : signed(7 downto 0); signal joystick1ax : signed(7 downto 0); @@ -384,7 +389,8 @@ leds(1) <= '1' when force_bs > 14 else '0'; -- indicate unsupported mapper -- BTN_SR 9 -- BTN_SELECT 10 -- BTN_START 11 -joyDS2 <= x"0000"; +joyDS2_p1 <= x"0000"; +joyDS2_p2 <= x"0000"; joyDigital <= x"0000"; joyUsb1 <= extra_button0 & joystick1(7 downto 4) & joystick1(3) & joystick1(2) & joystick1(1) & joystick1(0); joyUsb2 <= extra_button1 & joystick2(7 downto 4) & joystick2(3) & joystick2(2) & joystick2(1) & joystick2(0); @@ -398,14 +404,17 @@ process(clk) begin if rising_edge(clk) then case port_1_sel is - when "0000" => joyA <= joyDigital; - when "0001" => joyA <= joyUsb1; - when "0010" => joyA <= joyUsb2; - when "0011" => joyA <= joyNumpad; - when "0100" => joyA <= joyDS2; - when "0101" => joyA <= joyMouse; - when "0110" => joyA <= (others => '0'); - when others => null; + when "0000" => joyA <= joyDigital;-- 0 + when "0001" => joyA <= joyUsb1; -- 1 + when "0010" => joyA <= joyUsb2; -- 2 + when "0011" => joyA <= joyNumpad; -- 3 + when "0100" => joyA <= joyDS2_p1; -- 4 + when "0101" => joyA <= joyMouse; -- 5 + when "0110" => joyA <= (others => '0'); --6 Off + when "0111" => joyA <= joyDS2_p2; -- 7 + when "1000" => joyA <= (others => '0'); -- 8 R #2 D9 PMOD + when "1001" => joyA <= (others => '0'); -- 9 R #2 D9 ALT + when others => joyA <= (others => '0'); end case; end if; end process; @@ -418,28 +427,36 @@ begin when "0001" => joyB <= joyUsb1; when "0010" => joyB <= joyUsb2; when "0011" => joyB <= joyNumpad; - when "0100" => joyB <= joyDS2; + when "0100" => joyB <= joyDS2_p1; when "0101" => joyB <= joyMouse; when "0110" => joyB <= (others => '0'); - when others => null; + when "0111" => joyB <= joyDS2_p2; + when "1000" => joyB <= (others => '0'); -- 8 R #2 D9 PMOD + when "1001" => joyB <= (others => '0'); -- 9 R #2 D9 ALT + when others => joyB <= (others => '0'); end case; end if; end process; -pd1 <= not paddle_1 when port_1_sel = "0100" else +-- paddle pins +pd1 <= not paddle_1 when port_1_sel = "0100" else + not paddle_3 when port_1_sel = "0111" else joystick1_x_pos when port_1_sel = "0001" else std_logic_vector(not mx(7) & mx(6 downto 0)) when port_1_sel = "0101" else x"ff"; -pd2 <= not paddle_2 when port_1_sel = "0100" else - joystick1_y_pos(7 downto 0) when port_1_sel = "0001" else +pd2 <= not paddle_2 when port_1_sel = "0100" else + not paddle_4 when port_1_sel = "0111" else + joystick1_y_pos when port_1_sel = "0001" else std_logic_vector(not my(7) & my(6 downto 0)) when port_1_sel = "0101" else x"ff"; -pd3 <= not paddle_3 when port_2_sel = "0100" else - joystick2_x_pos(7 downto 0) when port_2_sel = "0010" else +pd3 <= not paddle_3 when port_2_sel = "0111" else + not paddle_1 when port_2_sel = "0100" else + joystick2_x_pos when port_2_sel = "0010" else std_logic_vector(not mx(7) & mx(6 downto 0)) when port_2_sel = "0101" else x"ff"; -pd4 <= not paddle_4 when port_2_sel = "0100" else - joystick2_y_pos(7 downto 0) when port_2_sel = "0010" else +pd4 <= not paddle_4 when port_2_sel = "0111" else + not paddle_2 when port_2_sel = "0100" else + joystick2_y_pos when port_2_sel = "0010" else std_logic_vector(not my(7) & my(6 downto 0)) when port_2_sel = "0101" else x"ff"; @@ -723,16 +740,35 @@ port map( enable => ioctl_wr and cart_download, cart_size => img_size_crt, data => dl_data, - force_bs => force_bs, + force_bs => force_bs_i, sc => scdetect ); +force_bs <= force_bs_i when img_present = '1' else force_bs_lock; + pal <= '1' when system_video_std(1 downto 0) = 2 else '0' when system_video_std(1 downto 0) = 1 else paldetect; sc <= '1' when system_sc(1 downto 0) = 2 else '0' when system_sc(1 downto 0) = 1 else - scdetect; + scdetect when img_present = '1' else + sc_lock; + +process(clk, pll_locked) + begin + if pll_locked = '0' then + sc_lock <= '0'; + force_bs_lock <= "00000"; + elsif rising_edge(clk) then + if sd_img_mounted(0) = '1' then + img_present <= '0' when sd_img_size = 0 else '1'; + sd_img_size_d <= sd_img_size; + elsif cart_download_d = '1' and cart_download = '0' then + sc_lock <= scdetect; + force_bs_lock <= force_bs_i; + end if; + end if; +end process; process(clk) begin