libdragon
|
Software console emulation for debugging and simple text output. More...
Files | |
file | console.c |
Console Support. | |
file | console.h |
Console Support. | |
Defines | |
#define | CONSOLE_SIZE ((sizeof(char) * CONSOLE_WIDTH * CONSOLE_HEIGHT) + sizeof(char)) |
Size of the console buffer in bytes. | |
#define | move_buffer() |
Macro to move the console up one line. | |
#define | TAB_WIDTH 5 |
Tab width. | |
Functions | |
static void | __console_render () |
Helper function to render the console. | |
void | console_set_render_mode (int mode) |
Set the console rendering mode. | |
static int | __console_write (char *buf, unsigned int len) |
Newlib hook to allow printf/iprintf to appear on console. | |
void | console_init () |
Initialize the console. | |
void | console_close () |
Close the console. | |
void | console_clear () |
Clear the console. | |
void | console_render () |
Render the console. | |
Variables | |
static char * | render_buffer = 0 |
The console buffer. | |
static int | render_now |
Internal state of the render mode. | |
static stdio_t | console_calls |
Structure used for hooking console commands to stdio. | |
Console Render Modes | |
#define | RENDER_MANUAL 0 |
Manual Rendering. | |
#define | RENDER_AUTOMATIC 1 |
Automatic Rendering. | |
Console Dimensions | |
#define | CONSOLE_WIDTH 35 |
The console width in characters. | |
#define | CONSOLE_HEIGHT 25 |
The console height in characters. |
Software console emulation for debugging and simple text output.
Console support is provided as a poor-man's console for simple debugging on the N64. It does not respect common escape sequences and is nonstandard in size. When using the console, code should be careful to make sure that the display system has not been initialized. Similarly, if the display system is needed, code should be sure that the console is not initialized.
Code wishing to use the console should first initialize the console support in libdragon with console_init. Once the console has been initialized, it wil operate in one of two modes. In automatic mode, every write to the console will be immediately displayed on the screen. The console will be scrolled when the buffer fills. In manual mode, the console will only be displayed after calling console_render. To set the render mode, use console_set_render_mode. To add data to the console, use #printf or #iprintf. To clear the console and reset the scroll, use console_clear. Once the console is not needed or when the code wishes to switch to the display subsystem, console_clear should be called to cleanly shut down the console support.
#define move_buffer | ( | ) |
memmove(render_buffer, render_buffer + (sizeof(char) * CONSOLE_WIDTH), CONSOLE_SIZE - (CONSOLE_WIDTH * sizeof(char))); \ pos -= CONSOLE_WIDTH;
Macro to move the console up one line.
#define RENDER_AUTOMATIC 1 |
Automatic Rendering.
The screen will be updated on every console interaction
#define RENDER_MANUAL 0 |
Manual Rendering.
The user must call console_render when the screen should be updated
#define TAB_WIDTH 5 |
Tab width.
static int __console_write | ( | char * | buf, |
unsigned int | len | ||
) | [static] |
Newlib hook to allow printf/iprintf to appear on console.
[in] | buf | Pointer to data buffer containing the data to write |
[in] | len | Length of data in bytes expected to be written |
void console_clear | ( | ) |
Clear the console.
Clear the console and set the virtual cursor back to the top left.
void console_close | ( | ) |
Close the console.
Free the console system. This will clean up any dynamic memry that was in use.
void console_init | ( | ) |
Initialize the console.
Initialize the console system. This will initialize the video properly, so a call to the display_init() fuction is not necessary.
void console_render | ( | ) |
Render the console.
Render the console to the screen. This should be called when in manual rendering mode to display the console to the screen. In automatic mode it is not necessary to call.
The color that is used to draw the text can be set using graphics_set_color.
void console_set_render_mode | ( | int | mode | ) |
Set the console rendering mode.
This sets the render mode of the console. The RENDER_AUTOMATIC mode allows console_printf to immediately be placed onto the screen. This is very similar to a normal console on a unix/windows system. The RENDER_MANUAL mode allows console_printf to be buffered, and displayed at a later date using console_render(). This is to allow a rendering interface somewhat analogous to curses
[in] | mode | Render mode (RENDER_AUTOMATIC or RENDER_MANUAL) |
stdio_t console_calls [static] |
{ 0, __console_write, 0 }
Structure used for hooking console commands to stdio.
int render_now [static] |
Internal state of the render mode.