From 24eeabe9a5e4be6a23d5033a07d7c19fdea47ddf Mon Sep 17 00:00:00 2001 From: InvisibleUp Date: Fri, 10 Jul 2020 22:36:04 -0400 Subject: [PATCH] Add custom B&W palette support --- src/HW/SCREEN/SCRNEMDV.c | 8 ++++++++ src/HW/SCREEN/SCRNEMDV.h | 2 ++ src/UI/SDL2/VIDEO.c | 24 ++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/src/HW/SCREEN/SCRNEMDV.c b/src/HW/SCREEN/SCRNEMDV.c index cd43c76..4209248 100644 --- a/src/HW/SCREEN/SCRNEMDV.c +++ b/src/HW/SCREEN/SCRNEMDV.c @@ -24,6 +24,7 @@ Macintosh port of vMac, by Philip Cummins. */ +#include #include "SYSDEPNS.h" #include "UI/MYOSGLUE.h" #include "UTIL/ENDIANAC.h" @@ -51,9 +52,12 @@ uint32_t vMacScreenByteWidth; uint32_t vMacScreenMonoNumBytes; uint32_t vMacScreenMonoByteWidth; bool UseLargeScreenHack; +char *ScreenColorBlack = NULL; +char *ScreenColorWhite = NULL; bool Screen_Init(void) { + // enable a palette because heck it return true; } @@ -74,6 +78,10 @@ bool Screen_LoadCfg() vMacScreenDepth = temp; okay = Config_GetBool(CONFIG_VIDEO_USEHACK, &UseLargeScreenHack, false); if (!okay) { return false; } + okay = Config_GetString(CONFIG_VIDEO_BLACK, &ScreenColorBlack, "#000000"); + if (!okay) { return false; } + okay = Config_GetString(CONFIG_VIDEO_WHITE, &ScreenColorWhite, "#FFFFFF"); + if (!okay) { return false; } // Compute the other sorts of things vMacScreenNumPixels = vMacScreenHeight * vMacScreenWidth; diff --git a/src/HW/SCREEN/SCRNEMDV.h b/src/HW/SCREEN/SCRNEMDV.h index b172e72..7f7e36e 100644 --- a/src/HW/SCREEN/SCRNEMDV.h +++ b/src/HW/SCREEN/SCRNEMDV.h @@ -33,5 +33,7 @@ extern uint32_t vMacScreenByteWidth; extern uint32_t vMacScreenMonoNumBytes; extern uint32_t vMacScreenMonoByteWidth; bool UseLargeScreenHack; +char *ScreenColorBlack; +char *ScreenColorWhite; #endif diff --git a/src/UI/SDL2/VIDEO.c b/src/UI/SDL2/VIDEO.c index 6a53086..89e87b9 100644 --- a/src/UI/SDL2/VIDEO.c +++ b/src/UI/SDL2/VIDEO.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include "CNFGRAPI.h" @@ -32,12 +33,33 @@ SDL_PixelFormat *format = NULL; uint8_t * ScalingBuff = nullpr; uint8_t * CLUT_final; +SDL_Color bwpalette[2]; +bool bwpalette_loaded = false; + // Set the display palette from the Macintosh's memory or w/e static int SetPalette(SDL_Palette *palette, const SDL_Color *macColors, int ncolors) { return SDL_SetPaletteColors(palette, macColors, 0, ncolors); } +static SDL_Color HexToColor(const char *hexIn, SDL_Color fallback) { + unsigned int r, g, b; + assert(hexIn != NULL); + int numRead = sscanf(hexIn, "#%02x%02x%02x", &r, &g, &b); + if (numRead != 3) { return fallback; } + SDL_Color result = {.r = r, .g = g, .b = b}; + return result; +} + +void LoadCustomPalette() +{ + if (bwpalette_loaded) { return; } + SDL_Color fallbacks[] = { {.r=255,.g=255,.b=255}, {.r=0,.b=0,.g=0} }; + bwpalette[0] = HexToColor(ScreenColorWhite, fallbacks[0]); + bwpalette[1] = HexToColor(ScreenColorBlack, fallbacks[1]); + bwpalette_loaded = true; +} + // Get pixel format for a given screen depth // Note: this is complete and total guesswork right now. Lol. uint32_t GetPixFormatFromDepth(int depth) @@ -80,6 +102,8 @@ GLOBALOSGLUPROC Screen_OutputFrame(uint8_t * src_ptr) vMacScreenByteWidth, src_format ); + LoadCustomPalette(); + SetPalette(src->format->palette, bwpalette, 2); // Setup dst surface SDL_LockTexture(texture, NULL, &pixels, &pitch);