Skip to content

Commit

Permalink
Add Fast-forward function (hold R trigger)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ban committed Nov 24, 2019
1 parent c50a562 commit 88821a4
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion dist/gcw0/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ B Button B Button
A Button A Button
Select Select
Start Start
L / R / POWER Menu
R trigger / POWER Menu
L trigger Fast Forward


General Menu Controls
Expand Down
1 change: 1 addition & 0 deletions dist/retrofw/gambatte.man.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ A Button A Button
Select Select
Start Start
POWER Menu
L trigger Fast Forward


General Menu Controls
Expand Down
2 changes: 1 addition & 1 deletion gambatte_sdl/builddate.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define BUILDDATE "20190831-183712"
#define BUILDDATE "20191124-160457"
26 changes: 18 additions & 8 deletions gambatte_sdl/src/gambatte_sdl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,8 +1044,8 @@ bool GambatteSdl::handleEvents(BlitterWrapper &blitter) {
case SDLK_RCTRL: // R button in bittboy - Reset button in PocketGo
#else
#if defined VERSION_OPENDINGUX
case SDLK_BACKSPACE: // L trigger
case SDLK_TAB: // R trigger
case SDLK_BACKSPACE: // R trigger
//case SDLK_TAB: // L trigger
#endif
case SDLK_HOME: // "power flick" in GCW Zero
case SDLK_END: // power/suspend button in retrofw
Expand Down Expand Up @@ -1101,7 +1101,7 @@ static std::size_t const gb_samples_per_frame = 35112;
static std::size_t const gambatte_max_overproduction = 2064;

static bool isFastForward(Uint8 const *keys) {
return keys[SDLK_F9];
return keys[SDLK_TAB];
}

int GambatteSdl::run(long const sampleRate, int const latency, int const periods,
Expand All @@ -1113,6 +1113,8 @@ int GambatteSdl::run(long const sampleRate, int const latency, int const periods
Uint8 const *const keys = SDL_GetKeyState(0);
std::size_t bufsamples = 0;
bool audioOutBufLow = false;
int ffwd = 0;
int ffwd_speed = 6;

SDL_PauseAudio(0);

Expand All @@ -1123,6 +1125,9 @@ int GambatteSdl::run(long const sampleRate, int const latency, int const periods

BlitterWrapper::Buf const &vbuf = blitter.inBuf();
std::size_t runsamples = gb_samples_per_frame - bufsamples;
if (isFastForward(keys)) {
runsamples = runsamples / ffwd_speed; //in ffwd mode: attempt to decrease the amount of used resources by lowering the number of samples per frame.
}
std::ptrdiff_t const vidFrameDoneSampleCnt = gambatte.runFor(
vbuf.pixels, vbuf.pitch, audioBuf + bufsamples, runsamples);
std::size_t const outsamples = vidFrameDoneSampleCnt >= 0
Expand All @@ -1131,10 +1136,15 @@ int GambatteSdl::run(long const sampleRate, int const latency, int const periods
bufsamples += runsamples;
bufsamples -= outsamples;

if (isFastForward(keys)) {
if (vidFrameDoneSampleCnt >= 0) {
blitter.draw();
blitter.present();
if (isFastForward(keys)) { // in ffwd mode: dont wait for frame time, dont write sound into the buffer and only draw one of every <ffwd_speed> frames.
if(ffwd < ffwd_speed) {
ffwd++;
} else {
ffwd = 0;
if (vidFrameDoneSampleCnt >= 0) {
blitter.draw();
blitter.present();
}
}
} else {
bool const blit = vidFrameDoneSampleCnt >= 0
Expand All @@ -1149,9 +1159,9 @@ int GambatteSdl::run(long const sampleRate, int const latency, int const periods
frameWait.waitForNextFrameTime(ft);
blitter.present();
}
std::memmove(audioBuf, audioBuf + outsamples, bufsamples * sizeof *audioBuf);
}

std::memmove(audioBuf, audioBuf + outsamples, bufsamples * sizeof *audioBuf);
if(menuin == -2){
menuin = -1;
main_menu();
Expand Down

1 comment on commit 88821a4

@bardeci
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correction: Holding L Trigger activates fast forward

Please sign in to comment.