shithub: choc

Download patch

ref: 8b90786fab780b4dfc95240ccd1c905eec80fc9b
parent: 12c984cff816ca46aff78ddeb9a7ce018cf4bc5c
author: Simon Howard <fraggle@soulsphere.org>
date: Fri Dec 28 11:27:23 EST 2018

textscreen: Add API to change color palette.

This is possible under DOS as well by writing to the appropriate VGA
registers, and the vanilla setup tool actually does this in earlier
versions to set "Romero Blue".

--- a/textscreen/txt_main.h
+++ b/textscreen/txt_main.h
@@ -149,6 +149,9 @@
 // Update the whole screen
 void TXT_UpdateScreen(void);
 
+// Set the RGB value for a particular entry in the color palette:
+void TXT_SetColor(txt_color_t color, int r, int g, int b);
+
 // Read a character from the keyboard
 int TXT_GetChar(void);
 
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -85,7 +85,7 @@
 // Unicode key mapping; see codepage.h.
 static const short code_page_to_unicode[] = CODE_PAGE_TO_UNICODE;
 
-static SDL_Color ega_colors[] =
+static const SDL_Color ega_colors[] =
 {
     {0x00, 0x00, 0x00, 0xff},          // 0: Black
     {0x00, 0x00, 0xa8, 0xff},          // 1: Blue
@@ -306,6 +306,15 @@
     SDL_FreeSurface(screenbuffer);
     screenbuffer = NULL;
     SDL_QuitSubSystem(SDL_INIT_VIDEO);
+}
+
+void TXT_SetColor(txt_color_t color, int r, int g, int b)
+{
+    SDL_Color c = {r, g, b, 0xff};
+
+    SDL_LockSurface(screenbuffer);
+    SDL_SetPaletteColors(screenbuffer->format->palette, &c, color, 1);
+    SDL_UnlockSurface(screenbuffer);
 }
 
 unsigned char *TXT_GetScreenData(void)