The unified diff between revisions [81f2a8bb..] and [adff2b70..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'src/lsi/vm.c'

#
# old_revision [81f2a8bbe94638a22f5651ee07112ceabd50285c]
# new_revision [adff2b70cc1870df9f9b4d736b855dffae74eca2]
#
# patch "src/lsi/vm.c"
#  from [e2e905076968e53dd131de512d042191f64d91bf]
#    to [494a44702b477512e9979cc5799f7e188fa19d2b]
#
============================================================
--- src/lsi/vm.c	e2e905076968e53dd131de512d042191f64d91bf
+++ src/lsi/vm.c	494a44702b477512e9979cc5799f7e188fa19d2b
@@ -257,6 +257,19 @@ gloadarrayout:
 	return 1;
 }
 
+int vm_intfn___stackdump(void) {
+	int n = vm_current->sp - vm_current->stackbase;
+	int i;
+
+	printf("\n=====Stack dump======\n");
+	for (i = 0; i < n; i++) {
+		int e = stack_get(vm_current, i);
+		printf("%x\t%d\n", e, e);
+	}
+
+	return 1;
+}
+
 int vm_intfn_printint(void)
 {
 	printf("%d", stack_get(vm_current, 1));
@@ -472,18 +485,14 @@ int vm_intfn_cmdsocket_write(void)
 	char *buffer = stack_getstr(vm_current, len, 2);
 	int newoff;
 
-	printf("cmdsocket_write in vm\n");
-
 	newoff = cmdsocket_write(buffer, len, off);
 	stack_poke(vm_current, 1, newoff);
 
 	if (newoff != len) {
-		printf("cmdsocket_write sleeping\n");
 		vm_queue(vm_current, VM_CMDWRITEQ);
 		vm_current = NULL;
 		return 0;
 	}
-	printf("cmdsocket_write success\n");
 	return 1;
 }
 
@@ -772,12 +781,13 @@ int vm_intfn_map3d_setparams(void)
 
 int vm_intfn_map3d_setparams(void)
 {
-	map3d_setparams(stack_get(vm_current, 6), /* light */
-	    (double)stack_get(vm_current, 5), /* opan */
-	    (double)stack_get(vm_current, 4), /* otilt */
-	    (double)stack_getreal(vm_current, 3), /* lpan */
-	    (double)stack_getreal(vm_current, 2), /* ltilt */
-	    (double)stack_getreal(vm_current, 1)); /* dist */
+	map3d_setparams(stack_get(vm_current, 7), /* light */
+	    (double)stack_get(vm_current, 6), /* opan */
+	    (double)stack_get(vm_current, 5), /* otilt */
+	    (double)stack_getreal(vm_current, 4), /* lpan */
+	    (double)stack_getreal(vm_current, 3), /* ltilt */
+	    (double)stack_getreal(vm_current, 2), /* dist */
+	    (double)stack_get(vm_current, 1)); /* invert */
 	return 1;
 }
 
@@ -865,7 +875,9 @@ void vm_load_file(char *filename)
 	char *ptr;
 
 	fh = fopen(filename, "r");
-	assert(fh != NULL);
+	if (fh == NULL) {
+		err(1, "Failed to open '%s'", filename);
+	}
 
 	for (ptr = vm_codearea; ptr < vm_codearea+vm_codesize; ptr++) {
 		int c;
@@ -891,16 +903,19 @@ void vm_init_functions(void)
 	struct hashentry *ptr;
 
 	/* First, let's check the magic */
-	assert(vm_codearea[0] == MAGIC1);
-	assert(vm_codearea[1] == MAGIC2);
-	assert(vm_codearea[2] == VERSION1);
-	assert(vm_codearea[3] == VERSION2);
+	if ((vm_codearea[0] != MAGIC1) ||
+	    (vm_codearea[1] != MAGIC2))
+		errx(1, "Bad magic - not a lightscript binary");
+	if ((vm_codearea[2] != VERSION1) ||
+	    (vm_codearea[3] != VERSION2))
+		errx(1, "Bad version - recompile");
 
-	assert(GETINT(vm_codearea, 8) == vm_abiversion1);
-	assert(GETINT(vm_codearea, 12) == vm_abiversion2);
-	assert(GETINT(vm_codearea, 16) == vm_abiversion3);
-	assert(GETINT(vm_codearea, 20) == vm_abiversion4);
-	assert(GETINT(vm_codearea, 24) == vm_abiversion5);
+	if ((GETINT(vm_codearea, 8) != vm_abiversion1) ||
+	    (GETINT(vm_codearea, 12) != vm_abiversion2) ||
+	    (GETINT(vm_codearea, 16) != vm_abiversion3) ||
+	    (GETINT(vm_codearea, 20) != vm_abiversion4) ||
+	    (GETINT(vm_codearea, 24) != vm_abiversion5))
+		errx(1, "Incompatible ABI version - recompile");
 
 	/* Now, get the function table pointer */
 	t = GETINT(vm_codearea, 4);
@@ -991,8 +1006,6 @@ int vm_spawn_args(char *fn, int n, ...)
 	}
 	newt->sp = newt->stackbase;
 
-	stack_push(newt, 0); 	/* Return value */
-
 	/* Push optional arguments */
 	va_start(ap, n);
 	while (n--) {
@@ -1002,6 +1015,8 @@ int vm_spawn_args(char *fn, int n, ...)
 	}
 	va_end(ap);
 
+	stack_push(newt, 0); 	/* Return value */
+
 	/* Push return address here, to point to some special thread exit
 	   routine */
 	stack_push(newt, 0);	/* Return address */