From c9f4238e99cc4fb8fd264f8824205ad887803800 Mon Sep 17 00:00:00 2001 From: dborth Date: Fri, 25 Sep 2009 18:46:25 +0000 Subject: [PATCH] add code for usb gecko debugging --- source/ngc/vba.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/source/ngc/vba.cpp b/source/ngc/vba.cpp index 599b695..83ccf89 100644 --- a/source/ngc/vba.cpp +++ b/source/ngc/vba.cpp @@ -39,6 +39,10 @@ #include "gamesettings.h" #include "wiiusbsupport.h" +extern "C" { +extern void __exception_setreload(int t); +} + extern int emulating; void StopColorizing(); void gbSetPalette(u32 RRGGBB[]); @@ -200,6 +204,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 +}; + +static void USBGeckoOutput() +{ + LWP_MutexInit(&gecko_mutex, false); + gecko = usb_isgeckoalive(1); + + devoptab_list[STD_OUT] = &gecko_out; + devoptab_list[STD_ERR] = &gecko_out; +} + /**************************************************************************** * main * @@ -207,6 +265,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