allow redirecting stderr to 3dmoo

This commit is contained in:
Dave Murphy 2014-12-13 14:03:12 +00:00
parent 478d11f468
commit ab3b081398
2 changed files with 57 additions and 0 deletions

View File

@ -102,6 +102,13 @@ typedef struct PrintConsole
#define CONSOLE_CONCEAL (1<<7) #define CONSOLE_CONCEAL (1<<7)
#define CONSOLE_CROSSED_OUT (1<<8) #define CONSOLE_CROSSED_OUT (1<<8)
//! Console debug devices supported by libnds.
typedef enum {
debugDevice_NULL, //!< swallows prints to stderr
debugDevice_3DMOO, //!< Directs stderr debug statements to 3dmoo
debugDevice_CONSOLE, //!< Directs stderr debug statements to 3DS console window
} debugDevice;
/*! \brief Loads the font into the console /*! \brief Loads the font into the console
\param console pointer to the console to update, if NULL it will update the current console \param console pointer to the console to update, if NULL it will update the current console
\param font the font to load \param font the font to load
@ -136,6 +143,12 @@ PrintConsole *consoleSelect(PrintConsole* console);
*/ */
PrintConsole* consoleInit(gfxScreen_t screen, PrintConsole* console); PrintConsole* consoleInit(gfxScreen_t screen, PrintConsole* console);
/*! \brief Initializes debug console output on stderr to the specified device
\param device The debug device (or devices) to output debug print statements to
*/
void consoleDebugInit(debugDevice device);
//! Clears the screan by using iprintf("\x1b[2J"); //! Clears the screan by using iprintf("\x1b[2J");
void consoleClear(void); void consoleClear(void);

View File

@ -3,6 +3,7 @@
#include <sys/iosupport.h> #include <sys/iosupport.h>
#include <3ds/gfx.h> #include <3ds/gfx.h>
#include <3ds/console.h> #include <3ds/console.h>
#include <3ds/svc.h>
#include "default_font_bin.h" #include "default_font_bin.h"
@ -467,6 +468,25 @@ static const devoptab_t dotab_stdout = {
NULL NULL
}; };
//---------------------------------------------------------------------------------
ssize_t debug_write(struct _reent *r, int fd, const char *ptr, size_t len) {
//---------------------------------------------------------------------------------
svcOutputDebugString(ptr,len);
return len;
}
static const devoptab_t dotab_3dmoo = {
"3dmoo",
0,
NULL,
NULL,
debug_write,
NULL,
NULL,
NULL
};
static const devoptab_t dotab_null = { static const devoptab_t dotab_null = {
"null", "null",
0, 0,
@ -519,6 +539,30 @@ PrintConsole* consoleInit(gfxScreen_t screen, PrintConsole* console) {
return currentConsole; return currentConsole;
} }
//---------------------------------------------------------------------------------
void consoleDebugInit(debugDevice device){
//---------------------------------------------------------------------------------
int buffertype = _IONBF;
switch(device) {
case debugDevice_3DMOO:
devoptab_list[STD_ERR] = &dotab_3dmoo;
buffertype = _IOLBF;
break;
case debugDevice_CONSOLE:
devoptab_list[STD_ERR] = &dotab_stdout;
break;
case debugDevice_NULL:
devoptab_list[STD_ERR] = &dotab_null;
break;
}
setvbuf(stderr, NULL , buffertype, 0);
}
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------
PrintConsole *consoleSelect(PrintConsole* console){ PrintConsole *consoleSelect(PrintConsole* console){
//--------------------------------------------------------------------------------- //---------------------------------------------------------------------------------