|
1 | 1 | #ifndef __LIBOGC_CONSOLE_H__ |
2 | 2 | #define __LIBOGC_CONSOLE_H__ |
3 | 3 |
|
4 | | -/*! |
5 | | - * \file console.h |
6 | | - * \brief Console subsystem |
| 4 | +/** |
| 5 | + * @file console.h |
| 6 | + * @brief ogc stdio support. |
| 7 | + * |
| 8 | + * Provides stdio integration for printing to the framebuffer as well as debug print |
| 9 | + * functionality provided by stderr. |
7 | 10 | * |
8 | 11 | */ |
9 | 12 |
|
@@ -94,8 +97,133 @@ void CON_GetPosition(int *cols, int *rows); |
94 | 97 | */ |
95 | 98 | void CON_EnableGecko(int channel,int safe); |
96 | 99 |
|
| 100 | +/// A callback for printing a character. |
| 101 | +typedef bool(*ConsolePrint)(void* con, int c); |
| 102 | + |
| 103 | +/// A font struct for the console. |
| 104 | +typedef struct ConsoleFont |
| 105 | +{ |
| 106 | + u8* gfx; ///< A pointer to the font graphics |
| 107 | + u16 asciiOffset; ///< Offset to the first valid character in the font table |
| 108 | + u16 numChars; ///< Number of characters in the font graphics |
| 109 | +}ConsoleFont; |
| 110 | + |
| 111 | +/** |
| 112 | + * @brief Console structure used to store the state of a console render context. |
| 113 | + * |
| 114 | + * Default values from consoleGetDefault(); |
| 115 | + * @code |
| 116 | + * PrintConsole defaultConsole = |
| 117 | + * { |
| 118 | + * //Font: |
| 119 | + * { |
| 120 | + * (u8*)default_font_bin, //font gfx |
| 121 | + * 0, //first ascii character in the set |
| 122 | + * 128, //number of characters in the font set |
| 123 | + * }, |
| 124 | + * 0,0, //cursorX cursorY |
| 125 | + * 0,0, //prevcursorX prevcursorY |
| 126 | + * 40, //console width |
| 127 | + * 30, //console height |
| 128 | + * 0, //window x |
| 129 | + * 0, //window y |
| 130 | + * 32, //window width |
| 131 | + * 24, //window height |
| 132 | + * 3, //tab size |
| 133 | + * 0, //font character offset |
| 134 | + * 0, //print callback |
| 135 | + * false //console initialized |
| 136 | + * }; |
| 137 | + * @endcode |
| 138 | + */ |
| 139 | + |
| 140 | +typedef struct PrintConsole |
| 141 | +{ |
| 142 | + ConsoleFont font; ///< Font of the console |
| 143 | + |
| 144 | + void *destbuffer; ///< Framebuffer address |
| 145 | + int con_xres,con_yres,con_stride; |
| 146 | + int target_x,target_y, tgt_stride; |
| 147 | + |
| 148 | + int cursorX; ///< Current X location of the cursor (as a tile offset by default) |
| 149 | + int cursorY; ///< Current Y location of the cursor (as a tile offset by default) |
| 150 | + |
| 151 | + int prevCursorX; ///< Internal state |
| 152 | + int prevCursorY; ///< Internal state |
| 153 | + |
| 154 | + int con_cols; ///< Width of the console hardware layer in characters |
| 155 | + int con_rows; ///< Height of the console hardware layer in characters |
| 156 | + |
| 157 | + int windowX; ///< Window X location in characters (not implemented) |
| 158 | + int windowY; ///< Window Y location in characters (not implemented) |
| 159 | + int windowWidth; ///< Window width in characters (not implemented) |
| 160 | + int windowHeight; ///< Window height in characters (not implemented) |
| 161 | + |
| 162 | + int tabSize; ///< Size of a tab |
| 163 | + unsigned int fg; ///< Foreground color |
| 164 | + unsigned int bg; ///< Background color |
| 165 | + unsigned int flags; ///< Attribute flags |
| 166 | + |
| 167 | + 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). |
| 168 | + |
| 169 | + bool consoleInitialised; ///< True if the console is initialized |
| 170 | +} PrintConsole; |
| 171 | + |
| 172 | +/// Console debug devices supported by libogc. |
| 173 | +typedef enum { |
| 174 | + debugDevice_NULL, ///< Swallows prints to stderr |
| 175 | + debugDevice_EXI, ///< Outputs stderr debug statements using exi uart |
| 176 | + debugDevice_CONSOLE, ///< Directs stderr debug statements to console window |
| 177 | +} debugDevice; |
| 178 | + |
| 179 | +/** |
| 180 | + * @brief Loads the font into the console. |
| 181 | + * @param console Pointer to the console to update, if NULL it will update the current console. |
| 182 | + * @param font The font to load. |
| 183 | + */ |
| 184 | +void consoleSetFont(PrintConsole* console, ConsoleFont* font); |
| 185 | + |
| 186 | +/** |
| 187 | + * @brief Sets the print window. |
| 188 | + * @param console Console to set, if NULL it will set the current console window. |
| 189 | + * @param x X location of the window. |
| 190 | + * @param y Y location of the window. |
| 191 | + * @param width Width of the window. |
| 192 | + * @param height Height of the window. |
| 193 | + */ |
| 194 | +void consoleSetWindow(PrintConsole* console, unsigned int x, unsigned int y, unsigned int width, unsigned int height); |
| 195 | + |
| 196 | +/** |
| 197 | + * @brief Gets a pointer to the console with the default values. |
| 198 | + * This should only be used when using a single console or without changing the console that is returned, otherwise use consoleInit(). |
| 199 | + * @return A pointer to the console with the default values. |
| 200 | + */ |
| 201 | +PrintConsole* consoleGetDefault(void); |
| 202 | + |
| 203 | +/** |
| 204 | + * @brief Make the specified console the render target. |
| 205 | + * @param console A pointer to the console struct (must have been initialized with consoleInit(PrintConsole* console)). |
| 206 | + * @return A pointer to the previous console. |
| 207 | + */ |
| 208 | +PrintConsole *consoleSelect(PrintConsole* console); |
| 209 | + |
| 210 | +/** |
| 211 | + * @brief Initialise the console. |
| 212 | + * @param console A pointer to the console data to initialize (if it's NULL, the default console will be used). |
| 213 | + * @return A pointer to the current console. |
| 214 | + */ |
| 215 | +PrintConsole* consoleInit(PrintConsole* console); |
| 216 | + |
| 217 | +/** |
| 218 | + * @brief Initializes debug console output on stderr to the specified device. |
| 219 | + * @param device The debug device (or devices) to output debug print statements to. |
| 220 | + */ |
| 221 | +void consoleDebugInit(debugDevice device); |
| 222 | + |
| 223 | +/// Clears the screen by using iprintf("\x1b[2J"); |
| 224 | +void consoleClear(void); |
| 225 | + |
97 | 226 | #ifdef __cplusplus |
98 | | - } |
| 227 | +} |
99 | 228 | #endif |
100 | | - |
101 | 229 | #endif |
0 commit comments