[Scummvm-cvs-logs] SF.net SVN: scummvm:[41844] scummvm/trunk/engines/kyra

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Thu Jun 25 03:29:14 CEST 2009


Revision: 41844
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41844&view=rev
Author:   lordhoto
Date:     2009-06-25 01:29:14 +0000 (Thu, 25 Jun 2009)

Log Message:
-----------
Initial support for Kyrandia 1 PC-9801 Japanese 16 color.

Modified Paths:
--------------
    scummvm/trunk/engines/kyra/kyra_lok.cpp
    scummvm/trunk/engines/kyra/screen.h
    scummvm/trunk/engines/kyra/screen_lok.cpp
    scummvm/trunk/engines/kyra/screen_lok.h
    scummvm/trunk/engines/kyra/staticres.cpp

Modified: scummvm/trunk/engines/kyra/kyra_lok.cpp
===================================================================
--- scummvm/trunk/engines/kyra/kyra_lok.cpp	2009-06-25 01:11:47 UTC (rev 41843)
+++ scummvm/trunk/engines/kyra/kyra_lok.cpp	2009-06-25 01:29:14 UTC (rev 41844)
@@ -157,7 +157,10 @@
 }
 
 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();
 

Modified: scummvm/trunk/engines/kyra/screen.h
===================================================================
--- scummvm/trunk/engines/kyra/screen.h	2009-06-25 01:11:47 UTC (rev 41843)
+++ scummvm/trunk/engines/kyra/screen.h	2009-06-25 01:29:14 UTC (rev 41844)
@@ -233,7 +233,7 @@
 	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 @@
 	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);

Modified: scummvm/trunk/engines/kyra/screen_lok.cpp
===================================================================
--- scummvm/trunk/engines/kyra/screen_lok.cpp	2009-06-25 01:11:47 UTC (rev 41843)
+++ scummvm/trunk/engines/kyra/screen_lok.cpp	2009-06-25 01:29:14 UTC (rev 41844)
@@ -28,7 +28,6 @@
 
 namespace Kyra {
 
-
 Screen_LoK::Screen_LoK(KyraEngine_LoK *vm, OSystem *system)
 	: Screen(vm, system) {
 	_vm = vm;
@@ -239,4 +238,106 @@
 	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

Modified: scummvm/trunk/engines/kyra/screen_lok.h
===================================================================
--- scummvm/trunk/engines/kyra/screen_lok.h	2009-06-25 01:11:47 UTC (rev 41843)
+++ scummvm/trunk/engines/kyra/screen_lok.h	2009-06-25 01:29:14 UTC (rev 41844)
@@ -77,6 +77,23 @@
 	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

Modified: scummvm/trunk/engines/kyra/staticres.cpp
===================================================================
--- scummvm/trunk/engines/kyra/staticres.cpp	2009-06-25 01:11:47 UTC (rev 41843)
+++ scummvm/trunk/engines/kyra/staticres.cpp	2009-06-25 01:29:14 UTC (rev 41844)
@@ -2104,6 +2104,15 @@
 
 #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 },


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list