mirror of
https://github.com/dborth/fceugx.git
synced 2025-01-07 14:28:18 +01:00
more stable threading, file IO corrections, inline video functions
This commit is contained in:
parent
6749937c89
commit
aa53a572ba
@ -59,6 +59,7 @@ lwp_t devicethread = LWP_THREAD_NULL;
|
|||||||
static void *
|
static void *
|
||||||
devicecallback (void *arg)
|
devicecallback (void *arg)
|
||||||
{
|
{
|
||||||
|
sleep(1);
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
@ -73,7 +74,7 @@ devicecallback (void *arg)
|
|||||||
|
|
||||||
if(isMounted[METHOD_USB])
|
if(isMounted[METHOD_USB])
|
||||||
{
|
{
|
||||||
if(!usb->isInserted()) // check if the device was removed - doesn't work on USB!
|
if(!usb->isInserted()) // check if the device was removed
|
||||||
{
|
{
|
||||||
unmountRequired[METHOD_USB] = true;
|
unmountRequired[METHOD_USB] = true;
|
||||||
isMounted[METHOD_USB] = false;
|
isMounted[METHOD_USB] = false;
|
||||||
@ -100,7 +101,7 @@ devicecallback (void *arg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
usleep(500000); // suspend thread for 1/2 sec
|
sleep(1); // suspend thread for 1 sec
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -477,30 +478,32 @@ LoadFile (char * rbuffer, char *filepath, u32 length, int method, bool silent)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct stat fileinfo;
|
struct stat fileinfo;
|
||||||
fstat(file->_file, &fileinfo);
|
if(fstat(file->_file, &fileinfo) == 0)
|
||||||
size = fileinfo.st_size;
|
|
||||||
|
|
||||||
memcpy (rbuffer, zipbuffer, readsize); // copy what we already read
|
|
||||||
|
|
||||||
u32 offset = readsize;
|
|
||||||
u32 nextread = 0;
|
|
||||||
while(offset < size)
|
|
||||||
{
|
{
|
||||||
if(size - offset > 1024*512) nextread = 1024*512;
|
size = fileinfo.st_size;
|
||||||
else nextread = size-offset;
|
|
||||||
ShowProgress ("Loading...", offset, size);
|
|
||||||
readsize = fread (rbuffer + offset, 1, nextread, file); // read in next chunk
|
|
||||||
|
|
||||||
if(readsize <= 0 || readsize > nextread)
|
memcpy (rbuffer, zipbuffer, readsize); // copy what we already read
|
||||||
break; // read failure
|
|
||||||
|
|
||||||
if(readsize > 0)
|
u32 offset = readsize;
|
||||||
offset += readsize;
|
u32 nextread = 0;
|
||||||
|
while(offset < size)
|
||||||
|
{
|
||||||
|
if(size - offset > 1024*512) nextread = 1024*512;
|
||||||
|
else nextread = size-offset;
|
||||||
|
ShowProgress ("Loading...", offset, size);
|
||||||
|
readsize = fread (rbuffer + offset, 1, nextread, file); // read in next chunk
|
||||||
|
|
||||||
|
if(readsize <= 0 || readsize > nextread)
|
||||||
|
break; // read failure
|
||||||
|
|
||||||
|
if(readsize > 0)
|
||||||
|
offset += readsize;
|
||||||
|
}
|
||||||
|
CancelAction();
|
||||||
|
|
||||||
|
if(offset != size) // # bytes read doesn't match # expected
|
||||||
|
size = 0;
|
||||||
}
|
}
|
||||||
CancelAction();
|
|
||||||
|
|
||||||
if(offset != size) // # bytes read doesn't match # expected
|
|
||||||
size = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -569,8 +572,17 @@ SaveFile (char * buffer, char *filepath, u32 datasize, int method, bool silent)
|
|||||||
|
|
||||||
if (file > 0)
|
if (file > 0)
|
||||||
{
|
{
|
||||||
written = fwrite (savebuffer, 1, datasize, file);
|
u32 writesize, nextwrite;
|
||||||
if(written < datasize) written = 0;
|
while(written < datasize)
|
||||||
|
{
|
||||||
|
if(datasize - written > 16*1024) nextwrite=16*1024;
|
||||||
|
else nextwrite = datasize-written;
|
||||||
|
writesize = fwrite (buffer+written, 1, nextwrite, file);
|
||||||
|
if(writesize != nextwrite) break; // write failure
|
||||||
|
written += writesize;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(written != datasize) written = 0;
|
||||||
fclose (file);
|
fclose (file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ InitVideoThread ()
|
|||||||
* Stock code to copy the GX buffer to the current display mode.
|
* Stock code to copy the GX buffer to the current display mode.
|
||||||
* Also increments the frameticker, as it's called for each vb.
|
* Also increments the frameticker, as it's called for each vb.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void
|
static inline void
|
||||||
copy_to_xfb (u32 arg)
|
copy_to_xfb (u32 arg)
|
||||||
{
|
{
|
||||||
if (copynow == GX_TRUE)
|
if (copynow == GX_TRUE)
|
||||||
@ -313,7 +313,7 @@ copy_to_xfb (u32 arg)
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Scaler Support Functions
|
* Scaler Support Functions
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void
|
static inline void
|
||||||
draw_init ()
|
draw_init ()
|
||||||
{
|
{
|
||||||
GX_ClearVtxDesc ();
|
GX_ClearVtxDesc ();
|
||||||
@ -342,7 +342,7 @@ draw_init ()
|
|||||||
GX_InvVtxCache (); // update vertex cache
|
GX_InvVtxCache (); // update vertex cache
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static inline void
|
||||||
draw_vert (u8 pos, u8 c, f32 s, f32 t)
|
draw_vert (u8 pos, u8 c, f32 s, f32 t)
|
||||||
{
|
{
|
||||||
GX_Position1x8 (pos);
|
GX_Position1x8 (pos);
|
||||||
@ -350,7 +350,7 @@ draw_vert (u8 pos, u8 c, f32 s, f32 t)
|
|||||||
GX_TexCoord2f32 (s, t);
|
GX_TexCoord2f32 (s, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static inline void
|
||||||
draw_square (Mtx v)
|
draw_square (Mtx v)
|
||||||
{
|
{
|
||||||
Mtx m; // model matrix.
|
Mtx m; // model matrix.
|
||||||
@ -409,7 +409,7 @@ void StopGX()
|
|||||||
*
|
*
|
||||||
* This function updates the quad aspect ratio.
|
* This function updates the quad aspect ratio.
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
static void
|
static inline void
|
||||||
UpdateScaling()
|
UpdateScaling()
|
||||||
{
|
{
|
||||||
int xscale, yscale;
|
int xscale, yscale;
|
||||||
|
@ -41,6 +41,8 @@
|
|||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "fceuload.h"
|
#include "fceuload.h"
|
||||||
|
|
||||||
|
#define THREAD_SLEEP 100
|
||||||
|
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
static GuiImageData * pointer[4];
|
static GuiImageData * pointer[4];
|
||||||
#endif
|
#endif
|
||||||
@ -101,7 +103,7 @@ HaltGui()
|
|||||||
|
|
||||||
// wait for thread to finish
|
// wait for thread to finish
|
||||||
while(!LWP_ThreadIsSuspended(guithread))
|
while(!LWP_ThreadIsSuspended(guithread))
|
||||||
usleep(50);
|
usleep(THREAD_SLEEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -196,7 +198,7 @@ WindowPrompt(const char *title, const char *msg, const char *btn1Label, const ch
|
|||||||
|
|
||||||
while(choice == -1)
|
while(choice == -1)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
if(btn1.GetState() == STATE_CLICKED)
|
if(btn1.GetState() == STATE_CLICKED)
|
||||||
choice = 1;
|
choice = 1;
|
||||||
@ -205,7 +207,7 @@ WindowPrompt(const char *title, const char *msg, const char *btn1Label, const ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50);
|
promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50);
|
||||||
while(promptWindow.GetEffect() > 0) usleep(50);
|
while(promptWindow.GetEffect() > 0) usleep(THREAD_SLEEP);
|
||||||
HaltGui();
|
HaltGui();
|
||||||
mainWindow->Remove(&promptWindow);
|
mainWindow->Remove(&promptWindow);
|
||||||
mainWindow->SetState(STATE_DEFAULT);
|
mainWindow->SetState(STATE_DEFAULT);
|
||||||
@ -293,6 +295,7 @@ UpdateGUI (void *arg)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
usleep(THREAD_SLEEP);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -382,7 +385,7 @@ ProgressWindow(char *title, char *msg)
|
|||||||
|
|
||||||
while(showProgress)
|
while(showProgress)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync();
|
usleep(20000);
|
||||||
|
|
||||||
if(showProgress == 1)
|
if(showProgress == 1)
|
||||||
{
|
{
|
||||||
@ -415,6 +418,7 @@ static void * ProgressThread (void *arg)
|
|||||||
LWP_SuspendThread (progressthread);
|
LWP_SuspendThread (progressthread);
|
||||||
|
|
||||||
ProgressWindow(progressTitle, progressMsg);
|
ProgressWindow(progressTitle, progressMsg);
|
||||||
|
usleep(THREAD_SLEEP);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -445,7 +449,7 @@ CancelAction()
|
|||||||
|
|
||||||
// wait for thread to finish
|
// wait for thread to finish
|
||||||
while(!LWP_ThreadIsSuspended(progressthread))
|
while(!LWP_ThreadIsSuspended(progressthread))
|
||||||
usleep(50);
|
usleep(THREAD_SLEEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -600,7 +604,7 @@ static void OnScreenKeyboard(char * var, u32 maxlen)
|
|||||||
|
|
||||||
while(save == -1)
|
while(save == -1)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
if(okBtn.GetState() == STATE_CLICKED)
|
if(okBtn.GetState() == STATE_CLICKED)
|
||||||
save = 1;
|
save = 1;
|
||||||
@ -693,7 +697,7 @@ SettingWindow(const char * title, GuiWindow * w)
|
|||||||
|
|
||||||
while(save == -1)
|
while(save == -1)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
if(okBtn.GetState() == STATE_CLICKED)
|
if(okBtn.GetState() == STATE_CLICKED)
|
||||||
save = 1;
|
save = 1;
|
||||||
@ -830,6 +834,7 @@ static void WindowCredits(void * ptr)
|
|||||||
if(userInput[i].wpad.btns_d || userInput[i].pad.btns_d)
|
if(userInput[i].wpad.btns_d || userInput[i].pad.btns_d)
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
|
usleep(THREAD_SLEEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear buttons pressed
|
// clear buttons pressed
|
||||||
@ -944,7 +949,7 @@ static int MenuGameSelection()
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
// update gameWindow based on arrow buttons
|
// update gameWindow based on arrow buttons
|
||||||
// set MENU_EXIT if A button pressed on a game
|
// set MENU_EXIT if A button pressed on a game
|
||||||
@ -1313,7 +1318,7 @@ static int MenuGame()
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
int level;
|
int level;
|
||||||
@ -1603,7 +1608,7 @@ static int MenuGameSaves(int action)
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync ();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
ret = saveBrowser.GetClickedSave();
|
ret = saveBrowser.GetClickedSave();
|
||||||
|
|
||||||
@ -1851,7 +1856,7 @@ static int MenuGameSettings()
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
if(mappingBtn.GetState() == STATE_CLICKED)
|
if(mappingBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
@ -1972,7 +1977,7 @@ static int MenuGameCheats()
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync ();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
for(i=0; i < Cheat.num_cheats; i++)
|
for(i=0; i < Cheat.num_cheats; i++)
|
||||||
sprintf (options.value[i], "%s", Cheat.c[i].enabled == true ? "On" : "Off");
|
sprintf (options.value[i], "%s", Cheat.c[i].enabled == true ? "On" : "Off");
|
||||||
@ -2085,7 +2090,7 @@ static int MenuSettingsMappings()
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync ();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
if(nesBtn.GetState() == STATE_CLICKED)
|
if(nesBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
@ -2249,7 +2254,7 @@ static int MenuSettingsMappingsController()
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync ();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
if(wiimoteBtn.GetState() == STATE_CLICKED)
|
if(wiimoteBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
@ -2348,7 +2353,7 @@ ButtonMappingWindow()
|
|||||||
|
|
||||||
while(pressed == 0)
|
while(pressed == 0)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
if(mapMenuCtrl == CTRLR_GCPAD)
|
if(mapMenuCtrl == CTRLR_GCPAD)
|
||||||
{
|
{
|
||||||
@ -2491,7 +2496,7 @@ static int MenuSettingsMappingsMap()
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync ();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
for(i=0; i < options.length; i++)
|
for(i=0; i < options.length; i++)
|
||||||
{
|
{
|
||||||
@ -2800,7 +2805,7 @@ static int MenuSettingsVideo()
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync ();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
// don't allow original render mode if progressive video mode detected
|
// don't allow original render mode if progressive video mode detected
|
||||||
if (GCSettings.render==0 && progressive)
|
if (GCSettings.render==0 && progressive)
|
||||||
@ -3042,7 +3047,7 @@ static int MenuSettings()
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync ();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
if(savingBtn.GetState() == STATE_CLICKED)
|
if(savingBtn.GetState() == STATE_CLICKED)
|
||||||
{
|
{
|
||||||
@ -3148,7 +3153,7 @@ static int MenuSettingsFile()
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync ();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
// some load/save methods are not implemented - here's where we skip them
|
// some load/save methods are not implemented - here's where we skip them
|
||||||
// they need to be skipped in the order they were enumerated in snes9xGX.h
|
// they need to be skipped in the order they were enumerated in snes9xGX.h
|
||||||
@ -3329,7 +3334,7 @@ static int MenuSettingsMenu()
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync ();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
if (GCSettings.ExitAction == 1)
|
if (GCSettings.ExitAction == 1)
|
||||||
@ -3463,7 +3468,7 @@ static int MenuSettingsNetwork()
|
|||||||
|
|
||||||
while(menu == MENU_NONE)
|
while(menu == MENU_NONE)
|
||||||
{
|
{
|
||||||
VIDEO_WaitVSync ();
|
usleep(THREAD_SLEEP);
|
||||||
|
|
||||||
strncpy (options.value[0], GCSettings.smbip, 15);
|
strncpy (options.value[0], GCSettings.smbip, 15);
|
||||||
strncpy (options.value[1], GCSettings.smbshare, 19);
|
strncpy (options.value[1], GCSettings.smbshare, 19);
|
||||||
@ -3640,6 +3645,7 @@ MainMenu (int menu)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
lastMenu = currentMenu;
|
lastMenu = currentMenu;
|
||||||
|
usleep(THREAD_SLEEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HW_RVL
|
#ifdef HW_RVL
|
||||||
|
Loading…
Reference in New Issue
Block a user