Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 143 additions & 5 deletions gc/ogc/console.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#ifndef __LIBOGC_CONSOLE_H__
#define __LIBOGC_CONSOLE_H__

/*!
* \file console.h
* \brief Console subsystem
/**
* @file console.h
* @brief ogc stdio support.
*
* Provides stdio integration for printing to the framebuffer as well as debug print
* functionality provided by stderr.
*
*/

Expand All @@ -15,6 +18,7 @@

#define CONSOLE_ESC(x) "\x1b[" #x
#define CONSOLE_RESET CONSOLE_ESC(0m)

#define CONSOLE_BLACK CONSOLE_ESC(30m)
#define CONSOLE_RED CONSOLE_ESC(31;1m)
#define CONSOLE_GREEN CONSOLE_ESC(32;1m)
Expand All @@ -24,6 +28,15 @@
#define CONSOLE_CYAN CONSOLE_ESC(36;1m)
#define CONSOLE_WHITE CONSOLE_ESC(37;1m)

#define CONSOLE_BG_BLACK CONSOLE_ESC(40m)
#define CONSOLE_BG_RED CONSOLE_ESC(41;1m)
#define CONSOLE_BG_GREEN CONSOLE_ESC(42;1m)
#define CONSOLE_BG_YELLOW CONSOLE_ESC(43;1m)
#define CONSOLE_BG_BLUE CONSOLE_ESC(44;1m)
#define CONSOLE_BG_MAGENTA CONSOLE_ESC(45;1m)
#define CONSOLE_BG_CYAN CONSOLE_ESC(46;1m)
#define CONSOLE_BG_WHITE CONSOLE_ESC(47;1m)

#define CONSOLE_COLOR_BLACK 0
#define CONSOLE_COLOR_RED 1
#define CONSOLE_COLOR_GREEN 2
Expand Down Expand Up @@ -94,8 +107,133 @@ void CON_GetPosition(int *cols, int *rows);
*/
void CON_EnableGecko(int channel,int safe);

/// A callback for printing a character.
typedef bool(*ConsolePrint)(void* con, int c);

/// A font struct for the console.
typedef struct ConsoleFont
{
u8* gfx; ///< A pointer to the font graphics
u16 asciiOffset; ///< Offset to the first valid character in the font table
u16 numChars; ///< Number of characters in the font graphics
}ConsoleFont;

/**
* @brief Console structure used to store the state of a console render context.
*
* Default values from consoleGetDefault();
* @code
* PrintConsole defaultConsole =
* {
* //Font:
* {
* (u8*)default_font_bin, //font gfx
* 0, //first ascii character in the set
* 128, //number of characters in the font set
* },
* 0,0, //cursorX cursorY
* 0,0, //prevcursorX prevcursorY
* 40, //console width
* 30, //console height
* 0, //window x
* 0, //window y
* 32, //window width
* 24, //window height
* 3, //tab size
* 0, //font character offset
* 0, //print callback
* false //console initialized
* };
* @endcode
*/

typedef struct PrintConsole
{
ConsoleFont font; ///< Font of the console

void *destbuffer; ///< Framebuffer address
int con_xres,con_yres,con_stride;
int target_x,target_y, tgt_stride;

int cursorX; ///< Current X location of the cursor (as a tile offset by default)
int cursorY; ///< Current Y location of the cursor (as a tile offset by default)

int prevCursorX; ///< Internal state
int prevCursorY; ///< Internal state

int con_cols; ///< Width of the console hardware layer in characters
int con_rows; ///< Height of the console hardware layer in characters

int windowX; ///< Window X location in characters (not implemented)
int windowY; ///< Window Y location in characters (not implemented)
int windowWidth; ///< Window width in characters (not implemented)
int windowHeight; ///< Window height in characters (not implemented)

int tabSize; ///< Size of a tab
unsigned int fg; ///< Foreground color
unsigned int bg; ///< Background color
unsigned int flags; ///< Attribute flags

ConsolePrint PrintChar; ///< Callback for printing a character. Should return true if it has handled rendering the graphics (else the print engine will attempt to render via tiles).

bool consoleInitialised; ///< True if the console is initialized
} PrintConsole;

/// Console debug devices supported by libogc.
typedef enum {
debugDevice_NULL, ///< Swallows prints to stderr
debugDevice_EXI, ///< Outputs stderr debug statements using exi uart
debugDevice_CONSOLE, ///< Directs stderr debug statements to console window
} debugDevice;

/**
* @brief Loads the font into the console.
* @param console Pointer to the console to update, if NULL it will update the current console.
* @param font The font to load.
*/
void consoleSetFont(PrintConsole* console, ConsoleFont* font);

/**
* @brief Sets the print window.
* @param console Console to set, if NULL it will set the current console window.
* @param x X location of the window.
* @param y Y location of the window.
* @param width Width of the window.
* @param height Height of the window.
*/
void consoleSetWindow(PrintConsole* console, unsigned int x, unsigned int y, unsigned int width, unsigned int height);

/**
* @brief Gets a pointer to the console with the default values.
* This should only be used when using a single console or without changing the console that is returned, otherwise use consoleInit().
* @return A pointer to the console with the default values.
*/
PrintConsole* consoleGetDefault(void);

/**
* @brief Make the specified console the render target.
* @param console A pointer to the console struct (must have been initialized with consoleInit(PrintConsole* console)).
* @return A pointer to the previous console.
*/
PrintConsole *consoleSelect(PrintConsole* console);

/**
* @brief Initialise the console.
* @param console A pointer to the console data to initialize (if it's NULL, the default console will be used).
* @return A pointer to the current console.
*/
PrintConsole* consoleInit(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 screen by using iprintf("\x1b[2J");
void consoleClear(void);

#ifdef __cplusplus
}
}
#endif

#endif
Loading