initial stubs related to error handling device

FossilOrigin-Name: 83006b5213a91e8d35f2c8c873e203cc7225ec5b7636f7ba9222c1c712883bbc
This commit is contained in:
crc 2023-05-15 10:49:07 +00:00
parent 9834bf1de5
commit e92e91f02b
6 changed files with 71 additions and 4 deletions

View file

@ -42,10 +42,11 @@ ENABLED += -DENABLE_UNIX
ENABLED += -DENABLE_RNG
ENABLED += -DENABLE_CLOCK
ENABLED += -DENABLE_SCRIPTING
#ENABLED += -DENABLE_SOCKETS
# ENABLED += -DENABLE_SOCKETS
ENABLED += -DENABLE_SIGNALS
ENABLED += -DENABLE_MULTICORE
ENABLED += -DENABLE_FFI
# ENABLED += -DENABLE_FFI
ENABLED += -DENABLE_ERROR
ENABLED += -DENABLE_UNSIGNED
ENABLED += -DENABLE_MALLOC
ENABLED += -DENABLE_BLOCKS
@ -70,6 +71,7 @@ DEVICES += interface/block.retro
DEVICES += interface/deprecated.retro
DEVICES += interface/double.retro
DEVICES += interface/malloc.retro
DEVICES += interface/error.retro
DEVICES += interface/final.retro
# -------------------------------------------------------------

View file

@ -25,7 +25,6 @@ dirs:
clean:
rm -f bin/*
# installation targets
install: build install-data install-docs install-examples install-manpages

2
interface/error.retro Normal file
View file

@ -0,0 +1,2 @@
~~~
~~~

34
vm/nga-c/dev-error.c Normal file
View file

@ -0,0 +1,34 @@
/***************************************************************
Copyright (c) Charles Childers
**************************************************************/
/*
| 001 | Data Stack Underflow |
| 002 | Data Stack Overflow |
| 003 | Address Stack Underflow |
| 004 | Address Stack Overflow |
| 005 | Invalid Memory Access |
| 006 | Division by Zero |
*/
#ifdef ENABLE_ERROR
void register_error_handler(NgaState *vm) {
CELL ErrorID = stack_pop(vm);
CELL ErrorHandler = stack_pop(vm);
vm->ErrorHandlers[ErrorID] = ErrorHandler;
}
void io_error(NgaState *vm) {
switch (stack_pop(vm)) {
case 0: register_error_handler(vm);
default: break;
}
}
void query_err(NgaState *vm) {
stack_push(vm, 0);
stack_push(vm, 1234);
}
#endif

View file

@ -533,7 +533,7 @@ CELL ngaImage[] = { 1793,19438,19887,19931,202309,417,389,1249,1535,0,11254,0,10
1793,10393,2,2049,104,2049,2740,1,417,1,17,2049,66,10,1,10381,2049,2229,2049,3125,
10,1,10374,2049,2449,2049,417,10,10250,10423,168,12041,8246849872898570441,115,58,101,118,97,108,117,
97,116,101,0,2049,10315,2049,5573,2049,10315,2,2049,10339,2049,10372,10,10407,10443,156,0,
0,76,80,0,0,10435,10455,156,0,0,73,110,100,101,120,0,0,14,0,0,
0,76,80,0,0,10435,10455,156,0,0,73,110,100,101,120,0,0,13,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,10444,10497,168,0,0,110,101,120,116,0,3841,10443,
1,10455,17,2049,3864,10,10487,10515,168,0,0,112,114,101,112,0,1,10443,2049,3864,

View file

@ -120,6 +120,10 @@ struct NgaState {
char BlockFile[1025];
#endif
#ifdef ENABLE_ERROR
CELL ErrorHandlers[64];
#endif
/* Scripting */
char **sys_argv;
int sys_argc;
@ -220,21 +224,41 @@ void inst_iq(NgaState *); void inst_ii(NgaState *);
void guard(NgaState *vm, int n, int m, int diff) {
if (vm->cpu[vm->active].sp < n) {
#ifdef ENABLE_ERROR
if (vm->ErrorHandlers[1] != 0) {
}
#else
printf("E: Data Stack Underflow");
vm->cpu[vm->active].sp = 0;
return;
#endif
}
if (((vm->cpu[vm->active].sp + m) - n) > (STACK_DEPTH - 1)) {
#ifdef ENABLE_ERROR
if (vm->ErrorHandlers[2] != 0) {
}
#else
printf("E: Data Stack Overflow");
vm->cpu[vm->active].sp = 0;
return;
#endif
}
if (diff) {
if (vm->cpu[vm->active].rp + diff < 0) {
#ifdef ENABLE_ERROR
if (vm->ErrorHandlers[3] != 0) {
}
#else
return;
#endif
}
if (vm->cpu[vm->active].rp + diff > (ADDRESSES - 1)) {
#ifdef ENABLE_ERROR
if (vm->ErrorHandlers[1] != 4) {
}
#else
return;
#endif
}
}
}
@ -1293,6 +1317,12 @@ void inst_di(NgaState *vm) {
CELL a, b;
a = TOS;
b = NOS;
if (b == 0) {
#ifdef ENABLE_ERROR
if (vm->ErrorHandlers[6] != 0) {
}
#endif
}
if (vm->cpu[vm->active].u != 0) {
TOS = (unsigned)b / (unsigned)a;
NOS = (unsigned)b % (unsigned)a;