/* -------------------------------------------------------------------------- */
struct NEDsim {
- /* Various X resources */
+ // Various X resources
Display * dpy;
Window win;
GC gc;
- // TODO: Explain these
+ // Tracks the width and height (in pixels) of 'win' on 'dpy'.
int dpy_width, dpy_height;
- // TODO: Explain that this is created during init, then lights are populated/overwritten on each frame.
+ // To ensure the NED display is always synchronized/valid, we
+ // double-buffer. This is that buffer.
Pixmap panel;
- /* Delay (in microseconds) between clock cycles in the NED CPU. */
- size_t delay;
-
+ // The front panel is defined in a fixed grid of 'cells' which are then
+ // scaled and projected onto the actual screen. This variable tracks the
+ // size of one 'cell' in screen pixels.
int cell_size;
+ // Like above, this variable tracks the scaled size (in pixels) of cell
+ // borders when projecting them on the screen.
int border_size;
+
+ // Since the panel will be smaller than the display window, these two
+ // variable track the location (in pixels) of the upper left corner of the
+ // NED panel (pretending it didn't have rounded corners) relative to the
+ // display window's origin.
int origin_x_offset, origin_y_offset;
+
+ // Delay (in microseconds) between clock cycles in the NED CPU.
+ size_t delay;
+
+ // Since the heap and stack areas are resized to fit the display, this
+ // variable tracks their height.
int num_data_rows;
+ // This is an index into the color_list[] array, selecting a color scheme.
size_t color_index;
+ // If the display is unsuitable (e.g. too small), this boolean is 'true'.
+ // With this, we blank the display but keep the simulation itself running,
+ // allowing the ongoing simulation to display when the situation is
+ // corrected, and allowing us to avoid boring the user with unnecessary
+ // simulation restarts.
Bool suitable_display;
+ // The font size is dynamically adjusted based on display size. This
+ // variable stores the full font description, including the correct font
+ // size, all in the X11 font specifier format. For example,
+ // -*-helvetica-*-r-*-*-72-*-*-*-*-*-*-*
+ // if the display were using a 72 point helvetica font without emphasis.
char * current_font;
- // TODO: Explain that this contains all the actual state of the NED machine being simulated.
+ // This struct contains all machine state for the simulated NED computer.
struct NEDstate * nedstate;
};
struct color_rgb {
- // TODO: Explain why this is an unsigned short. Copy from WolframAutomata.
+ // The type 'unsigned short' comes from the XColor struct definition.
+ // The red, green, and blue values are always in the range 0 to 65535
+ // inclusive, independent of the number of bits actually used in the
+ // display hardware. The server scales these values to the range used
+ // by the hardware. Black is represented by (0,0,0), and white is
+ // represented by (65535,65535,65535).
unsigned short red, green, blue;
};
struct color_scheme {
- // TODO: Explain all this.
+ // The following entries define a full color scheme for a NED panel.
struct color_rgb
- panel_bg,
- panel_fg,
- light_on,
- light_off,
- error_on,
- error_off,
- primary,
- secondary,
- tertiary,
- border,
- text;
+ panel_bg, // Empty screen space not taken up by the panel
+ panel_fg, // Panel body/faceplate
+ light_on, // Illuminated data indicator
+ light_off, // Non-illuminated data indicator
+ error_on, // Illuminated error indicator
+ error_off, // Non-illuminated error indicator
+ primary, // Primary panel color (see: logo background)
+ secondary, // Secondary panel color (see: "HALT" text background)
+ tertiary, // Tertiary panel color (see: "subgeniuskitty.com" text background)
+ border, // Cell borders
+ text; // Panel text
};
+// All included color schemes for NEDsim are defined in this array. To select a
+// particular color scheme at runtime, use the `-color N` CLI option.
static struct color_scheme color_list[] = {
- // TODO: Explain all this.
- // TODO: Add other color schemes, like purple PDP-11/70.
- // TODO: http://www.chdickman.com/pdp8/DECcolors/
- {
+ { // This color scheme is inspired by the KI10 version of the PDP-10.
+ // Many RGB values came from: http://www.chdickman.com/pdp8/DECcolors/
{63479,63479,63479}, // 092-XXXX-123
{ 5140, 2056, 5654}, // 092-XXXX-152
- {65535,11051,15677}, // 092-XXXX-139 - edit
- {20000,13107,12850}, // 092-XXXX-154 - edit
- {65535,13107,12850}, // homemade
- {20000,13107,12850}, // 092-XXXX-154 - edit
+ {65535,11051,15677}, // homemade, derived from 092-XXXX-139
+ {20000,13107,12850}, // homemade, derived from 092-XXXX-154
+ {65535,13107,12850}, // homemade, derived from 092-XXXX-154
+ {20000,13107,12850}, // homemade, derived from 092-XXXX-154
{ 4112,12850,20046}, // 092-XXXX-145
{12336,29555,37008}, // 092-XXXX-151
{30326,24158, 6425}, // 092-XXXX-157
{63479,63479,63479}, // 092-XXXX-123
{63479,63479,63479} // 092-XXXX-123
+ },
+ { // This color scheme is (very loosely) inspired by the first version of the PDP-11/70.
+ // Many RGB values came from: http://www.chdickman.com/pdp8/DECcolors/
+ {63479,63479,63479}, // 092-XXXX-123
+ { 5140, 2056, 5654}, // 092-XXXX-152
+ {51400,34952,26682}, // homemade, derived from 092-XXXX-136
+ {20000,13107,12850}, // homemade, derived from 092-XXXX-154
+ {65535,13107,12850}, // homemade, derived from 092-XXXX-154
+ {20000,13107,12850}, // homemade, derived from 092-XXXX-154
+ {28270, 8995,19532}, // 092-XXXX-140
+ {40092,11051,15677}, // 092-XXXX-139
+ {15000,21000, 4000}, // homemade, derived from 092-XXXX-129
+ {63479,63479,63479}, // 092-XXXX-123
+ {63479,63479,63479} // 092-XXXX-123
}
};
nedsim->gc = XCreateGC(nedsim->dpy, nedsim->win, GCForeground, &gcv);
nedsim->panel = XCreatePixmap(nedsim->dpy, nedsim->win, nedsim->dpy_width, nedsim->dpy_height, xgwa.depth);
- // TODO: Do this properly.
- nedsim->color_index = 0;
+ // If the user specified a color, use it. Otherwise, select at random from
+ // the available color schemes.
+ nedsim->color_index = get_integer_resource(nedsim->dpy, "color", "Integer");
+ if (nedsim->color_index == -1) {
+ nedsim->color_index = random() % sizeof(color_list)/sizeof(color_list[0]);
+ } else if (nedsim->color_index >= sizeof(color_list)/sizeof(color_list[0])) {
+ fprintf(stderr, "WARNING: Color index out of range.\n");
+ nedsim->color_index = 0;
+ }
// TODO: Save the GIMP reference diagram somewhere, along with notes about the size/spacing, and that each cell is 10 pixels across in the reference image.
static const char * NEDsim_defaults[] = {
"*delay: 250",
+ "*color: -1",
0
};
static XrmOptionDescRec NEDsim_options[] = {
{ "-delay", ".delay", XrmoptionSepArg, 0 },
{ "-binary", ".binary", XrmoptionSepArg, 0 },
+ { "-color", ".color", XrmoptionSepArg, 0 },
{ 0, 0, 0, 0 }
};