2011-06-26 10:09:56 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dreamweb/dreamweb.h"
|
2011-06-25 18:05:05 +00:00
|
|
|
#include "engines/metaengine.h"
|
2011-12-18 00:54:51 +00:00
|
|
|
#include "graphics/thumbnail.h"
|
2011-06-25 18:05:05 +00:00
|
|
|
#include "gui/saveload.h"
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/translation.h"
|
2011-12-17 20:30:54 +00:00
|
|
|
#include "common/serializer.h"
|
2011-06-26 10:09:56 +00:00
|
|
|
|
|
|
|
namespace DreamGen {
|
|
|
|
|
2011-12-03 19:32:41 +00:00
|
|
|
// Temporary storage for loading the room from a savegame
|
|
|
|
Room g_madeUpRoomDat;
|
|
|
|
|
2011-12-17 20:30:54 +00:00
|
|
|
|
|
|
|
void syncReelRoutine(Common::Serializer &s, ReelRoutine *reel) {
|
|
|
|
s.syncAsByte(reel->reallocation);
|
|
|
|
s.syncAsByte(reel->mapX);
|
|
|
|
s.syncAsByte(reel->mapY);
|
2011-12-17 21:26:17 +00:00
|
|
|
#if 1
|
2011-12-17 20:30:54 +00:00
|
|
|
s.syncAsByte(reel->b3);
|
|
|
|
s.syncAsByte(reel->b4);
|
2011-12-17 21:26:17 +00:00
|
|
|
#else
|
|
|
|
s.syncAsUint16LE(reel->_reelPointer);
|
|
|
|
#endif
|
2011-12-17 20:30:54 +00:00
|
|
|
s.syncAsByte(reel->period);
|
|
|
|
s.syncAsByte(reel->counter);
|
|
|
|
s.syncAsByte(reel->b7);
|
|
|
|
}
|
|
|
|
|
2011-12-01 19:43:43 +00:00
|
|
|
void DreamGenContext::loadGame() {
|
2011-06-25 18:05:05 +00:00
|
|
|
if (data.byte(kCommandtype) != 246) {
|
|
|
|
data.byte(kCommandtype) = 246;
|
2011-12-01 19:43:43 +00:00
|
|
|
commandOnly(41);
|
2011-06-25 18:05:05 +00:00
|
|
|
}
|
|
|
|
if (data.word(kMousebutton) == data.word(kOldbutton))
|
|
|
|
return; // "noload"
|
2011-12-03 15:54:39 +00:00
|
|
|
if (data.word(kMousebutton) == 1)
|
|
|
|
doLoad(-1);
|
2011-06-26 10:09:56 +00:00
|
|
|
}
|
|
|
|
|
2011-06-25 18:30:16 +00:00
|
|
|
// if -1, open menu to ask for slot to load
|
|
|
|
// if >= 0, directly load from that slot
|
2011-12-03 15:54:39 +00:00
|
|
|
void DreamGenContext::doLoad(int savegameId) {
|
2011-06-26 10:09:56 +00:00
|
|
|
data.byte(kLoadingorsave) = 1;
|
2011-06-25 18:05:05 +00:00
|
|
|
|
2011-06-25 18:30:16 +00:00
|
|
|
if (ConfMan.getBool("dreamweb_originalsaveload") && savegameId == -1) {
|
2011-12-01 19:43:43 +00:00
|
|
|
showOpBox();
|
|
|
|
showLoadOps();
|
2011-06-25 18:05:05 +00:00
|
|
|
data.byte(kCurrentslot) = 0;
|
2011-12-01 19:43:43 +00:00
|
|
|
showSlots();
|
|
|
|
showNames();
|
2011-06-25 18:05:05 +00:00
|
|
|
data.byte(kPointerframe) = 0;
|
2011-12-01 19:43:43 +00:00
|
|
|
workToScreenM();
|
|
|
|
namesToOld();
|
2011-06-25 18:05:05 +00:00
|
|
|
data.byte(kGetback) = 0;
|
|
|
|
|
2011-12-03 15:30:51 +00:00
|
|
|
while (data.byte(kGetback) == 0) {
|
2011-11-21 16:56:49 +00:00
|
|
|
if (quitRequested())
|
|
|
|
return;
|
2011-12-01 19:43:43 +00:00
|
|
|
delPointer();
|
|
|
|
readMouse();
|
|
|
|
showPointer();
|
|
|
|
vSync();
|
|
|
|
dumpPointer();
|
|
|
|
dumpTextLine();
|
2011-11-14 20:38:40 +00:00
|
|
|
RectWithCallback loadlist[] = {
|
2011-12-01 19:43:43 +00:00
|
|
|
{ kOpsx+176,kOpsx+192,kOpsy+60,kOpsy+76,&DreamGenContext::getBackToOps },
|
|
|
|
{ kOpsx+128,kOpsx+190,kOpsy+12,kOpsy+100,&DreamGenContext::actualLoad },
|
|
|
|
{ kOpsx+2,kOpsx+92,kOpsy+4,kOpsy+81,&DreamGenContext::selectSlot },
|
2011-12-15 12:41:30 +00:00
|
|
|
{ 0,320,0,200,&DreamBase::blank },
|
2011-11-14 20:38:40 +00:00
|
|
|
{ 0xFFFF,0,0,0,0 }
|
|
|
|
};
|
2011-12-01 19:43:43 +00:00
|
|
|
checkCoords(loadlist);
|
2011-06-25 18:05:05 +00:00
|
|
|
if (data.byte(kGetback) == 2)
|
|
|
|
return; // "quitloaded"
|
|
|
|
}
|
|
|
|
} else {
|
2011-06-25 18:30:16 +00:00
|
|
|
|
|
|
|
if (savegameId == -1) {
|
|
|
|
// Open dialog to get savegameId
|
|
|
|
|
|
|
|
const EnginePlugin *plugin = NULL;
|
|
|
|
Common::String gameId = ConfMan.get("gameid");
|
|
|
|
EngineMan.findGame(gameId, &plugin);
|
|
|
|
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Restore game:"), _("Restore"));
|
|
|
|
dialog->setSaveMode(false);
|
|
|
|
savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
|
|
|
delete dialog;
|
|
|
|
}
|
2011-06-25 18:05:05 +00:00
|
|
|
|
|
|
|
if (savegameId < 0) {
|
|
|
|
data.byte(kGetback) = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-01 19:43:43 +00:00
|
|
|
loadPosition(savegameId);
|
2011-06-25 18:05:05 +00:00
|
|
|
|
|
|
|
data.byte(kGetback) = 1;
|
|
|
|
}
|
|
|
|
|
2011-12-03 15:00:55 +00:00
|
|
|
// If we reach this point, loadPosition() has just been called.
|
2011-12-03 19:32:41 +00:00
|
|
|
// Among other things, it will have filled g_MadeUpRoomDat.
|
2011-12-03 15:00:55 +00:00
|
|
|
|
2011-06-25 18:30:16 +00:00
|
|
|
// kTempgraphics might not have been allocated if we bypassed all menus
|
|
|
|
if (data.word(kTempgraphics) != 0xFFFF)
|
2011-12-01 19:43:43 +00:00
|
|
|
getRidOfTemp();
|
2011-06-25 18:30:16 +00:00
|
|
|
|
2011-12-03 19:32:41 +00:00
|
|
|
startLoading(g_madeUpRoomDat);
|
2011-12-01 19:43:43 +00:00
|
|
|
loadRoomsSample();
|
2011-06-26 10:09:56 +00:00
|
|
|
data.byte(kRoomloaded) = 1;
|
|
|
|
data.byte(kNewlocation) = 255;
|
2011-12-01 19:43:43 +00:00
|
|
|
clearSprites();
|
|
|
|
initMan();
|
|
|
|
initRain();
|
2011-06-26 10:09:56 +00:00
|
|
|
data.word(kTextaddressx) = 13;
|
|
|
|
data.word(kTextaddressy) = 182;
|
|
|
|
data.byte(kTextlen) = 240;
|
|
|
|
startup();
|
2011-12-09 16:18:32 +00:00
|
|
|
workToScreenCPP();
|
2011-06-26 10:09:56 +00:00
|
|
|
data.byte(kGetback) = 4;
|
|
|
|
}
|
|
|
|
|
2011-06-25 18:05:05 +00:00
|
|
|
|
2011-12-01 19:43:43 +00:00
|
|
|
void DreamGenContext::saveGame() {
|
2011-06-25 18:05:05 +00:00
|
|
|
if (data.byte(kMandead) == 2) {
|
|
|
|
blank();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.byte(kCommandtype) != 247) {
|
|
|
|
data.byte(kCommandtype) = 247;
|
2011-12-01 19:43:43 +00:00
|
|
|
commandOnly(44);
|
2011-06-25 18:05:05 +00:00
|
|
|
}
|
|
|
|
if (data.word(kMousebutton) != 1)
|
|
|
|
return;
|
|
|
|
|
2011-06-26 10:09:56 +00:00
|
|
|
data.byte(kLoadingorsave) = 2;
|
2011-06-25 18:05:05 +00:00
|
|
|
|
|
|
|
if (ConfMan.getBool("dreamweb_originalsaveload")) {
|
2011-12-01 19:43:43 +00:00
|
|
|
showOpBox();
|
|
|
|
showSaveOps();
|
2011-06-25 18:05:05 +00:00
|
|
|
data.byte(kCurrentslot) = 0;
|
2011-12-01 19:43:43 +00:00
|
|
|
showSlots();
|
|
|
|
showNames();
|
|
|
|
workToScreenM();
|
|
|
|
namesToOld();
|
2011-06-25 18:05:05 +00:00
|
|
|
data.word(kBufferin) = 0;
|
|
|
|
data.word(kBufferout) = 0;
|
|
|
|
data.byte(kGetback) = 0;
|
|
|
|
|
2011-12-03 15:30:51 +00:00
|
|
|
while (data.byte(kGetback) == 0) {
|
2011-11-21 16:56:49 +00:00
|
|
|
if (quitRequested())
|
|
|
|
return;
|
2011-12-01 19:43:43 +00:00
|
|
|
delPointer();
|
|
|
|
checkInput();
|
|
|
|
readMouse();
|
|
|
|
showPointer();
|
|
|
|
vSync();
|
|
|
|
dumpPointer();
|
|
|
|
dumpTextLine();
|
2011-11-14 20:38:40 +00:00
|
|
|
|
|
|
|
RectWithCallback savelist[] = {
|
2011-12-01 19:43:43 +00:00
|
|
|
{ kOpsx+176,kOpsx+192,kOpsy+60,kOpsy+76,&DreamGenContext::getBackToOps },
|
|
|
|
{ kOpsx+128,kOpsx+190,kOpsy+12,kOpsy+100,&DreamGenContext::actualSave },
|
|
|
|
{ kOpsx+2,kOpsx+92,kOpsy+4,kOpsy+81,&DreamGenContext::selectSlot },
|
2011-12-15 12:41:30 +00:00
|
|
|
{ 0,320,0,200,&DreamBase::blank },
|
2011-11-14 20:38:40 +00:00
|
|
|
{ 0xFFFF,0,0,0,0 }
|
|
|
|
};
|
2011-12-01 19:43:43 +00:00
|
|
|
checkCoords(savelist);
|
2011-06-25 18:05:05 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
const EnginePlugin *plugin = NULL;
|
|
|
|
Common::String gameId = ConfMan.get("gameid");
|
|
|
|
EngineMan.findGame(gameId, &plugin);
|
|
|
|
GUI::SaveLoadChooser *dialog = new GUI::SaveLoadChooser(_("Save game:"), _("Save"));
|
|
|
|
dialog->setSaveMode(true);
|
|
|
|
int savegameId = dialog->runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
|
|
|
|
Common::String game_description = dialog->getResultString();
|
|
|
|
if (game_description.empty())
|
|
|
|
game_description = "Untitled";
|
|
|
|
delete dialog;
|
|
|
|
|
|
|
|
if (savegameId < 0) {
|
|
|
|
data.byte(kGetback) = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-11 14:57:03 +00:00
|
|
|
char descbuf[17] = { 2, 0 };
|
2011-12-17 18:06:55 +00:00
|
|
|
Common::strlcpy((char*)descbuf + 1, game_description.c_str(), 16);
|
2011-06-25 18:05:05 +00:00
|
|
|
unsigned int desclen = game_description.size();
|
|
|
|
if (desclen > 15)
|
|
|
|
desclen = 15;
|
|
|
|
// zero terminate, and pad with ones
|
|
|
|
descbuf[++desclen] = 0;
|
2011-12-17 17:30:06 +00:00
|
|
|
while (desclen < 16)
|
2011-06-25 18:05:05 +00:00
|
|
|
descbuf[++desclen] = 1;
|
2011-11-26 17:07:34 +00:00
|
|
|
|
|
|
|
// TODO: The below is copied from actualsave
|
2011-12-01 19:43:43 +00:00
|
|
|
getRidOfTemp();
|
|
|
|
restoreAll(); // reels
|
2011-06-25 18:05:05 +00:00
|
|
|
data.word(kTextaddressx) = 13;
|
|
|
|
data.word(kTextaddressy) = 182;
|
|
|
|
data.byte(kTextlen) = 240;
|
2011-12-01 19:43:43 +00:00
|
|
|
redrawMainScrn();
|
2011-12-18 00:54:51 +00:00
|
|
|
workToScreenCPP(); // show the main screen without the mouse pointer
|
|
|
|
|
|
|
|
// We need to save after the scene has been redrawn, to capture the
|
|
|
|
// correct screen thumbnail
|
|
|
|
savePosition(savegameId, descbuf);
|
|
|
|
|
2011-12-01 19:43:43 +00:00
|
|
|
workToScreenM();
|
2011-06-25 18:05:05 +00:00
|
|
|
data.byte(kGetback) = 4;
|
|
|
|
}
|
2011-06-26 10:09:56 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 12:41:30 +00:00
|
|
|
void DreamBase::namesToOld() {
|
2011-12-11 14:57:03 +00:00
|
|
|
memcpy(_saveNamesOld, _saveNames, 17*7);
|
2011-11-17 14:08:34 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 12:41:30 +00:00
|
|
|
void DreamBase::oldToNames() {
|
2011-12-11 14:57:03 +00:00
|
|
|
memcpy(_saveNames, _saveNamesOld, 17*7);
|
2011-11-17 14:08:34 +00:00
|
|
|
}
|
2011-06-25 18:05:05 +00:00
|
|
|
|
2011-12-01 19:43:43 +00:00
|
|
|
void DreamGenContext::saveLoad() {
|
2011-11-21 15:49:45 +00:00
|
|
|
if (data.word(kWatchingtime) || (data.byte(kPointermode) == 2)) {
|
|
|
|
blank();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (data.byte(kCommandtype) != 253) {
|
|
|
|
data.byte(kCommandtype) = 253;
|
2011-12-01 19:43:43 +00:00
|
|
|
commandOnly(43);
|
2011-11-21 15:49:45 +00:00
|
|
|
}
|
|
|
|
if ((data.word(kMousebutton) != data.word(kOldbutton)) && (data.word(kMousebutton) & 1))
|
2011-12-01 19:43:43 +00:00
|
|
|
doSaveLoad();
|
2011-11-21 15:49:45 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 12:41:30 +00:00
|
|
|
void DreamGenContext::doSaveLoad() {
|
|
|
|
data.byte(kPointerframe) = 0;
|
|
|
|
data.word(kTextaddressx) = 70;
|
|
|
|
data.word(kTextaddressy) = 182-8;
|
|
|
|
data.byte(kTextlen) = 181;
|
|
|
|
data.byte(kManisoffscreen) = 1;
|
|
|
|
clearWork();
|
|
|
|
createPanel2();
|
|
|
|
underTextLine();
|
|
|
|
getRidOfAll();
|
|
|
|
loadSaveBox();
|
|
|
|
showOpBox();
|
|
|
|
showMainOps();
|
|
|
|
workToScreenCPP();
|
|
|
|
|
|
|
|
RectWithCallback opsList[] = {
|
|
|
|
{ kOpsx+59,kOpsx+114,kOpsy+30,kOpsy+76,&DreamGenContext::getBackFromOps },
|
|
|
|
{ kOpsx+10,kOpsx+77,kOpsy+10,kOpsy+59,&DreamBase::DOSReturn },
|
|
|
|
{ kOpsx+128,kOpsx+190,kOpsy+16,kOpsy+100,&DreamGenContext::discOps },
|
|
|
|
{ 0,320,0,200,&DreamBase::blank },
|
|
|
|
{ 0xFFFF,0,0,0,0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
bool firstOps = true;
|
|
|
|
|
|
|
|
do { // restart ops
|
|
|
|
if (firstOps) {
|
|
|
|
firstOps = false;
|
|
|
|
} else {
|
|
|
|
showOpBox();
|
|
|
|
showMainOps();
|
|
|
|
workToScreenM();
|
|
|
|
}
|
|
|
|
data.byte(kGetback) = 0;
|
|
|
|
|
|
|
|
do { // wait ops
|
|
|
|
if (data.byte(kQuitrequested)) {
|
|
|
|
data.byte(kManisoffscreen) = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
readMouse();
|
|
|
|
showPointer();
|
|
|
|
vSync();
|
|
|
|
dumpPointer();
|
|
|
|
dumpTextLine();
|
|
|
|
delPointer();
|
|
|
|
checkCoords(opsList);
|
|
|
|
} while (!data.byte(kGetback));
|
|
|
|
} while (data.byte(kGetback) == 2);
|
|
|
|
|
|
|
|
data.word(kTextaddressx) = 13;
|
|
|
|
data.word(kTextaddressy) = 182;
|
|
|
|
data.byte(kTextlen) = 240;
|
|
|
|
if (data.byte(kGetback) != 4) {
|
|
|
|
getRidOfTemp();
|
|
|
|
restoreAll();
|
|
|
|
redrawMainScrn();
|
|
|
|
workToScreenM();
|
|
|
|
data.byte(kCommandtype) = 200;
|
|
|
|
}
|
|
|
|
data.byte(kManisoffscreen) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamBase::showMainOps() {
|
2011-12-01 19:43:43 +00:00
|
|
|
showFrame(tempGraphics(), kOpsx+10, kOpsy+10, 8, 0);
|
|
|
|
showFrame(tempGraphics(), kOpsx+59, kOpsy+30, 7, 0);
|
|
|
|
showFrame(tempGraphics(), kOpsx+128+4, kOpsy+12, 1, 0);
|
2011-11-21 17:10:19 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 12:41:30 +00:00
|
|
|
void DreamBase::showDiscOps() {
|
2011-12-01 19:43:43 +00:00
|
|
|
showFrame(tempGraphics(), kOpsx+128+4, kOpsy+12, 1, 0);
|
|
|
|
showFrame(tempGraphics(), kOpsx+10, kOpsy+10, 9, 0);
|
|
|
|
showFrame(tempGraphics(), kOpsx+59, kOpsy+30, 10, 0);
|
|
|
|
showFrame(tempGraphics(), kOpsx+176+2, kOpsy+60-4, 5, 0);
|
2011-11-26 17:31:54 +00:00
|
|
|
}
|
|
|
|
|
2011-12-01 19:43:43 +00:00
|
|
|
void DreamGenContext::actualSave() {
|
2011-11-26 16:43:50 +00:00
|
|
|
if (data.byte(kCommandtype) != 222) {
|
|
|
|
data.byte(kCommandtype) = 222;
|
2011-12-01 19:43:43 +00:00
|
|
|
commandOnly(44);
|
2011-11-26 16:43:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!(data.word(kMousebutton) & 1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned int slot = data.byte(kCurrentslot);
|
|
|
|
|
2011-12-11 14:57:03 +00:00
|
|
|
const char *desc = &_saveNames[17*slot];
|
2011-11-26 17:07:34 +00:00
|
|
|
if (desc[1] == 0) // The actual description string starts at desc[1]
|
2011-11-26 16:43:50 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-01 19:43:43 +00:00
|
|
|
savePosition(slot, desc);
|
2011-11-26 16:43:50 +00:00
|
|
|
|
2011-12-01 19:43:43 +00:00
|
|
|
getRidOfTemp();
|
|
|
|
restoreAll(); // reels
|
2011-11-26 16:23:40 +00:00
|
|
|
data.word(kTextaddressx) = 13;
|
|
|
|
data.word(kTextaddressy) = 182;
|
|
|
|
data.byte(kTextlen) = 240;
|
2011-12-01 19:43:43 +00:00
|
|
|
redrawMainScrn();
|
|
|
|
workToScreenM();
|
2011-11-26 16:23:40 +00:00
|
|
|
data.byte(kGetback) = 4;
|
|
|
|
}
|
|
|
|
|
2011-12-01 19:43:43 +00:00
|
|
|
void DreamGenContext::actualLoad() {
|
2011-11-26 16:46:50 +00:00
|
|
|
if (data.byte(kCommandtype) != 221) {
|
|
|
|
data.byte(kCommandtype) = 221;
|
2011-12-01 19:43:43 +00:00
|
|
|
commandOnly(41);
|
2011-11-26 16:46:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data.word(kMousebutton) == data.word(kOldbutton) || data.word(kMousebutton) != 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned int slot = data.byte(kCurrentslot);
|
|
|
|
|
2011-12-11 14:57:03 +00:00
|
|
|
const char *desc = &_saveNames[17*slot];
|
2011-11-26 17:07:34 +00:00
|
|
|
if (desc[1] == 0) // The actual description string starts at desc[1]
|
2011-11-26 16:46:50 +00:00
|
|
|
return;
|
|
|
|
|
2011-12-01 19:43:43 +00:00
|
|
|
loadPosition(data.byte(kCurrentslot));
|
2011-11-26 16:23:40 +00:00
|
|
|
data.byte(kGetback) = 1;
|
|
|
|
}
|
|
|
|
|
2011-12-11 14:57:03 +00:00
|
|
|
void DreamGenContext::savePosition(unsigned int slot, const char *descbuf) {
|
2011-11-26 17:07:34 +00:00
|
|
|
|
2011-12-03 15:00:55 +00:00
|
|
|
const Room ¤tRoom = g_roomData[data.byte(kLocation)];
|
2011-11-26 17:07:34 +00:00
|
|
|
|
2011-12-03 15:00:55 +00:00
|
|
|
Room madeUpRoom = currentRoom;
|
|
|
|
madeUpRoom.roomsSample = data.byte(kRoomssample);
|
|
|
|
madeUpRoom.mapX = data.byte(kMapx);
|
|
|
|
madeUpRoom.mapY = data.byte(kMapy);
|
|
|
|
madeUpRoom.liftFlag = data.byte(kLiftflag);
|
|
|
|
madeUpRoom.b21 = data.byte(kManspath);
|
|
|
|
madeUpRoom.facing = data.byte(kFacing);
|
|
|
|
madeUpRoom.b27 = 255;
|
2011-11-26 17:07:34 +00:00
|
|
|
|
2011-12-09 14:50:38 +00:00
|
|
|
Common::String filename = engine->getSavegameFilename(slot);
|
2011-12-09 15:04:45 +00:00
|
|
|
debug(1, "savePosition: slot %d filename %s", slot, filename.c_str());
|
2011-12-09 14:50:38 +00:00
|
|
|
Common::OutSaveFile *outSaveFile = engine->getSaveFileManager()->openForSaving(filename);
|
|
|
|
if (!outSaveFile) // TODO: Do proper error handling!
|
|
|
|
error("save could not be opened for writing");
|
2011-11-26 15:38:06 +00:00
|
|
|
|
2011-12-03 14:47:24 +00:00
|
|
|
// Initialize new header
|
|
|
|
FileHeader header;
|
|
|
|
|
|
|
|
// Note: _desc is not zero-terminated
|
|
|
|
const char *desc = "DREAMWEB DATA FILE COPYRIGHT 1992 CREATIVE REALITY";
|
|
|
|
assert(strlen(desc) == sizeof(header._desc));
|
|
|
|
memcpy(header._desc, desc, sizeof(header._desc));
|
|
|
|
memset(&header._len[0], 0, sizeof(header._len));
|
|
|
|
memset(&header._padding[0], 0, sizeof(header._padding));
|
|
|
|
|
2011-11-26 15:38:06 +00:00
|
|
|
// fill length fields in savegame file header
|
|
|
|
uint16 len[6] = { 17, kLengthofvars, kLengthofextra,
|
|
|
|
4*kNumchanges, 48, kLenofreelrouts };
|
|
|
|
for (int i = 0; i < 6; ++i)
|
2011-12-03 14:47:24 +00:00
|
|
|
header.setLen(i, len[i]);
|
2011-11-26 15:38:06 +00:00
|
|
|
|
2011-12-18 00:54:51 +00:00
|
|
|
// Write a new section with data that we need for ScummVM (version,
|
|
|
|
// thumbnail, played time etc). We don't really care for its size,
|
|
|
|
// so we just set it to a magic number.
|
|
|
|
header.setLen(6, SCUMMVM_BLOCK_MAGIC_SIZE);
|
|
|
|
|
2011-12-09 14:50:38 +00:00
|
|
|
outSaveFile->write((const uint8 *)&header, sizeof(FileHeader));
|
|
|
|
outSaveFile->write(descbuf, len[0]);
|
|
|
|
outSaveFile->write(data.ptr(kStartvars, len[1]), len[1]);
|
|
|
|
outSaveFile->write(getSegment(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]);
|
|
|
|
outSaveFile->write(getSegment(data.word(kBuffers)).ptr(kListofchanges, len[3]), len[3]);
|
2011-12-03 15:00:55 +00:00
|
|
|
|
|
|
|
// len[4] == 48, which is sizeof(Room) plus 16 for 'Roomscango'
|
2011-12-09 14:50:38 +00:00
|
|
|
outSaveFile->write((const uint8 *)&madeUpRoom, sizeof(Room));
|
|
|
|
outSaveFile->write(data.ptr(kRoomscango, 16), 16);
|
|
|
|
|
2011-12-17 20:30:54 +00:00
|
|
|
// TODO: Convert more to serializer?
|
|
|
|
Common::Serializer s(0, outSaveFile);
|
2011-12-18 11:38:53 +00:00
|
|
|
for (unsigned int i = 0; 8*i < kLenofreelrouts - 1; ++i) {
|
|
|
|
syncReelRoutine(s, (ReelRoutine *)data.ptr(kReelroutines + 8*i, 8));
|
2011-12-17 20:30:54 +00:00
|
|
|
}
|
2011-12-18 11:38:53 +00:00
|
|
|
// Terminator
|
|
|
|
s.syncAsByte(*data.ptr(kReelroutines + kLenofreelrouts - 1, 1));
|
2011-12-09 14:50:38 +00:00
|
|
|
|
2011-12-18 00:54:51 +00:00
|
|
|
// ScummVM data block
|
|
|
|
outSaveFile->writeUint32BE(SCUMMVM_HEADER);
|
|
|
|
outSaveFile->writeByte(SAVEGAME_VERSION);
|
|
|
|
TimeDate curTime;
|
|
|
|
g_system->getTimeAndDate(curTime);
|
|
|
|
uint32 saveDate = ((curTime.tm_mday & 0xFF) << 24) | (((curTime.tm_mon + 1) & 0xFF) << 16) | ((curTime.tm_year + 1900) & 0xFFFF);
|
|
|
|
uint32 saveTime = ((curTime.tm_hour & 0xFF) << 16) | (((curTime.tm_min) & 0xFF) << 8) | ((curTime.tm_sec) & 0xFF);
|
|
|
|
uint32 playTime = g_engine->getTotalPlayTime() / 1000;
|
|
|
|
outSaveFile->writeUint32LE(saveDate);
|
|
|
|
outSaveFile->writeUint32LE(saveTime);
|
|
|
|
outSaveFile->writeUint32LE(playTime);
|
|
|
|
Graphics::saveThumbnail(*outSaveFile);
|
|
|
|
|
2011-12-09 14:50:38 +00:00
|
|
|
outSaveFile->finalize();
|
|
|
|
if (outSaveFile->err()) {
|
|
|
|
// TODO: Do proper error handling
|
|
|
|
warning("an error occurred while writing the savegame");
|
|
|
|
}
|
2011-12-03 15:00:55 +00:00
|
|
|
|
2011-12-09 14:50:38 +00:00
|
|
|
delete outSaveFile;
|
2011-11-26 14:56:32 +00:00
|
|
|
}
|
|
|
|
|
2011-12-01 19:43:43 +00:00
|
|
|
void DreamGenContext::loadPosition(unsigned int slot) {
|
2011-11-26 14:56:32 +00:00
|
|
|
data.word(kTimecount) = 0;
|
2011-12-01 19:43:43 +00:00
|
|
|
clearChanges();
|
2011-11-26 16:07:40 +00:00
|
|
|
|
2011-12-09 15:04:45 +00:00
|
|
|
Common::String filename = engine->getSavegameFilename(slot);
|
|
|
|
debug(1, "loadPosition: slot %d filename %s", slot, filename.c_str());
|
|
|
|
Common::InSaveFile *inSaveFile = engine->getSaveFileManager()->openForLoading(filename);
|
|
|
|
if (!inSaveFile) // TODO: Do proper error handling!
|
|
|
|
error("save could not be opened for reading");
|
2011-11-26 16:07:40 +00:00
|
|
|
|
2011-12-03 14:47:24 +00:00
|
|
|
FileHeader header;
|
|
|
|
|
2011-12-09 15:04:45 +00:00
|
|
|
inSaveFile->read((uint8 *)&header, sizeof(FileHeader));
|
2011-11-26 16:07:40 +00:00
|
|
|
|
|
|
|
// read segment lengths from savegame file header
|
|
|
|
int len[6];
|
|
|
|
for (int i = 0; i < 6; ++i)
|
2011-12-03 14:47:24 +00:00
|
|
|
len[i] = header.len(i);
|
2011-11-26 16:07:40 +00:00
|
|
|
if (len[0] != 17)
|
|
|
|
::error("Error loading save: description buffer isn't 17 bytes");
|
|
|
|
|
2011-11-26 17:07:34 +00:00
|
|
|
if (slot < 7) {
|
2011-12-11 14:57:03 +00:00
|
|
|
inSaveFile->read(&_saveNames[17*slot], len[0]);
|
2011-11-26 17:07:34 +00:00
|
|
|
} else {
|
|
|
|
// The savenames buffer only has room for 7 descriptions
|
|
|
|
uint8 namebuf[17];
|
2011-12-09 15:04:45 +00:00
|
|
|
inSaveFile->read(namebuf, 17);
|
2011-11-26 17:07:34 +00:00
|
|
|
}
|
2011-12-09 15:04:45 +00:00
|
|
|
inSaveFile->read(data.ptr(kStartvars, len[1]), len[1]);
|
|
|
|
inSaveFile->read(getSegment(data.word(kExtras)).ptr(kExframedata, len[2]), len[2]);
|
|
|
|
inSaveFile->read(getSegment(data.word(kBuffers)).ptr(kListofchanges, len[3]), len[3]);
|
2011-12-03 15:00:55 +00:00
|
|
|
|
|
|
|
// len[4] == 48, which is sizeof(Room) plus 16 for 'Roomscango'
|
2011-12-03 19:32:41 +00:00
|
|
|
// Note: the values read into g_madeUpRoomDat are only used in actualLoad,
|
2011-12-03 15:30:51 +00:00
|
|
|
// which is (almost) immediately called after this function
|
2011-12-09 15:04:45 +00:00
|
|
|
inSaveFile->read((uint8 *)&g_madeUpRoomDat, sizeof(Room));
|
|
|
|
inSaveFile->read(data.ptr(kRoomscango, 16), 16);
|
2011-12-03 15:00:55 +00:00
|
|
|
|
2011-12-17 20:30:54 +00:00
|
|
|
// TODO: Use serializer for more
|
|
|
|
Common::Serializer s(inSaveFile, 0);
|
2011-12-18 11:38:53 +00:00
|
|
|
for (unsigned int i = 0; 8*i < kLenofreelrouts - 1; ++i) {
|
|
|
|
syncReelRoutine(s, (ReelRoutine *)data.ptr(kReelroutines + 8*i, 8));
|
2011-12-17 20:30:54 +00:00
|
|
|
}
|
2011-12-18 11:38:53 +00:00
|
|
|
// Terminator
|
|
|
|
s.syncAsByte(*data.ptr(kReelroutines + kLenofreelrouts - 1, 1));
|
2011-11-26 16:07:40 +00:00
|
|
|
|
2011-12-18 00:54:51 +00:00
|
|
|
// Check if there's a ScummVM data block
|
|
|
|
if (header.len(6) == SCUMMVM_BLOCK_MAGIC_SIZE) {
|
|
|
|
uint32 tag = inSaveFile->readUint32BE();
|
|
|
|
if (tag != SCUMMVM_HEADER) {
|
|
|
|
warning("ScummVM data block found, but the block header is incorrect - skipping");
|
|
|
|
delete inSaveFile;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte version = inSaveFile->readByte();
|
|
|
|
if (version > SAVEGAME_VERSION) {
|
|
|
|
warning("ScummVM data block found, but it has been saved with a newer version of ScummVM - skipping");
|
|
|
|
delete inSaveFile;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
inSaveFile->skip(4); // saveDate
|
|
|
|
inSaveFile->skip(4); // saveTime
|
|
|
|
uint32 playTime = inSaveFile->readUint32LE();
|
|
|
|
g_engine->setTotalPlayTime(playTime * 1000);
|
|
|
|
|
|
|
|
// The thumbnail data follows, but we don't need it here
|
|
|
|
}
|
|
|
|
|
2011-12-09 15:04:45 +00:00
|
|
|
delete inSaveFile;
|
2011-11-26 14:56:32 +00:00
|
|
|
}
|
|
|
|
|
2011-12-11 14:57:03 +00:00
|
|
|
// Count number of save files, and load their descriptions into _saveNames
|
2011-12-03 14:18:45 +00:00
|
|
|
unsigned int DreamGenContext::scanForNames() {
|
2011-12-17 17:30:06 +00:00
|
|
|
// Initialize the first 7 slots (like the original code expects)
|
2011-12-03 14:18:45 +00:00
|
|
|
for (unsigned int slot = 0; slot < 7; ++slot) {
|
2011-12-17 17:30:06 +00:00
|
|
|
_saveNames[17 * slot + 0] = 2;
|
|
|
|
_saveNames[17 * slot + 1] = 0;
|
2011-12-11 14:57:03 +00:00
|
|
|
for (int i = 2; i < 17; ++i)
|
2011-12-17 17:30:06 +00:00
|
|
|
_saveNames[17 * slot + i] = 1; // initialize with 1's
|
|
|
|
}
|
2011-12-03 14:18:45 +00:00
|
|
|
|
2011-12-17 17:30:06 +00:00
|
|
|
Common::SaveFileManager *saveFileMan = g_system->getSavefileManager();
|
|
|
|
Common::StringArray files = saveFileMan->listSavefiles("DREAMWEB.D??");
|
|
|
|
Common::sort(files.begin(), files.end());
|
|
|
|
|
|
|
|
SaveStateList saveList;
|
|
|
|
for (uint i = 0; i < files.size(); ++i) {
|
|
|
|
const Common::String &file = files[i];
|
|
|
|
Common::InSaveFile *stream = saveFileMan->openForLoading(file);
|
|
|
|
if (!stream)
|
|
|
|
error("cannot open save file %s", file.c_str());
|
|
|
|
char name[17] = {};
|
|
|
|
stream->seek(0x61);
|
|
|
|
stream->read(name, sizeof(name) - 1);
|
|
|
|
delete stream;
|
|
|
|
|
|
|
|
int slotNum = atoi(file.c_str() + file.size() - 2);
|
|
|
|
SaveStateDescriptor sd(slotNum, name);
|
|
|
|
saveList.push_back(sd);
|
|
|
|
if (slotNum < 7)
|
|
|
|
Common::strlcpy(&_saveNames[17 * slotNum + 1], name, 16); // the first character is unused
|
2011-12-03 14:18:45 +00:00
|
|
|
}
|
|
|
|
|
2011-12-17 17:30:06 +00:00
|
|
|
al = saveList.size() <= 7 ? (uint8)saveList.size() : 7;
|
2011-12-03 14:18:45 +00:00
|
|
|
|
2011-12-17 17:30:06 +00:00
|
|
|
return saveList.size();
|
2011-12-03 14:05:57 +00:00
|
|
|
}
|
|
|
|
|
2011-12-03 15:46:44 +00:00
|
|
|
void DreamGenContext::loadOld() {
|
2011-12-03 15:54:39 +00:00
|
|
|
if (data.byte(kCommandtype) != 252) {
|
|
|
|
data.byte(kCommandtype) = 252;
|
|
|
|
commandOnly(48);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(data.word(kMousebutton) & 1))
|
|
|
|
return;
|
|
|
|
|
|
|
|
doLoad(-1);
|
|
|
|
|
|
|
|
if (data.byte(kGetback) == 4 || quitRequested())
|
|
|
|
return;
|
|
|
|
|
2011-12-03 15:46:44 +00:00
|
|
|
showDecisions();
|
|
|
|
workToScreenM();
|
|
|
|
data.byte(kGetback) = 0;
|
|
|
|
}
|
|
|
|
|
2011-12-04 23:45:42 +00:00
|
|
|
void DreamGenContext::loadSaveBox() {
|
|
|
|
loadIntoTemp("DREAMWEB.G08");
|
|
|
|
}
|
2011-12-03 15:46:44 +00:00
|
|
|
|
2011-12-11 14:16:57 +00:00
|
|
|
// show savegame names (original interface), and set kCursorpos
|
|
|
|
void DreamBase::showNames() {
|
|
|
|
for (int slot = 0; slot < 7; ++slot) {
|
|
|
|
// The first character of the savegame name is unused
|
2011-12-11 14:57:03 +00:00
|
|
|
Common::String name(&_saveNames[17*slot + 1]);
|
2011-12-11 14:16:57 +00:00
|
|
|
|
|
|
|
if (slot != data.byte(kCurrentslot)) {
|
|
|
|
printDirect((const uint8 *)name.c_str(), kOpsx + 21, kOpsy + 10*slot + 10, 200, false);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (data.byte(kLoadingorsave) != 2) {
|
|
|
|
data.word(kCharshift) = 91;
|
|
|
|
printDirect((const uint8 *)name.c_str(), kOpsx + 21, kOpsy + 10*slot + 10, 200, false);
|
|
|
|
data.word(kCharshift) = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pos = name.size();
|
|
|
|
data.byte(kCursorpos) = pos;
|
|
|
|
name += '/'; // cursor character
|
|
|
|
printDirect((const uint8 *)name.c_str(), kOpsx + 21, kOpsy + 10*slot + 10, 200, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-11 14:45:53 +00:00
|
|
|
void DreamGenContext::checkInput() {
|
|
|
|
if (data.byte(kLoadingorsave) == 3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
readKey();
|
|
|
|
|
2011-12-11 14:57:03 +00:00
|
|
|
// The first character of the savegame name is unused
|
|
|
|
char *name = &_saveNames[17*data.byte(kCurrentslot) + 1];
|
2011-12-11 14:45:53 +00:00
|
|
|
|
|
|
|
if (data.byte(kCurrentkey) == 0) {
|
|
|
|
return;
|
|
|
|
} else if (data.byte(kCurrentkey) == 13) {
|
|
|
|
data.byte(kLoadingorsave) = 3;
|
|
|
|
} else if (data.byte(kCurrentkey) == 8) {
|
|
|
|
if (data.byte(kCursorpos) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
--data.byte(kCursorpos);
|
|
|
|
name[data.byte(kCursorpos)] = 0;
|
|
|
|
name[data.byte(kCursorpos)+1] = 1;
|
|
|
|
} else {
|
|
|
|
if (data.byte(kCursorpos) == 14)
|
|
|
|
return;
|
|
|
|
|
|
|
|
name[data.byte(kCursorpos)] = data.byte(kCurrentkey);
|
|
|
|
name[data.byte(kCursorpos)+1] = 0;
|
|
|
|
name[data.byte(kCursorpos)+2] = 1;
|
|
|
|
++data.byte(kCursorpos);
|
|
|
|
}
|
|
|
|
|
|
|
|
showOpBox();
|
|
|
|
showNames();
|
|
|
|
showSlots();
|
|
|
|
showSaveOps();
|
|
|
|
workToScreenM();
|
|
|
|
}
|
|
|
|
|
2011-12-15 12:41:30 +00:00
|
|
|
void DreamGenContext::selectSlot() {
|
|
|
|
if (data.byte(kCommandtype) != 244) {
|
|
|
|
data.byte(kCommandtype) = 244;
|
|
|
|
commandOnly(45);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.word(kMousebutton) != 1 || data.word(kMousebutton) == data.word(kOldbutton))
|
|
|
|
return; // noselslot
|
|
|
|
if (data.byte(kLoadingorsave) == 3)
|
|
|
|
data.byte(kLoadingorsave)--;
|
|
|
|
|
|
|
|
oldToNames();
|
|
|
|
int y = data.word(kMousey) - (kOpsy + 4);
|
|
|
|
if (y < 11)
|
|
|
|
data.byte(kCurrentslot) = 0;
|
|
|
|
else
|
|
|
|
data.byte(kCurrentslot) = y / 11;
|
|
|
|
|
|
|
|
delPointer();
|
|
|
|
showOpBox();
|
|
|
|
showSlots();
|
|
|
|
showNames();
|
|
|
|
if (data.byte(kLoadingorsave) == 1)
|
|
|
|
showLoadOps();
|
|
|
|
else
|
|
|
|
showSaveOps();
|
|
|
|
readMouse();
|
|
|
|
showPointer();
|
|
|
|
workToScreen();
|
|
|
|
delPointer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DreamGenContext::selectSlot2() {
|
|
|
|
if (data.word(kMousebutton))
|
|
|
|
data.byte(kLoadingorsave) = 2;
|
|
|
|
selectSlot();
|
|
|
|
}
|
2011-12-11 14:45:53 +00:00
|
|
|
|
2011-12-06 16:43:23 +00:00
|
|
|
} // End of namespace DreamGen
|