#include "screenhack.h"
#include "simulator.h"
-
-// TODO: What should I do about this define? I would like to be able to specify the address so I can do things like display the code itself if nothign interesting happens in RAM.
-#define HEAP_START_ADDRESS 0x20000000
+#include "ned_programs/embedded_ned_program_declarations.h"
/* -------------------------------------------------------------------------- */
/* Front Panel Layout */
// if the display were using a 72 point helvetica font without emphasis.
char * current_font;
+ // Contains the address of the top of the heap window. In total, the heap
+ // window will display from `heap_window_offset` to
+ // `heap_window_offset+num_data_rows`.
+ uint32_t heap_window_offset;
+
// This struct contains all machine state for the simulated NED computer.
struct NEDstate * nedstate;
};
}
};
+// Each instance of this struct will describe a single NED1 program embedded in
+// NEDsim as a binary blob. See `ned_programs/README.md` for details.
+struct ned_program {
+ const uint8_t * binary_blob; // Pointer to raw NED1 machine code
+ const size_t * blob_size; // Size of raw NED1 machine code
+ uint32_t heap_window_offset; // Location of window into NED system RAM
+};
+
+// All NED1 programs embedded in NEDsim should be manually added to this array.
+// See `ned_programs/README.md` for details.
+static struct ned_program ned_programs[] = {
+ {
+ integer_stack,
+ &integer_stack_size,
+ 0x20000000
+ }
+};
+
/* -------------------------------------------------------------------------- */
/* Helper Functions */
/* -------------------------------------------------------------------------- */
// Draw the heap lights.
for (int i = 0; i < nedsim->num_data_rows; i++) {
draw_wordline_lights(nedsim,
- ram_r_word(nedsim->nedstate, HEAP_START_ADDRESS+(i*BPW)),
+ ram_r_word(nedsim->nedstate, nedsim->heap_window_offset+(i*BPW)),
HEAP_X_OFFSET, HEAP_Y_OFFSET+HEAP_LABEL_HEIGHT+i
);
}
HEAP_WIDTH, HEAP_LABEL_HEIGHT, False
);
char address[11];
- snprintf(address, sizeof(address), "0x%08X", HEAP_START_ADDRESS);
+ snprintf(address, sizeof(address), "0x%08X", nedsim->heap_window_offset);
draw_text(nedsim, address, (HEAP_X_OFFSET+(HEAP_WIDTH/2)+1), HEAP_Y_OFFSET,
HEAP_WIDTH, HEAP_LABEL_HEIGHT, False
);
free(nedsim->nedstate);
}
- // TODO: Replace all this with proper code to free everything related to the screensaver itself.
XFreeGC(nedsim->dpy, nedsim->gc);
XFreePixmap(nedsim->dpy, nedsim->panel);
free(nedsim);
// 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");
+ size_t id = random() % sizeof(ned_programs)/sizeof(ned_programs[0]);
+ nedsim->nedstate = init_simulator(NULL, ned_programs[id].binary_blob, ned_programs[id].blob_size);
+ nedsim->heap_window_offset = ned_programs[id].heap_window_offset;
} else {
- nedsim->nedstate = init_simulator(input_file);
+ nedsim->nedstate = init_simulator(input_file, NULL, 0);
+ // Note: Since we're accepting this as a runtime CLI option, we really
+ // should verify that `heap_window_offset+num_data_rows` doesn't exceed
+ // the limits of NED's simulated RAM. However, since the RAM size is a
+ // #define located in the simulator itself, and since I mostly plan to
+ // use this screensaver with built-in programs, for now we'll just let
+ // it segfault if the user requests a window outside simulated RAM.
+ nedsim->heap_window_offset = get_integer_resource(nedsim->dpy, "heapwindow", "Integer");
}
// If the user did not select a color scheme, select one randomly.
static const char * NEDsim_defaults[] = {
"*delay: 250",
- "*color: -1",
+ "*color: -1",
+ "*heapwindow: 0x20000000",
0
};
{ "-delay", ".delay", XrmoptionSepArg, 0 },
{ "-binary", ".binary", XrmoptionSepArg, 0 },
{ "-color", ".color", XrmoptionSepArg, 0 },
+ { "-heapwindow", ".heapwindow", XrmoptionSepArg, 0 },
{ 0, 0, 0, 0 }
};