diff options
-rw-r--r-- | engines/gargoyle/frotz/frotz.cpp | 6 | ||||
-rw-r--r-- | engines/gargoyle/frotz/frotz.h | 7 | ||||
-rw-r--r-- | engines/gargoyle/frotz/mem.cpp | 46 | ||||
-rw-r--r-- | engines/gargoyle/frotz/mem.h | 18 |
4 files changed, 76 insertions, 1 deletions
diff --git a/engines/gargoyle/frotz/frotz.cpp b/engines/gargoyle/frotz/frotz.cpp index 77c33034ec..d5cdaf33ad 100644 --- a/engines/gargoyle/frotz/frotz.cpp +++ b/engines/gargoyle/frotz/frotz.cpp @@ -40,9 +40,15 @@ Frotz::Frotz(OSystem *syst, const GargoyleGameDescription *gameDesc) : Glk(syst, } void Frotz::runGame(Common::SeekableReadStream *gameFile) { + initialize(); + // TODO } +void Frotz::initialize() { + _mem.initialize(); +} + Common::Error Frotz::loadGameState(int slot) { return Common::kNoError; } diff --git a/engines/gargoyle/frotz/frotz.h b/engines/gargoyle/frotz/frotz.h index e1f3d9fe30..e1fb36c7b4 100644 --- a/engines/gargoyle/frotz/frotz.h +++ b/engines/gargoyle/frotz/frotz.h @@ -36,6 +36,11 @@ namespace Frotz { * Frotz interpreter for Z-code games */ class Frotz : public Glk { +private: + /** + * Perform any initialization + */ + void initialize(); public: UserOptions _options; Header _header; @@ -43,7 +48,7 @@ public: Mem _mem; // Story file name, id number and size - Common::String _storyName; + Common::SeekableReadStream *_gameFile; Story _storyId; size_t _storySize; diff --git a/engines/gargoyle/frotz/mem.cpp b/engines/gargoyle/frotz/mem.cpp index 4bd2324312..1b43e93d20 100644 --- a/engines/gargoyle/frotz/mem.cpp +++ b/engines/gargoyle/frotz/mem.cpp @@ -21,6 +21,7 @@ */ #include "gargoyle/frotz/mem.h" +#include "gargoyle/frotz/frotz.h" #include "common/textconsole.h" namespace Gargoyle { @@ -54,6 +55,51 @@ const Mem::StoryEntry Mem::RECORDS[25] = { { UNKNOWN, 0, "------" } }; +Mem::Mem() : story_fp(nullptr), blorb_ofs(0), blorb_len(0) { +} + +void Mem::initialize() { +/* + long size; + zword addr; + unsigned n; + int i, j; + */ + initializeStoryFile(); + + // TODO: More stuff +} + +void Mem::initializeStoryFile() { + Common::SeekableReadStream *f = g_vm->_gameFile; + giblorb_map_t *map; + giblorb_result_t res; + uint32 magic; + + story_fp = f; + magic = f->readUint32BE(); + + if (magic == MKTAG('F', 'O', 'R', 'M')) { + if (g_vm->giblorb_set_resource_map(f)) + error("This Blorb file seems to be invalid."); + + map = g_vm->giblorb_get_resource_map(); + + if (g_vm->giblorb_load_resource(map, giblorb_method_FilePos, &res, giblorb_ID_Exec, 0)) + error("This Blorb file does not contain an executable chunk."); + if (res.chunktype != MKTAG('Z', 'C', 'O', 'D')) + error("This Blorb file contains an executable chunk, but it is not a Z-code file."); + + blorb_ofs = res.data.startpos; + blorb_len = res.length; + } else { + blorb_ofs = 0; + blorb_len = f->size(); + } + + if (blorb_len < 64) + error("This file is too small to be a Z-code file."); +} } // End of namespace Scott } // End of namespace Gargoyle diff --git a/engines/gargoyle/frotz/mem.h b/engines/gargoyle/frotz/mem.h index 4abe464bde..8882a582c4 100644 --- a/engines/gargoyle/frotz/mem.h +++ b/engines/gargoyle/frotz/mem.h @@ -35,6 +35,24 @@ class Mem { char _serial[7]; }; static const StoryEntry RECORDS[25]; +private: + Common::SeekableReadStream *story_fp; + uint blorb_ofs, blorb_len; +private: + /** + * Handles setting the story file, parsing it if it's a Blorb file + */ + void initializeStoryFile(); +public: + /** + * Constructor + */ + Mem(); + + /** + * Initialize + */ + void initialize(); }; } // End of namespace Frotz |