GLK: ALAN2: Fix quitting in-game

This commit is contained in:
Paul Gilbert 2019-06-22 22:02:51 -07:00
parent 3683e74d65
commit c0d5981ff9
8 changed files with 37 additions and 22 deletions

View file

@ -315,8 +315,11 @@ void debug() {
$iX -- exit debug mode\
$iQ -- quit game");
break;
case 'Q':
terminate(0);
case 'Q': {
Context ctx;
terminate(ctx, 0);
break;
}
case 'X':
dbgflg = FALSE; /* Fall through to 'G' */
case 'G':

View file

@ -166,7 +166,7 @@ Boolean confirm(MsgKind msgno) {
return (buf[0] == '\0');
}
void quit() {
void quit(CONTEXT) {
char buf[80];
para();
@ -174,18 +174,20 @@ void quit() {
col = 1;
statusline();
prmsg(M_QUITACTION);
if (!readline(buf)) terminate(0);
if (!readline(buf)) {
CALL1(terminate, 0)
}
if (strcmp(buf, "restart") == 0)
//longjmp(restart_label, TRUE);
::error("TODO: restart");
else if (strcmp(buf, "restore") == 0) {
if (strcmp(buf, "restart") == 0) {
g_vm->setRestart(true);
LONG_JUMP
} else if (strcmp(buf, "restore") == 0) {
restore();
return;
} else if (strcmp(buf, "quit") == 0)
terminate(0);
LONG_JUMP
} else if (strcmp(buf, "quit") == 0) {
CALL1(terminate, 0)
}
}
syserr("Fallthrough in QUIT");
}
void restart() {

View file

@ -27,6 +27,7 @@
*/
#include "glk/alan2/types.h"
#include "glk/alan2/jumps.h"
namespace Glk {
namespace Alan2 {
@ -61,7 +62,7 @@ extern void score(Aword sc);
extern void visits(Aword v);
extern void schedule(Aword evt, Aword whr, Aword aft);
extern void cancl(Aword evt);
extern void quit(void);
extern void quit(CONTEXT);
extern void restart(void);
extern void save(void);
extern void restore(void);

View file

@ -146,6 +146,11 @@ static void depcase() {
}
void interpret(Aaddr adr) {
Context ctx;
interpret(ctx, adr);
}
void interpret(CONTEXT, Aaddr adr) {
Aaddr oldpc;
Aword i;
@ -233,7 +238,7 @@ void interpret(Aaddr adr) {
case I_QUIT: {
if (stpflg)
printf("QUIT");
quit();
CALL0(quit)
break;
}
case I_LOOK: {

View file

@ -23,10 +23,13 @@
#ifndef GLK_ALAN2_INTER
#define GLK_ALAN2_INTER
#include "glk/alan2/jumps.h"
namespace Glk {
namespace Alan2 {
extern void interpret(Aaddr adr);
extern void interpret(CONTEXT, Aaddr adr);
} // End of namespace Alan2
} // End of namespace Glk

View file

@ -114,13 +114,14 @@ Boolean skipsp = FALSE;
return buffers...
*/
void terminate(int code) {
void terminate(CONTEXT, int code) {
newline();
free(memory);
if (logflg)
fclose(logfil);
g_vm->glk_exit();
LONG_JUMP
}
/*======================================================================
@ -885,7 +886,7 @@ static void do_it(CONTEXT) {
else
printf("\n<VERB %d, %s (ONLY), Body:>\n", cur.vrb, trace);
}
interpret(alt[i]->action);
CALL1(interpret, alt[i]->action)
if (fail) return;
if (alt[i]->qual == (Aword)Q_ONLY) return;
}
@ -908,7 +909,7 @@ static void do_it(CONTEXT) {
sprintf(trace, "in PARAMETER %d", i - 1);
printf("\n<VERB %d, %s, Body:>\n", cur.vrb, trace);
}
interpret(alt[i]->action);
CALL1(interpret, alt[i]->action)
if (fail) return;
}
done[i] = TRUE;
@ -929,7 +930,7 @@ static void do_it(CONTEXT) {
sprintf(trace, "in PARAMETER %d", i - 1);
printf("\n<VERB %d, %s (AFTER), Body:>\n", cur.vrb, trace);
}
interpret(alt[i]->action);
CALL1(interpret, alt[i]->action)
if (fail) return;
}
i--;

View file

@ -99,7 +99,7 @@ extern Boolean needsp;
#define endOfTable(x) eot((Aword *) x)
extern void *allocate(unsigned long len);
extern void terminate(int code);
extern void terminate(CONTEXT, int code);
extern void usage(void);
extern void error(CONTEXT, MsgKind msg);
extern void syserr(const char *msg);

View file

@ -150,7 +150,7 @@ static char *gettoken(char *tokBuf) {
return tokBuf;
}
static void agetline() {
static void agetline(CONTEXT) {
para();
do {
statusline();
@ -164,7 +164,7 @@ static void agetline() {
return;
newline();
quit();
CALL0(quit)
}
getPageSize();
@ -189,7 +189,7 @@ static void scan(CONTEXT) {
int w;
char *str;
agetline();
CALL0(agetline)
if (g_vm->shouldQuit())
return;