From 4fc57179c8a847666cbf646370a85ec796692aec Mon Sep 17 00:00:00 2001 From: neuromancer Date: Thu, 5 Jan 2023 21:14:35 -0300 Subject: [PATCH] FREESCAPE: improved handling of colors in Driller for C64 --- engines/freescape/games/driller.cpp | 2 +- engines/freescape/games/palettes.cpp | 39 +++++++--------- engines/freescape/gfx.cpp | 66 ++++++++++++++++++++++++---- engines/freescape/gfx.h | 4 +- 4 files changed, 78 insertions(+), 33 deletions(-) diff --git a/engines/freescape/games/driller.cpp b/engines/freescape/games/driller.cpp index 7f4ede551a5..a54940d9b5a 100644 --- a/engines/freescape/games/driller.cpp +++ b/engines/freescape/games/driller.cpp @@ -734,7 +734,7 @@ void DrillerEngine::drawCPCUI(Graphics::Surface *surface) { uint32 color = 1; uint8 r, g, b; - _gfx->selectColorFromCPCPalette(color, r, g, b); + _gfx->selectColorFromFourColorPalette(color, r, g, b); uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b); color = 0; diff --git a/engines/freescape/games/palettes.cpp b/engines/freescape/games/palettes.cpp index 1c586f9c2ce..1f4c8766fe6 100644 --- a/engines/freescape/games/palettes.cpp +++ b/engines/freescape/games/palettes.cpp @@ -44,21 +44,21 @@ byte dos_EGA_palette[16][3] = { byte kDrillerC64Palette[16][3] = { {0x00, 0x00, 0x00}, - {0xff, 0xff, 0xff}, - {0x88, 0x00, 0x00}, - {0xdd, 0x88, 0x55}, - {0x00, 0xcc, 0x55}, - {0xcc, 0x44, 0xcc}, - {0x00, 0x00, 0xaa}, - {0xee, 0xee, 0x77}, - {0xaa, 0xff, 0xee}, - {0x66, 0x44, 0x00}, - {0xff, 0x77, 0x77}, - {0x33, 0x33, 0x33}, - {0x77, 0x77, 0x77}, - {0xaa, 0xff, 0x66}, - {0x00, 0x88, 0xff}, - {0xbb, 0xbb, 0xbb} + {0xFF, 0xFF, 0xFF}, + {0x68, 0x37, 0x2B}, + {0x70, 0xA4, 0xB2}, + {0x6F, 0x3D, 0x86}, + {0x58, 0x8D, 0x43}, + {0x35, 0x28, 0x79}, + {0xB8, 0xC7, 0x6F}, + {0x6F, 0x4F, 0x25}, + {0x43, 0x39, 0x00}, + {0x9A, 0x67, 0x59}, + {0x44, 0x44, 0x44}, + {0x6C, 0x6C, 0x6C}, + {0x9A, 0xD2, 0x84}, + {0x6C, 0x5E, 0xB5}, + {0x95, 0x95, 0x95} }; byte kDrillerZXPalette[9][3] = { @@ -108,13 +108,6 @@ byte kDrillerCPCPalette[32][3] = { {0x80, 0x80, 0xff}, // 31 }; -byte kDrillerCPCPalette1[27][3] = { - {0x00, 0x00, 0x00}, // 0: black - {0xff, 0x80, 0x00}, // 1: orange - {0x00, 0xff, 0xff}, // 2: cyan - {0x00, 0x80, 0x00}, // 3: green -}; - void FreescapeEngine::loadColorPalette() { if (_renderMode == Common::kRenderEGA) { _gfx->_palette = (byte *)&dos_EGA_palette; @@ -165,7 +158,7 @@ void FreescapeEngine::loadPalettes(Common::SeekableReadStream *file, int offset) void FreescapeEngine::swapPalette(uint16 levelID) { if (isAmiga() || isAtariST()) _gfx->_palette = _paletteByArea[levelID]; - else if (isSpectrum() || isCPC()) { + else if (isSpectrum() || isCPC() || isC64()) { _gfx->_inkColor = _areaMap[levelID]->_inkColor; _gfx->_paperColor = _areaMap[levelID]->_paperColor; _gfx->_underFireBackgroundColor = _areaMap[levelID]->_underFireBackgroundColor; diff --git a/engines/freescape/gfx.cpp b/engines/freescape/gfx.cpp index 14580f0871c..17f6c16013d 100644 --- a/engines/freescape/gfx.cpp +++ b/engines/freescape/gfx.cpp @@ -93,16 +93,66 @@ bool Renderer::getRGBAtCGA(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 & return true; } + +void Renderer::extractC64Indexes(uint8 cm1, uint8 cm2, uint8 &i1, uint8 &i2) { + if (cm1 == 0xaa && cm2 == 0x5a) { + i1 = 2; + i2 = 3; + } else if (cm1 == 0x4f && cm2 == 0x46) { + i1 = 0; + i2 = 2; + } else if (cm1 == 0x56 && cm2 == 0x45) { + i1 = 0; + i2 = 1; + } else if (cm1 == 0xa0 && cm2 == 0x55) { + i1 = 1; + i2 = 3; + } else if (cm1 == 0x4c && cm2 == 0x54) { + i1 = 1; + i2 = 2; + } else if (cm1 == 0x41 && cm2 == 0x52) { + i1 = 0; + i2 = 3; + } else if (cm1 == 0x5a && cm2 == 0xa5) { + i1 = 0; + i2 = 0; + } else if (cm1 == 0xbb && cm2 == 0xee) { + i1 = 0; + i2 = 0; + } else if (cm1 == 0x5f && cm2 == 0xaf) { + i1 = 0; + i2 = 0; + } else if (cm1 == 0xfb && cm2 == 0xfe) { + i1 = 0; + i2 = 0; + } else { + i1 = 0; + i2 = 0; + } +} + + bool Renderer::getRGBAtC64(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2) { if (index == _keyColor) return false; + if (index <= 4) { // Solid colors + selectColorFromFourColorPalette(index - 1, r1, g1, b1); + r2 = r1; + g2 = g1; + b2 = b1; + return true; + } + + uint8 i1, i2; byte *entry = (*_colorMap)[index - 1]; - byte be = *(entry); - readFromPalette(be >> 4, r1, g1, b1); + uint8 cm1 = *(entry); entry++; - be = *(entry); - readFromPalette(be >> 4, r2, g2, b2); + uint8 cm2 = *(entry); + + extractC64Indexes(cm1, cm2, i1, i2); + selectColorFromFourColorPalette(i1, r1, g1, b1); + selectColorFromFourColorPalette(i2, r2, g2, b2); return true; } @@ -170,7 +220,7 @@ void Renderer::extractCPCIndexes(uint8 cm1, uint8 cm2, uint8 &i1, uint8 &i2) { error("%x %x", cm1, cm2); } -void Renderer::selectColorFromCPCPalette(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1) { +void Renderer::selectColorFromFourColorPalette(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1) { if (index == 0) { r1 = 0; g1 = 0; @@ -191,7 +241,7 @@ bool Renderer::getRGBAtCPC(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 & assert (_renderMode == Common::kRenderCPC); if (index <= 4) { // Solid colors - selectColorFromCPCPalette(index - 1, r1, g1, b1); + selectColorFromFourColorPalette(index - 1, r1, g1, b1); r2 = r1; g2 = g1; b2 = b1; @@ -205,8 +255,8 @@ bool Renderer::getRGBAtCPC(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 & uint8 cm2 = *(entry); extractCPCIndexes(cm1, cm2, i1, i2); - selectColorFromCPCPalette(i1, r1, g1, b1); - selectColorFromCPCPalette(i2, r2, g2, b2); + selectColorFromFourColorPalette(i1, r1, g1, b1); + selectColorFromFourColorPalette(i2, r2, g2, b2); return true; } diff --git a/engines/freescape/gfx.h b/engines/freescape/gfx.h index 3d43afc9094..a8b08b5cd66 100644 --- a/engines/freescape/gfx.h +++ b/engines/freescape/gfx.h @@ -105,7 +105,9 @@ public: bool getRGBAtEGA(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2); bool getRGBAtZX(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1, uint8 &r2, uint8 &g2, uint8 &b2, byte *stipple); void extractCPCIndexes(uint8 cm1, uint8 cm2, uint8 &i1, uint8 &i2); - void selectColorFromCPCPalette(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1); + void extractC64Indexes(uint8 cm1, uint8 cm2, uint8 &i1, uint8 &i2); + + void selectColorFromFourColorPalette(uint8 index, uint8 &r1, uint8 &g1, uint8 &b1); virtual void setStippleData(byte *data) {}; virtual void useStipple(bool enabled) {};