timing changes

This commit is contained in:
dborth 2008-10-21 23:07:16 +00:00
parent f641aba760
commit a17c9f74a5
3 changed files with 52 additions and 68 deletions

View File

@ -41,12 +41,6 @@ int ConfigRequested = 0;
bool isWii; bool isWii;
uint8 *xbsave=NULL; uint8 *xbsave=NULL;
long long prev;
long long now;
long long gettime();
u32 diff_usec(long long start,long long end);
extern bool romLoaded; extern bool romLoaded;
extern int cleanSFMDATA(); extern int cleanSFMDATA();
@ -55,44 +49,6 @@ extern uint8 FDSBIOS[8192];
void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count);
/****************************************************************************
* setFrameTimer()
* change frame timings depending on whether ROM is NTSC or PAL
***************************************************************************/
int normaldiff;
void setFrameTimer()
{
if (GCSettings.timing) // PAL
{
if(vmode_60hz == 1)
normaldiff = 20000; // 50hz
else
normaldiff = 16667; // 60hz
}
else
{
if(vmode_60hz == 1)
normaldiff = 16667; // 60hz
else
normaldiff = 20000; // 50hz
}
FrameTimer = 0;
prev = gettime();
}
void SyncSpeed()
{
now = gettime();
int diff = normaldiff - diff_usec(prev, now);
if (diff > 0) // ahead - take a nap
usleep(diff);
prev = now;
FrameTimer--;
}
/**************************************************************************** /****************************************************************************
* ipl_set_config * ipl_set_config
* lowlevel Qoob Modchip disable * lowlevel Qoob Modchip disable
@ -219,12 +175,8 @@ int main(int argc, char *argv[])
ConfigRequested = 0; ConfigRequested = 0;
break; // leave emulation loop break; // leave emulation loop
} }
SyncSpeed();
} }
} }
return 0;
} }
/**************************************************************************** /****************************************************************************

View File

@ -20,6 +20,7 @@
#include "driver.h" #include "driver.h"
#include "gcvideo.h" #include "gcvideo.h"
#include "fceuconfig.h"
#include "images/nesback.h" #include "images/nesback.h"
extern unsigned int SMBTimer; extern unsigned int SMBTimer;
@ -54,7 +55,39 @@ static Mtx projectionMatrix,modelViewMatrix;
void CheesyScale(unsigned char *XBuf); void CheesyScale(unsigned char *XBuf);
int whichfb = 0; int whichfb = 0;
int copynow = GX_FALSE; int copynow = GX_FALSE;
u32 FrameTimer = 0;
long long prev;
long long now;
long long gettime();
u32 diff_usec(long long start,long long end);
/****************************************************************************
* setFrameTimer()
* change frame timings depending on whether ROM is NTSC or PAL
***************************************************************************/
int normaldiff;
void setFrameTimer()
{
if (GCSettings.timing == 1) // PAL
normaldiff = 20000; // 50hz
else
normaldiff = 16667; // 60hz
prev = gettime();
}
void SyncSpeed()
{
now = gettime();
int diff = normaldiff - diff_usec(prev, now);
if (diff > 0) // ahead - take a nap
usleep(diff);
prev = now;
}
/**************************************************************************** /****************************************************************************
* VideoThreading * VideoThreading
@ -67,8 +100,8 @@ static unsigned char vbstack[TSTACK];
/**************************************************************************** /****************************************************************************
* vbgetback * vbgetback
* *
* This callback enables the emulator to keep running while waiting for a * This callback enables the emulator to keep running while managing proper
* vertical blank. * timing
* *
* Putting LWP to good use :) * Putting LWP to good use :)
***************************************************************************/ ***************************************************************************/
@ -77,7 +110,7 @@ vbgetback (void *arg)
{ {
while (1) while (1)
{ {
VIDEO_WaitVSync (); /**< Wait for video vertical blank */ SyncSpeed();
LWP_SuspendThread (vbthread); LWP_SuspendThread (vbthread);
} }
@ -112,7 +145,6 @@ static void copy_to_xfb()
copynow = GX_FALSE; copynow = GX_FALSE;
} }
SMBTimer++; SMBTimer++;
FrameTimer++;
// FDS switch disk requested - need to eject, select, and insert // FDS switch disk requested - need to eject, select, and insert
// but not all at once! // but not all at once!
@ -332,30 +364,30 @@ void initDisplay()
if (vmode->viTVMode == VI_TVMODE_NTSC_PROG) if (vmode->viTVMode == VI_TVMODE_NTSC_PROG)
progressive = true; progressive = true;
VIDEO_Configure(vmode); VIDEO_Configure(vmode);
screenheight = vmode->xfbHeight; screenheight = vmode->xfbHeight;
xfb[0] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode)); xfb[0] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode));
xfb[1] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode)); xfb[1] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode));
VIDEO_ClearFrameBuffer (vmode, xfb[0], COLOR_BLACK); VIDEO_ClearFrameBuffer (vmode, xfb[0], COLOR_BLACK);
VIDEO_ClearFrameBuffer (vmode, xfb[1], COLOR_BLACK); VIDEO_ClearFrameBuffer (vmode, xfb[1], COLOR_BLACK);
VIDEO_SetNextFramebuffer (xfb[0]); VIDEO_SetNextFramebuffer (xfb[0]);
VIDEO_SetBlack(FALSE); VIDEO_SetBlack(FALSE);
VIDEO_Flush(); VIDEO_Flush();
VIDEO_WaitVSync(); VIDEO_WaitVSync();
if(vmode->viTVMode&VI_NON_INTERLACE) if(vmode->viTVMode&VI_NON_INTERLACE)
VIDEO_WaitVSync(); VIDEO_WaitVSync();
VIDEO_SetPostRetraceCallback((VIRetraceCallback)UpdatePadsCB); VIDEO_SetPostRetraceCallback((VIRetraceCallback)UpdatePadsCB);
VIDEO_SetPreRetraceCallback((VIRetraceCallback)copy_to_xfb); VIDEO_SetPreRetraceCallback((VIRetraceCallback)copy_to_xfb);
StartGX(); StartGX();
InitVideoThread (); InitVideoThread ();
} }
/**************************************************************************** /****************************************************************************

View File

@ -16,6 +16,7 @@ void clearscreen ();
void showscreen (); void showscreen ();
void initDisplay(); void initDisplay();
void RenderFrame(char *XBuf, int style); void RenderFrame(char *XBuf, int style);
void setFrameTimer();
// color palettes // color palettes
#define MAXPAL 12 #define MAXPAL 12
@ -29,6 +30,5 @@ extern struct st_palettes palettes[];
extern int FDSSwitchRequested; extern int FDSSwitchRequested;
extern int vmode_60hz; extern int vmode_60hz;
extern bool progressive; extern bool progressive;
extern u32 FrameTimer;
#endif #endif