diff --git a/source/ngc/fceugx.cpp b/source/ngc/fceugx.cpp index e8d02fb..d7934b2 100644 --- a/source/ngc/fceugx.cpp +++ b/source/ngc/fceugx.cpp @@ -46,6 +46,10 @@ void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); +extern "C" { +extern void __exception_setreload(int t); +} + static int fskipc = 0; static uint8 *gfx=0; static int32 *sound=0; @@ -207,6 +211,60 @@ static void CreateAppPath(char origpath[]) #endif } +/**************************************************************************** + * USB Gecko Debugging + ***************************************************************************/ + +static bool gecko = false; +static mutex_t gecko_mutex = 0; + +static ssize_t __out_write(struct _reent *r, int fd, const char *ptr, size_t len) +{ + u32 level; + + if (!ptr || len <= 0 || !gecko) + return -1; + + LWP_MutexLock(gecko_mutex); + level = IRQ_Disable(); + usb_sendbuffer(1, ptr, len); + IRQ_Restore(level); + LWP_MutexUnlock(gecko_mutex); + return len; +} + +const devoptab_t gecko_out = { + "stdout", // device name + 0, // size of file structure + NULL, // device open + NULL, // device close + __out_write,// device write + NULL, // device read + NULL, // device seek + NULL, // device fstat + NULL, // device stat + NULL, // device link + NULL, // device unlink + NULL, // device chdir + NULL, // device rename + NULL, // device mkdir + 0, // dirStateSize + NULL, // device diropen_r + NULL, // device dirreset_r + NULL, // device dirnext_r + NULL, // device dirclose_r + NULL // device statvfs_r +}; + +void USBGeckoOutput() +{ + LWP_MutexInit(&gecko_mutex, false); + gecko = usb_isgeckoalive(1); + + devoptab_list[STD_OUT] = &gecko_out; + devoptab_list[STD_ERR] = &gecko_out; +} + /**************************************************************************** * main * This is where it all happens! @@ -214,6 +272,9 @@ static void CreateAppPath(char origpath[]) int main(int argc, char *argv[]) { + //USBGeckoOutput(); // uncomment to enable USB gecko output + __exception_setreload(8); + #ifdef HW_DOL ipl_set_config(6); // disable Qoob modchip #endif