aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gfx.cpp66
-rw-r--r--script_v2.cpp10
-rw-r--r--scumm.h1
3 files changed, 68 insertions, 9 deletions
diff --git a/gfx.cpp b/gfx.cpp
index 7e6d8d28be..e4c01f2602 100644
--- a/gfx.cpp
+++ b/gfx.cpp
@@ -2638,3 +2638,69 @@ void Scumm::drawBomp(BompDrawData * bd)
CHECK_HEAP;
}
+
+void Scumm::createSpecialPalette(int16 a, int16 b, int16 c, int16 d, int16 e, int16 colorMin, int16 colorMax)
+{
+ byte *palPtr;
+ byte *curPtr;
+ byte *searchPtr;
+
+ byte colorComp1;
+ byte colorComp2;
+ byte colorComp3;
+
+ byte searchComp1;
+ byte searchComp2;
+ byte searchComp3;
+
+ short int bestResult;
+ short int currentResult;
+ byte currentIndex;
+
+ int i;
+ int j;
+
+ palPtr = getPalettePtr();
+
+ for(i=colorMin;i<colorMax;i++)
+ _proc_special_palette[i]=i;
+
+ curPtr = palPtr + colorMin*3;
+
+ for(i=colorMin;i<colorMax;i++)
+ {
+ /* colorComp1=((((*curPtr++)>>2)*c)>>8)&0x7F;
+ colorComp2=((((*curPtr++)>>2)*d)>>8)&0x7F;
+ colorComp3=((((*curPtr++)>>2)*e)>>8)&0x7F;*/
+
+ /* Yazoo: I can't get the right formula, so I made one that just work fine with SamnMax flashlight */
+
+ colorComp1=(*curPtr++)+10;
+ colorComp2=(*curPtr++)+10;
+ colorComp3=(*curPtr++)+10;
+
+
+ searchPtr = palPtr;
+ bestResult = 0x7FFF;
+ currentIndex = 0;
+
+ for(j=0;j<256;j++)
+ {
+ searchComp1 = (*searchPtr++);
+ searchComp2 = (*searchPtr++);
+ searchComp3 = (*searchPtr++);
+
+ currentResult = abs(searchComp1-colorComp1) + abs(searchComp2-colorComp2) + abs(searchComp3-colorComp3);
+
+ if(currentResult<bestResult)
+ if(currentIndex >= a && currentIndex <= b)
+ {
+ _proc_special_palette[i]=currentIndex;
+ bestResult=currentResult;
+ }
+
+ currentIndex++;
+ }
+
+ }
+} \ No newline at end of file
diff --git a/script_v2.cpp b/script_v2.cpp
index 5562805cdb..8a4df8e907 100644
--- a/script_v2.cpp
+++ b/script_v2.cpp
@@ -2798,15 +2798,7 @@ void Scumm::o6_miscOps()
case 108: /* create proc_special_palette */
case 109:
- int i;
- byte j;
- for(i=0;i<256;i++)
- {
- j=rand();
- _proc_special_palette[i]=j;
- }
- warning("stub o6_miscOps_108(%d,%d,%d,%d,%d,%d,%d)", args[1], args[2],
- args[3], args[4], args[5], 0, 256);
+ createSpecialPalette(args[1], args[2],args[3], args[4], args[5], 0, 256);
break;
case 110:
diff --git a/scumm.h b/scumm.h
index 28cc197466..e8b3ce6e0d 100644
--- a/scumm.h
+++ b/scumm.h
@@ -1134,6 +1134,7 @@ public:
void initVirtScreen(int slot, int top, int height, bool twobufs, bool fourextra);
void initBGBuffers();
void initCycl(byte *ptr); // Color cycle
+ void createSpecialPalette(int16 a, int16 b, int16 c, int16 d, int16 e, int16 colorMin, int16 colorMax);
void drawObject(int obj, int arg);
void drawRoomObjects(int arg);