Skip to content
Open
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
53 changes: 35 additions & 18 deletions gc/ogc/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,42 @@ typedef struct ConsoleFont
* @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
* //Font:
* {
* (u8*)console_font_8x16, //font gfx
* 0, //first ascii character in the set
* 256 //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
* };
* colorTable,
* (u16*)NULL,
* 0,0, //con_xres con_yres
* 0, //con_stride
* 0,0, //target_x target_y
* 0, //tgt_stride
* 0,0, //cursorX cursorY
* 0,0, //prevcursorX prevcursorY
* 80, //console width
* 30, //console height
* 0, //window x
* 0, //window y
* 80, //window width
* 30, //window height
* 3, //tab size
* 7, //foreground color
* 0, //background color
* 0, //flags
* 0, //print callback
* false //console initialized
* }
* @endcode
*/

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

u32 *colorPalette; ///< Color palette of the console

void *destbuffer; ///< Framebuffer address
int con_xres, con_yres; ///< Console buffer width/height in pixels
int con_stride; ///< Size of one row in the console buffer in bytes
Expand Down Expand Up @@ -195,6 +205,13 @@ typedef enum {
*/
void consoleSetFont(PrintConsole* console, ConsoleFont* font);

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

/**
* @brief Sets the print window.
* @param console Console to set, if NULL it will set the current console window.
Expand Down
33 changes: 19 additions & 14 deletions libogc/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static const u32 single_RGB8_to_YCbCr(const u8 r, const u8 g, const u8 b)
}

//set up the palette for color printing
static const u32 colorTable[] = {
static u32 colorTable[] = {
0x10801080, // black
0x317031b1, // red
0x51605157, // green
Expand Down Expand Up @@ -128,6 +128,7 @@ PrintConsole defaultConsole =
0, //first ascii character in the set
256 //number of characters in the font set
},
colorTable,
(u16*)NULL,
0,0, //con_xres con_yres
0, //con_stride
Expand Down Expand Up @@ -271,12 +272,12 @@ static void __console_drawc(int c)
} else if (currentConsole->flags & CONSOLE_COLOR_FAINT) {
fgcolor += 16;
}
fgcolor = colorTable[fgcolor];
fgcolor = currentConsole->colorPalette[fgcolor];
}

if (!(currentConsole->flags & CONSOLE_BG_CUSTOM)) {
if (currentConsole->flags & CONSOLE_COLOR_BG_BRIGHT) bgcolor +=8;
bgcolor = colorTable[bgcolor];
bgcolor = currentConsole->colorPalette[bgcolor];
}

if (currentConsole->flags & CONSOLE_COLOR_REVERSE) {
Expand Down Expand Up @@ -368,7 +369,7 @@ static void __console_clear_line(int line, int from, int to)
unsigned int bgcolor = con->bg;

if (!(currentConsole->flags & CONSOLE_BG_CUSTOM)) {
bgcolor = colorTable[bgcolor];
bgcolor = currentConsole->colorPalette[bgcolor];
}

p = __console_get_window_start_ptr();
Expand Down Expand Up @@ -399,7 +400,7 @@ static void __console_clear(void)

unsigned int bgcolor = con->bg;
if (!(currentConsole->flags & CONSOLE_BG_CUSTOM)) {
bgcolor = colorTable[bgcolor];
bgcolor = currentConsole->colorPalette[bgcolor];
}

//get console pointer
Expand Down Expand Up @@ -1074,15 +1075,6 @@ ssize_t __console_write(struct _reent *r,void *fd,const char *ptr, size_t len)

void CON_Init(void *framebuffer,int xstart,int ystart,int xres,int yres,int stride)
{

// clear given framebuffer to black
u32 *ptr = (u32*)framebuffer;

for(int i=0; i<yres*stride/4; i++) {
ptr[i] = colorTable[0];
}
DCStoreRange(framebuffer, yres * stride);

// xstart and ystart are offsets within the provided framebuffer
// reduce xres and yres accordingly to prevent OOB writes
xres = xres - xstart;
Expand All @@ -1093,7 +1085,13 @@ void CON_Init(void *framebuffer,int xstart,int ystart,int xres,int yres,int stri
yres = (yres / FONT_YSIZE) * FONT_YSIZE;
__console_init(framebuffer,xstart,ystart,xres,yres,stride);

// clear given framebuffer to black
u32 *ptr = (u32*)framebuffer;

for(int i=0; i<yres*stride/4; i++) {
ptr[i] = currentConsole->colorPalette[0];
}
DCStoreRange(framebuffer, yres * stride);
}

s32 CON_InitEx(GXRModeObj *rmode, s32 conXOrigin,s32 conYOrigin,s32 conWidth,s32 conHeight)
Expand Down Expand Up @@ -1221,6 +1219,13 @@ void consoleSetFont(PrintConsole* console, ConsoleFont* font)
console->font = *font;
}

void consoleSetPalette(PrintConsole* console, u32 *palette)
{
if(!console) console = currentConsole;

console->colorPalette = palette;
}

void consoleSetWindow(PrintConsole* console, unsigned int x, unsigned int y, unsigned int width, unsigned int height)
{
if(!console) console = currentConsole;
Expand Down