From 62835600e5ce02aae8ca5bd17ced394f7f9f72ec Mon Sep 17 00:00:00 2001 From: dborth Date: Fri, 25 Sep 2009 18:45:51 +0000 Subject: [PATCH] add code for usb gecko debugging --- source/ngc/snes9xGX.cpp | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/source/ngc/snes9xGX.cpp b/source/ngc/snes9xGX.cpp index cf001bb..fac69e5 100644 --- a/source/ngc/snes9xGX.cpp +++ b/source/ngc/snes9xGX.cpp @@ -65,6 +65,10 @@ int ExitRequested = 0; char appPath[1024]; int appLoadMethod = METHOD_AUTO; +extern "C" { +extern void __exception_setreload(int t); +} + /**************************************************************************** * Shutdown / Reboot / Exit ***************************************************************************/ @@ -314,6 +318,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 * @@ -331,6 +389,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