proper timing and frameskip code, turbo works properly

This commit is contained in:
dborth 2009-10-02 08:05:20 +00:00
parent ed04c842e5
commit 71a1b71e18
6 changed files with 59 additions and 16 deletions

View File

@ -52,6 +52,7 @@ extern void __exception_setreload(int t);
}
static int fskipc = 0;
static int fskip = 0;
static uint8 *gfx=0;
static int32 *sound=0;
static int32 ssize=0;
@ -62,6 +63,7 @@ int ResetRequested = 0;
int ExitRequested = 0;
char appPath[1024] = { 0 };
int frameskip = 0;
int turbomode = 0;
unsigned char * nesrom = NULL;
/****************************************************************************
@ -345,16 +347,46 @@ int main(int argc, char *argv[])
SetPalette();
FCEUI_DisableSpriteLimitation(GCSettings.spritelimit ^ 1);
fskip=0;
fskipc=0;
frameskip=0;
while(1) // emulation loop
{
#ifdef FRAMESKIP
fskipc=(fskipc+1)%(frameskip+1);
#endif
fskip = 0;
if(turbomode)
{
fskip = 1;
if(fskipc >= 18)
{
fskipc = 0;
fskip = 0;
}
else
{
fskipc++;
}
}
else if(frameskip > 0)
{
fskip = 1;
if(fskipc >= frameskip)
{
fskipc = 0;
fskip = 0;
}
else
{
fskipc++;
}
}
FCEUI_Emulate(&gfx, &sound, &ssize, fskipc);
FCEUI_Emulate(&gfx, &sound, &ssize, fskip);
FCEUD_Update(gfx, sound, ssize);
SyncSpeed();
if(ResetRequested)
{

View File

@ -104,6 +104,7 @@ extern int ShutdownRequested;
extern int ExitRequested;
extern char appPath[];
extern int frameskip;
extern int turbomode;
extern bool romLoaded;
#endif

View File

@ -634,9 +634,7 @@ LoadFile (char * rbuffer, char *filepath, u32 length, bool silent)
u32 readsize = 0;
int retry = 1;
int device;
printf("loading %s\n", filepath);
if(!FindDevice(filepath, &device))
return 0;

View File

@ -199,7 +199,7 @@ static GXRModeObj *tvmodes[2] = {
* change frame timings depending on whether ROM is NTSC or PAL
***************************************************************************/
static long long normaldiff;
static u32 normaldiff;
void setFrameTimer()
{
@ -207,17 +207,28 @@ void setFrameTimer()
normaldiff = 20000; // 50hz
else
normaldiff = 16667; // 60hz
prev = gettime();
}
static void SyncSpeed()
void SyncSpeed()
{
now = gettime();
while (diff_usec(prev, now) < normaldiff)
if(turbomode)
{
now = gettime();
usleep(50);
// do nothing
}
else if (diff_usec(prev, now) > normaldiff)
{
frameskip++;
}
else // ahead, so hold up
{
while (diff_usec(prev, now) < normaldiff)
{
now = gettime();
usleep(50);
}
}
prev = now;
}
@ -242,7 +253,7 @@ vbgetback (void *arg)
{
while (1)
{
SyncSpeed();
VIDEO_WaitVSync ();
LWP_SuspendThread (vbthread);
}

View File

@ -25,6 +25,7 @@ void StopGX();
void ResetVideo_Emu ();
void RenderFrame(unsigned char *XBuf);
void setFrameTimer();
void SyncSpeed();
void zoom (float speed);
void zoom_reset ();
void SetPalette();

View File

@ -624,9 +624,9 @@ void GetJoy()
// Turbo mode
// RIGHT on c-stick and on classic ctrlr right joystick
if(userInput[0].pad.substickX > 70 || userInput[0].WPAD_Stick(1,0) > 70)
frameskip = 1;
turbomode = 1;
else
frameskip = 0;
turbomode = 0;
// request to go back to menu
if(MenuRequested())