starting to work on some stability fixes

This commit is contained in:
zeromus 2006-07-20 06:10:45 +00:00
parent 6d115a081a
commit e4675d9616
4 changed files with 400 additions and 170 deletions

View File

@ -1234,12 +1234,14 @@ BOOL CALLBACK DebuggerCallB(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
}
break;
case 105: //Step Into
//mbg merge 7/19/06 also put the whole block inside the if (previously only updateregs was... was it a bug?)
//mbg merge 7/18/06 changed pausing check and set
if (FCEUI_EmulationPaused())
if (FCEUI_EmulationPaused()) {
UpdateRegs(hwndDlg);
step = 1;
FCEUI_SetEmulationPaused(0);
UpdateDebugger();
step = 1;
FCEUI_SetEmulationPaused(0);
UpdateDebugger();
}
break;
case 106: //Step Out
//mbg merge 7/18/06 changed pausing check and set

View File

@ -284,6 +284,8 @@ FCEUX\n\
MessageBox(hAppWnd,TempArray,"About FCEUXD SP",MB_OK);
}
//mbg 6/30/06 - indicates that the main loop should close the game as soon as it can
int closeGame = 0;
void DoFCEUExit(void)
{
@ -294,6 +296,8 @@ void DoFCEUExit(void)
"E-x-i-t?"
};
KillDebugger(); //mbg merge 7/19/06 added
if(exiting) /* Eh, oops. I'll need to try to fix this later. */
return;
@ -306,11 +310,7 @@ void DoFCEUExit(void)
FCEUD_AviStop();
exiting=1;
if(GI)
{
FCEUI_CloseGame();
GI=0;
}
closeGame = 1;//mbg 6/30/06 - for housekeeping purposes we need to exit after the emulation cycle finishes
}
void DoPriority(void)
@ -451,6 +451,14 @@ doloopy:
FCEUI_Emulate(&gfx, &sound, &ssize, 0);
xbsave = gfx;
FCEUD_Update(gfx, sound, ssize);
//mbg 6/30/06 - close game if we were commanded to by calls nested in FCEUI_Emulate()
if(closeGame)
{
FCEUI_CloseGame();
GI = 0;
}
//mbg merge 7/19/06
@ -517,6 +525,208 @@ void _updateWindow() {
NTViewDoBlit(0);
}
//void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count)
//{
// static int skipcount = 0;
// int temp_fps_scale=(NoWaiting&1)?(256*16):fps_scale;
// int maxskip = (temp_fps_scale<=256) ? 0 : temp_fps_scale>>8;
//
// int ocount = Count;
// // apply frame scaling to Count
// Count = (Count<<8)/temp_fps_scale;
//
// //Disable sound and throttling for BotMode--we want max speed!
// if(FCEU_BotMode())
// {
// if(XBuf && (skipcount >= 64))
// {
// skipcount = 0;
// FCEUD_BlitScreen(XBuf);
// }
// else
// {
// skipcount++;
// }
// UpdateFCEUWindow();
// FCEUD_UpdateInput();
// return;
// }
//
// if(!(soundoptions&SO_OLDUP) && soundo && temp_fps_scale >= 64)
// {
// // sounds better with FPS scaling, and is much less code than the other version...
//
// int32 writeSize = GetWriteSound();
// int32 writeCount = Count;
///*
// // prevents delay when exiting fast-forward
// if((NoWaiting&1) && writeCount>writeSize)
// writeCount=writeSize;
//*/
//
// if(Buffer && (writeCount))
// FCEUD_WriteSoundData(Buffer,temp_fps_scale,MAX(writeSize,writeCount));
//
// if(XBuf && (skipcount >= maxskip))
// {
// skipcount = 0;
// FCEUD_BlitScreen(XBuf);
// _updateMemWatch();
// }
// else
// skipcount++;
//
// _updateWindow();
// }
// else
// {
// // I don't understand this code, so I kept it around as an option ("old sound update")
// // in case it's doing something clever and necessary that I can't fathom
// // (oops, also it seems to be important for speeds <25% so it's always used then)
//
// const int soundScale = !(soundoptions&SO_OLDUP) ? temp_fps_scale : 256;
//
// if(Count)
// {
// int32 can=GetWriteSound();
// static int uflow=0;
// int32 tmpcan;
// extern int FCEUDnetplay;
//
// // don't underflow when scaling fps
// if(can >= GetMaxSound() && fps_scale<=256) uflow=1; // Go into massive underflow mode.
//
// if(can > Count) can=Count;
// else uflow=0;
//
// FCEUD_WriteSoundData(Buffer,soundScale,can);
//
// tmpcan = GetWriteSound();
// // don't underflow when scaling fps
// if(fps_scale>256 || ((tmpcan < Count*0.90) && !uflow) || (skipcount >= maxskip))
// {
// if(XBuf && (skipcount >= maxskip))
// {
// skipcount = 0;
// FCEUD_BlitScreen(XBuf);
// _updateMemWatch();
// }
// else
// {
// skipcount++;
// //FCEU_printf("Skipped0");
// // FCEU_PrintError("Skipped0");
// }
// Buffer+=can;
// Count-=can;
// if(Count)
// {
// if(NoWaiting)
// {
// can=GetWriteSound();
// if(Count>can) Count=can;
// FCEUD_WriteSoundData(Buffer,soundScale,Count);
// }
// else
// {
// int cnum=0;
// extern int silencer;
// while(Count>0)
// {
// FCEUD_WriteSoundData(Buffer,soundScale,(Count<ocount) ? Count : ocount);
// if(!(soundoptions&SO_OLDUP))
// {
// cnum++;
// if(cnum>2)
// silencer=1;
// }
// Count -= ocount;
// // prevent long updates from interfering with gui responsiveness:
//
// //mbg merge 7/19/06
// //UpdateFCEUWindow();
// //FCEUD_UpdateInput();
// _updateWindow();
// }
// silencer=0;
// }
// }
// }
// else
// {
// skipcount++;
// //FCEU_printf("Skipped");
//#ifdef NETWORK
// if(!NoWaiting && FCEUDnetplay && (uflow || tmpcan >= (Count * 0.90)))
// {
// if(Count > tmpcan) Count=tmpcan;
// while(tmpcan > 0)
// {
// //printf("Overwrite: %d\n", (Count <= tmpcan)?Count : tmpcan);
// FCEUD_WriteSoundData(Buffer,soundScale,(Count <= tmpcan)?Count : tmpcan);
// tmpcan -= Count;
// }
// }
//#endif
// }
// }
// else
// {
// /* This complex statement deserves some explanation.
// Make sure this special speed throttling hasn't been disabled by the user
// first. Second, we don't want to throttle the speed if the fast-forward
// button is pressed down(or during certain network play conditions).
//
// Now, if we're at this point, we'll throttle speed if sound is disabled.
// Otherwise, it gets a bit more complicated. We'll throttle speed if focus
// to FCE Ultra has been lost and we're writing to the primary sound buffer
// because our sound code won't block. Blocking does seem to work when
// writing to a secondary buffer, so we won't throttle when a secondary
// buffer is used.
// */
//
// //doagain: //mbg merge 6/30/06
//
// int skipthis = 0;
//
// if(!(eoptions&EO_NOTHROTTLE) || fps_scale != 256)
// if(!NoWaiting)
// if(!soundo || (soundo && nofocus && !(soundoptions&SO_SECONDARY)) || FCEUI_EmulationPaused() )
// skipthis = SpeedThrottle();
//
// if(XBuf)
// {
// if((!skipthis && !NoWaiting) || (skipcount >= maxskip))
// {
// FCEUD_BlitScreen(XBuf);
// _updateMemWatch();
// skipcount = 0;
// }
// else
// {
// skipcount++;
// }
// }
//
// //mbg merge 7/19/06 - since tasbuild we have code in main that attempts to do stuff like this
// //mbg merge 6/30/06
// //if(FCEUI_EmulationPaused())
// //{
// // StopSound();
// // Sleep(50);
// // BlockingCheck();
// // goto doagain;
// //}
// }
//
// //mbg merge 7/19/06
// //UpdateFCEUWindow();
// //FCEUD_UpdateInput();
// _updateWindow();
//
// } // end of !(old sound code) block
//}
void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count)
{
static int skipcount = 0;
@ -527,6 +737,7 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count)
// apply frame scaling to Count
Count = (Count<<8)/temp_fps_scale;
//mbg merge 7/19/06 - leaving this untouched but untested
//Disable sound and throttling for BotMode--we want max speed!
if(FCEU_BotMode())
{
@ -544,181 +755,121 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count)
return;
}
if(!(soundoptions&SO_OLDUP) && soundo && temp_fps_scale >= 64)
{
// sounds better with FPS scaling, and is much less code than the other version...
//mbg naive code
if(soundo && Buffer && Count) {
int32 writeSize = GetWriteSound();
int32 writeCount = Count;
/*
// prevents delay when exiting fast-forward
if((NoWaiting&1) && writeCount>writeSize)
writeCount=writeSize;
*/
if(Buffer && (writeCount))
FCEUD_WriteSoundData(Buffer,temp_fps_scale,MAX(writeSize,writeCount));
if(XBuf && (skipcount >= maxskip))
{
skipcount = 0;
FCEUD_BlitScreen(XBuf);
_updateMemWatch();
}
else
skipcount++;
_updateWindow();
FCEUD_WriteSoundData(Buffer,temp_fps_scale,MAX(writeSize,writeCount));
}
else
if(XBuf)
FCEUD_BlitScreen(XBuf);
_updateWindow();
//delay until we unpause
while(FCEUI_EmulationPaused())
{
// I don't understand this code, so I kept it around as an option ("old sound update")
// in case it's doing something clever and necessary that I can't fathom
// (oops, also it seems to be important for speeds <25% so it's always used then)
Sleep(50);
BlockingCheck();
}
const int soundScale = !(soundoptions&SO_OLDUP) ? temp_fps_scale : 256;
// if(soundo) //&& temp_fps_scale >= 64
// {
// // sounds better with FPS scaling, and is much less code than the other version...
//
// int32 writeSize = GetWriteSound();
// int32 writeCount = Count;
///*
// // prevents delay when exiting fast-forward
// if((NoWaiting&1) && writeCount>writeSize)
// writeCount=writeSize;
//*/
//
// if(Buffer && (writeCount))
// FCEUD_WriteSoundData(Buffer,temp_fps_scale,MAX(writeSize,writeCount));
//
// if(XBuf && (skipcount >= maxskip))
// {
// skipcount = 0;
// FCEUD_BlitScreen(XBuf);
// _updateMemWatch();
// }
// else
// skipcount++;
//
// _updateWindow();
// }
//#ifdef NETWORK
// if(!NoWaiting && FCEUDnetplay && (uflow || tmpcan >= (Count * 0.90)))
// {
// if(Count > tmpcan) Count=tmpcan;
// while(tmpcan > 0)
// {
// //printf("Overwrite: %d\n", (Count <= tmpcan)?Count : tmpcan);
// FCEUD_WriteSoundData(Buffer,soundScale,(Count <= tmpcan)?Count : tmpcan);
// tmpcan -= Count;
// }
// }
//#endif
// {
// /* This complex statement deserves some explanation.
// Make sure this special speed throttling hasn't been disabled by the user
// first. Second, we don't want to throttle the speed if the fast-forward
// button is pressed down(or during certain network play conditions).
if(Count)
{
int32 can=GetWriteSound();
static int uflow=0;
int32 tmpcan;
extern int FCEUDnetplay;
// Now, if we're at this point, we'll throttle speed if sound is disabled.
// Otherwise, it gets a bit more complicated. We'll throttle speed if focus
// to FCE Ultra has been lost and we're writing to the primary sound buffer
// because our sound code won't block. Blocking does seem to work when
// writing to a secondary buffer, so we won't throttle when a secondary
// buffer is used.
// */
// don't underflow when scaling fps
if(can >= GetMaxSound() && fps_scale<=256) uflow=1; // Go into massive underflow mode.
// //doagain: //mbg merge 6/30/06
if(can > Count) can=Count;
else uflow=0;
// int skipthis = 0;
FCEUD_WriteSoundData(Buffer,soundScale,can);
// if(!(eoptions&EO_NOTHROTTLE) || fps_scale != 256)
// if(!NoWaiting)
// if(!soundo || (soundo && nofocus && !(soundoptions&SO_SECONDARY)) || FCEUI_EmulationPaused() )
// skipthis = SpeedThrottle();
tmpcan = GetWriteSound();
// don't underflow when scaling fps
if(fps_scale>256 || ((tmpcan < Count*0.90) && !uflow) || (skipcount >= maxskip))
{
if(XBuf && (skipcount >= maxskip))
{
skipcount = 0;
FCEUD_BlitScreen(XBuf);
_updateMemWatch();
}
else
{
skipcount++;
//FCEU_printf("Skipped0");
// FCEU_PrintError("Skipped0");
}
Buffer+=can;
Count-=can;
if(Count)
{
if(NoWaiting)
{
can=GetWriteSound();
if(Count>can) Count=can;
FCEUD_WriteSoundData(Buffer,soundScale,Count);
}
else
{
int cnum=0;
extern int silencer;
while(Count>0)
{
FCEUD_WriteSoundData(Buffer,soundScale,(Count<ocount) ? Count : ocount);
if(!(soundoptions&SO_OLDUP))
{
cnum++;
if(cnum>2)
silencer=1;
}
Count -= ocount;
// prevent long updates from interfering with gui responsiveness:
// if(XBuf)
// {
// if((!skipthis && !NoWaiting) || (skipcount >= maxskip))
// {
// FCEUD_BlitScreen(XBuf);
// _updateMemWatch();
// skipcount = 0;
// }
// else
// {
// skipcount++;
// }
// }
//mbg merge 7/19/06
//UpdateFCEUWindow();
//FCEUD_UpdateInput();
_updateWindow();
}
silencer=0;
}
}
}
else
{
skipcount++;
//FCEU_printf("Skipped");
#ifdef NETWORK
if(!NoWaiting && FCEUDnetplay && (uflow || tmpcan >= (Count * 0.90)))
{
if(Count > tmpcan) Count=tmpcan;
while(tmpcan > 0)
{
//printf("Overwrite: %d\n", (Count <= tmpcan)?Count : tmpcan);
FCEUD_WriteSoundData(Buffer,soundScale,(Count <= tmpcan)?Count : tmpcan);
tmpcan -= Count;
}
}
#endif
}
}
else
{
/* This complex statement deserves some explanation.
Make sure this special speed throttling hasn't been disabled by the user
first. Second, we don't want to throttle the speed if the fast-forward
button is pressed down(or during certain network play conditions).
// //mbg merge 7/19/06 - since tasbuild we have code in main that attempts to do stuff like this
// //mbg merge 6/30/06
// //if(FCEUI_EmulationPaused())
// //{
// // StopSound();
// // Sleep(50);
// // BlockingCheck();
// // goto doagain;
// //}
// }
Now, if we're at this point, we'll throttle speed if sound is disabled.
Otherwise, it gets a bit more complicated. We'll throttle speed if focus
to FCE Ultra has been lost and we're writing to the primary sound buffer
because our sound code won't block. Blocking does seem to work when
writing to a secondary buffer, so we won't throttle when a secondary
buffer is used.
*/
// //mbg merge 7/19/06
// //UpdateFCEUWindow();
// //FCEUD_UpdateInput();
// _updateWindow();
//doagain: //mbg merge 6/30/06
int skipthis = 0;
if(!(eoptions&EO_NOTHROTTLE) || fps_scale != 256)
if(!NoWaiting)
if(!soundo || (soundo && nofocus && !(soundoptions&SO_SECONDARY)) || FCEUI_EmulationPaused() )
skipthis = SpeedThrottle();
if(XBuf)
{
if((!skipthis && !NoWaiting) || (skipcount >= maxskip))
{
FCEUD_BlitScreen(XBuf);
_updateMemWatch();
skipcount = 0;
}
else
{
skipcount++;
}
}
//mbg merge 7/19/06 - since tasbuild we have code in main that attempts to do stuff like this
//mbg merge 6/30/06
//if(FCEUI_EmulationPaused())
//{
// StopSound();
// Sleep(50);
// BlockingCheck();
// goto doagain;
//}
}
//mbg merge 7/19/06
//UpdateFCEUWindow();
//FCEUD_UpdateInput();
_updateWindow();
} // end of !(old sound code) block
//} // end of !(old sound code) block
}
/*
void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count)
{

View File

@ -281,6 +281,83 @@ int FCEUD_WriteSoundData(int32 *Buffer, int scale, int Count)
return iCount;
}
/*
//mbg merge 7/19/06 an experiment in understanding the sound update code
int FCEUD_WriteSoundData(int32 *Buffer, int scale, int Count)
{
#define WSD_BUFSIZE (2 * 96000 / 50)
int P;
int iCount=0;
static int16 MBuffer[WSD_BUFSIZE*2];
//if(!(soundoptions&SO_OLDUP))
//{
//shouldnt the sound be stopped?
//if(FCEUI_EmulationPaused())
// memset(MBuffer, 0, WSD_BUFSIZE); // slow and/or unnecessary
//why?
//if(FCEUI_EmulationPaused()) scale >>= 1;
// limit frequency change to between 50% and 200%
//if(scale > 512) scale = 512;
//if(scale < 128) scale = 128;
//}
int silence = FCEUI_EmulationPaused() | silencer;
for(;Count>0;Count-=WSD_BUFSIZE)
{
//int amt = (soundoptions&SO_OLDUP) ? Count : (Count > WSD_BUFSIZE ? WSD_BUFSIZE : Count);
int amt = (Count > WSD_BUFSIZE ? WSD_BUFSIZE : Count);
if(!bittage)
{
if(silence)
for(P=0;P<amt;P++)
*(((uint8*)MBuffer)+P)=((int8)(Buffer[0]>>8))^128;
else if(scale == 256) // exactly 100% speed
for(P=0;P<amt;P++)
*(((uint8*)MBuffer)+P)=((int8)(Buffer[P]>>8))^128;
else // change sound frequency
for(P=0;P<amt;P++)
*(((uint8*)MBuffer)+P)=((int8)(Buffer[P*scale/256]>>8))^128;
RawWrite(MBuffer,amt);
}
else // force 8-bit sound is off:
{
if(silence)
for(P=0;P<amt;P++)
MBuffer[P]=Buffer[0];
else if(scale == 256) // exactly 100% speed
for(P=0;P<amt;P++)
MBuffer[P]=Buffer[P];
else // change sound frequency
for(int chan=0;chan<2;chan++) {
int16 *dest = MBuffer+chan;
int32 *src = Buffer+chan;
int work = amt>>1;
for(P=0;P<work;P++) {
//interpolate
int loc = P*scale;
int mix = src[(loc>>8)<<1];
mix += ((src[((loc>>8)+1)<<1]-mix)*(loc&255))>>8;
dest[P<<1] = mix;
}
}
RawWrite(MBuffer,amt * 2);
}
iCount+=amt;
}
// FCEUI_AviSoundUpdate((void*)MBuffer, Count);
return iCount;
}
*/
int InitSound()
{
DSCAPS dscaps;

View File

@ -900,7 +900,7 @@ static int RecalcCustom(void)
BOOL SetDlgItemDouble(HWND hDlg, int item, double value)
{
char buf[8];
char buf[9]; //mbg merge 7/19/06 changed to 9 to leave room for \0
sprintf(buf,"%.6f",value);
return SetDlgItemText(hDlg, item, buf); //mbg merge 7/17/06 added this return value
}