aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2019-07-05 20:12:52 -0700
committerPaul Gilbert2019-07-06 15:27:09 -0700
commitf28d3b74969896d048ec57aa7e0200f258205423 (patch)
tree173cd293e94ac6b71cfebf7b1b14da46b1841429
parent3165fa628ab44022ee8370d0244137295f3c59f1 (diff)
downloadscummvm-rg350-f28d3b74969896d048ec57aa7e0200f258205423.tar.gz
scummvm-rg350-f28d3b74969896d048ec57aa7e0200f258205423.tar.bz2
scummvm-rg350-f28d3b74969896d048ec57aa7e0200f258205423.zip
GLK: ALAN3: Further refactoring of setjmp calls
-rw-r--r--engines/glk/alan3/act.cpp23
-rw-r--r--engines/glk/alan3/debug.cpp2
-rw-r--r--engines/glk/alan3/exe.cpp64
-rw-r--r--engines/glk/alan3/exe.h10
-rw-r--r--engines/glk/alan3/inter.cpp8
-rw-r--r--engines/glk/alan3/main.cpp23
-rw-r--r--engines/glk/alan3/scan.cpp4
7 files changed, 59 insertions, 75 deletions
diff --git a/engines/glk/alan3/act.cpp b/engines/glk/alan3/act.cpp
index cdc95f9217..13ca56aa27 100644
--- a/engines/glk/alan3/act.cpp
+++ b/engines/glk/alan3/act.cpp
@@ -96,36 +96,33 @@ static void executeCommand(CONTEXT, int verb, Parameter parameters[]) {
*/
void action(CONTEXT, int verb, Parameter parameters[], Parameter multipleMatches[]) {
int multiplePosition;
-#ifdef TODO
char marker[10];
-#endif
multiplePosition = findMultiplePosition(parameters);
if (multiplePosition != -1) {
-#ifdef TODO
- jmp_buf savedReturnLabel;
- memcpy(savedReturnLabel, returnLabel, sizeof(returnLabel));
sprintf(marker, "($%d)", multiplePosition + 1); /* Prepare a printout with $1/2/3 */
for (int i = 0; !isEndOfArray(&multipleMatches[i]); i++) {
copyParameter(&parameters[multiplePosition], &multipleMatches[i]);
setGlobalParameters(parameters); /* Need to do this here since the marker use them */
output(marker);
- // TODO: if execution for one parameter aborts we should return here, not to top level
- if (setjmp(returnLabel) == NO_JUMP_RETURN)
- executeCommand(verb, parameters);
+
+ // WARNING: The original did a temporary grabbing of the returnLabel setjmp point here.
+ // Which is why I manually check the context return instead of using the CALL macro
+ executeCommand(context, verb, parameters);
+ if (context._break && context._label.hasPrefix("return"))
+ context._break = false;
+ if (context._break)
+ return;
+
if (multipleMatches[i + 1].instance != EOD)
para();
}
- memcpy(returnLabel, savedReturnLabel, sizeof(returnLabel));
+
parameters[multiplePosition].instance = 0;
-#else
- syserr("TODO: action");
-#endif
} else {
setGlobalParameters(parameters);
CALL2(executeCommand, verb, parameters)
}
-
}
} // End of namespace Alan3
diff --git a/engines/glk/alan3/debug.cpp b/engines/glk/alan3/debug.cpp
index 4705010829..114019d520 100644
--- a/engines/glk/alan3/debug.cpp
+++ b/engines/glk/alan3/debug.cpp
@@ -745,7 +745,7 @@ static void readCommand(CONTEXT, char buf[], size_t maxLen) {
FUNC2(g_io->readLine, flag, buf, maxLen)
if (!flag) {
newline();
- quitGame();
+ CALL0(quitGame)
}
lin = 1;
c = buf[0];
diff --git a/engines/glk/alan3/exe.cpp b/engines/glk/alan3/exe.cpp
index 499eaee4f9..8c22742347 100644
--- a/engines/glk/alan3/exe.cpp
+++ b/engines/glk/alan3/exe.cpp
@@ -54,13 +54,6 @@ 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 */
-//jmp_buf returnLabel; /* Error (or undo) long jump return point */
-//jmp_buf forfeitLabel; /* Player forfeit by an empty command */
-
-
/* PRIVATE CONSTANTS */
#define WIDTH 80
@@ -192,7 +185,7 @@ static void sayUndoneCommand(char *words) {
/*======================================================================*/
-void undo(void) {
+void undo(CONTEXT) {
forgetGameState();
if (anySavedState()) {
recallGameState();
@@ -200,68 +193,73 @@ void undo(void) {
} else {
printMessage(M_NO_UNDO);
}
-#ifdef TODO
- longjmp(returnLabel, UNDO_RETURN);
-#else
- syserr("TODO: undo longjmp");
-#endif
+
+ LONG_JUMP_LABEL("returnUndo")
}
/*======================================================================*/
-void quitGame(void) {
-#ifdef TODO
+void quitGame(CONTEXT) {
char buf[80];
+ bool flag;
current.location = where(HERO, DIRECT);
para();
while (TRUE) {
col = 1;
- statusline();
+ CALL0(g_io->statusLine)
printMessage(M_QUITACTION);
- if (!readline(buf)) terminate(0);
- if (strcasecmp(buf, "restart") == 0)
- longjmp(restartLabel, TRUE);
- else if (strcasecmp(buf, "restore") == 0) {
- restore();
+ FUNC2(g_io->readLine, flag, buf, 80)
+ if (!flag)
+ CALL1(terminate, 0)
+
+ if (strcasecmp(buf, "restart") == 0) {
+ LONG_JUMP_LABEL("restart")
+
+ } else if (strcasecmp(buf, "restore") == 0) {
+ g_vm->loadGame();
return;
+
} else if (strcasecmp(buf, "quit") == 0) {
- terminate(0);
+ CALL1(terminate, 0)
+
} else if (strcasecmp(buf, "undo") == 0) {
if (gameStateChanged) {
rememberCommands();
rememberGameState();
- undo();
+ CALL0(undo)
} else {
if (anySavedState()) {
recallGameState();
sayUndoneCommand(playerWordsAsCommandString());
- } else
+ } else {
printMessage(M_NO_UNDO);
- longjmp(returnLabel, UNDO_RETURN);
+ }
+
+ LONG_JUMP_LABEL("returnUndo")
}
}
}
-#endif
+
syserr("Fallthrough in QUIT");
}
/*======================================================================*/
-void restartGame(void) {
-#ifdef TODO
+void restartGame(CONTEXT) {
Aint previousLocation = current.location;
current.location = where(HERO, DIRECT);
para();
- if (confirm(M_REALLY)) {
- longjmp(restartLabel, TRUE);
+
+ bool flag;
+ FUNC1(confirm, flag, M_REALLY)
+ if (flag) {
+ LONG_JUMP_LABEL("restart")
}
+
current.location = previousLocation;
-#else
- syserr("TODO: restartGame");
-#endif
}
diff --git a/engines/glk/alan3/exe.h b/engines/glk/alan3/exe.h
index 79e77207dd..df5892c159 100644
--- a/engines/glk/alan3/exe.h
+++ b/engines/glk/alan3/exe.h
@@ -47,10 +47,6 @@ namespace Alan3 {
extern Common::SeekableReadStream *textFile; // The text and message file
extern bool printFlag;
-/* Long jump buffer for restart, errors and undo */
-//extern jmp_buf returnLabel;
-
-
/* FUNCTIONS */
extern void sys(Aword fpos, Aword len);
extern void sayInteger(int val);
@@ -61,9 +57,9 @@ extern char *getStringFromFile(Aword fpos, Aword len);
extern void print(Aword fpos, Aword len);
extern void score(Aword sc);
extern void visits(Aword v);
-extern void undo(void);
-extern void quitGame(void);
-extern void restartGame(void);
+extern void undo(CONTEXT);
+extern void quitGame(CONTEXT);
+extern void restartGame(CONTEXT);
extern void use(CONTEXT, int act, int scr);
extern void stop(int act);
diff --git a/engines/glk/alan3/inter.cpp b/engines/glk/alan3/inter.cpp
index 3647548a41..4708cf8bd3 100644
--- a/engines/glk/alan3/inter.cpp
+++ b/engines/glk/alan3/inter.cpp
@@ -590,7 +590,7 @@ void interpret(CONTEXT, Aaddr adr) {
case I_QUIT: {
if (traceInstructionOption)
printf("QUIT\t\t\t\t\t\t");
- quitGame();
+ CALL0(quitGame)
break;
}
case I_LOOK: {
@@ -602,19 +602,19 @@ void interpret(CONTEXT, Aaddr adr) {
case I_SAVE: {
if (traceInstructionOption)
printf("SAVE\t\t\t\t\t\t");
- g_vm->saveGame();
+ (void)g_vm->saveGame();
break;
}
case I_RESTORE: {
if (traceInstructionOption)
printf("RESTORE\t\t\t\t\t\t");
- g_vm->loadGame();
+ (void)g_vm->loadGame();
break;
}
case I_RESTART: {
if (traceInstructionOption)
printf("RESTART\t\t\t\t\t\t");
- restartGame();
+ CALL0(restartGame)
break;
}
diff --git a/engines/glk/alan3/main.cpp b/engines/glk/alan3/main.cpp
index de65b095d3..e56ac87b1c 100644
--- a/engines/glk/alan3/main.cpp
+++ b/engines/glk/alan3/main.cpp
@@ -744,10 +744,11 @@ void run(void) {
Stack theStack = NULL;
Context ctx;
+ openFiles();
+ load(ctx); // Load program
+
do {
ctx.clear();
- openFiles();
- load(ctx); // Load program
if (ctx._break)
break;
@@ -765,23 +766,15 @@ void run(void) {
while (!g_vm->shouldQuit()) {
if (!(ctx._break && ctx._label == "forfeit")) {
if (ctx._break) {
- assert(ctx._label == "return");
-#ifdef TODO
- // Return here if error during execution
- switch (setjmp(returnLabel)) {
- case NO_JUMP_RETURN:
- break;
- case ERROR_RETURN:
+ assert(ctx._label.hasPrefix("return"));
+
+ if (ctx._label == "returnError") {
forgetGameState();
forceNewPlayerInput();
- break;
- case UNDO_RETURN:
+ } else if (ctx._label == "returnUndo") {
forceNewPlayerInput();
- break;
- default:
- syserr("Unexpected longjmp() return value");
}
-#endif
+
ctx.clear();
} else {
if (debugOption)
diff --git a/engines/glk/alan3/scan.cpp b/engines/glk/alan3/scan.cpp
index 8f3ab80cbd..788e5ca90d 100644
--- a/engines/glk/alan3/scan.cpp
+++ b/engines/glk/alan3/scan.cpp
@@ -151,7 +151,7 @@ static void getLine(CONTEXT) {
FUNC2(g_io->readLine, flag, buf, 255);
if (!flag) {
newline();
- quitGame();
+ CALL0(quitGame)
}
getPageSize();
@@ -179,7 +179,7 @@ static void getLine(CONTEXT) {
token = gettoken(NULL);
if (token != NULL) /* More tokens? */
CALL1(error, M_WHAT)
- undo();
+ CALL0(undo)
}
}
} while (token == NULL);