[gamecode] Preserve base registers across calls

With this, functions can call other functions without having to worry
about whether the base registers they set up are still valid.
This commit is contained in:
Bill Currie 2022-01-17 15:08:58 +09:00
parent 8da1163a82
commit 736387bc88
2 changed files with 3 additions and 0 deletions

View file

@ -1801,6 +1801,7 @@ extern const char *pr_gametype;
typedef struct strref_s strref_t;
typedef struct {
pr_uivec4_t bases; ///< base registers on entry to function
pr_uint_t staddr; ///< Return statement.
pr_uint_t stack_ptr; ///< data stack on entry to function
bfunction_t *func; ///< Calling function.

View file

@ -146,6 +146,7 @@ PR_PushFrame (progs_t *pr)
if (pr->globals.stack) {
frame->stack_ptr = *pr->globals.stack;
}
frame->bases = pr->pr_bases;
frame->func = pr->pr_xfunction;
frame->tstr = pr->pr_xtstr;
@ -182,6 +183,7 @@ PR_PopFrame (progs_t *pr)
pr->pr_xfunction = frame->func;
pr->pr_xstatement = frame->staddr;
pr->pr_xtstr = frame->tstr;
pr->pr_bases = frame->bases;
// restore data stack (discard any locals)
if (pr->globals.stack) {
*pr->globals.stack = frame->stack_ptr;