frameskip changes, fix xer asm reloc problem

This commit is contained in:
dborth 2008-10-31 07:53:09 +00:00
parent 2e96b28e24
commit 62c8dc546a
2 changed files with 30 additions and 74 deletions

View File

@ -45,6 +45,8 @@
extern "C" extern "C"
{ {
#include "tbtime.h" #include "tbtime.h"
long long gettime();
u32 diff_usec(long long start,long long end);
} }
static tb_t start, now; static tb_t start, now;
@ -118,50 +120,43 @@ bool systemPauseOnFrame()
{ {
return false; return false;
} }
/*
void GC_Sleep(u32 dwMiliseconds)
{
int nVBlanks = (dwMiliseconds / 16);
while (nVBlanks-- > 0)
{
VIDEO_WaitVSync();
}
}
*/
static u32 autoFrameSkipLastTime = 0; static u32 lastTime = 0;
#define RATE60HZ 166666.67 // 1/6 second or 166666.67 usec
void system10Frames(int rate) void system10Frames(int rate)
{ {
u32 time = systemGetClock(); u32 time = gettime();
u32 diff = time - autoFrameSkipLastTime; u32 diff = diff_usec(lastTime, time);
// difference should be 1/6 second or (1/6)*1000 ms or 167 ms // expected diff - actual diff
int timeOff = (167 - diff); u32 timeOff = RATE60HZ - diff;
if(timeOff > 0 && timeOff < 100) // we're running ahead! if(timeOff > 0 && timeOff < 100000) // we're running ahead!
usleep(timeOff*1000); // let's take a nap usleep(timeOff); // let's take a nap
else else
timeOff = 0; // timeoff was not valid timeOff = 0; // timeoff was not valid
int speed = (RATE60HZ/diff)*100;
if (cartridgeType == 2) // GBA games require frameskipping if (cartridgeType == 2) // GBA games require frameskipping
{ {
// consider increasing skip // consider increasing skip
if(diff >= 270) if(speed < 98)
systemFrameSkip += 4;
else if(diff >= 240)
systemFrameSkip += 3;
else if(diff >= 210)
systemFrameSkip += 2;
else if(diff >= 170)
systemFrameSkip += 1; systemFrameSkip += 1;
else if(speed < 80)
systemFrameSkip += 2;
else if(speed < 70)
systemFrameSkip += 3;
else if(speed < 60)
systemFrameSkip += 4;
// consider decreasing skip // consider decreasing skip
else if(diff <= 90) else if(speed > 185)
systemFrameSkip -= 3; systemFrameSkip -= 3;
else if(diff <= 120) else if(speed > 145)
systemFrameSkip -= 2; systemFrameSkip -= 2;
else if(diff <= 135) else if(speed > 125)
systemFrameSkip -= 1; systemFrameSkip -= 1;
// correct invalid frame skip values // correct invalid frame skip values
@ -170,44 +165,7 @@ void system10Frames(int rate)
else if(systemFrameSkip < 0) else if(systemFrameSkip < 0)
systemFrameSkip = 0; systemFrameSkip = 0;
} }
lastTime = gettime();
autoFrameSkipLastTime = time + timeOff; // total time = processing time + sleep time
/*
// Original VBA SDL frameskip algorithm
int speed = 100;
if(diff)
speed = (1000000/rate)/diff;
if(speed >= 98)
{
frameskipadjust++;
if(frameskipadjust >= 3)
{
frameskipadjust=0;
if(systemFrameSkip > 0)
systemFrameSkip--;
}
}
else
{
if(speed < 80)
frameskipadjust -= (90 - speed)/5;
else if(systemFrameSkip < 9)
frameskipadjust--;
if(frameskipadjust <= -2)
{
frameskipadjust += 2;
if(systemFrameSkip < 9)
systemFrameSkip++;
}
}
autoFrameSkipLastTime = time;
*/
} }
/**************************************************************************** /****************************************************************************
@ -836,7 +794,7 @@ bool LoadVBAROM(int method)
emulating = 1; emulating = 1;
// reset frameskip variables // reset frameskip variables
autoFrameSkipLastTime = systemFrameSkip = 0; lastTime = systemFrameSkip = 0;
// Start system clock // Start system clock
mftb(&start); mftb(&start);

View File

@ -172,12 +172,11 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
C_FLAG = (Flags >> 25) & 1; \ C_FLAG = (Flags >> 25) & 1; \
V_FLAG = (Flags >> 26) & 1; \ V_FLAG = (Flags >> 26) & 1; \
} }
// Wii port - doesn't compile! #define ADC_RD_RS \
/* #define ADC_RD_RS \
{\ {\
register int Flags; \ register int Flags; \
register int Result; \ register int Result; \
asm volatile("mtspr xer, %4\n" \ asm volatile("mtspr 1, %4\n" \
"addeo. %0, %2, %3\n" \ "addeo. %0, %2, %3\n" \
"mcrxr cr1\n" \ "mcrxr cr1\n" \
"mfcr %1\n" \ "mfcr %1\n" \
@ -192,7 +191,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
N_FLAG = (Flags >> 31) & 1; \ N_FLAG = (Flags >> 31) & 1; \
C_FLAG = (Flags >> 25) & 1; \ C_FLAG = (Flags >> 25) & 1; \
V_FLAG = (Flags >> 26) & 1; \ V_FLAG = (Flags >> 26) & 1; \
}*/ }
#define SUB_RD_RS_RN(N) \ #define SUB_RD_RS_RN(N) \
{\ {\
register int Flags; \ register int Flags; \
@ -265,12 +264,11 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
C_FLAG = (Flags >> 25) & 1; \ C_FLAG = (Flags >> 25) & 1; \
V_FLAG = (Flags >> 26) & 1; \ V_FLAG = (Flags >> 26) & 1; \
} }
// Wii port - doesn't compile for some reason #define SBC_RD_RS \
/* #define SBC_RD_RS \
{\ {\
register int Flags; \ register int Flags; \
register int Result; \ register int Result; \
asm volatile("mtspr xer, %4\n" \ asm volatile("mtspr 1, %4\n" \
"subfeo. %0, %3, %2\n" \ "subfeo. %0, %3, %2\n" \
"mcrxr cr1\n" \ "mcrxr cr1\n" \
"mfcr %1\n" \ "mfcr %1\n" \
@ -285,7 +283,7 @@ static INSN_REGPARM void thumbBreakpoint(u32 opcode)
N_FLAG = (Flags >> 31) & 1; \ N_FLAG = (Flags >> 31) & 1; \
C_FLAG = (Flags >> 25) & 1; \ C_FLAG = (Flags >> 25) & 1; \
V_FLAG = (Flags >> 26) & 1; \ V_FLAG = (Flags >> 26) & 1; \
}*/ }
#define NEG_RD_RS \ #define NEG_RD_RS \
{\ {\
register int Flags; \ register int Flags; \