From ae6ae33bed6ce27603c9f4d952010fb63498ea66 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Fri, 28 Jun 2019 21:36:24 -0700 Subject: GLK: ALAN3: Fix setup and outputing of text data --- engines/glk/alan3/alan3.cpp | 29 +++++++++++++---------------- engines/glk/alan3/exe.cpp | 12 +++++++----- engines/glk/alan3/exe.h | 4 ++-- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/engines/glk/alan3/alan3.cpp b/engines/glk/alan3/alan3.cpp index 10850f83cf..950e9cd73a 100644 --- a/engines/glk/alan3/alan3.cpp +++ b/engines/glk/alan3/alan3.cpp @@ -46,10 +46,13 @@ Alan3::Alan3(OSystem *syst, const GlkGameDescription &gameDesc) : GlkAPI(syst, g // main codfil = nullptr; -// txtfil = nullptr; + textFile = nullptr; // logfil = nullptr; memory = nullptr; + // exe + printFlag = false; + // options verboseOption = false; ignoreErrorOption = false; @@ -93,25 +96,21 @@ bool Alan3::initialize() { // Set up the code file to point to the already opened game file codfil = &_gameFile; - /* + if (_gameFile.size() < 8) { GUIErrorMessage(_("This is too short to be a valid Alan3 file.")); return false; } - if (_gameFile.readUint32BE() != MKTAG(2, 8, 1, 0)) { - GUIErrorMessage(_("This is not a valid Alan3 file.")); + // In Alan 3, the text data comes from the adventure file itself + Common::File *txt = new Common::File(); + if (!txt->open(getFilename())) { + GUIErrorMessage("Could not open adventure file for text data"); + delete txt; return false; } + textFile = txt; - // Open up the text file - txtfil = new Common::File(); - if (!txtfil->open(Common::String::format("%s.dat", _advName.c_str()))) { - GUIErrorMessage("Could not open adventure text data file"); - delete txtfil; - return false; - } - */ // Check for a save being loaded directly from the launcher _saveSlot = ConfMan.hasKey("save_slot") ? ConfMan.getInt("save_slot") : -1; @@ -120,10 +119,8 @@ bool Alan3::initialize() { void Alan3::deinitialize() { free(memory); - /* - delete txtfil; - delete logfil; - */ + delete textFile; +// delete logfil; } Common::Error Alan3::readSaveData(Common::SeekableReadStream *rs) { diff --git a/engines/glk/alan3/exe.cpp b/engines/glk/alan3/exe.cpp index 34c9c615d9..5c6f09b2b7 100644 --- a/engines/glk/alan3/exe.cpp +++ b/engines/glk/alan3/exe.cpp @@ -50,10 +50,12 @@ namespace Glk { namespace Alan3 { -/* PUBLIC DATA */ - +// PUBLIC DATA Common::SeekableReadStream *textFile; +// PUBLIC DATA - formerly method statics +bool printFlag; // Printing already? + /* Long jump buffers */ // TODO move to longjump.c? or error.c, and abstract them into functions? //jmp_buf restartLabel; /* Restart long jump return point */ @@ -94,7 +96,6 @@ void print(Aword fpos, Aword len) { int ch = 0; int i; long savfp = 0; /* Temporary saved text file position */ - static bool printFlag = FALSE; /* Printing already? */ bool savedPrintFlag = printFlag; void *info = NULL; /* Saved decoding info */ @@ -126,9 +127,10 @@ void print(Aword fpos, Aword len) { else ch = textFile->readByte(); + if (ch == EOFChar) + break; // Or end of text? + str[i] = ch; - if (textFile->pos() >= textFile->size()) /* Or end of text? */ - break; } str[i] = '\0'; diff --git a/engines/glk/alan3/exe.h b/engines/glk/alan3/exe.h index 77fb70a578..428f112609 100644 --- a/engines/glk/alan3/exe.h +++ b/engines/glk/alan3/exe.h @@ -43,8 +43,8 @@ namespace Alan3 { /* DATA */ -/* The text and message file */ -extern Common::SeekableReadStream *textFile; +extern Common::SeekableReadStream *textFile; // The text and message file +extern bool printFlag; /* Long jump buffer for restart, errors and undo */ //extern jmp_buf restartLabel; -- cgit v1.2.3