ftpiiu_plugin/source/console.c

110 lines
1.7 KiB
C
Raw Normal View History

2014-11-23 23:39:00 +01:00
#include "console.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#ifdef _3DS
#include <3ds.h>
#endif
#include "debug.h"
#include "gfx.h"
2014-11-23 23:39:00 +01:00
#ifdef _3DS
2014-12-06 23:01:02 +01:00
#include "banner_bin.h"
2014-11-23 23:39:00 +01:00
static PrintConsole status_console;
static PrintConsole main_console;
2014-11-23 23:39:00 +01:00
/*! initialize console subsystem */
void
console_init(void)
{
consoleInit(GFX_TOP, &status_console);
consoleSetWindow(&status_console, 0, 0, 50, 1);
2014-11-23 23:39:00 +01:00
consoleInit(GFX_TOP, &main_console);
consoleSetWindow(&main_console, 0, 1, 50, 29);
2014-11-23 23:39:00 +01:00
consoleSelect(&main_console);
2015-01-08 06:30:22 +01:00
consoleDebugInit(debugDevice_NULL);
2014-11-23 23:39:00 +01:00
}
/*! set status bar contents
*
* @param[in] fmt format string
* @param[in] ... format arguments
*/
void
console_set_status(const char *fmt, ...)
{
va_list ap;
consoleSelect(&status_console);
2014-11-23 23:39:00 +01:00
va_start(ap, fmt);
vprintf(fmt, ap);
2015-01-08 06:30:22 +01:00
vfprintf(stderr, fmt, ap);
2014-11-23 23:39:00 +01:00
va_end(ap);
consoleSelect(&main_console);
2014-11-23 23:39:00 +01:00
}
/*! add text to the console
*
* @param[in] fmt format string
* @param[in] ... format arguments
*/
void
console_print(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
2015-01-08 06:30:22 +01:00
vfprintf(stderr, fmt, ap);
2014-11-23 23:39:00 +01:00
va_end(ap);
}
/*! draw console to screen */
void
console_render(void)
{
/* clear all screens */
2014-12-06 23:01:02 +01:00
gfxDrawSprite(GFX_BOTTOM, GFX_LEFT, (u8*)banner_bin, 240, 320, 0, 0);
2014-11-23 23:39:00 +01:00
/* flush framebuffer */
gfxFlushBuffers();
gspWaitForVBlank();
gfxSwapBuffers();
}
#else
/* this is a lot easier when you have a real console */
void
console_init(void)
{
}
void
console_set_status(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
fputc('\n', stdout);
}
void
console_print(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vprintf(fmt, ap);
va_end(ap);
}
void console_render(void)
{
}
#endif