libnds
Data Structures | Typedefs | Enumerations | Functions
console.h File Reference

NDS stdio support. More...

#include <stdio.h>
#include <nds/arm9/background.h>
#include <nds/ndstypes.h>

Data Structures

struct  ConsoleFont
 A font struct for the console. More...
 
struct  PrintConsole
 Console structure used to store the state of a console render context. More...
 

Typedefs

typedef struct ConsoleFont ConsoleFont
 A font struct for the console. More...
 
typedef ssize_t(* ConsoleOutFn) (const char *ptr, size_t len)
 Function type used by libnds to redirect characters sent to stdout and stderr (skipping the call to the ConsolePrint handler).
 
typedef bool(* ConsolePrint) (void *con, char c)
 Function type used by the PrintConsole struct to send characters to the console.
 
typedef struct PrintConsole PrintConsole
 Console structure used to store the state of a console render context. More...
 

Enumerations

enum  DebugDevice {
  DebugDevice_NULL = 0x0 ,
  DebugDevice_NOCASH = 0x1 ,
  DebugDevice_CONSOLE = 0x02
}
 Console debug devices supported by libnds. More...
 

Functions

void consoleClear (void)
 Clears the screan by using printf("\x1b[2J");.
 
void consoleDebugInit (DebugDevice device)
 Initializes the debug console output on stderr to the specified device. More...
 
PrintConsoleconsoleDemoInit (void)
 Initialize the console to a default state for prototyping. More...
 
PrintConsoleconsoleGetDefault (void)
 Gets a pointer to the console with the default values. More...
 
PrintConsoleconsoleInit (PrintConsole *console, int layer, BgType type, BgSize size, int mapBase, int tileBase, bool mainDisplay, bool loadGraphics)
 Initialise the console. More...
 
PrintConsoleconsoleSelect (PrintConsole *console)
 Make the specified console the render target. More...
 
void consoleSetCustomStderr (ConsoleOutFn fn)
 Sets the function where stderr is sent, bypassing the PrintConsole handler. More...
 
void consoleSetCustomStdout (ConsoleOutFn fn)
 Sets the function where stdout is sent, bypassing the PrintConsole handler. More...
 
void consoleSetFont (PrintConsole *console, ConsoleFont *font)
 Loads the font into the console. More...
 
void consoleSetWindow (PrintConsole *console, int x, int y, int width, int height)
 Sets the print window. More...
 

Detailed Description

NDS stdio support.

Provides stdio integration for printing to the DS screen as well as debug print functionality provided by stderr.

General usage is to initialize the console by calling consoleDemoInit() or to customize the console usage by calling consoleInit()

The default instance utilizes the sub display, approximatly 4 KiB of VRAM C starting at tile base 3 and 2 KiB of map at map base 22.

Debug printing is performed by initializing the debug console via consoleDebugInit() as follows:

fprintf(stderr, "debug message in no$gba window %i", stuff);
@ DebugDevice_NOCASH
Directs stderr to the no$gba debug window.
Definition: console.h:166
void consoleDebugInit(DebugDevice device)
Initializes the debug console output on stderr to the specified device.

OR

fprintf(stderr, "debug message on DS console screen");
@ DebugDevice_CONSOLE
Directs stderr to the DS console window.
Definition: console.h:167

The print console must be initialized to use DB_CONSOLE.

Typedef Documentation

◆ ConsoleFont

typedef struct ConsoleFont ConsoleFont

A font struct for the console.

If convertSingleColor is true, the font is treated as a single color font where all non zero pixels are set to a value of 15 or 255 (4bpp / 8bpp respectivly). This ensures only one palette entry is utilized for font rendering.

◆ PrintConsole

typedef struct PrintConsole PrintConsole

Console structure used to store the state of a console render context.

Default values from consoleGetDefault();

PrintConsole defaultConsole =
{
// Font:
{
(u16 *)default_font_bin, // Font gfx
0, // Font palette
0, // Font color count
4, // bpp
0, // First ascii character in the set
128, // Number of characters in the font set
true, // Convert to single color
},
0, // Font background map
0, // Font background gfx
31, // Map base
0, // Char base
0, // BG layer in use
-1, // BG id
0, 0, // CursorX cursorY
0, 0, // PrevcursorX prevcursorY
32, // Console width
24, // Console height
0, // Window x
0, // Window y
32, // Window width
24, // Window height
3, // Tab size
0, // Font character offset
0, // Selected palette
0, // Print callback
false, // Console initialized
true, // Load graphics
};
uint16_t u16
16 bit unsigned integer.
Definition: ndstypes.h:97
Console structure used to store the state of a console render context.
Definition: console.h:113

Enumeration Type Documentation

◆ DebugDevice

Console debug devices supported by libnds.

Enumerator
DebugDevice_NULL 

Ignores prints to stderr.

DebugDevice_NOCASH 

Directs stderr to the no$gba debug window.

DebugDevice_CONSOLE 

Directs stderr to the DS console window.

Function Documentation

◆ consoleDebugInit()

void consoleDebugInit ( DebugDevice  device)

Initializes the debug console output on stderr to the specified device.

Parameters
deviceThe debug device (or devices) to output debug print to.

◆ consoleDemoInit()

PrintConsole * consoleDemoInit ( void  )

Initialize the console to a default state for prototyping.

This function sets the console to use sub display, VRAM_C, and BG0 and enables MODE_0_2D on the sub display. It is intended for use in prototyping applications which need print ability and not actual game use. Print functionality can be utilized with just this call.

Returns
A pointer to the current PrintConsole.

◆ consoleGetDefault()

PrintConsole * consoleGetDefault ( void  )

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().

Returns
A pointer to the console with the default values.

◆ consoleInit()

PrintConsole * consoleInit ( PrintConsole console,
int  layer,
BgType  type,
BgSize  size,
int  mapBase,
int  tileBase,
bool  mainDisplay,
bool  loadGraphics 
)

Initialise the console.

Parameters
consoleA pointer to the console data to initialze (if it's NULL, the default console will be used).
layerBackground layer to use.
typeType of the background.
sizeSize of the background.
mapBaseMap base.
tileBaseTile graphics base.
mainDisplayIf true main engine is used, otherwise false.
loadGraphicsIf true the default font graphics will be loaded into the layer.
Returns
A pointer to the current console.

◆ consoleSelect()

PrintConsole * consoleSelect ( PrintConsole console)

Make the specified console the render target.

Parameters
consoleA pointer to the console struct (must have been initialized with consoleInit(PrintConsole* console)
Returns
A pointer to the previous console.

◆ consoleSetCustomStderr()

void consoleSetCustomStderr ( ConsoleOutFn  fn)

Sets the function where stderr is sent, bypassing the PrintConsole handler.

To reset it to the libnds console handler, call this function with NULL as an argument, or call consoleDebugInit().

Parameters
fnCallback where stderr is sent.

◆ consoleSetCustomStdout()

void consoleSetCustomStdout ( ConsoleOutFn  fn)

Sets the function where stdout is sent, bypassing the PrintConsole handler.

To reset it to the libnds console handler, call this function with NULL as an argument.

Parameters
fnCallback where stdout is sent.

◆ consoleSetFont()

void consoleSetFont ( PrintConsole console,
ConsoleFont font 
)

Loads the font into the console.

Parameters
consolePointer to the console to update. If NULL, it will update the current console.
fontThe font to load.

◆ consoleSetWindow()

void consoleSetWindow ( PrintConsole console,
int  x,
int  y,
int  width,
int  height 
)

Sets the print window.

Parameters
consoleConsole to set. If NULL it will set the current console window
xX location of the window.
yY location of the window.
widthWidth of the window.
heightHeight of the window.