aboutsummaryrefslogtreecommitdiff
path: root/engines/made/database.cpp
diff options
context:
space:
mode:
authorBenjamin Haisch2008-04-30 20:36:19 +0000
committerBenjamin Haisch2008-04-30 20:36:19 +0000
commit7509d66caf516d87f938f66a20f4ce81367a8305 (patch)
tree3ce463b2c13d8d0c1ad5259279f49e3e4f10a300 /engines/made/database.cpp
parente866aefdfdf7386cd3f5c94a058dd329c44b8fde (diff)
downloadscummvm-rg350-7509d66caf516d87f938f66a20f4ce81367a8305.tar.gz
scummvm-rg350-7509d66caf516d87f938f66a20f4ce81367a8305.tar.bz2
scummvm-rg350-7509d66caf516d87f938f66a20f4ce81367a8305.zip
Implemented savegame loading/saving and sprite clipping
Fixed bug in Screen::printTextEx Implemented opcodes: - o1_DRAWTEXT - o1_DRAWMENU - o1_MENUCOUNT - o1_SAVEGAME - o1_LOADGAME - o1_GAMENAME svn-id: r31794
Diffstat (limited to 'engines/made/database.cpp')
-rw-r--r--engines/made/database.cpp84
1 files changed, 79 insertions, 5 deletions
diff --git a/engines/made/database.cpp b/engines/made/database.cpp
index 7c6afda197..d5c45fa1b9 100644
--- a/engines/made/database.cpp
+++ b/engines/made/database.cpp
@@ -23,8 +23,10 @@
*
*/
+#include "common/system.h"
#include "common/endian.h"
#include "common/util.h"
+#include "common/savefile.h"
#include "made/database.h"
@@ -222,8 +224,7 @@ void GameDatabase::load(Common::SeekableReadStream &sourceS) {
uint32 objectsSize = sourceS.readUint32LE();
_mainCodeObjectIndex = sourceS.readUint16LE();
- debug(2, "objectIndexOffs = %08X; objectCount = %d; gameStateOffs = %08X; gameStateSize = %d; objectsOffs = %08X; objectsSize = %d\n",
- objectIndexOffs, objectCount, gameStateOffs, _gameStateSize, objectsOffs, objectsSize);
+ //debug(2, "objectIndexOffs = %08X; objectCount = %d; gameStateOffs = %08X; gameStateSize = %d; objectsOffs = %08X; objectsSize = %d\n", objectIndexOffs, objectCount, gameStateOffs, _gameStateSize, objectsOffs, objectsSize);
_gameState = new byte[_gameStateSize];
sourceS.seek(gameStateOffs);
@@ -241,14 +242,14 @@ void GameDatabase::load(Common::SeekableReadStream &sourceS) {
// Constant objects are loaded from disk, while variable objects exist
// in the _gameState buffer.
- debug(2, "obj(%04X) ofs = %08X\n", i, objectOffsets[i]);
+ //debug(2, "obj(%04X) ofs = %08X\n", i, objectOffsets[i]);
if (objectOffsets[i] & 1) {
- debug(2, "-> const %08X\n", objectsOffs + objectOffsets[i] - 1);
+ //debug(2, "-> const %08X\n", objectsOffs + objectOffsets[i] - 1);
sourceS.seek(objectsOffs + objectOffsets[i] - 1);
obj->load(sourceS);
} else {
- debug(2, "-> var\n");
+ //debug(2, "-> var\n");
obj->load(_gameState + objectOffsets[i]);
}
_objects.push_back(obj);
@@ -256,6 +257,79 @@ void GameDatabase::load(Common::SeekableReadStream &sourceS) {
}
+bool GameDatabase::getSavegameDescription(const char *filename, Common::String &description) {
+
+ Common::InSaveFile *in;
+
+ if (!(in = g_system->getSavefileManager()->openForLoading(filename))) {
+ return false;
+ }
+
+ char desc[64];
+
+ in->skip(4); // TODO: Verify marker 'SGAM'
+ in->skip(4); // TODO: Verify size
+ in->skip(2); // TODO: Verify version
+ in->read(desc, 64);
+ description = desc;
+
+ printf("description = %s\n", description.c_str()); fflush(stdout);
+
+ delete in;
+
+ return true;
+
+}
+
+int16 GameDatabase::savegame(const char *filename, const char *description, int16 version) {
+
+ Common::OutSaveFile *out;
+
+ if (!(out = g_system->getSavefileManager()->openForSaving(filename))) {
+ warning("Can't create file '%s', game not saved", filename);
+ return 6;
+ }
+
+ uint32 size = 4 + 4 + 2 + _gameStateSize;
+ char desc[64];
+
+ strncpy(desc, description, 64);
+
+ out->writeUint32BE(MKID_BE('SGAM'));
+ out->writeUint32LE(size);
+ out->writeUint16LE(version);
+ out->write(desc, 64);
+ out->write(_gameState, _gameStateSize);
+
+ delete out;
+
+ return 0;
+
+}
+
+int16 GameDatabase::loadgame(const char *filename, int16 version) {
+
+ Common::InSaveFile *in;
+
+ if (!(in = g_system->getSavefileManager()->openForLoading(filename))) {
+ warning("Can't open file '%s', game not loaded", filename);
+ return 1;
+ }
+
+ //uint32 expectedSize = 4 + 4 + 2 + _gameStateSize;
+
+ in->skip(4); // TODO: Verify marker 'SGAM'
+ in->skip(4); // TODO: Verify size
+ in->skip(2); // TODO: Verify version
+ in->skip(64); // skip savegame description
+ in->read(_gameState, _gameStateSize);
+
+ delete in;
+
+ return 0;
+
+}
+
int16 GameDatabase::getVar(int16 index) {
return (int16)READ_LE_UINT16(_gameState + index * 2);
}