Skip to content

Commit

Permalink
Added Fast Forward key to speed up emulation when desired
Browse files Browse the repository at this point in the history
  • Loading branch information
tswilliamson committed Mar 1, 2020
1 parent 6f4a63d commit 56eb48f
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -30,6 +30,7 @@ You can configure your own keys in the Settings menu, these are the default I fo
: Turbo B: X^2
- Save State : X (multiply), which is the alpha 'S' key for save
- Load State : -> (store), which is the alpha 'L' key for load
- Fast Forward: ^ (caret), runs CPU at full speed running rendering every 8th frame, about 3x speed

Note that if you set the turbo setting to 30 Hz, this may be too fast for some games causing them to malfunction.

Expand Down
1 change: 1 addition & 0 deletions src/frontend.cpp
Expand Up @@ -598,6 +598,7 @@ MenuOption remapOptions[] =
{ "P1 Turbo B", "", false, Option_RemapKey, Option_GetKeyDetails, NES_P1_TURBO_B},
{ "Save State", "", false, Option_RemapKey, Option_GetKeyDetails, NES_SAVESTATE},
{ "Load State", "", false, Option_RemapKey, Option_GetKeyDetails, NES_LOADSTATE},
{ "Fast Fwd", "", false, Option_RemapKey, Option_GetKeyDetails, NES_FASTFORWARD},
{ "P2 A", "", false, Option_RemapKey, Option_GetKeyDetails, NES_P2_A},
{ "P2 B", "", false, Option_RemapKey, Option_GetKeyDetails, NES_P2_B},
{ "P2 Select", "", false, Option_RemapKey, Option_GetKeyDetails, NES_P2_SELECT},
Expand Down
1 change: 1 addition & 0 deletions src/nes.h
Expand Up @@ -22,6 +22,7 @@ enum NesKeys {
NES_P1_TURBO_B,
NES_SAVESTATE,
NES_LOADSTATE,
NES_FASTFORWARD,
NES_P2_A,
NES_P2_B,
NES_P2_SELECT,
Expand Down
4 changes: 4 additions & 0 deletions src/nes_input.cpp
Expand Up @@ -45,6 +45,10 @@ inline unsigned char readButton(int buttonNo) {
return isDown[buttonNo];
}

bool EmulatorSettings::CheckCachedKey(NesKeys key) {
return isDown[(int)key];
}

void input_writeStrobe(unsigned char value) {
value &= 1;

Expand Down
12 changes: 8 additions & 4 deletions src/nes_ppu.cpp
Expand Up @@ -502,6 +502,10 @@ void nes_ppu::step() {
skipFrame = (frameCounter % frameSkipValue) != 0;
}

if (nesSettings.CheckCachedKey(NES_FASTFORWARD)) {
skipFrame = (frameCounter & 7) != 0;
}

// clear vblank and sprite 0 flag
SetPPUSTATUS(PPUSTATUS & ~(PPUSTAT_NMI | PPUSTAT_SPRITE0));

Expand Down Expand Up @@ -607,19 +611,19 @@ void nes_ppu::step() {
}
#endif

if (keyDown_fast(nesSettings.keyMap[NES_SAVESTATE])) // F3 in simulator, 'S" on device
input_cacheKeys();

if (nesSettings.CheckCachedKey(NES_SAVESTATE)) // F3 in simulator, 'S" on device
{
nesCart.SaveState();
nesCart.BuildFileBlocks();
}

if (keyDown_fast(nesSettings.keyMap[NES_LOADSTATE])) // F4 in simulator, 'L' on device
if (nesSettings.CheckCachedKey(NES_LOADSTATE)) // F4 in simulator, 'L' on device
{
nesCart.LoadState();
}

input_cacheKeys();

} else if (scanline == 243) {
// frame is over, don't run until scanline 262, so add 18 scanlines worth (2047 extra clocks!)
if (nesCart.isPAL == 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/scanline_dma.cpp
Expand Up @@ -129,7 +129,7 @@ void nes_ppu::resolveScanline(int scrollOffset) {

void nes_ppu::finishFrame(bool bSkippedFrame) {
// run frame timing
if (nesSettings.GetSetting(ST_Speed) != 4) {
if (nesSettings.GetSetting(ST_Speed) != 4 && nesSettings.CheckCachedKey(NES_FASTFORWARD) == false) {
// use TMU1 to establish time between frames
static unsigned int counterStart = 0x7FFFFFFF; // max int
unsigned int counterRegs = 0x0004;
Expand Down
1 change: 1 addition & 0 deletions src/settings.cpp
Expand Up @@ -152,6 +152,7 @@ void EmulatorSettings::SetDefaults() {
keyMap[NES_P1_DOWN] = 37;
keyMap[NES_SAVESTATE] = 43; // 'S'
keyMap[NES_LOADSTATE] = 25; // 'L'
keyMap[NES_FASTFORWARD] = 57; // '^'

// simulator only defaults
#if TARGET_WINSIM
Expand Down
1 change: 1 addition & 0 deletions src/settings.h
Expand Up @@ -47,6 +47,7 @@ struct EmulatorSettings {
static SettingGroup GetSettingGroup(SettingType setting);
static bool GetSettingAvailable(SettingType setting);

static bool CheckCachedKey(NesKeys key);
private:
uint8 values[MAX_SETTINGS];
};
Expand Down

0 comments on commit 56eb48f

Please sign in to comment.