restructure main loops

This commit is contained in:
dborth 2009-02-08 22:30:42 +00:00
parent 25b192c940
commit 4aefa04e9d
2 changed files with 78 additions and 93 deletions

View File

@ -1082,7 +1082,8 @@ MainMenu (int selectedMenu)
case -1: // Button B case -1: // Button B
// Return to Game // Return to Game
quit = 1; if(SNESROMSize > 0)
quit = 1;
break; break;
} }
} }

View File

@ -78,9 +78,9 @@ void ExitCleanup()
{ {
LWP_SuspendThread (devicethread); LWP_SuspendThread (devicethread);
UnmountAllFAT(); UnmountAllFAT();
CloseShare();
#ifdef HW_RVL #ifdef HW_RVL
CloseShare();
DI_Close(); DI_Close();
#endif #endif
} }
@ -192,100 +192,92 @@ void setFrameTimerMethod()
extern void S9xInitSync(); extern void S9xInitSync();
bool CheckVideo = 0; // for forcing video reset in video.cpp bool CheckVideo = 0; // for forcing video reset in video.cpp
extern uint32 prevRenderedFrameCount; extern uint32 prevRenderedFrameCount;
static int selectedMenu = -1;
void void
emulate () emulate ()
{ {
S9xSetSoundMute (TRUE);
AudioStart ();
S9xInitSync(); // Eke-Eke: initialize frame Sync
setFrameTimerMethod(); // set frametimer method every time a ROM is loaded
while (1) while (1)
{ {
S9xMainLoop (); // go back to checking if devices were inserted/removed
NGCReportButtons (); // since we're entering the menu
LWP_ResumeThread (devicethread);
if(ResetRequested) ConfigRequested = 1;
if(SNESROMSize > 0 && selectedMenu != 2)
selectedMenu = 2;
MainMenu (selectedMenu); // go to menu
ConfigRequested = 0;
Settings.SuperScopeMaster = (GCSettings.Superscope > 0 ? true : false);
Settings.MouseMaster = (GCSettings.Mouse > 0 ? true : false);
Settings.JustifierMaster = (GCSettings.Justifier > 0 ? true : false);
SetControllers ();
// stop checking if devices were removed/inserted
// since we're starting emulation again
LWP_SuspendThread (devicethread);
ResetVideo_Emu();
FrameTimer = 0;
setFrameTimerMethod(); // set frametimer method every time a ROM is loaded
CheckVideo = 1; // force video update
prevRenderedFrameCount = IPPU.RenderedFramesCount;
while(1)
{ {
S9xSoftReset (); // reset game S9xMainLoop ();
ResetRequested = 0; NGCReportButtons ();
}
if (ConfigRequested) if(ResetRequested)
{
// go back to checking if devices were inserted/removed
// since we're entering the menu
LWP_ResumeThread (devicethread);
// change to menu video mode
ResetVideo_Menu ();
if ( GCSettings.AutoSave == 1 )
{ {
SaveSRAM ( GCSettings.SaveMethod, SILENT ); S9xSoftReset (); // reset game
ResetRequested = 0;
} }
else if ( GCSettings.AutoSave == 2 )
if (ConfigRequested)
{ {
if ( WaitPromptChoice ("Save Freeze State?", "Don't Save", "Save") ) // go back to checking if devices were inserted/removed
NGCFreezeGame ( GCSettings.SaveMethod, SILENT ); // since we're entering the menu
} LWP_ResumeThread (devicethread);
else if ( GCSettings.AutoSave == 3 )
{ // change to menu video mode
if ( WaitPromptChoice ("Save SRAM and Freeze State?", "Don't Save", "Save") ) ResetVideo_Menu ();
if ( GCSettings.AutoSave == 1 )
{ {
SaveSRAM(GCSettings.SaveMethod, SILENT ); SaveSRAM ( GCSettings.SaveMethod, SILENT );
NGCFreezeGame ( GCSettings.SaveMethod, SILENT );
} }
else if ( GCSettings.AutoSave == 2 )
{
if ( WaitPromptChoice ("Save Freeze State?", "Don't Save", "Save") )
NGCFreezeGame ( GCSettings.SaveMethod, SILENT );
}
else if ( GCSettings.AutoSave == 3 )
{
if ( WaitPromptChoice ("Save SRAM and Freeze State?", "Don't Save", "Save") )
{
SaveSRAM(GCSettings.SaveMethod, SILENT );
NGCFreezeGame ( GCSettings.SaveMethod, SILENT );
}
}
#ifdef HW_RVL
if(ShutdownRequested)
ShutdownWii();
#endif
// save zoom level
SavePrefs(SILENT);
break;
} }
}
#ifdef HW_RVL }
if(ShutdownRequested)
ShutdownWii();
#endif
// GUI Stuff
/*
gui_alloc();
gui_makebg ();
gui_clearscreen();
gui_draw ();
gui_showscreen ();
//gui_savescreen ();
*/
MainMenu (2); // go to game menu
// save zoom level
SavePrefs(SILENT);
FrameTimer = 0;
setFrameTimerMethod (); // set frametimer method every time a ROM is loaded
Settings.SuperScopeMaster = (GCSettings.Superscope > 0 ? true : false);
Settings.MouseMaster = (GCSettings.Mouse > 0 ? true : false);
Settings.JustifierMaster = (GCSettings.Justifier > 0 ? true : false);
SetControllers ();
//S9xReportControllers ();
ConfigRequested = 0;
#ifdef _DEBUG_VIDEO
// log stuff
fprintf(debughandle, "\n\nPlaying ROM: %s", Memory.ROMFilename);
fprintf(debughandle, "\nrender: %u", GCSettings.render);
#endif
CheckVideo = 1; // force video update
prevRenderedFrameCount = IPPU.RenderedFramesCount;
// stop checking if devices were removed/inserted
// since we're starting emulation again
LWP_SuspendThread (devicethread);
}//if ConfigRequested
}//while
} }
void CreateAppPath(char origpath[]) void CreateAppPath(char origpath[])
@ -337,13 +329,11 @@ main(int argc, char *argv[])
DI_Init(); // first DI_Init(); // first
#endif #endif
int selectedMenu = -1;
#ifdef DEBUG_WII #ifdef DEBUG_WII
DEBUG_Init(GDBSTUB_DEVICE_USB, 1); // init debugging DEBUG_Init(GDBSTUB_DEVICE_USB, 1); // init debugging
//_break(); //_break();
#endif #endif
InitDeviceThread(); InitDeviceThread();
// Initialise video // Initialise video
@ -464,16 +454,10 @@ main(int argc, char *argv[])
} }
#endif #endif
// Get the user to load a ROM S9xSetSoundMute (TRUE);
while (SNESROMSize <= 0) AudioStart ();
{ S9xInitSync(); // initialize frame sync
MainMenu (selectedMenu);
}
// Emulate // Emulate
emulate (); emulate ();
// NO! - We're never leaving here!
while (1);
return 0;
} }