From 004f6900b11e0ce841816f06e851ec37b8907466 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Thu, 25 Jun 2009 01:29:14 +0000 Subject: Initial support for Kyrandia 1 PC-9801 Japanese 16 color. svn-id: r41844 --- engines/kyra/kyra_lok.cpp | 5 ++- engines/kyra/screen.h | 4 +- engines/kyra/screen_lok.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++- engines/kyra/screen_lok.h | 17 ++++++++ engines/kyra/staticres.cpp | 9 ++++ 5 files changed, 134 insertions(+), 4 deletions(-) diff --git a/engines/kyra/kyra_lok.cpp b/engines/kyra/kyra_lok.cpp index 4d3b3e75c1..4042317f20 100644 --- a/engines/kyra/kyra_lok.cpp +++ b/engines/kyra/kyra_lok.cpp @@ -157,7 +157,10 @@ KyraEngine_LoK::~KyraEngine_LoK() { } Common::Error KyraEngine_LoK::init() { - _screen = new Screen_LoK(this, _system); + if (_flags.platform == Common::kPlatformPC98 && _flags.useHiResOverlay) + _screen = new Screen_LoK_16(this, _system); + else + _screen = new Screen_LoK(this, _system); assert(_screen); _screen->setResolution(); diff --git a/engines/kyra/screen.h b/engines/kyra/screen.h index b4541a53fb..b469a3ca23 100644 --- a/engines/kyra/screen.h +++ b/engines/kyra/screen.h @@ -233,7 +233,7 @@ public: int fadePalStep(const Palette &pal, int diff); void setPaletteIndex(uint8 index, uint8 red, uint8 green, uint8 blue); - void setScreenPalette(const Palette &pal); + virtual void setScreenPalette(const Palette &pal); void getRealPalette(int num, uint8 *dst); Palette &getPalette(int num); @@ -330,7 +330,7 @@ protected: void updateDirtyRectsOvl(); void scale2x(byte *dst, int dstPitch, const byte *src, int srcPitch, int w, int h); - void mergeOverlay(int x, int y, int w, int h); + virtual void mergeOverlay(int x, int y, int w, int h); // overlay specific byte *getOverlayPtr(int pageNum); diff --git a/engines/kyra/screen_lok.cpp b/engines/kyra/screen_lok.cpp index fbeb2a7a63..4a70001111 100644 --- a/engines/kyra/screen_lok.cpp +++ b/engines/kyra/screen_lok.cpp @@ -28,7 +28,6 @@ namespace Kyra { - Screen_LoK::Screen_LoK(KyraEngine_LoK *vm, OSystem *system) : Screen(vm, system) { _vm = vm; @@ -239,4 +238,106 @@ int Screen_LoK::getRectSize(int x, int y) { return ((x*y) << 3); } +#pragma mark - + +Screen_LoK_16::Screen_LoK_16(KyraEngine_LoK *vm, OSystem *system) : Screen_LoK(vm, system) { +} + +void Screen_LoK_16::setScreenPalette(const Palette &pal) { + _screenPalette->copy(pal); + + for (int i = 0; i < 256; ++i) + paletteMap(i, pal[i * 3 + 0] << 2, pal[i * 3 + 1] << 2, pal[i * 3 + 2] << 2); + + uint8 palette[16 * 4]; + for (int i = 0; i < 16; ++i) { + palette[i * 4 + 0] = (_palette16[i * 3 + 0] * 0xFF) / 0x0F; + palette[i * 4 + 1] = (_palette16[i * 3 + 1] * 0xFF) / 0x0F; + palette[i * 4 + 2] = (_palette16[i * 3 + 2] * 0xFF) / 0x0F; + palette[i * 4 + 3] = 0; + } + + _system->setPalette(palette, 0, 16); +} + +void Screen_LoK_16::paletteMap(uint8 idx, int r, int g, int b) { + const int red = r; + const int green = g; + const int blue = b; + + uint16 rgbDiff = 1000; + int rDiff = 0, gDiff = 0, bDiff = 0; + + int index1 = -1; + + for (int i = 0; i < 16; ++i) { + const int realR = _palette16[i * 3 + 0] << 4; + const int realG = _palette16[i * 3 + 1] << 4; + const int realB = _palette16[i * 3 + 2] << 4; + + uint16 diff = ABS(r - realR) + ABS(g - realG) + ABS(b - realB); + + if (diff < rgbDiff) { + rgbDiff = diff; + index1 = i; + + rDiff = r - realR; + gDiff = g - realG; + bDiff = b - realB; + } + } + + r = rDiff / 4 + red; + g = gDiff / 4 + green; + b = bDiff / 4 + blue; + + rgbDiff = 1000; + int index2 = -1; + + for (int i = 0; i < 16; ++i) { + const int realR = _palette16[i * 3 + 0] << 4; + const int realG = _palette16[i * 3 + 1] << 4; + const int realB = _palette16[i * 3 + 2] << 4; + + uint16 diff = ABS(r - realR) + ABS(g - realG) + ABS(b - realB); + + if (diff < rgbDiff) { + rgbDiff = diff; + index2 = i; + } + } + + _paletteMap[idx * 4 + 0] = index2; + _paletteMap[idx * 4 + 3] = index2; + + _paletteMap[idx * 4 + 1] = index1; + _paletteMap[idx * 4 + 2] = index1; +} + +void Screen_LoK_16::convertTo16Colors(uint8 *page, int w, int h) { + const int rowAdd = 1280 - w; + + uint8 *row1 = page; + uint8 *row2 = page + 640; + + for (int i = 0; i < h; i += 2) { + for (int k = 0; k < w; k += 2) { + *row1 = _paletteMap[*row1 * 4 + 0]; ++row1; + *row1 = _paletteMap[*row1 * 4 + 1]; ++row1; + + *row2 = _paletteMap[*row2 * 4 + 2]; ++row2; + *row2 = _paletteMap[*row2 * 4 + 3]; ++row2; + } + + row1 += rowAdd; + row2 += rowAdd; + } +} + +void Screen_LoK_16::mergeOverlay(int x, int y, int w, int h) { + Screen_LoK::mergeOverlay(x, y, w, h); + + convertTo16Colors(_sjisOverlayPtrs[0] + y * 640 + x, w, h); +} + } // end of namespace Kyra diff --git a/engines/kyra/screen_lok.h b/engines/kyra/screen_lok.h index d74da66df5..39a5cc3571 100644 --- a/engines/kyra/screen_lok.h +++ b/engines/kyra/screen_lok.h @@ -77,6 +77,23 @@ protected: uint8 *_saveLoadPageOvl[8]; }; +class Screen_LoK_16 : public Screen_LoK { +public: + Screen_LoK_16(KyraEngine_LoK *vm, OSystem *system); + + void setScreenPalette(const Palette &pal); +private: + void updateDirtyRectsOvl(); + + void convertTo16Colors(uint8 *page, int w, int h); + void mergeOverlay(int x, int y, int w, int h); + + void paletteMap(uint8 idx, int r, int g, int b); + uint8 _paletteMap[1024]; + + static const uint8 _palette16[48]; +}; + } // end of namespace Kyra #endif diff --git a/engines/kyra/staticres.cpp b/engines/kyra/staticres.cpp index 2192af29a9..86680a7b76 100644 --- a/engines/kyra/staticres.cpp +++ b/engines/kyra/staticres.cpp @@ -2104,6 +2104,15 @@ void GUI_LoL::initStaticData() { #endif // ENABLE_LOL +const uint8 Screen_LoK_16::_palette16[48] = { + 0x00, 0x00, 0x00, 0x02, 0x07, 0x0B, 0x0C, 0x06, 0x04, + 0x0E, 0x09, 0x07, 0x00, 0x06, 0x03, 0x00, 0x0C, 0x07, + 0x0A, 0x0A, 0x0A, 0x08, 0x03, 0x03, 0x02, 0x02, 0x02, + 0x08, 0x0B, 0x0E, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x0A, + 0x05, 0x05, 0x05, 0x00, 0x0F, 0x0F, 0x0F, 0x0D, 0x00, + 0x0F, 0x0F, 0x0F +}; + const ScreenDim Screen_LoK::_screenDimTable[] = { { 0x00, 0x00, 0x28, 0xC8, 0x0F, 0x0C, 0x00, 0x00 }, { 0x08, 0x48, 0x18, 0x38, 0x0F, 0x0C, 0x00, 0x00 }, -- cgit v1.2.3