X-Git-Url: https://git.subgeniuskitty.com/screensavers/.git/blobdiff_plain/503470d7ddb5b5a0a42987abbb14b90c5eb705d9..8ab082d84a6c5507681253236953a43977a221db:/hacks/NEDsim/NEDsim.c diff --git a/hacks/NEDsim/NEDsim.c b/hacks/NEDsim/NEDsim.c index 2b576f0..2d78973 100644 --- a/hacks/NEDsim/NEDsim.c +++ b/hacks/NEDsim/NEDsim.c @@ -4,11 +4,6 @@ // TODO: // - Write a brief description of the machine being simulated. Only one thread, reduced RAM, no meaningful console when running as screensaver, etc. -// CLI Flags: -// -path-to-aout-binary -// -path-to-font-file -// -speed - // Ideas for sample programs to include: // - Build list of integers on the stack (DUP, IM_1, ADD). // - Calculate prime numbers, placing them on the stack. @@ -677,8 +672,16 @@ NEDsim_event(Display * dpy, Window win, void * closure, XEvent * event) static void NEDsim_free(Display * dpy, Window win, void * closure) { - // TODO: Replace all this with proper code to free everything. struct NEDsim * nedsim = closure; + + if (nedsim->nedstate != NULL) { + free(nedsim->nedstate->active_thread->psw); + free(nedsim->nedstate->active_thread); + free(nedsim->nedstate->hack); + free(nedsim->nedstate); + } + + // TODO: Replace all this with proper code to free everything related to the screensaver itself. XFreeGC(nedsim->dpy, nedsim->gc); free(nedsim); } @@ -707,8 +710,15 @@ NEDsim_init(Display * dpy, Window win) nedsim->delay = get_integer_resource(nedsim->dpy, "delay", "Integer"); nedsim->delay *= 1000; /* Turn milliseconds into microseconds. */ - // TODO: Read in the a.out file. This should be done in the simulator's init function call? - nedsim->nedstate = init_simulator(); + // Load the program file specified by the user or, if none is specified, + // randomly select one of the included programs. + char * input_file = get_string_resource(nedsim->dpy, "binary", "String"); + if (input_file == NULL) { + // TODO: Need to include some default programs and randomly select one to load into RAM. + nedsim->nedstate = init_simulator("./test.out"); + } else { + nedsim->nedstate = init_simulator(input_file); + } nedsim->gc = XCreateGC(nedsim->dpy, nedsim->win, GCForeground, &gcv); @@ -797,6 +807,7 @@ static const char * NEDsim_defaults[] = { static XrmOptionDescRec NEDsim_options[] = { { "-delay", ".delay", XrmoptionSepArg, 0 }, + { "-binary", ".binary", XrmoptionSepArg, 0 }, { 0, 0, 0, 0 } };