Skip to content

Commit

Permalink
GLK: ALAN3: Context clearing in main loop, add packing to code struct…
Browse files Browse the repository at this point in the history
…ures
  • Loading branch information
dreammaster committed Jul 6, 2019
1 parent f2f4639 commit 4d7cfeb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 35 deletions.
54 changes: 29 additions & 25 deletions engines/glk/alan3/acode.h
Expand Up @@ -319,10 +319,12 @@ enum ATrans {

#define AwordSizeOf(x) (sizeof(x)/sizeof(Aword))

#include "common/pack-start.h" // START STRUCT PACKING

struct ArticleEntry {
Aaddr address; /* Address of article code */
Abool isForm; /* Is the article a complete form? */
};
} PACKED_STRUCT;

struct ClassEntry { /* CLASS TABLE */
Aword code; /* Own code */
Expand All @@ -339,7 +341,7 @@ struct ClassEntry { /* CLASS TABLE */
Aaddr mentioned; /* Address of code for Mentioned clause */
Aaddr verbs; /* Address of verb table */
Aaddr entered; /* Address of code for Entered clause */
};
} PACKED_STRUCT;

struct InstanceEntry { /* INSTANCE TABLE */
Aint code; /* Own code */
Expand All @@ -360,37 +362,37 @@ struct InstanceEntry { /* INSTANCE TABLE */
Aaddr verbs; /* Address of local verb list */
Aaddr entered; /* Address of entered code (location only) */
Aaddr exits; /* Address of exit list */
};
} PACKED_STRUCT;

struct AttributeEntry { /* ATTRIBUTE LIST */
Aint code; /* Its code */
Aptr value; /* Its value, a string has a dynamic
string pointer, a set has a pointer
to a dynamically allocated set */
Aaddr id; /* Address to the name */
};
} PACKED_STRUCT;

struct AttributeHeaderEntry { /* ATTRIBUTE LIST in header */
Aint code; /* Its code */
Aword value; /* Its value, a string has a dynamic
string pointer, a set has a pointer
to a dynamically allocated set */
Aaddr id; /* Address to the name */
};
} PACKED_STRUCT;

struct ExitEntry { /* EXIT TABLE structure */
Aword code; /* Direction code */
Aaddr checks; /* Address of check table */
Aaddr action; /* Address of action code */
Aword target; /* Id for the target location */
};
} PACKED_STRUCT;


struct RuleEntry { /* RULE TABLE */
Abool alreadyRun;
Aaddr exp; /* Address to expression code */
Aaddr stms; /* Address to run */
};
} PACKED_STRUCT;


#define RESTRICTIONCLASS_CONTAINER (-2)
Expand All @@ -401,7 +403,7 @@ struct RestrictionEntry { /* PARAMETER RESTRICTION TABLE */
Aint parameterNumber; /* Parameter number */
Aint _class; /* Parameter class code */
Aaddr stms; /* Exception statements */
};
} PACKED_STRUCT;

struct ContainerEntry { /* CONTAINER TABLE */
Aword owner; /* Owner instance index */
Expand All @@ -411,81 +413,81 @@ struct ContainerEntry { /* CONTAINER TABLE */
Aaddr empty; /* Address to code for header when empty */
Aaddr extractChecks; /* Address to check before extracting */
Aaddr extractStatements; /* Address to execute when extracting */
};
} PACKED_STRUCT;


struct ElementEntry { /* SYNTAX ELEMENT TABLES */
Aint code; /* Code for this element, 0 -> parameter */
Aword flags; /* Flags for multiple/omni (if parameter), syntax number/verb of EOS */
Aaddr next; /* Address to next element table ... */
/* ... or restrictions if code == EOS */
};
} PACKED_STRUCT;

struct SyntaxEntryPreBeta2 { /* SYNTAX TABLE */
Aint code; /* Code for verb word */
Aaddr elms; /* Address to element tables */
};
} PACKED_STRUCT;

struct SyntaxEntry { /* SYNTAX TABLE */
Aint code; /* Code for verb word, or 0 if starting with parameter */
Aaddr elms; /* Address to element tables */
Aaddr parameterNameTable; /* Address to a table of id-addresses giving the names of the parameters */
};
} PACKED_STRUCT;

struct ParameterMapEntry { /* PARAMETER MAPPING TABLE */
Aint syntaxNumber;
Aaddr parameterMapping;
Aint verbCode;
};
} PACKED_STRUCT;

struct EventEntry { /* EVENT TABLE */
Aaddr id; /* Address to name string */
Aaddr code;
};
} PACKED_STRUCT;

struct ScriptEntry { /* SCRIPT TABLE */
Aaddr id; /* Address to name string */
Aint code; /* Script number */
Aaddr description; /* Optional description statements */
Aaddr steps; /* Address to steps */
};
} PACKED_STRUCT;

struct StepEntry { /* STEP TABLE */
Aaddr after; /* Expression to say after how many ticks? */
Aaddr exp; /* Expression to condition saying when */
Aaddr stms; /* Address to the actual code */
};
} PACKED_STRUCT;

struct AltEntry { /* VERB ALTERNATIVE TABLE */
Aword qual; /* Verb execution qualifier */
Aint param; /* Parameter number */
Aaddr checks; /* Address of the check table */
Aaddr action; /* Address of the action code */
};
} PACKED_STRUCT;

struct SourceFileEntry { /* SOURCE FILE NAME TABLE */
Aint fpos;
Aint len;
};
} PACKED_STRUCT;

struct SourceLineEntry { /* SOURCE LINE TABLE */
Aint file;
Aint line;
};
} PACKED_STRUCT;

struct StringInitEntry { /* STRING INITIALISATION TABLE */
Aword fpos; /* File position */
Aword len; /* Length */
Aint instanceCode; /* Where to store it */
Aint attributeCode;
};
} PACKED_STRUCT;

struct SetInitEntry { /* SET INITIALISATION TABLE */
Aint size; /* Size of the initial set */
Aword setAddress; /* Address to the initial set */
Aint instanceCode; /* Where to store it */
Aint attributeCode;
};
} PACKED_STRUCT;

struct DictionaryEntry { /* Dictionary */
Aaddr string; /* ACODE address to string */
Expand All @@ -494,7 +496,7 @@ struct DictionaryEntry { /* Dictionary */
Aaddr adjectiveRefs; /* Address to reference list */
Aaddr nounRefs; /* Address to reference list */
Aaddr pronounRefs; /* Address to reference list */
};
} PACKED_STRUCT;



Expand Down Expand Up @@ -555,7 +557,7 @@ struct ACodeHeader {
Aword txtcrc; /* Checksum for text data file */
Aaddr ifids; /* Address to IFIDS */
Aaddr prompt;
};
} PACKED_STRUCT;

struct Pre3_0beta2Header {
/* Important info */
Expand Down Expand Up @@ -611,7 +613,7 @@ struct Pre3_0beta2Header {
Aword acdcrc; /* Checksum for acd code (excl. hdr) */
Aword txtcrc; /* Checksum for text data file */
Aaddr ifids; /* Address to IFIDS */
};
} PACKED_STRUCT;

struct Pre3_0alpha5Header {
/* Important info */
Expand Down Expand Up @@ -666,7 +668,9 @@ struct Pre3_0alpha5Header {
Aaddr freq; /* Address to Char freq's for coding */
Aword acdcrc; /* Checksum for acd code (excl. hdr) */
Aword txtcrc; /* Checksum for text data file */
};
} PACKED_STRUCT;

#include "common/pack-end.h" // END STRUCT PACKING

/* Error message numbers */
enum MsgKind {
Expand Down
22 changes: 12 additions & 10 deletions engines/glk/alan3/main.cpp
Expand Up @@ -738,6 +738,7 @@ void run(void) {
Context ctx;

do {
ctx.clear();
openFiles();
load(); // Load program

Expand All @@ -753,16 +754,7 @@ void run(void) {
init();

while (!g_vm->shouldQuit()) {
if (!ctx._break) {
if (debugOption)
debug(FALSE, 0, 0);

if (stackDepth(theStack) != 0)
syserr("Stack is not empty in main loop");

if (!current.meta)
runPendingEvents();
} else {
if (ctx._break) {
#ifdef TODO
// Return here if error during execution
switch (setjmp(returnLabel)) {
Expand All @@ -779,6 +771,16 @@ void run(void) {
syserr("Unexpected longjmp() return value");
}
#endif
ctx.clear();
} else {
if (debugOption)
debug(FALSE, 0, 0);

if (stackDepth(theStack) != 0)
syserr("Stack is not empty in main loop");

if (!current.meta)
runPendingEvents();
}

recursionDepth = 0;
Expand Down

0 comments on commit 4d7cfeb

Please sign in to comment.