Skip to content

Commit

Permalink
Turbo mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorgelig committed May 16, 2019
1 parent fc8f0f7 commit c333f48
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 21 deletions.
14 changes: 10 additions & 4 deletions SNES.sv
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,20 @@ parameter CONF_STR = {
"OH,Multitap,Disabled,Port2;",
"-;",
"OPQ,Super Scope,Disabled,Joy1,Joy2,Mouse;",
"OR,Super Scope Btn,Joy,Mouse;",
"OST,Cross,Small,Big,None;",
"D4OR,Super Scope Btn,Joy,Mouse;",
"D4OST,Cross,Small,Big,None;",
"-;",
"D3O4,Turbo,Disable,Enable;",
"-;",
"R0,Reset;",
"J1,A(SS Fire),B(SS Cursor),X(SS TurboSw),Y(SS Pause),LT(SS Cursor),RT(SS Fire),Select,Start;",
"V,v",`BUILD_DATE
};
// free bits: 4,L,M,U,V
// free bits: L,M,U,V

wire [1:0] buttons;
wire [31:0] status;
wire [15:0] status_menumask = {~gg_available, ~GSU_ACTIVE, ~bk_ena};
wire [15:0] status_menumask = {!GUN_MODE, ~turbo_allow, ~gg_available, ~GSU_ACTIVE, ~bk_ena};
wire forced_scandoubler;
reg [31:0] sd_lba;
reg sd_rd = 0;
Expand Down Expand Up @@ -339,6 +341,7 @@ end
//////////////////////////// SYSTEM ///////////////////////////////////

wire GSU_ACTIVE;
wire turbo_allow;

main main
(
Expand Down Expand Up @@ -417,6 +420,9 @@ main main
.GG_CODE(gg_code),
.GG_RESET((code_download && ioctl_wr && !ioctl_addr) || cart_download),
.GG_AVAILABLE(gg_available),

.TURBO(status[4] & turbo_allow),
.TURBO_ALLOW(turbo_allow),

.AUDIO_L(AUDIO_L),
.AUDIO_R(AUDIO_R)
Expand Down
47 changes: 32 additions & 15 deletions src/CPU.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ entity SCPU is
JOY2_DI : in std_logic_vector(1 downto 0);
JOY_STRB : out std_logic;
JOY1_CLK : out std_logic;
JOY2_CLK : out std_logic;

JOY2_CLK : out std_logic;

TURBO : in std_logic;

DBG_CPU_BRK : out std_logic;
DBG_REG : in std_logic_vector(7 downto 0);
DBG_DAT : out std_logic_vector(7 downto 0);
Expand All @@ -58,7 +60,10 @@ architecture rtl of SCPU is
signal INT_CLKR_CE, INT_CLKF_CE, DOT_CLK_CE : std_logic;
signal P65_CLK_CNT : unsigned(3 downto 0);
signal DMA_CLK_CNT : unsigned(2 downto 0);
signal DMA_LAST_CLOCK : unsigned(2 downto 0);
signal DMA_MID_CLOCK : unsigned(2 downto 0);
signal CPU_LAST_CLOCK : unsigned(3 downto 0);
signal CPU_MID_CLOCK : unsigned(3 downto 0);
signal CPU_ACTIVEr, DMA_ACTIVEr : std_logic;
signal H_CNT : unsigned(8 downto 0);
signal V_CNT : unsigned(8 downto 0);
Expand Down Expand Up @@ -228,9 +233,17 @@ begin

DMA_ACTIVE <= DMA_RUN or HDMA_RUN;

process( SPEED, MEMSEL, REFRESHED, CPU_ACTIVEr )
process( SPEED, MEMSEL, REFRESHED, CPU_ACTIVEr, TURBO )
begin
if REFRESHED = '1' and CPU_ACTIVEr = '1' then
CPU_MID_CLOCK <= x"2";
DMA_MID_CLOCK <= "011";
DMA_LAST_CLOCK <= "111";
if TURBO = '1' then
CPU_LAST_CLOCK <= x"3";
CPU_MID_CLOCK <= x"1";
DMA_LAST_CLOCK <= "011";
DMA_MID_CLOCK <= "001";
elsif REFRESHED = '1' and CPU_ACTIVEr = '1' then
CPU_LAST_CLOCK <= x"7";
elsif SPEED = FAST or (SPEED = SLOWFAST and MEMSEL = '1') then
CPU_LAST_CLOCK <= x"5";
Expand All @@ -250,13 +263,17 @@ begin
CPU_ACTIVEr <= '1';
DMA_ACTIVEr <= '0';
elsif rising_edge(CLK) then
DMA_CLK_CNT <= DMA_CLK_CNT + 1;
DMA_CLK_CNT <= DMA_CLK_CNT + 1;
if DMA_CLK_CNT = DMA_LAST_CLOCK then
DMA_CLK_CNT <= (others => '0');
end if;

P65_CLK_CNT <= P65_CLK_CNT + 1;
if P65_CLK_CNT = CPU_LAST_CLOCK then
P65_CLK_CNT <= (others => '0');
end if;
if DMA_ACTIVEr = '0' and DMA_ACTIVE = '1' and DMA_CLK_CNT = 7 and REFRESHED = '0' then

if DMA_ACTIVEr = '0' and DMA_ACTIVE = '1' and DMA_CLK_CNT = DMA_LAST_CLOCK and REFRESHED = '0' then
DMA_ACTIVEr <= '1';
elsif DMA_ACTIVEr = '1' and DMA_ACTIVE = '0' and REFRESHED = '0' then
DMA_ACTIVEr <= '0';
Expand All @@ -269,13 +286,13 @@ begin
end if;

if DMA_ACTIVEr = '1' or ENABLE = '0' then
if DMA_CLK_CNT = 4-1 then
if DMA_CLK_CNT = DMA_MID_CLOCK then
INT_CLK <= '1';
elsif DMA_CLK_CNT = 8-1 then
elsif DMA_CLK_CNT = DMA_LAST_CLOCK then
INT_CLK <= '0';
end if;
elsif CPU_ACTIVEr = '1' then
if P65_CLK_CNT = 3-1 then
elsif CPU_ACTIVEr = '1' then
if P65_CLK_CNT = CPU_MID_CLOCK then
INT_CLK <= '1';
elsif P65_CLK_CNT = CPU_LAST_CLOCK then
INT_CLK <= '0';
Expand All @@ -295,17 +312,17 @@ begin
if DMA_CLK_CNT(1 downto 0) = 4-1 then
DOT_CLK_CE <= '1';
end if;

INT_CLKF_CE <= '0';
INT_CLKR_CE <= '0';
if DMA_ACTIVEr = '1' or ENABLE = '0' then
if DMA_CLK_CNT = 4-1 then
if DMA_CLK_CNT = DMA_MID_CLOCK then
INT_CLKR_CE <= '1';
elsif DMA_CLK_CNT = 8-1 then
elsif DMA_CLK_CNT = DMA_LAST_CLOCK then
INT_CLKF_CE <= '1';
end if;
elsif CPU_ACTIVEr = '1' then
if P65_CLK_CNT = 3-1 then
if P65_CLK_CNT = CPU_MID_CLOCK then
INT_CLKR_CE <= '1';
elsif P65_CLK_CNT = CPU_LAST_CLOCK then
INT_CLKF_CE <= '1';
Expand Down
8 changes: 6 additions & 2 deletions src/SNES.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ entity SNES is
GG_CODE : in std_logic_vector(128 downto 0);
GG_RESET : in std_logic;
GG_AVAILABLE: out std_logic;

TURBO : in std_logic;

AUDIO_L : out std_logic_vector(15 downto 0);
AUDIO_R : out std_logic_vector(15 downto 0)
Expand Down Expand Up @@ -229,8 +231,10 @@ begin
JOY2_DI => JOY2_DI,
JOY_STRB => JOY_STRB,
JOY1_CLK => JOY1_CLK,
JOY2_CLK => JOY2_CLK,

JOY2_CLK => JOY2_CLK,

TURBO => TURBO,

DBG_CPU_BRK => CPU_BRK,
DBG_REG => DBG_REG,
DBG_DAT => DBG_SCPU_DAT,
Expand Down
7 changes: 7 additions & 0 deletions src/main.v
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ module main
input GG_RESET,
output GG_AVAILABLE,

input TURBO,
output TURBO_ALLOW,

output [15:0] AUDIO_L,
output [15:0] AUDIO_R
);
Expand Down Expand Up @@ -183,6 +186,8 @@ SNES SNES
.gg_code(GG_CODE),
.gg_reset(GG_RESET),
.gg_available(GG_AVAILABLE),

.turbo(TURBO),

.audio_l(AUDIO_L),
.audio_r(AUDIO_R)
Expand Down Expand Up @@ -487,6 +492,8 @@ SA1Map SA1Map
assign MAP_ACTIVE[3] = 0;
`endif

assign TURBO_ALLOW = ~(MAP_ACTIVE[3] | MAP_ACTIVE[1]);

always @(*) begin
case (MAP_ACTIVE)
`ifdef USE_CX4
Expand Down

0 comments on commit c333f48

Please sign in to comment.