diff options
Diffstat (limited to 'engines/glk/frotz/mem.cpp')
-rw-r--r-- | engines/glk/frotz/mem.cpp | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/engines/glk/frotz/mem.cpp b/engines/glk/frotz/mem.cpp index 227b67358d..ea3ca183c7 100644 --- a/engines/glk/frotz/mem.cpp +++ b/engines/glk/frotz/mem.cpp @@ -36,8 +36,44 @@ Mem::Mem() : story_fp(nullptr), story_size(0), first_undo(nullptr), last_undo(nu void Mem::initialize() { initializeStoryFile(); loadGameHeader(); + loadMemory(); initializeUndo(); + // Read header extension table + hx_table_size = get_header_extension(HX_TABLE_SIZE); + hx_unicode_table = get_header_extension(HX_UNICODE_TABLE); + hx_flags = get_header_extension(HX_FLAGS); +} + +void Mem::initializeStoryFile() { + if (story_fp->size() < 64) + error("This file is too small to be a Z-code file."); +} + +void Mem::loadGameHeader() { + // Load header + zmp = (byte *)malloc(64); + story_fp->seek(0); + story_fp->read(zmp, 64); + + Common::MemoryReadStream h(zmp, 64); + loadHeader(h); + + // Calculate story file size in bytes + if (h_file_size != 0) { + story_size = (long)2 * h_file_size; + + if (h_version >= V4) + story_size *= 2; + if (h_version >= V6) + story_size *= 2; + } else { + // Some old games lack the file size entry + story_size = story_fp->size(); + } +} + +void Mem::loadMemory() { // Allocate memory for story data if ((zmp = (zbyte *)realloc(zmp, story_size)) == nullptr) error("Out of memory"); @@ -51,16 +87,6 @@ void Mem::initialize() { if (story_fp->read(zmp + size, n) != n) error("Story file read error"); } - - // Read header extension table - hx_table_size = get_header_extension(HX_TABLE_SIZE); - hx_unicode_table = get_header_extension(HX_UNICODE_TABLE); - hx_flags = get_header_extension(HX_FLAGS); -} - -void Mem::initializeStoryFile() { - if (story_fp->size() < 64) - error("This file is too small to be a Z-code file."); } void Mem::initializeUndo() { @@ -82,31 +108,8 @@ void Mem::initializeUndo() { _undo_slots = 0; } - if (reserve_mem != 0) - delete reserved; -} - -void Mem::loadGameHeader() { - // Load header - zmp = (byte *)malloc(64); - story_fp->seek(0); - story_fp->read(zmp, 64); - - Common::MemoryReadStream h(zmp, 64); - loadHeader(h); - - // Calculate story file size in bytes - if (h_file_size != 0) { - story_size = (long)2 * h_file_size; - - if (h_version >= V4) - story_size *= 2; - if (h_version >= V6) - story_size *= 2; - } else { - // Some old games lack the file size entry - story_size = story_fp->size(); - } + if (reserve_mem) + delete[] reserved; } zword Mem::get_header_extension(int entry) { |