From c422e39bf8caa0e95b3202e444cc0190d4708248 Mon Sep 17 00:00:00 2001 From: Martin Kiewitz Date: Tue, 27 Jul 2010 17:51:44 +0000 Subject: SCI: implemented kPalette(save/restore) svn-id: r51381 --- engines/sci/engine/kernel_tables.h | 2 +- engines/sci/engine/kgraphics.cpp | 6 +++--- engines/sci/engine/savegame.cpp | 16 ++++++++++++++-- engines/sci/graphics/helpers.h | 15 --------------- engines/sci/graphics/palette.cpp | 36 ++++++++++++++++++++++++++++++++++++ engines/sci/graphics/palette.h | 3 +++ 6 files changed, 57 insertions(+), 21 deletions(-) diff --git a/engines/sci/engine/kernel_tables.h b/engines/sci/engine/kernel_tables.h index b684b17b02..ca4c8754a1 100644 --- a/engines/sci/engine/kernel_tables.h +++ b/engines/sci/engine/kernel_tables.h @@ -215,7 +215,7 @@ static const SciKernelMapSubEntry kPalette_subops[] = { { SIG_SCIALL, 5, MAP_CALL(PaletteFindColor), "iii", NULL }, { SIG_SCIALL, 6, MAP_CALL(PaletteAnimate), "i*", NULL }, { SIG_SCIALL, 7, MAP_CALL(PaletteSave), "", NULL }, - { SIG_SCIALL, 8, MAP_CALL(PaletteRestore), "i", NULL }, + { SIG_SCIALL, 8, MAP_CALL(PaletteRestore), "[r0]", NULL }, SCI_SUBOPENTRY_TERMINATOR }; diff --git a/engines/sci/engine/kgraphics.cpp b/engines/sci/engine/kgraphics.cpp index 78fb78d42c..56518f10bf 100644 --- a/engines/sci/engine/kgraphics.cpp +++ b/engines/sci/engine/kgraphics.cpp @@ -616,16 +616,16 @@ reg_t kPaletteAnimate(EngineState *s, int argc, reg_t *argv) { reg_t kPaletteSave(EngineState *s, int argc, reg_t *argv) { if (g_sci->getResMan()->isVGA()) { - warning("kPalette(7), save palette to heap STUB"); + return g_sci->_gfxPalette->kernelSave(); } return NULL_REG; } reg_t kPaletteRestore(EngineState *s, int argc, reg_t *argv) { if (g_sci->getResMan()->isVGA()) { - warning("kPalette(8), restore palette from heap STUB"); + g_sci->_gfxPalette->kernelRestore(argv[0]); } - return s->r_acc; + return argv[0]; } reg_t kPalVary(EngineState *s, int argc, reg_t *argv) { diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp index 3de555cad3..806c8893b4 100644 --- a/engines/sci/engine/savegame.cpp +++ b/engines/sci/engine/savegame.cpp @@ -563,6 +563,18 @@ void StringTable::saveLoadWithSerializer(Common::Serializer &ser) { } #endif +void GfxPalette::palVarySaveLoadPalette(Common::Serializer &s, Palette *palette) { + s.syncBytes(palette->mapping, 256); + s.syncAsUint32LE(palette->timestamp); + for (int i = 0; i < 256; i++) { + s.syncAsByte(palette->colors[i].used); + s.syncAsByte(palette->colors[i].r); + s.syncAsByte(palette->colors[i].g); + s.syncAsByte(palette->colors[i].b); + } + s.syncBytes(palette->intensity, 256); +} + void GfxPalette::saveLoadWithSerializer(Common::Serializer &s) { if (s.getVersion() < 24) return; @@ -572,8 +584,8 @@ void GfxPalette::saveLoadWithSerializer(Common::Serializer &s) { s.syncAsSint32LE(_palVaryResourceId); if (_palVaryResourceId != -1) { - _palVaryOriginPalette.saveLoadWithSerializer(s); - _palVaryTargetPalette.saveLoadWithSerializer(s); + palVarySaveLoadPalette(s, &_palVaryOriginPalette); + palVarySaveLoadPalette(s, &_palVaryTargetPalette); s.syncAsSint16LE(_palVaryStep); s.syncAsSint16LE(_palVaryStepStop); s.syncAsSint16LE(_palVaryDirection); diff --git a/engines/sci/graphics/helpers.h b/engines/sci/graphics/helpers.h index 115a4c996e..8f26ca296b 100644 --- a/engines/sci/graphics/helpers.h +++ b/engines/sci/graphics/helpers.h @@ -83,13 +83,6 @@ struct Window : public Port { struct Color { byte used; byte r, g, b; - - void saveLoadWithSerializer(Common::Serializer &s) { - s.syncAsByte(used); - s.syncAsByte(r); - s.syncAsByte(g); - s.syncAsByte(b); - } }; struct Palette { @@ -97,14 +90,6 @@ struct Palette { uint32 timestamp; Color colors[256]; byte intensity[256]; - - void saveLoadWithSerializer(Common::Serializer &s) { - s.syncBytes(mapping, 256); - s.syncAsUint32LE(timestamp); - for (int i = 0; i < 256; i++) - colors[i].saveLoadWithSerializer(s); - s.syncBytes(intensity, 256); - } }; struct PalSchedule { diff --git a/engines/sci/graphics/palette.cpp b/engines/sci/graphics/palette.cpp index 00d59c7b92..5c17f76558 100644 --- a/engines/sci/graphics/palette.cpp +++ b/engines/sci/graphics/palette.cpp @@ -488,6 +488,42 @@ void GfxPalette::kernelAnimateSet() { setOnScreen(); } +reg_t GfxPalette::kernelSave() { + SegManager *segMan = g_sci->getEngineState()->_segMan; + reg_t memoryId = segMan->allocateHunkEntry("kPalette(save)", 1024); + byte *memoryPtr = segMan->getHunkPointer(memoryId); + if (memoryPtr) { + for (int colorNr = 0; colorNr < 256; colorNr++) { + *memoryPtr++ = _sysPalette.colors[colorNr].used; + *memoryPtr++ = _sysPalette.colors[colorNr].r; + *memoryPtr++ = _sysPalette.colors[colorNr].g; + *memoryPtr++ = _sysPalette.colors[colorNr].b; + } + } + return memoryId; +} + +void GfxPalette::kernelRestore(reg_t memoryHandle) { + SegManager *segMan = g_sci->getEngineState()->_segMan; + if (!memoryHandle.isNull()) { + byte *memoryPtr = segMan->getHunkPointer(memoryHandle); + if (!memoryPtr) + error("Bad handle used for kPalette(restore)"); + + Palette restoredPalette; + + restoredPalette.timestamp = 0; + for (int colorNr = 0; colorNr < 256; colorNr++) { + restoredPalette.colors[colorNr].used = *memoryPtr++; + restoredPalette.colors[colorNr].r = *memoryPtr++; + restoredPalette.colors[colorNr].g = *memoryPtr++; + restoredPalette.colors[colorNr].b = *memoryPtr++; + } + + set(&restoredPalette, true); + } +} + void GfxPalette::kernelAssertPalette(GuiResourceId resourceId) { // Sometimes invalid viewIds are asked for, ignore those (e.g. qfg1vga) //if (!_resMan->testResource(ResourceId(kResourceTypeView, resourceId))) diff --git a/engines/sci/graphics/palette.h b/engines/sci/graphics/palette.h index b9cd308281..e10c10718d 100644 --- a/engines/sci/graphics/palette.h +++ b/engines/sci/graphics/palette.h @@ -63,6 +63,8 @@ public: int16 kernelFindColor(uint16 r, uint16 g, uint16 b); bool kernelAnimate(byte fromColor, byte toColor, int speed); void kernelAnimateSet(); + reg_t kernelSave(); + void kernelRestore(reg_t memoryHandle); void kernelAssertPalette(GuiResourceId resourceId); void kernelSyncScreenPalette(); @@ -81,6 +83,7 @@ public: Palette _sysPalette; virtual void saveLoadWithSerializer(Common::Serializer &s); + void palVarySaveLoadPalette(Common::Serializer &s, Palette *palette); private: void palVaryInit(); -- cgit v1.2.3