From be8501069952b2633cd62939d35dba6fc83bed13 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 28 Oct 2019 20:40:52 -0700 Subject: GLK: ARCHETYPE: Various startup fixes --- engines/glk/archetype/archetype.cpp | 8 +--- engines/glk/archetype/archetype.h | 5 --- engines/glk/archetype/expression.cpp | 8 ++-- engines/glk/archetype/expression.h | 6 +-- engines/glk/archetype/interpreter.cpp | 16 +++++--- engines/glk/archetype/keywords.h | 1 + engines/glk/archetype/linked_list.cpp | 6 ++- engines/glk/archetype/misc.cpp | 3 +- engines/glk/archetype/misc.h | 1 - engines/glk/archetype/saveload.cpp | 72 +++++++++++++++++------------------ engines/glk/archetype/saveload.h | 4 +- 11 files changed, 65 insertions(+), 65 deletions(-) (limited to 'engines') diff --git a/engines/glk/archetype/archetype.cpp b/engines/glk/archetype/archetype.cpp index 4b19c57854..37b40ab335 100644 --- a/engines/glk/archetype/archetype.cpp +++ b/engines/glk/archetype/archetype.cpp @@ -93,7 +93,7 @@ Common::Error Archetype::writeGameData(Common::WriteStream *ws) { void Archetype::interpret() { Translating = false; - bool success = loadGame(); + bool success = load_game(&_gameFile); _gameFile.close(); if (!success) @@ -109,10 +109,6 @@ void Archetype::interpret() { cleanup(result); } -bool Archetype::loadGame() { - return false; -} - void Archetype::write(const String &fmt, ...) { // TODO } @@ -773,7 +769,7 @@ void Archetype::exec_stmt(StatementPtr the_stmt, ResultType &result, ContextType else if (the_stmt->_kind == ST_STOP) { g_vm->writeln(); g_vm->writeln(); - error("%s", VERSION); + error("%f", VERSION_NUM); } break; diff --git a/engines/glk/archetype/archetype.h b/engines/glk/archetype/archetype.h index dec950ca74..f671df3193 100644 --- a/engines/glk/archetype/archetype.h +++ b/engines/glk/archetype/archetype.h @@ -72,11 +72,6 @@ private: */ void interpret(); - /** - * Loads the text adventure game - */ - bool loadGame(); - /** * Given an object number, attribute number, anddesired_type, returns the value of the lookup * in the given result.If the desired_type is LVALUE, then it creates a new attribute node diff --git a/engines/glk/archetype/expression.cpp b/engines/glk/archetype/expression.cpp index 6f71dd502d..f468b4fec3 100644 --- a/engines/glk/archetype/expression.cpp +++ b/engines/glk/archetype/expression.cpp @@ -25,11 +25,12 @@ namespace Glk { namespace Archetype { -bool Right_Assoc[NUM_OPERS + 1]; -bool Binary[NUM_OPERS + 1]; -int8 Precedence[NUM_OPERS + 1]; +bool Right_Assoc[NUM_OPERS + 2]; +bool Binary[NUM_OPERS + 2]; +int8 Precedence[NUM_OPERS + 2]; void expression_init() { + Binary[OP_NOP] = false; Binary[OP_LPAREN] = false; Binary[OP_DOT] = true; Binary[OP_CHS] = false; @@ -124,6 +125,5 @@ void expression_init() { Precedence[OP_ASSIGN] = 1; } - } // End of namespace Archetype } // End of namespace Glk diff --git a/engines/glk/archetype/expression.h b/engines/glk/archetype/expression.h index 3fc600787a..4e927ec400 100644 --- a/engines/glk/archetype/expression.h +++ b/engines/glk/archetype/expression.h @@ -78,9 +78,9 @@ typedef ExprNode *ExprPtr; typedef ExprPtr ExprTree; // Global variables -extern bool Right_Assoc[NUM_OPERS + 1]; -extern bool Binary[NUM_OPERS + 1]; -extern int8 Precedence[NUM_OPERS + 1]; +extern bool Right_Assoc[NUM_OPERS + 2]; +extern bool Binary[NUM_OPERS + 2]; +extern int8 Precedence[NUM_OPERS + 2]; extern void expression_init(); diff --git a/engines/glk/archetype/interpreter.cpp b/engines/glk/archetype/interpreter.cpp index 108b948605..de4273fa82 100644 --- a/engines/glk/archetype/interpreter.cpp +++ b/engines/glk/archetype/interpreter.cpp @@ -423,14 +423,20 @@ bool load_game(Common::ReadStream *f_in) { } } + // Get the textual version of the game's version. This is easier than dealing with + // the Pascal Real type the game files use for their version number + String versionStr; + while (!f_in->eos() && (ch = (char)f_in->readByte()) != '\n') + versionStr += ch; + fileVersion = atof(versionStr.c_str()); + // Bleed off string version information while (!f_in->eos() && ch != 26) ch = f_in->readByte(); - // Check encoded version - // TODO: Figure out real format - fileVersion = 0; + // Skip over 6 byte Real encoded version number (void)f_in->readUint32LE(); + (void)f_in->readUint16LE(); if (fileVersion > VERSION_NUM) { g_vm->writeln("This version of PERFORM is %.1f; file version is %.1f", @@ -440,7 +446,7 @@ bool load_game(Common::ReadStream *f_in) { } // Get encryption information - Encryption = (EncryptionType)f_in->readUint16LE(); + Encryption = (EncryptionType)f_in->readByte(); // Read the timestamp. It is used to verify saved game states, and also to prime the encryption GTimeStamp = f_in->readUint32LE(); @@ -455,7 +461,7 @@ bool load_game(Common::ReadStream *f_in) { cryptinit(Encryption, GTimeStamp); // Where's the main object? - MainObject = f_in->readSint32LE(); + MainObject = f_in->readUint16LE(); load_obj_list(f_in, g_vm->Object_List); load_obj_list(f_in, g_vm->Type_List); diff --git a/engines/glk/archetype/keywords.h b/engines/glk/archetype/keywords.h index f36c66e20b..118a119dec 100644 --- a/engines/glk/archetype/keywords.h +++ b/engines/glk/archetype/keywords.h @@ -77,6 +77,7 @@ enum ReservedWordId { }; enum OperatorId { + OP_NOP = 0, OP_CONCAT = 1, OP_C_CONCAT = 2, OP_MULTIPLY = 3, diff --git a/engines/glk/archetype/linked_list.cpp b/engines/glk/archetype/linked_list.cpp index 90cca17981..bc4719ca48 100644 --- a/engines/glk/archetype/linked_list.cpp +++ b/engines/glk/archetype/linked_list.cpp @@ -27,7 +27,11 @@ namespace Glk { namespace Archetype { void new_list(ListType &the_list) { - the_list = new NodeType(); + the_list = (ListType)malloc(sizeof(NodeType)); + add_bytes(sizeof(NodeType)); + the_list->key = 0; + the_list->data = nullptr; + the_list->next = nullptr; } void dispose_list(ListType &the_list) { diff --git a/engines/glk/archetype/misc.cpp b/engines/glk/archetype/misc.cpp index 34c067c2b0..e5a858ba00 100644 --- a/engines/glk/archetype/misc.cpp +++ b/engines/glk/archetype/misc.cpp @@ -28,8 +28,7 @@ namespace Glk { namespace Archetype { const char *const VERSION_STUB = "Archetype version "; -const char *const VERSION = "Archetype version 1.02"; -const double VERSION_NUM = 1.01; +const double VERSION_NUM = 1.02; size_t Bytes; int Debug; diff --git a/engines/glk/archetype/misc.h b/engines/glk/archetype/misc.h index 0799077a85..8d93ce7c9d 100644 --- a/engines/glk/archetype/misc.h +++ b/engines/glk/archetype/misc.h @@ -110,7 +110,6 @@ public: enum ClassifyType { TYPE_ID, OBJECT_ID, ATTRIBUTE_ID, ENUMERATE_ID, UNDEFINED_ID }; -extern const char *const VERSION; extern const char *const VERSION_STUB; extern const double VERSION_NUM; extern size_t Bytes; // Bytes consumed by allocated memory diff --git a/engines/glk/archetype/saveload.cpp b/engines/glk/archetype/saveload.cpp index 2a965e3039..5c018c854d 100644 --- a/engines/glk/archetype/saveload.cpp +++ b/engines/glk/archetype/saveload.cpp @@ -42,7 +42,7 @@ void saveload_init() { // ===================== Forward Declarations ======================= static void walk_item_list(MissionType mission, Common::Stream *bfile, - ListType elements, ContentType content); + ListType &elements, ContentType content); static void walk_expr(MissionType mission, Common::Stream *bfile, ExprTree &the_expr); static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr &the_stmt); @@ -50,11 +50,11 @@ static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr & // Wrappers -void load_item_list(Common::ReadStream *f_in, ListType elements, ContentType content) { +void load_item_list(Common::ReadStream *f_in, ListType &elements, ContentType content) { walk_item_list(LOAD, f_in, elements, content); } -void dump_item_list(Common::WriteStream *f_out, ListType elements, ContentType content) { +void dump_item_list(Common::WriteStream *f_out, ListType &elements, ContentType content) { walk_item_list(DUMP, f_out, elements, content); } @@ -70,7 +70,7 @@ void dispose_item_list(ListType &elements, ContentType content) { * @param elements list of items * @param content contents of each of the items */ -void walk_item_list(MissionType mission, Common::Stream *bfile, ListType elements, ContentType content) { +void walk_item_list(MissionType mission, Common::Stream *bfile, ListType &elements, ContentType content) { StatementKind sentinel; StatementPtr this_stmt; ExprTree this_expr; @@ -85,7 +85,7 @@ void walk_item_list(MissionType mission, Common::Stream *bfile, ListType element switch (mission) { case LOAD: assert(readStream); - sentinel = (StatementKind)readStream->readUint32LE(); + sentinel = (StatementKind)readStream->readUint16LE(); new_list(elements); yet_more = sentinel == CONT_SEQ; break; @@ -107,13 +107,13 @@ void walk_item_list(MissionType mission, Common::Stream *bfile, ListType element assert(readStream); np = (NodePtr)malloc(sizeof(NodeType)); add_bytes(sizeof(NodeType)); - np->key = readStream->readSint32LE(); + np->key = readStream->readSint16LE(); break; case DUMP: assert(writeStream); - writeStream->writeUint32LE(vContSeq); - writeStream->writeSint32LE(np->key); + writeStream->writeUint16LE(vContSeq); + writeStream->writeSint16LE(np->key); break; default: @@ -189,7 +189,7 @@ void walk_item_list(MissionType mission, Common::Stream *bfile, ListType element case LOAD: assert(readStream); append_to_list(elements, np); - sentinel = (StatementKind)readStream->readUint32LE(); + sentinel = (StatementKind)readStream->readUint16LE(); yet_more = sentinel == CONT_SEQ; break; @@ -206,7 +206,7 @@ void walk_item_list(MissionType mission, Common::Stream *bfile, ListType element // Postlude switch (mission) { case DUMP: - writeStream->writeUint32LE(vEndSeq); + writeStream->writeUint16LE(vEndSeq); break; case FREE: dispose_list(elements); @@ -260,7 +260,7 @@ static void walk_expr(MissionType mission, Common::Stream *bfile, ExprTree &the_ assert(readStream); the_expr = (ExprTree)malloc(sizeof(ExprNode)); add_bytes(sizeof(ExprNode)); - the_expr->_kind = (AclType)readStream->readUint32LE(); + the_expr->_kind = (AclType)readStream->readUint16LE(); break; case DUMP: @@ -271,7 +271,7 @@ static void walk_expr(MissionType mission, Common::Stream *bfile, ExprTree &the_ while (the_expr->_kind == OPER && the_expr->_oper.op_name == OP_LPAREN) the_expr = the_expr->_oper.right; - writeStream->writeUint32LE(the_expr->_kind); + writeStream->writeUint16LE(the_expr->_kind); break; case FREE: @@ -306,10 +306,10 @@ static void walk_expr(MissionType mission, Common::Stream *bfile, ExprTree &the_ case NUMERIC: switch (mission) { case LOAD: - the_expr->_numeric.acl_int = readStream->readSint32LE(); + the_expr->_numeric.acl_int = readStream->readSint16LE(); break; case DUMP: - writeStream->writeSint32LE(the_expr->_numeric.acl_int); + writeStream->writeSint16LE(the_expr->_numeric.acl_int); break; default: break; @@ -321,10 +321,10 @@ static void walk_expr(MissionType mission, Common::Stream *bfile, ExprTree &the_ case QUOTE_LIT: switch (mission) { case LOAD: - the_expr->_msgTextQuote.index = readStream->readSint32LE(); + the_expr->_msgTextQuote.index = readStream->readSint16LE(); break; case DUMP: - writeStream->writeSint32LE(the_expr->_msgTextQuote.index); + writeStream->writeSint16LE(the_expr->_msgTextQuote.index); break; default: break; @@ -334,8 +334,8 @@ static void walk_expr(MissionType mission, Common::Stream *bfile, ExprTree &the_ case IDENT: switch (mission) { case LOAD: - the_expr->_ident.ident_kind = (ClassifyType)readStream->readUint32LE(); - the_expr->_ident.ident_int = readStream->readSint32LE(); + the_expr->_ident.ident_kind = (ClassifyType)readStream->readUint16LE(); + the_expr->_ident.ident_int = readStream->readSint16LE(); break; case DUMP: if (Translating && the_expr->_ident.ident_kind == DefaultClassification) { @@ -348,8 +348,8 @@ static void walk_expr(MissionType mission, Common::Stream *bfile, ExprTree &the_ the_expr->_ident.ident_int = temp; } - writeStream->writeUint32LE(the_expr->_ident.ident_kind); - writeStream->writeSint32LE(the_expr->_ident.ident_int); + writeStream->writeUint16LE(the_expr->_ident.ident_kind); + writeStream->writeSint16LE(the_expr->_ident.ident_int); break; default: break; @@ -439,7 +439,7 @@ static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr & if (readStream->eos()) return; - sentinel = (StatementKind)readStream->readUint32LE(); + sentinel = (StatementKind)readStream->readUint16LE(); if (sentinel == END_SEQ) return; @@ -450,10 +450,10 @@ static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr & case DUMP: if (the_stmt == nullptr) { - writeStream->writeUint32LE(vEndSeq); + writeStream->writeUint16LE(vEndSeq); return; } else { - writeStream->writeUint32LE(this_stmt->_kind); + writeStream->writeUint16LE(this_stmt->_kind); } break; @@ -491,10 +491,10 @@ static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr & case ST_CREATE: switch (mission) { case LOAD: - this_stmt->_create.archetype = readStream->readSint32LE(); + this_stmt->_create.archetype = readStream->readSint16LE(); break; case DUMP: - writeStream->writeSint32LE(this_stmt->_create.archetype); + writeStream->writeSint16LE(this_stmt->_create.archetype); break; default: break; @@ -519,7 +519,7 @@ static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr & switch (mission) { case LOAD: new_list(this_stmt->_write.print_list); - sentinel = (StatementKind)readStream->readUint32LE(); + sentinel = (StatementKind)readStream->readUint16LE(); while (sentinel != END_SEQ) { walk_expr(mission, bfile, this_expr); @@ -529,7 +529,7 @@ static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr & np->data = this_expr; append_to_list(this_stmt->_write.print_list, np); - sentinel = (StatementKind)readStream->readUint32LE(); + sentinel = (StatementKind)readStream->readUint16LE(); } break; @@ -538,7 +538,7 @@ static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr & np = nullptr; while (iterate_list(this_stmt->_write.print_list, np)) { if (mission == DUMP) - writeStream->writeUint32LE(vContSeq); + writeStream->writeUint16LE(vContSeq); this_expr = (ExprTree)np->data; walk_expr(mission, bfile, this_expr); @@ -547,7 +547,7 @@ static void walk_stmt(MissionType mission, Common::Stream *bfile, StatementPtr & } if (mission == DUMP) - writeStream->writeUint32LE(vEndSeq); + writeStream->writeUint16LE(vEndSeq); else dispose_list(this_stmt->_write.print_list); break; @@ -581,11 +581,11 @@ void load_object(Common::ReadStream *f_in, ObjectPtr &the_object) { the_object = (ObjectPtr)malloc(sizeof(ObjectType)); add_bytes(sizeof(ObjectType)); - the_object->inherited_from = f_in->readSint32LE(); + the_object->inherited_from = f_in->readSint16LE(); load_item_list(f_in, the_object->attributes, EXPR_LIST); load_item_list(f_in, the_object->methods, STMT_LIST); - sentinel = (StatementKind)f_in->readUint32LE(); + sentinel = (StatementKind)f_in->readUint16LE(); if (sentinel == CONT_SEQ) load_stmt(f_in, the_object->other); else @@ -593,14 +593,14 @@ void load_object(Common::ReadStream *f_in, ObjectPtr &the_object) { } void dump_object(Common::WriteStream *f_out, const ObjectPtr the_object) { - f_out->writeUint32LE(the_object->inherited_from); + f_out->writeUint16LE(the_object->inherited_from); dump_item_list(f_out, the_object->attributes, EXPR_LIST); dump_item_list(f_out, the_object->methods, STMT_LIST); if (the_object->other == nullptr) { - f_out->writeUint32LE(vEndSeq); + f_out->writeUint16LE(vEndSeq); } else { - f_out->writeUint32LE(vContSeq); + f_out->writeUint16LE(vContSeq); dump_stmt(f_out, the_object->other); } } @@ -625,7 +625,7 @@ void load_obj_list(Common::ReadStream *f_in, XArrayType &obj_list) { int i, list_size; new_xarray(obj_list); - list_size = f_in->readUint32LE(); + list_size = f_in->readUint16LE(); for (i = 0; i < list_size; ++i) { load_object(f_in, new_object); @@ -643,7 +643,7 @@ void dump_obj_list(Common::WriteStream *f_out, XArrayType &obj_list) { void *p; ObjectPtr this_obj; - f_out->writeUint32LE(obj_list.size()); + f_out->writeUint16LE(obj_list.size()); for (i = 0; i < obj_list.size(); ++i) { if (index_xarray(obj_list, i, p)) { diff --git a/engines/glk/archetype/saveload.h b/engines/glk/archetype/saveload.h index fe6251be9c..0f98eb2d7a 100644 --- a/engines/glk/archetype/saveload.h +++ b/engines/glk/archetype/saveload.h @@ -53,8 +53,8 @@ extern bool Translating; extern void saveload_init(); -extern void load_item_list(Common::ReadStream *f_in, ListType elements, ContentType content); -extern void dump_item_list(Common::WriteStream *f_out, ListType elements, ContentType content); +extern void load_item_list(Common::ReadStream *f_in, ListType &elements, ContentType content); +extern void dump_item_list(Common::WriteStream *f_out, ListType &elements, ContentType content); extern void dispose_item_list(ListType &elements, ContentType content); extern void load_expr(Common::ReadStream *f_in, ExprTree &the_expr); -- cgit v1.2.3