From 20cd7848a45719583e2f2f64f6ff84fe9a2f654c Mon Sep 17 00:00:00 2001 From: Korbo Qwerty Lamp Date: Sun, 18 Oct 2026 09:59:13 -0500 Subject: [PATCH] external color palette support --- gc/ogc/console.h | 53 ++++++++++++++++++++++++++++++++---------------- libogc/console.c | 33 +++++++++++++++++------------- 2 files changed, 54 insertions(+), 32 deletions(-) diff --git a/gc/ogc/console.h b/gc/ogc/console.h index 230ba6be7..4d94b09f0 100644 --- a/gc/ogc/console.h +++ b/gc/ogc/console.h @@ -125,25 +125,33 @@ 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 */ @@ -151,6 +159,8 @@ 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 @@ -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. diff --git a/libogc/console.c b/libogc/console.c index 0f2a88ba4..06d7d889e 100644 --- a/libogc/console.c +++ b/libogc/console.c @@ -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 @@ -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 @@ -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) { @@ -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(); @@ -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 @@ -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; icolorPalette[0]; + } + DCStoreRange(framebuffer, yres * stride); } s32 CON_InitEx(GXRModeObj *rmode, s32 conXOrigin,s32 conYOrigin,s32 conWidth,s32 conHeight) @@ -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;