From 68f2fa9b09b35586a5f38ef548a3d151fa0fd172 Mon Sep 17 00:00:00 2001 From: crc <> Date: Tue, 28 Mar 2023 18:30:12 +0000 Subject: [PATCH] nga-c: add stub guard() function (ref #96) FossilOrigin-Name: 872b8371d1eed28ce2b6405055f5ada8b174c2c55b5dbbbfd35e857dff4665a6 --- vm/nga-c/retro.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/vm/nga-c/retro.c b/vm/nga-c/retro.c index c834964..228406d 100644 --- a/vm/nga-c/retro.c +++ b/vm/nga-c/retro.c @@ -237,6 +237,25 @@ void inst_iq(NgaState *); void inst_ii(NgaState *); /* Global Variables -------------------------------------------------- */ +void guard(NgaState *vm, int n, int m, int diff) { + if (vm->cpu[vm->active].sp < n) { + vm->cpu[vm->active].sp = 0; + return; + } + if (((vm->cpu[vm->active].sp + m) - n) > (STACK_DEPTH - 1)) { + vm->cpu[vm->active].sp = 0; + return; + } + if (diff) { + if (vm->cpu[vm->active].rp + diff < 0) { + return; + } + if (vm->cpu[vm->active].rp + diff > (ADDRESSES - 1)) { + return; + } + } +} + /* Dynamic Memory / `malloc` support --------------------------------- */ #ifdef ENABLE_MALLOC #ifdef BIT64