Skip to content

Commit

Permalink
Add speedhack manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Twinaphex committed Sep 5, 2012
1 parent d413990 commit 97bf78c
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 18 deletions.
32 changes: 31 additions & 1 deletion libretro/libretro.c
Expand Up @@ -291,6 +291,8 @@ void retro_get_system_av_info(struct retro_system_av_info *info)
static void snes_init (void)
{
memset(&Settings, 0, sizeof(Settings));
Settings.SpeedhackGameID = SPEEDHACK_NONE;
Settings.Transparency = TRUE;
Settings.FrameTimePAL = 20000;
Settings.FrameTimeNTSC = 16667;
Settings.SoundPlaybackRate = 32000;
Expand Down Expand Up @@ -434,8 +436,8 @@ static void report_buttons (void)

void retro_run (void)
{
S9xMainLoop();

S9xMainLoop();
poll_cb();

report_buttons();
Expand Down Expand Up @@ -507,8 +509,36 @@ unsigned retro_get_region (void)
return Settings.PAL ? RETRO_REGION_PAL : RETRO_REGION_NTSC;
}

static void speedhacks_manager (void)
{
switch(Settings.SpeedhackGameID)
{
case SPEEDHACK_DKC1:
{
uint8 level = Memory.RAM[0x003E]; /* current level - 7E003E */
//fprintf(stderr, "current_level: %d.\n", ram);
if(level == 49 || level == 217 || level == 66 || level == 67)
PPU.SFXSpeedupHack = TRUE;
else
PPU.SFXSpeedupHack = FALSE;
break;
}
#if 0
case SPEEDHACK_SUPER_METROID:
{
uint8 song = (Memory.RAM[0x07f3] | Memory.RAM[0x07f4] << 8);
fprintf(stderr, "current_song: %d.\n", song);
}
#endif
default:
break;
}
}

void S9xDeinitUpdate(int width, int height)
{
if(Settings.SpeedhackGameID > SPEEDHACK_NONE)
speedhacks_manager();
/* Chrono Trigger mid-frame overscan hack - field to battle transition */
if (Settings.ChronoTriggerFrameHack & (height == 239))
height = 224;
Expand Down
1 change: 1 addition & 0 deletions src/cpuexec.c
Expand Up @@ -273,6 +273,7 @@ void S9xMainLoop (void)
Registers.PCw++;
(*Opcodes[Op].S9xOpcode)();


if (Settings.SA1)
S9xSA1MainLoop();

Expand Down
34 changes: 21 additions & 13 deletions src/memmap.c
Expand Up @@ -2593,10 +2593,6 @@ void InitROM (void)
MATCH_NA("SeikenDensetsu3Sample1") || /* Seiken Densetsu 3 */
MATCH_NA("ROMANCING SAGA3")) /* Romancing Saga 3 */
{
#if defined(_XBOX1) || defined(GEKKO)
/* These systems are too slow for hi-res rendering with SNES9x 1.52 */
Settings.SupportHiRes = FALSE;
#endif
PPU.DisableMosaicHack = FALSE;
}
else
Expand All @@ -2606,21 +2602,19 @@ void InitROM (void)
if (
MATCH_NA("VORTEX") || /* Vortex */
MATCH_NA("Super Street Fighter21") || /* Super Street Fighter II */
//MATCH_NA("FINAL FANTASY 3") || /* Final Fantasy III (US)*/
MATCH_NA("STAR FOX 2")) /* Star Fox 2 */
PPU.SFXSpeedupHack = TRUE;
else
PPU.SFXSpeedupHack = FALSE;

#ifdef __LIBRETRO__
fprintf(stderr, "PPU.SFXSpeedupHack = %d\n", PPU.SFXSpeedupHack);
#endif

/* FORCIBLY DISABLE HIGH-RES */
if (
MATCH_NA("DONKEY KONG COUNTRY") /* Donkey Kong Country */
|| MATCH_ID("ADNE") /* Donkey Kong Country 2 (US) */
|| MATCH_ID("AD8") /* Doom */
#if defined(_XBOX1) || defined(GEKKO)
|| MATCH_ID("AD8") /* Doom */
|| MATCH_NN("SeikenDensetsu3")
|| MATCH_NA("SeikenDensetsu3Sample1") /* Seiken Densetsu 3 */
|| MATCH_NA("ROMANCING SAGA3") /* Romancing Saga 3 */
Expand Down Expand Up @@ -2833,16 +2827,14 @@ void InitROM (void)
|| MATCH_NA("SUPER TURRICAN 2") /* Super Turrican 2*/
|| MATCH_NA("DUNGEON MASTER") /* Dungeon Master*/
|| MATCH_NA("DOOM TROOPERS") /* Doom Troopers*/
|| MATCH_NA("DOOM") /* Doom */
|| MATCH_NA("XAK 1") /* Xak 1*/
|| MATCH_NA("XARDION") /* Xardion*/
)
PPU.RenderSub = FALSE;
else
PPU.RenderSub = TRUE;

#ifdef __LIBRETRO__
fprintf(stderr, "PPU.RenderSub = %d\n", PPU.RenderSub);
#endif

/* Clipping hack - gains around 5-7 extra fps - only use it
for specific games where nothing breaks with this hack on */
Expand All @@ -2855,10 +2847,26 @@ void InitROM (void)
else
PPU.FullClipping = TRUE;

#ifdef __LIBRETRO__
fprintf(stderr, "PPU.FullClipping = %d\n", PPU.FullClipping);
/* SPEED HACK PATHS */
if(
MATCH_NA("DONKEY KONG COUNTRY") /* Donkey Kong Country 1 */
)
Settings.SpeedhackGameID = SPEEDHACK_DKC1;
#if 0
else if(
MATCH_NA("Super Metroid") /* Super Metroid*/
)
Settings.SpeedhackGameID = SPEEDHACK_SUPER_METROID;
#endif
else
Settings.SpeedhackGameID = SPEEDHACK_NONE;

}
fprintf(stderr, "PPU.RenderSub = %d\n", PPU.RenderSub);
fprintf(stderr, "PPU.FullClipping = %d\n", PPU.FullClipping);
fprintf(stderr, "Settings.Transparency = %d\n", Settings.Transparency);
fprintf(stderr, "Settings.SpeedhackGameID = %d\n", Settings.SpeedhackGameID);
fprintf(stderr, "PPU.SFXSpeedupHack = %d\n", PPU.SFXSpeedupHack);

if (Settings.AccessoryAutoDetection == ACCESSORY_AUTODETECTION_CONFIRM)
{
Expand Down
7 changes: 7 additions & 0 deletions src/memmap.h
Expand Up @@ -217,6 +217,13 @@
#define MAP_TYPE_ROM 1
#define MAP_TYPE_RAM 2

enum speedhacks
{
SPEEDHACK_NONE = 0,
SPEEDHACK_DKC1,
SPEEDHACK_SUPER_METROID,
};

typedef struct
{
int32 HeaderCount;
Expand Down
3 changes: 3 additions & 0 deletions src/snes9x.h
Expand Up @@ -381,6 +381,8 @@ struct SSettings
uint32 FrameTimePAL;
uint32 FrameTimeNTSC;

uint32 SpeedhackGameID;

uint32 SoundPlaybackRate;
uint32 SoundInputRate;

Expand Down Expand Up @@ -446,6 +448,7 @@ struct SSettings
bool8 CurrentROMisSuperScopeCompatible;
bool8 CurrentROMisJustifierCompatible;
bool8 SupportHiRes;
bool8 Transparency;
};

struct SSNESGameFixes
Expand Down
13 changes: 9 additions & 4 deletions src/tile.c
Expand Up @@ -659,12 +659,17 @@ void S9xSelectTileRenderers (int BGMode, bool8 sub, bool8 obj)
GFX.DrawMode7BG1Nomath = DM7BG1[0];
GFX.DrawMode7BG2Nomath = DM7BG2[0];

i = (Memory.FillRAM[0x2131] & 0x80) ? 4 : 1;
if (Memory.FillRAM[0x2131] & 0x40)
if (!Settings.Transparency)
i = 0;
else
{
i++;
if (Memory.FillRAM[0x2130] & 2)
i = (Memory.FillRAM[0x2131] & 0x80) ? 4 : 1;
if (Memory.FillRAM[0x2131] & 0x40)
{
i++;
if (Memory.FillRAM[0x2130] & 2)
i++;
}
}

GFX.DrawTileMath = DT[i];
Expand Down

0 comments on commit 97bf78c

Please sign in to comment.