dbltw/vm/main.c
2020-05-13 19:08:25 -05:00

52 lines
962 B
C

#include <stdio.h>
#include "vm.h"
// /home/scott/joey/rpgengine/dbltw/test.bin
void func_print(VMContextT *context, juint16 args) {
int x;
for (x=0; x<args; x++) {
vmPop(context, &context->working[0]);
if (vmIsItemNumber(&context->working[0])) {
printf("%d", context->working[0].value);
} else {
printf("%s", context->working[0].text);
}
}
}
int main(int argc, char *argv[]) {
char *programFile;
VMContextT context;
// Get arguments
if (argc != 2) {
printf("Usage: %s binary.bin\n", argv[0]);
return 1;
}
programFile = argv[1];
jlUtilStartup("VM Test");
if (!vmCreate(&context)) {
printf("Unable to initialize VM.\n");
} else {
vmAddFunction(&context, func_print);
if (!vmLoad(&context, programFile)) {
printf("Unable to load '%s'.\n", programFile);
} else {
vmRun(&context);
} // vmLoad
} // vmCreate
vmDestroy(&context);
printf("\nJlStaT = %lu\n", sizeof(jlStaT));
jlUtilShutdown();
}