nga-c: rewrite instruction bundle validator

FossilOrigin-Name: b49f50251dba7b01b1ae7883e0389fab97ae0c495c8e935f42d010cc1203927a
This commit is contained in:
crc 2023-11-21 17:42:28 +00:00
parent 69789a15a3
commit 3498583b9c

View file

@ -681,7 +681,7 @@ void execute(NgaState *vm, CELL cell) {
} }
} }
;
/*--------------------------------------------------------------------- /*---------------------------------------------------------------------
RETRO's `interpret` word expects a token on the stack. This next RETRO's `interpret` word expects a token on the stack. This next
function copies a token to the `TIB` (text input buffer) and then function copies a token to the `TIB` (text input buffer) and then
@ -742,10 +742,9 @@ void skip_indent(FILE *fp) {
---------------------------------------------------------------------*/ ---------------------------------------------------------------------*/
void dump_stack(NgaState *vm) { void dump_stack(NgaState *vm) {
CELL i;
if (ACTIVE.sp == 0) return; if (ACTIVE.sp == 0) return;
printf("\nStack: "); printf("\nStack: ");
for (i = 1; i <= ACTIVE.sp; i++) { for (CELL i = 1; i <= ACTIVE.sp; i++) {
if (i == ACTIVE.sp) if (i == ACTIVE.sp)
printf("[ TOS: %lld ]", (long long)ACTIVE.data[i]); printf("[ TOS: %lld ]", (long long)ACTIVE.data[i]);
else else
@ -755,10 +754,9 @@ void dump_stack(NgaState *vm) {
} }
void dump_astack(NgaState *vm) { void dump_astack(NgaState *vm) {
CELL i;
if (ACTIVE.rp == 0) return; if (ACTIVE.rp == 0) return;
printf("\nAddress Stack: "); printf("\nAddress Stack: ");
for (i = 1; i <= ACTIVE.rp; i++) { for (CELL i = 1; i <= ACTIVE.rp; i++) {
if (i == ACTIVE.rp) if (i == ACTIVE.rp)
printf("[ TOS: %lld ]", (long long)ACTIVE.address[i]); printf("[ TOS: %lld ]", (long long)ACTIVE.address[i]);
else else
@ -1568,17 +1566,19 @@ void process_opcode(NgaState *vm, CELL opcode) {
} }
int validate_opcode_bundle(CELL opcode) { int validate_opcode_bundle(CELL opcode) {
CELL raw = opcode; CELL remainingOpcode = opcode;
CELL current; int isValid = 1;
int valid = -1;
int i; for (int i = 0; i < 4; i++) {
for (i = 0; i < 4; i++) { CELL current = remainingOpcode & 0xFF;
current = raw & 0xFF; if (current < 0 || current > 29) {
if (!(current >= 0 && current <= 29)) isValid = 0;
valid = 0; break;
raw = raw >> 8; }
remainingOpcode >>= 8;
} }
return valid;
return isValid;
} }
void verbose_details(NgaState *vm, CELL opcode) { void verbose_details(NgaState *vm, CELL opcode) {