nga-c: add stub guard() function (ref #96)

FossilOrigin-Name: 872b8371d1eed28ce2b6405055f5ada8b174c2c55b5dbbbfd35e857dff4665a6
This commit is contained in:
crc 2023-03-28 18:30:12 +00:00
parent 55652d8a5d
commit 68f2fa9b09

View file

@ -237,6 +237,25 @@ void inst_iq(NgaState *); void inst_ii(NgaState *);
/* Global Variables -------------------------------------------------- */ /* 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 --------------------------------- */ /* Dynamic Memory / `malloc` support --------------------------------- */
#ifdef ENABLE_MALLOC #ifdef ENABLE_MALLOC
#ifdef BIT64 #ifdef BIT64