From a82ac8973d10dcdac885f686aa56ff4ecbc54643 Mon Sep 17 00:00:00 2001 From: Walter van Niftrik Date: Sun, 20 Mar 2016 11:48:07 +0100 Subject: ADL: Implement hires2 save/restore opcodes Note: underlying save/restore/restart code still incomplete --- engines/adl/adl.cpp | 2 +- engines/adl/adl.h | 9 ++++++--- engines/adl/adl_v2.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++-- engines/adl/adl_v2.h | 6 ++++++ engines/adl/hires2.cpp | 4 ++++ engines/adl/hires2.h | 16 ++++++++++------ 6 files changed, 71 insertions(+), 12 deletions(-) (limited to 'engines') diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp index a09ec69cd5..d95cfd519b 100644 --- a/engines/adl/adl.cpp +++ b/engines/adl/adl.cpp @@ -53,9 +53,9 @@ AdlEngine::AdlEngine(OSystem *syst, const AdlGameDescription *gd) : Engine(syst), _display(nullptr), _graphics(nullptr), - _gameDescription(gd), _isRestarting(false), _isRestoring(false), + _gameDescription(gd), _saveVerb(0), _saveNoun(0), _restoreVerb(0), diff --git a/engines/adl/adl.h b/engines/adl/adl.h index 5aba30eeab..2e413ac64d 100644 --- a/engines/adl/adl.h +++ b/engines/adl/adl.h @@ -167,6 +167,10 @@ public: protected: AdlEngine(OSystem *syst, const AdlGameDescription *gd); + // Engine + Common::Error loadGameState(int slot); + Common::Error saveGameState(int slot, const Common::String &desc); + Common::String readString(Common::ReadStream &stream, byte until = 0) const; Common::String readStringAt(Common::SeekableReadStream &stream, uint offset, byte until = 0) const; void openFile(Common::File &file, const Common::String &name) const; @@ -279,6 +283,8 @@ protected: // Game state State _state; + bool _isRestarting, _isRestoring; + private: virtual void runIntro() const { } virtual void init() = 0; @@ -290,9 +296,7 @@ private: // Engine Common::Error run(); bool hasFeature(EngineFeature f) const; - Common::Error loadGameState(int slot); bool canLoadGameStateCurrently(); - Common::Error saveGameState(int slot, const Common::String &desc); bool canSaveGameStateCurrently(); // Text output @@ -305,7 +309,6 @@ private: void getInput(uint &verb, uint &noun); const AdlGameDescription *_gameDescription; - bool _isRestarting, _isRestoring; byte _saveVerb, _saveNoun, _restoreVerb, _restoreNoun; bool _canSaveNow, _canRestoreNow; }; diff --git a/engines/adl/adl_v2.cpp b/engines/adl/adl_v2.cpp index 72d60ac0ab..029c37a05a 100644 --- a/engines/adl/adl_v2.cpp +++ b/engines/adl/adl_v2.cpp @@ -21,6 +21,7 @@ */ #include "common/random.h" +#include "common/error.h" #include "adl/adl_v2.h" #include "adl/display.h" @@ -81,9 +82,9 @@ void AdlEngine_v2::setupOpcodeTables() { Opcode(o2_moveAllItems); Opcode(o1_quit); OpcodeUnImpl(); - Opcode(o1_save); // TODO + Opcode(o2_save); // 0x10 - Opcode(o1_restore); // TODO + Opcode(o2_restore); Opcode(o1_restart); Opcode(o2_placeItem); Opcode(o1_setItemPic); @@ -259,6 +260,33 @@ int AdlEngine_v2::o2_moveAllItems(ScriptEnv &e) { return 2; } +int AdlEngine_v2::o2_save(ScriptEnv &e) { + int slot = askForSlot(_strings_v2.saveInsert); + + if (slot < 0) + return -1; + + saveGameState(slot, ""); + + _display->printString(_strings_v2.saveReplace); + inputString(); + return 0; +} + +int AdlEngine_v2::o2_restore(ScriptEnv &e) { + int slot = askForSlot(_strings_v2.restoreInsert); + + if (slot < 0) + return -1; + + loadGameState(slot); + _isRestoring = false; + + _display->printString(_strings_v2.restoreReplace); + inputString(); + return 0; +} + int AdlEngine_v2::o2_placeItem(ScriptEnv &e) { Item &item = getItem(e.arg(1)); @@ -294,4 +322,18 @@ int AdlEngine_v2::o2_initDisk(ScriptEnv &e) { return 0; } +int AdlEngine_v2::askForSlot(const Common::String &question) { + while (1) { + _display->printString(question); + + Common::String input = inputString(); + + if (shouldQuit()) + return -1; + + if (input.size() > 0 && input[0] >= APPLECHAR('A') && input[0] <= APPLECHAR('O')) + return input[0] - APPLECHAR('A'); + } +} + } // End of namespace Adl diff --git a/engines/adl/adl_v2.h b/engines/adl/adl_v2.h index 6da8caaff5..cea4a9310e 100644 --- a/engines/adl/adl_v2.h +++ b/engines/adl/adl_v2.h @@ -60,6 +60,8 @@ protected: int o2_moveItem(ScriptEnv &e); int o2_moveAllItems(ScriptEnv &e); + int o2_save(ScriptEnv &e); + int o2_restore(ScriptEnv &e); int o2_placeItem(ScriptEnv &e); int o2_tellTime(ScriptEnv &e); int o2_setRoomFromVar(ScriptEnv &e); @@ -67,11 +69,15 @@ protected: struct { Common::String time; + Common::String saveInsert, saveReplace; + Common::String restoreInsert, restoreReplace; } _strings_v2; uint _linesPrinted; private: + int askForSlot(const Common::String &question); + Common::RandomSource *_random; }; diff --git a/engines/adl/hires2.cpp b/engines/adl/hires2.cpp index 49e70a1631..71aeeb542b 100644 --- a/engines/adl/hires2.cpp +++ b/engines/adl/hires2.cpp @@ -85,6 +85,10 @@ void HiRes2Engine::init() { _strings.playAgain = readStringAt(f, IDI_HR2_OFS_STR_PLAY_AGAIN); _strings.pressReturn = readStringAt(f, IDI_HR2_OFS_STR_PRESS_RETURN); _strings_v2.time = readStringAt(f, IDI_HR2_OFS_STR_TIME, 0xff); + _strings_v2.saveInsert = readStringAt(f, IDI_HR2_OFS_STR_SAVE_INSERT); + _strings_v2.saveReplace = readStringAt(f, IDI_HR2_OFS_STR_SAVE_REPLACE); + _strings_v2.restoreInsert = readStringAt(f, IDI_HR2_OFS_STR_RESTORE_INSERT); + _strings_v2.restoreReplace = readStringAt(f, IDI_HR2_OFS_STR_RESTORE_REPLACE); _messageIds.cantGoThere = IDI_HR2_MSG_CANT_GO_THERE; _messageIds.dontUnderstand = IDI_HR2_MSG_DONT_UNDERSTAND; diff --git a/engines/adl/hires2.h b/engines/adl/hires2.h index 121a1f6739..15781097ef 100644 --- a/engines/adl/hires2.h +++ b/engines/adl/hires2.h @@ -66,12 +66,16 @@ namespace Adl { #define IDI_HR2_MSG_ITEM_NOT_HERE 4 #define IDI_HR2_MSG_THANKS_FOR_PLAYING 239 -#define IDI_HR2_OFS_STR_ENTER_COMMAND TSO(0x1a, 0x1, 0xbc) -#define IDI_HR2_OFS_STR_VERB_ERROR TSO(0x1a, 0x1, 0x4f) -#define IDI_HR2_OFS_STR_NOUN_ERROR TSO(0x1a, 0x1, 0x8e) -#define IDI_HR2_OFS_STR_PLAY_AGAIN TSO(0x1a, 0x8, 0x25) -#define IDI_HR2_OFS_STR_PRESS_RETURN TSO(0x1a, 0x8, 0x5f) -#define IDI_HR2_OFS_STR_TIME TSO(0x19, 0x7, 0xd7) +#define IDI_HR2_OFS_STR_ENTER_COMMAND TSO(0x1a, 0x1, 0xbc) +#define IDI_HR2_OFS_STR_VERB_ERROR TSO(0x1a, 0x1, 0x4f) +#define IDI_HR2_OFS_STR_NOUN_ERROR TSO(0x1a, 0x1, 0x8e) +#define IDI_HR2_OFS_STR_PLAY_AGAIN TSO(0x1a, 0x8, 0x25) +#define IDI_HR2_OFS_STR_PRESS_RETURN TSO(0x1a, 0x8, 0x5f) +#define IDI_HR2_OFS_STR_TIME TSO(0x19, 0x7, 0xd7) +#define IDI_HR2_OFS_STR_SAVE_INSERT TSO(0x1a, 0x6, 0x5f) +#define IDI_HR2_OFS_STR_SAVE_REPLACE TSO(0x1a, 0x6, 0xe5) +#define IDI_HR2_OFS_STR_RESTORE_INSERT TSO(0x1a, 0x7, 0x32) +#define IDI_HR2_OFS_STR_RESTORE_REPLACE TSO(0x1a, 0x7, 0xc2) struct Picture2 { byte nr; -- cgit v1.2.3