Minor cleanup of helper functions in NEDsim.
[screensavers] / hacks / NEDsim / NEDsim.c
CommitLineData
84b74595
AT
1/* (c) 2021 Aaron Taylor <ataylor at subgeniuskitty dot com> */
2/* See LICENSE.txt file for copyright and license details. */
3
84b74595
AT
4#include "screenhack.h"
5#include "simulator.h"
6
28edd14e
AT
7/* -------------------------------------------------------------------------- */
8/* Front Panel Layout */
9/* -------------------------------------------------------------------------- */
10
11// All of these values are in units of 'cells', not 'pixels'. Where applicable,
12// coordinates refer to the upper-left corner of a cell. See the files
13// `layout_reference.*` for details.
14
15#define OVERALL_WIDTH_IN_CELLS 70
16#define HEADER_HEIGHT_IN_CELLS 14
17#define FOOTER_HEIGHT_IN_CELLS 2
18
19#define LOGO_X_OFFSET 2
20#define LOGO_Y_OFFSET 2
21#define LOGO_WIDTH 20
22#define LOGO_NAME_HEIGHT 6
23#define LOGO_WEBSITE_HEIGHT 2
24
25#define HALT_X_OFFSET 26
26#define HALT_Y_OFFSET 2
27#define HALT_WIDTH 6
28#define HALT_LIGHT_HEIGHT 6
29#define HALT_LABEL_HEIGHT 2
30
31#define WORDLINE_BITS_PER_STRIPE 4
32#define WORDLINE_WIDTH 32
33#define WORDLINE_HEIGHT 1
34
35#define PC_X_OFFSET 36
36#define PC_Y_OFFSET 7
37#define PC_WIDTH 32
38#define PC_LABEL_HEIGHT 2
39#define PC_LIGHT_HEIGHT 1
40
41#define SC_X_OFFSET 42
42#define SC_Y_OFFSET 2
43#define SC_WIDTH 5
44#define SC_LABEL_HEIGHT 2
45#define SC_LIGHT_HEIGHT 1
46
47#define PSW_N_X_OFFSET 51
48#define PSW_Z_X_OFFSET 58
49#define PSW_Y_OFFSET 2
50#define PSW_LABEL_WIDTH 3
51#define PSW_LABEL_HEIGHT 2
52#define PSW_LIGHT_WIDTH 1
53#define PSW_LIGHT_HEIGHT 1
54
55#define STACK_X_OFFSET 2
56#define STACK_Y_OFFSET 12
57#define STACK_WIDTH 32
58#define STACK_LABEL_HEIGHT 2
59#define STACK_LIGHT_HEIGHT 1
60
61#define HEAP_X_OFFSET 36
62#define HEAP_Y_OFFSET 12
63#define HEAP_WIDTH 32
64#define HEAP_LABEL_HEIGHT 2
65#define HEAP_LIGHT_HEIGHT 1
66
84b74595
AT
67/* -------------------------------------------------------------------------- */
68/* Data Structures */
69/* -------------------------------------------------------------------------- */
70
71struct NEDsim {
f93fc861 72 // Various X resources
84b74595
AT
73 Display * dpy;
74 Window win;
75 GC gc;
76
f93fc861 77 // Tracks the width and height (in pixels) of 'win' on 'dpy'.
84b74595
AT
78 int dpy_width, dpy_height;
79
f93fc861
AT
80 // To ensure the NED display is always synchronized/valid, we
81 // double-buffer. This is that buffer.
84b74595
AT
82 Pixmap panel;
83
f93fc861
AT
84 // The front panel is defined in a fixed grid of 'cells' which are then
85 // scaled and projected onto the actual screen. This variable tracks the
86 // size of one 'cell' in screen pixels.
84b74595 87 int cell_size;
f93fc861
AT
88 // Like above, this variable tracks the scaled size (in pixels) of cell
89 // borders when projecting them on the screen.
84b74595 90 int border_size;
f93fc861
AT
91
92 // Since the panel will be smaller than the display window, these two
93 // variable track the location (in pixels) of the upper left corner of the
94 // NED panel (pretending it didn't have rounded corners) relative to the
95 // display window's origin.
84b74595 96 int origin_x_offset, origin_y_offset;
f93fc861
AT
97
98 // Delay (in microseconds) between clock cycles in the NED CPU.
99 size_t delay;
100
101 // Since the heap and stack areas are resized to fit the display, this
102 // variable tracks their height.
84b74595
AT
103 int num_data_rows;
104
f93fc861 105 // This is an index into the color_list[] array, selecting a color scheme.
84b74595
AT
106 size_t color_index;
107
f93fc861
AT
108 // If the display is unsuitable (e.g. too small), this boolean is 'true'.
109 // With this, we blank the display but keep the simulation itself running,
110 // allowing the ongoing simulation to display when the situation is
111 // corrected, and allowing us to avoid boring the user with unnecessary
112 // simulation restarts.
84b74595
AT
113 Bool suitable_display;
114
f93fc861
AT
115 // The font size is dynamically adjusted based on display size. This
116 // variable stores the full font description, including the correct font
117 // size, all in the X11 font specifier format. For example,
118 // -*-helvetica-*-r-*-*-72-*-*-*-*-*-*-*
119 // if the display were using a 72 point helvetica font without emphasis.
84b74595
AT
120 char * current_font;
121
f93fc861 122 // This struct contains all machine state for the simulated NED computer.
84b74595
AT
123 struct NEDstate * nedstate;
124};
125
126struct color_rgb {
f93fc861
AT
127 // The type 'unsigned short' comes from the XColor struct definition.
128 // The red, green, and blue values are always in the range 0 to 65535
129 // inclusive, independent of the number of bits actually used in the
130 // display hardware. The server scales these values to the range used
131 // by the hardware. Black is represented by (0,0,0), and white is
132 // represented by (65535,65535,65535).
84b74595
AT
133 unsigned short red, green, blue;
134};
135
136struct color_scheme {
f93fc861 137 // The following entries define a full color scheme for a NED panel.
84b74595 138 struct color_rgb
f93fc861
AT
139 panel_bg, // Empty screen space not taken up by the panel
140 panel_fg, // Panel body/faceplate
141 light_on, // Illuminated data indicator
142 light_off, // Non-illuminated data indicator
143 error_on, // Illuminated error indicator
144 error_off, // Non-illuminated error indicator
145 primary, // Primary panel color (see: logo background)
146 secondary, // Secondary panel color (see: "HALT" text background)
147 tertiary, // Tertiary panel color (see: "subgeniuskitty.com" text background)
148 border, // Cell borders
149 text; // Panel text
84b74595
AT
150};
151
f93fc861
AT
152// All included color schemes for NEDsim are defined in this array. To select a
153// particular color scheme at runtime, use the `-color N` CLI option.
84b74595 154static struct color_scheme color_list[] = {
f93fc861
AT
155 { // This color scheme is inspired by the KI10 version of the PDP-10.
156 // Many RGB values came from: http://www.chdickman.com/pdp8/DECcolors/
84b74595
AT
157 {63479,63479,63479}, // 092-XXXX-123
158 { 5140, 2056, 5654}, // 092-XXXX-152
f93fc861
AT
159 {65535,11051,15677}, // homemade, derived from 092-XXXX-139
160 {20000,13107,12850}, // homemade, derived from 092-XXXX-154
161 {65535,13107,12850}, // homemade, derived from 092-XXXX-154
162 {20000,13107,12850}, // homemade, derived from 092-XXXX-154
84b74595
AT
163 { 4112,12850,20046}, // 092-XXXX-145
164 {12336,29555,37008}, // 092-XXXX-151
165 {30326,24158, 6425}, // 092-XXXX-157
166 {63479,63479,63479}, // 092-XXXX-123
167 {63479,63479,63479} // 092-XXXX-123
f93fc861
AT
168 },
169 { // This color scheme is (very loosely) inspired by the first version of the PDP-11/70.
170 // Many RGB values came from: http://www.chdickman.com/pdp8/DECcolors/
171 {63479,63479,63479}, // 092-XXXX-123
172 { 5140, 2056, 5654}, // 092-XXXX-152
173 {51400,34952,26682}, // homemade, derived from 092-XXXX-136
174 {20000,13107,12850}, // homemade, derived from 092-XXXX-154
175 {65535,13107,12850}, // homemade, derived from 092-XXXX-154
176 {20000,13107,12850}, // homemade, derived from 092-XXXX-154
177 {28270, 8995,19532}, // 092-XXXX-140
178 {40092,11051,15677}, // 092-XXXX-139
179 {15000,21000, 4000}, // homemade, derived from 092-XXXX-129
180 {63479,63479,63479}, // 092-XXXX-123
181 {63479,63479,63479} // 092-XXXX-123
84b74595
AT
182 }
183};
184
185/* -------------------------------------------------------------------------- */
186/* Helper Functions */
187/* -------------------------------------------------------------------------- */
188
280460e6 189// Set foreground color for the current graphics context.
84b74595
AT
190static void
191set_color(struct NEDsim * nedsim, struct color_rgb * color)
192{
193 XColor temp;
194 XWindowAttributes xgwa;
195
196 XGetWindowAttributes(nedsim->dpy, nedsim->win, &xgwa);
197
198 temp.red = color->red;
199 temp.green = color->green;
200 temp.blue = color->blue;
201
202 XAllocColor(nedsim->dpy, xgwa.colormap, &temp);
203 XSetForeground(nedsim->dpy, nedsim->gc, temp.pixel);
204}
205
84b74595 206// TODO: Make this a lot faster.
280460e6 207// Set font size to fill 'size' cells vertically, minus space for border and padding.
84b74595
AT
208static void
209set_font_size(struct NEDsim * nedsim, int size)
210{
211 // vvv--- for border ---vvv vvv--- for padding ---vvv
212 int desired_height_in_pixels = (size * nedsim->cell_size) - (2 * nedsim->border_size) - (8 * nedsim->border_size);
213
214 const char * font_size_prefix = "-*-helvetica-*-r-*-*-";
215 const char * font_size_suffix = "-*-*-*-*-*-*-*";
216
217 size_t buffer_size = strlen(font_size_prefix) + strlen(font_size_suffix) + 100; // '100' since nobody needs font with size in 'points' greater than 100 decimal digits long.
218 char * font_full_name = malloc(buffer_size);
219 int font_size_in_points = 2; // Start with a 2 pt font and work our way up.
220
221 while (1) {
222 // Load the font.
223 snprintf(font_full_name, buffer_size, "%s%d%s", font_size_prefix, font_size_in_points, font_size_suffix);
224 XFontStruct * font = XLoadQueryFont(nedsim->dpy, font_full_name);
225 if (!font) {
226 printf("WARNING: Unable to load font %s. Probably gonna look wonky.\n", font_full_name);
227 font = XLoadQueryFont(nedsim->dpy, "fixed");
228 break;
229 }
230 XSetFont(nedsim->dpy, nedsim->gc, font->fid);
231
232 // Get the height.
233 int direction, ascent, descent;
234 XCharStruct overall;
235 XTextExtents(font, "X", 1, &direction, &ascent, &descent, &overall);
236
237 // Compare the height.
238 int height = overall.ascent - overall.descent;
239 if (height == desired_height_in_pixels) {
240 break;
241 } else if (height > desired_height_in_pixels) {
242 font_size_in_points--;
243 snprintf(font_full_name, buffer_size, "%s%d%s", font_size_prefix, font_size_in_points, font_size_suffix);
244 XFontStruct * font = XLoadQueryFont(nedsim->dpy, font_full_name);
245 if (!font) {
246 printf("WARNING: Unable to load font %s. Probably gonna look wonky.\n", font_full_name);
247 font = XLoadQueryFont(nedsim->dpy, "fixed");
248 break;
249 }
250 XSetFont(nedsim->dpy, nedsim->gc, font->fid);
251 break;
252 } else {
253 font_size_in_points++;
254 }
255 }
256
257 free(nedsim->current_font);
258 nedsim->current_font = font_full_name;
259}
260
280460e6
AT
261// Unlike most functions in this program that input/output in units of 'cells',
262// this function uses units of 'pixels' so the caller can track fractional cell
263// usage (e.g. for centering the text).
84b74595
AT
264static void
265get_text_size(struct NEDsim * nedsim, const char * text, int * x_size, int * y_size)
266{
267 int direction, ascent, descent;
268 XCharStruct overall;
269 XFontStruct * font = XLoadQueryFont(nedsim->dpy, nedsim->current_font);
270 XTextExtents(font, text, strlen(text), &direction, &ascent, &descent, &overall);
271 *x_size = overall.width;
272 *y_size = overall.ascent - overall.descent;
273}
274
280460e6
AT
275// When specifying the rectangular area to draw, all coordinates and sizes are
276// in units of 'cells'. Also, be aware that this function alters the
277// foreground color.
84b74595
AT
278static void
279draw_rect_area(struct NEDsim * nedsim, size_t x_origin, size_t y_origin, size_t x_size, size_t y_size,
280 Bool bord_top, Bool bord_bottom, Bool bord_left, Bool bord_right)
281{
280460e6 282 // First fill in the rectangular area...
84b74595
AT
283 x_origin *= nedsim->cell_size;
284 x_origin += nedsim->origin_x_offset;
285 y_origin *= nedsim->cell_size;
286 y_origin += nedsim->origin_y_offset;
287 x_size *= nedsim->cell_size;
288 y_size *= nedsim->cell_size;
839b757b 289 XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc, x_origin, y_origin, x_size, y_size);
84b74595 290
280460e6 291 // ...then give it a border, if requested.
84b74595
AT
292 set_color(nedsim, &color_list[nedsim->color_index].border);
293 if (bord_top) {
280460e6
AT
294 XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc,
295 x_origin, y_origin, x_size, nedsim->border_size);
84b74595
AT
296 }
297 if (bord_bottom) {
280460e6
AT
298 XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc,
299 x_origin, (y_origin + y_size - nedsim->border_size), x_size, nedsim->border_size);
84b74595
AT
300 }
301 if (bord_left) {
280460e6
AT
302 XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc,
303 x_origin, y_origin, nedsim->border_size, y_size);
84b74595
AT
304 }
305 if (bord_right) {
280460e6
AT
306 XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc,
307 (x_origin + x_size - nedsim->border_size), y_origin, nedsim->border_size, y_size);
84b74595
AT
308 }
309}
310
280460e6
AT
311// Draws filled circle in a square area with upper left corner at x,y. When
312// specifying the location and size to draw, all values are in units of
313// 'cells'. Also, be aware that this function alters the foreground color.
84b74595
AT
314static void
315draw_circular_area(struct NEDsim * nedsim, size_t x, size_t y, double diameter)
316{
317 // First, convert the function argument units from 'cells' to 'pixels'
318 x *= nedsim->cell_size;
319 y *= nedsim->cell_size;
320 diameter *= nedsim->cell_size;
321
322 // Add the panel's absolute x,y offset to the requested coordinates.
323 x += nedsim->origin_x_offset;
324 y += nedsim->origin_y_offset;
325
326 // Shrink the circle to be a bit smaller than the bounding box allows. Note
327 // that the three adjustment values must sum to 1.0.
328 // For example, 0.7 + 0.15 + 0.15 = 1.0.
329 x += (0.15 * diameter);
330 y += (0.15 * diameter);
331 diameter *= 0.7;
332
333 // Because we only draw the bottom border on repeated rows (e.g. draw_wordline()),
334 // we need to offset vertically by half a border height.
335 y -= (0.5 * nedsim->border_size);
336
337 // Start angle 0 and ending angle 360*64 is one full circle in Xlib units.
839b757b 338 XFillArc(nedsim->dpy, nedsim->panel, nedsim->gc, x, y, diameter, diameter, 0, 360*64);
84b74595
AT
339}
340
280460e6
AT
341// Draws the panel itself. Not the lights/labels/etc, but the flat sheet of
342// metal that is the front panel.
84b74595
AT
343static void
344draw_panel(struct NEDsim * nedsim)
345{
84b74595
AT
346 // Draw background color over entire window.
347 set_color(nedsim, &color_list[nedsim->color_index].panel_bg);
839b757b 348 XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc, 0, 0, nedsim->dpy_width, nedsim->dpy_height);
84b74595
AT
349
350 // Draw NED panel in foreground color.
351 set_color(nedsim, &color_list[nedsim->color_index].panel_fg);
839b757b 352 XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc,
84b74595
AT
353 nedsim->origin_x_offset,
354 nedsim->origin_y_offset,
355 nedsim->cell_size * OVERALL_WIDTH_IN_CELLS,
356 nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + nedsim->num_data_rows + FOOTER_HEIGHT_IN_CELLS)
357 );
a98a69c1
AT
358
359 // Give the panel rounded corners by first deleting the four right-angle corners...
360 set_color(nedsim, &color_list[nedsim->color_index].panel_bg);
839b757b 361 XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc,
a98a69c1
AT
362 nedsim->origin_x_offset,
363 nedsim->origin_y_offset,
364 nedsim->cell_size,
365 nedsim->cell_size
366 );
839b757b 367 XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc,
a98a69c1
AT
368 nedsim->origin_x_offset + (nedsim->cell_size * (OVERALL_WIDTH_IN_CELLS-1)),
369 nedsim->origin_y_offset,
370 nedsim->cell_size,
371 nedsim->cell_size
372 );
839b757b 373 XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc,
a98a69c1
AT
374 nedsim->origin_x_offset,
375 nedsim->origin_y_offset + (nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + nedsim->num_data_rows + FOOTER_HEIGHT_IN_CELLS - 1)),
376 nedsim->cell_size,
377 nedsim->cell_size
378 );
839b757b 379 XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc,
a98a69c1
AT
380 nedsim->origin_x_offset + (nedsim->cell_size * (OVERALL_WIDTH_IN_CELLS-1)),
381 nedsim->origin_y_offset + (nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + nedsim->num_data_rows + FOOTER_HEIGHT_IN_CELLS - 1)),
382 nedsim->cell_size,
383 nedsim->cell_size
384 );
385 // ...and then replacing them with filled arcs, forming rounded corners.
386 set_color(nedsim, &color_list[nedsim->color_index].panel_fg);
839b757b 387 XFillArc(nedsim->dpy, nedsim->panel, nedsim->gc,
a98a69c1
AT
388 nedsim->origin_x_offset,
389 nedsim->origin_y_offset,
390 nedsim->cell_size * 2, nedsim->cell_size * 2,
391 180*64, -90*64
392 );
839b757b 393 XFillArc(nedsim->dpy, nedsim->panel, nedsim->gc,
a98a69c1
AT
394 nedsim->origin_x_offset + (nedsim->cell_size * (OVERALL_WIDTH_IN_CELLS-2)),
395 nedsim->origin_y_offset,
396 nedsim->cell_size * 2, nedsim->cell_size * 2,
397 0, 90*64
398 );
839b757b 399 XFillArc(nedsim->dpy, nedsim->panel, nedsim->gc,
a98a69c1
AT
400 nedsim->origin_x_offset,
401 nedsim->origin_y_offset + (nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + nedsim->num_data_rows + FOOTER_HEIGHT_IN_CELLS - 2)),
402 nedsim->cell_size * 2, nedsim->cell_size * 2,
403 180*64, 90*64
404 );
839b757b 405 XFillArc(nedsim->dpy, nedsim->panel, nedsim->gc,
a98a69c1
AT
406 nedsim->origin_x_offset + (nedsim->cell_size * (OVERALL_WIDTH_IN_CELLS-2)),
407 nedsim->origin_y_offset + (nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + nedsim->num_data_rows + FOOTER_HEIGHT_IN_CELLS - 2)),
408 nedsim->cell_size * 2, nedsim->cell_size * 2,
409 0, -90*64
410 );
84b74595
AT
411}
412
280460e6 413// Draw the "NED" and "subgeniuskitty.com" logos on the front panel.
84b74595
AT
414static void
415draw_logo(struct NEDsim * nedsim)
416{
84b74595
AT
417 // First draw the two colored boxes that comprise the logo area.
418 set_color(nedsim, &color_list[nedsim->color_index].primary);
419 draw_rect_area(nedsim, LOGO_X_OFFSET, LOGO_Y_OFFSET, LOGO_WIDTH, LOGO_NAME_HEIGHT, True, True, False, False);
420 set_color(nedsim, &color_list[nedsim->color_index].tertiary);
421 draw_rect_area(nedsim, LOGO_X_OFFSET, LOGO_Y_OFFSET+LOGO_NAME_HEIGHT, LOGO_WIDTH, LOGO_WEBSITE_HEIGHT, False, True, False, False);
422
423 // Now draw the 'NED' text in the top box.
424 set_color(nedsim, &color_list[nedsim->color_index].text);
425 set_font_size(nedsim, LOGO_NAME_HEIGHT);
426 int text_x_size, text_y_size;
427 get_text_size(nedsim, "NED", &text_x_size, &text_y_size);
428 int local_x_offset = ((LOGO_WIDTH * nedsim->cell_size) - text_x_size) / 2;
429 int local_y_offset = ((LOGO_NAME_HEIGHT * nedsim->cell_size) - text_y_size) / 2;
839b757b 430 XDrawString(nedsim->dpy, nedsim->panel, nedsim->gc, (LOGO_X_OFFSET * nedsim->cell_size + nedsim->origin_x_offset + local_x_offset),
84b74595
AT
431 ((LOGO_Y_OFFSET+LOGO_NAME_HEIGHT) * nedsim->cell_size + nedsim->origin_y_offset - local_y_offset), "NED", 3);
432
433 // And draw the 'subgeniuskitty.com' text in the bottom box.
434 set_font_size(nedsim, LOGO_WEBSITE_HEIGHT);
435 get_text_size(nedsim, "subgeniuskitty.com", &text_x_size, &text_y_size);
436 local_x_offset = ((LOGO_WIDTH * nedsim->cell_size) - text_x_size) / 2;
437 local_y_offset = ((LOGO_WEBSITE_HEIGHT * nedsim->cell_size) - text_y_size) / 2;
839b757b 438 XDrawString(nedsim->dpy, nedsim->panel, nedsim->gc, (LOGO_X_OFFSET * nedsim->cell_size + nedsim->origin_x_offset + local_x_offset),
84b74595
AT
439 ((LOGO_Y_OFFSET+LOGO_NAME_HEIGHT+LOGO_WEBSITE_HEIGHT) * nedsim->cell_size + nedsim->origin_y_offset - local_y_offset), "subgeniuskitty.com", 18);
440}
441
280460e6 442// Draw the HALT indicator area on the front panel.
84b74595
AT
443static void
444draw_halt(struct NEDsim * nedsim)
445{
84b74595
AT
446 // First draw the two colored boxes that comprise the halt area.
447 set_color(nedsim, &color_list[nedsim->color_index].tertiary);
448 draw_rect_area(nedsim, HALT_X_OFFSET, HALT_Y_OFFSET, HALT_WIDTH, HALT_LIGHT_HEIGHT, True, True, False, False);
449 set_color(nedsim, &color_list[nedsim->color_index].secondary);
450 draw_rect_area(nedsim, HALT_X_OFFSET, HALT_Y_OFFSET+HALT_LIGHT_HEIGHT, HALT_WIDTH, HALT_LABEL_HEIGHT, False, True, False, False);
451
452 // And finally, draw the label.
453 set_color(nedsim, &color_list[nedsim->color_index].text);
454 int text_x_size, text_y_size;
455 get_text_size(nedsim, "HALT", &text_x_size, &text_y_size);
456 int local_x_offset = ((HALT_WIDTH * nedsim->cell_size) - text_x_size) / 2;
457 int local_y_offset = ((HALT_LABEL_HEIGHT * nedsim->cell_size) - text_y_size) / 2;
839b757b 458 XDrawString(nedsim->dpy, nedsim->panel, nedsim->gc, (HALT_X_OFFSET * nedsim->cell_size + nedsim->origin_x_offset + local_x_offset),
84b74595
AT
459 ((HALT_Y_OFFSET+HALT_LIGHT_HEIGHT+HALT_LABEL_HEIGHT) * nedsim->cell_size + nedsim->origin_y_offset - local_y_offset), "HALT", 4);
460}
461
280460e6
AT
462// Draw the 32 lights corresponding to 'word' at coordinates ('x','y').
463// Note that this function ONLY draws the lights and is used each frame for
464// updating the panel. To draw the wordline area itself, use draw_wordline().
84b74595
AT
465static void
466draw_wordline_lights(struct NEDsim * nedsim, uint32_t word, int x, int y)
467{
84b74595
AT
468 for (int i = 0; i < WORDLINE_WIDTH; i++) {
469 if (word & (1<<(WORDLINE_WIDTH-1-i))) {
470 set_color(nedsim, &color_list[nedsim->color_index].light_on);
471 } else {
472 set_color(nedsim, &color_list[nedsim->color_index].light_off);
473 }
474 draw_circular_area(nedsim, x+i, y, WORDLINE_HEIGHT);
475 }
476}
477
280460e6
AT
478// Draw a single 32-bit NED word line at coordinates ('x','y').
479// Note that this draws a wordline with value 0. To update with a specific
480// value, call draw_wordline_lights() after drawing the wordline area at least
481// once.
84b74595
AT
482static void
483draw_wordline(struct NEDsim * nedsim, int x, int y)
484{
485 // First, draw a solid box in the primary color over the entire wordline area.
486 set_color(nedsim, &color_list[nedsim->color_index].primary);
487 draw_rect_area(nedsim, x, y, WORDLINE_WIDTH, WORDLINE_HEIGHT, False, True, False, False);
488
489 // Now, draw stripes in the secondary color.
490 int i;
491 for (i = 0; i < (WORDLINE_WIDTH/(2*WORDLINE_BITS_PER_STRIPE)); i++) {
492 set_color(nedsim, &color_list[nedsim->color_index].secondary);
493 draw_rect_area(nedsim, (x+(i*(WORDLINE_WIDTH/WORDLINE_BITS_PER_STRIPE))), y,
494 WORDLINE_BITS_PER_STRIPE, WORDLINE_HEIGHT, False, True, False, False);
495 }
496
497 // Finally, draw the lights.
498 draw_wordline_lights(nedsim, 0, x, y);
499}
500
280460e6 501// Draw the Program Counter area (but don't populate it yet).
84b74595
AT
502static void
503draw_pc(struct NEDsim * nedsim)
504{
84b74595
AT
505 // First draw the two colored boxes that comprise the PC area.
506 set_color(nedsim, &color_list[nedsim->color_index].tertiary);
507 draw_rect_area(nedsim, PC_X_OFFSET, PC_Y_OFFSET, PC_WIDTH, PC_LABEL_HEIGHT, True, True, False, False);
508 draw_wordline(nedsim, PC_X_OFFSET, PC_Y_OFFSET+PC_LABEL_HEIGHT);
509
510 // Now draw the label text "PC".
511 set_color(nedsim, &color_list[nedsim->color_index].text);
512 int text_x_size, text_y_size;
513 get_text_size(nedsim, "PC", &text_x_size, &text_y_size);
514 int local_x_offset = ((PC_WIDTH * nedsim->cell_size) - text_x_size) / 2;
515 int local_y_offset = ((PC_LABEL_HEIGHT * nedsim->cell_size) - text_y_size) / 2;
839b757b 516 XDrawString(nedsim->dpy, nedsim->panel, nedsim->gc, (PC_X_OFFSET * nedsim->cell_size + nedsim->origin_x_offset + local_x_offset),
84b74595
AT
517 ((PC_Y_OFFSET+PC_LABEL_HEIGHT) * nedsim->cell_size + nedsim->origin_y_offset - local_y_offset), "PC", 2);
518}
519
280460e6 520// Draw the Stack Counter area (but don't populate it yet).
84b74595
AT
521static void
522draw_sc(struct NEDsim * nedsim)
523{
84b74595
AT
524 // First draw the two colored boxes that comprise the SC area.
525 set_color(nedsim, &color_list[nedsim->color_index].secondary);
526 draw_rect_area(nedsim, SC_X_OFFSET, SC_Y_OFFSET, SC_WIDTH, SC_LABEL_HEIGHT, True, True, False, False);
527 set_color(nedsim, &color_list[nedsim->color_index].tertiary);
528 draw_rect_area(nedsim, SC_X_OFFSET, SC_Y_OFFSET+SC_LABEL_HEIGHT, SC_WIDTH, SC_LIGHT_HEIGHT, False, True, False, False);
529
530 // Now draw the label text "SC".
531 set_color(nedsim, &color_list[nedsim->color_index].text);
532 int text_x_size, text_y_size;
533 get_text_size(nedsim, "SC", &text_x_size, &text_y_size);
534 int local_x_offset = ((SC_WIDTH * nedsim->cell_size) - text_x_size) / 2;
535 int local_y_offset = ((SC_LABEL_HEIGHT * nedsim->cell_size) - text_y_size) / 2;
839b757b 536 XDrawString(nedsim->dpy, nedsim->panel, nedsim->gc, (SC_X_OFFSET * nedsim->cell_size + nedsim->origin_x_offset + local_x_offset),
84b74595
AT
537 ((SC_Y_OFFSET+SC_LABEL_HEIGHT) * nedsim->cell_size + nedsim->origin_y_offset - local_y_offset), "SC", 2);
538}
539
280460e6 540// Draw areas for the two PSW flags, 'Z'ero and 'N'egative.
84b74595
AT
541static void
542draw_psw(struct NEDsim * nedsim)
543{
84b74595
AT
544 // First draw the four colored boxes that comprise the two PSW areas.
545 set_color(nedsim, &color_list[nedsim->color_index].secondary);
546 draw_rect_area(nedsim, PSW_N_X_OFFSET, PSW_Y_OFFSET, PSW_LABEL_WIDTH, PSW_LABEL_HEIGHT, True, True, False, False);
547 set_color(nedsim, &color_list[nedsim->color_index].secondary);
548 draw_rect_area(nedsim, PSW_Z_X_OFFSET, PSW_Y_OFFSET, PSW_LABEL_WIDTH, PSW_LABEL_HEIGHT, True, True, False, False);
549 set_color(nedsim, &color_list[nedsim->color_index].tertiary);
550 draw_rect_area(nedsim, (PSW_N_X_OFFSET + 1), PSW_Y_OFFSET+PSW_LABEL_HEIGHT, PSW_LIGHT_WIDTH, PSW_LIGHT_HEIGHT, False, True, False, False);
551 set_color(nedsim, &color_list[nedsim->color_index].tertiary);
552 draw_rect_area(nedsim, (PSW_Z_X_OFFSET + 1), PSW_Y_OFFSET+PSW_LABEL_HEIGHT, PSW_LIGHT_WIDTH, PSW_LIGHT_HEIGHT, False, True, False, False);
553
554 // Now draw the label text "N".
555 set_color(nedsim, &color_list[nedsim->color_index].text);
556 int text_x_size, text_y_size;
557 get_text_size(nedsim, "N", &text_x_size, &text_y_size);
558 int local_x_offset = ((PSW_LABEL_WIDTH * nedsim->cell_size) - text_x_size) / 2;
559 int local_y_offset = ((PSW_LABEL_HEIGHT * nedsim->cell_size) - text_y_size) / 2;
839b757b 560 XDrawString(nedsim->dpy, nedsim->panel, nedsim->gc, (PSW_N_X_OFFSET * nedsim->cell_size + nedsim->origin_x_offset + local_x_offset),
84b74595
AT
561 ((PSW_Y_OFFSET+PSW_LABEL_HEIGHT) * nedsim->cell_size + nedsim->origin_y_offset - local_y_offset), "N", 1);
562
563 // Now draw the label text "Z".
564 set_color(nedsim, &color_list[nedsim->color_index].text);
565 get_text_size(nedsim, "Z", &text_x_size, &text_y_size);
566 local_x_offset = ((PSW_LABEL_WIDTH * nedsim->cell_size) - text_x_size) / 2;
567 local_y_offset = ((PSW_LABEL_HEIGHT * nedsim->cell_size) - text_y_size) / 2;
839b757b 568 XDrawString(nedsim->dpy, nedsim->panel, nedsim->gc, (PSW_Z_X_OFFSET * nedsim->cell_size + nedsim->origin_x_offset + local_x_offset),
84b74595
AT
569 ((PSW_Y_OFFSET+PSW_LABEL_HEIGHT) * nedsim->cell_size + nedsim->origin_y_offset - local_y_offset), "Z", 1);
570}
571
280460e6 572// Draw the stack area (but don't populate it yet).
84b74595
AT
573static void
574draw_stack(struct NEDsim * nedsim)
575{
84b74595
AT
576 // First draw the two colored boxes that comprise the stack area.
577 set_color(nedsim, &color_list[nedsim->color_index].tertiary);
578 draw_rect_area(nedsim, STACK_X_OFFSET, STACK_Y_OFFSET, STACK_WIDTH, STACK_LABEL_HEIGHT, True, True, False, False);
579 for (int i = 0; i < nedsim->num_data_rows; i++) {
580 draw_wordline(nedsim, STACK_X_OFFSET, STACK_Y_OFFSET+STACK_LABEL_HEIGHT+i);
581 }
582
583 // Now draw the label text "Stack Size:".
584 set_color(nedsim, &color_list[nedsim->color_index].text);
585 int text_x_size, text_y_size;
586 get_text_size(nedsim, "Stack Size:", &text_x_size, &text_y_size);
587 int local_y_offset = ((STACK_LABEL_HEIGHT * nedsim->cell_size) - text_y_size) / 2;
839b757b 588 XDrawString(nedsim->dpy, nedsim->panel, nedsim->gc, ((STACK_X_OFFSET + 1) * nedsim->cell_size + nedsim->origin_x_offset),
84b74595
AT
589 ((STACK_Y_OFFSET+STACK_LABEL_HEIGHT) * nedsim->cell_size + nedsim->origin_y_offset - local_y_offset), "Stack Size:", 11);
590}
591
280460e6 592// Draw the heap area (but don't populate it yet).
84b74595
AT
593static void
594draw_heap(struct NEDsim * nedsim)
595{
84b74595
AT
596// 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.
597#define HEAP_START_ADDRESS 0x20000000
598
599 // First draw the two colored boxes that comprise the heap area.
600 set_color(nedsim, &color_list[nedsim->color_index].tertiary);
601 draw_rect_area(nedsim, HEAP_X_OFFSET, HEAP_Y_OFFSET, HEAP_WIDTH, HEAP_LABEL_HEIGHT, True, True, False, False);
602 for (int i = 0; i < nedsim->num_data_rows; i++) {
603 draw_wordline(nedsim, HEAP_X_OFFSET, HEAP_Y_OFFSET+HEAP_LABEL_HEIGHT+i);
604 }
605
606 // Now draw the label text "RAM Base:".
607 set_color(nedsim, &color_list[nedsim->color_index].text);
608 int text_x_size, text_y_size;
609 get_text_size(nedsim, "RAM Base:", &text_x_size, &text_y_size);
610 int local_y_offset = ((HEAP_LABEL_HEIGHT * nedsim->cell_size) - text_y_size) / 2;
839b757b 611 XDrawString(nedsim->dpy, nedsim->panel, nedsim->gc, ((HEAP_X_OFFSET + 1) * nedsim->cell_size + nedsim->origin_x_offset),
84b74595
AT
612 ((HEAP_Y_OFFSET+HEAP_LABEL_HEIGHT) * nedsim->cell_size + nedsim->origin_y_offset - local_y_offset), "RAM Base:", 9);
613
614 // Now draw the address text.
615 set_color(nedsim, &color_list[nedsim->color_index].text);
616 char address[11];
617 snprintf(address, sizeof(address), "0x%08X", HEAP_START_ADDRESS);
618 get_text_size(nedsim, address, &text_x_size, &text_y_size);
619 local_y_offset = ((HEAP_LABEL_HEIGHT * nedsim->cell_size) - text_y_size) / 2;
839b757b 620 XDrawString(nedsim->dpy, nedsim->panel, nedsim->gc, ((HEAP_X_OFFSET + 1 + (HEAP_WIDTH / 2)) * nedsim->cell_size + nedsim->origin_x_offset),
84b74595
AT
621 ((HEAP_Y_OFFSET+HEAP_LABEL_HEIGHT) * nedsim->cell_size + nedsim->origin_y_offset - local_y_offset), address, strlen(address));
622}
623
280460e6
AT
624// After the static front panel has been drawn at least once, this function
625// updates all the dynamic parts of the panel (lights + text values) and is
626// called every frame.
84b74595
AT
627static void
628update_display(struct NEDsim * nedsim)
629{
630 // Draw the halt indicator.
631 if (nedsim->nedstate->halted) {
632 set_color(nedsim, &color_list[nedsim->color_index].error_on);
633 } else {
634 set_color(nedsim, &color_list[nedsim->color_index].error_off);
635 }
636 draw_circular_area(nedsim, HALT_X_OFFSET, HALT_Y_OFFSET, HALT_WIDTH);
637
638 // Draw the PSW "N" light.
639 if (nedsim->nedstate->active_thread->psw->negative) {
640 set_color(nedsim, &color_list[nedsim->color_index].light_on);
641 } else {
642 set_color(nedsim, &color_list[nedsim->color_index].light_off);
643 }
644 draw_circular_area(nedsim, PSW_N_X_OFFSET+1, PSW_Y_OFFSET+PSW_LABEL_HEIGHT, PSW_LIGHT_HEIGHT);
645
646 // Draw the PSW "Z" light.
647 if (nedsim->nedstate->active_thread->psw->zero) {
648 set_color(nedsim, &color_list[nedsim->color_index].light_on);
649 } else {
650 set_color(nedsim, &color_list[nedsim->color_index].light_off);
651 }
652 draw_circular_area(nedsim, PSW_Z_X_OFFSET+1, PSW_Y_OFFSET+PSW_LABEL_HEIGHT, PSW_LIGHT_HEIGHT);
653
654
655 // Draw the SC.
656 int i;
657 for (i = 0; i < SC_WIDTH; i++) {
658 if ((SC_WIDTH-1-i) == nedsim->nedstate->active_thread->sc) {
659 set_color(nedsim, &color_list[nedsim->color_index].light_on);
660 } else {
661 set_color(nedsim, &color_list[nedsim->color_index].light_off);
662 }
663 draw_circular_area(nedsim, SC_X_OFFSET+i, SC_Y_OFFSET+SC_LABEL_HEIGHT, SC_LIGHT_HEIGHT);
664 }
665
666 // Draw the PC.
667 draw_wordline_lights(nedsim, nedsim->nedstate->active_thread->pc, PC_X_OFFSET, PC_Y_OFFSET+PC_LABEL_HEIGHT);
668
669 // Draw the stack lights.
670 int64_t top_of_stack = ((int64_t)nedsim->nedstate->active_thread->sp) - 1;
671 for (i = 0; i < nedsim->num_data_rows; i++) {
672 if ((top_of_stack-i) >= 0) {
673 draw_wordline_lights(nedsim, nedsim->nedstate->active_thread->stack[top_of_stack-i], STACK_X_OFFSET, STACK_Y_OFFSET+STACK_LABEL_HEIGHT+i);
674 } else {
675 draw_wordline_lights(nedsim, 0, STACK_X_OFFSET, STACK_Y_OFFSET+STACK_LABEL_HEIGHT+i);
676 }
677 }
678
679 // Draw the stack size in text.
680 set_color(nedsim, &color_list[nedsim->color_index].tertiary);
681 draw_rect_area(nedsim, STACK_X_OFFSET+(STACK_WIDTH/2), STACK_Y_OFFSET, STACK_WIDTH/2, STACK_LABEL_HEIGHT, True, True, False, False);
682 set_color(nedsim, &color_list[nedsim->color_index].text);
683 char stack_size[11];
684 snprintf(stack_size, sizeof(stack_size), "0x%08X", nedsim->nedstate->active_thread->sp);
685 int text_x_size, text_y_size;
686 get_text_size(nedsim, stack_size, &text_x_size, &text_y_size);
687 int local_y_offset = ((STACK_LABEL_HEIGHT * nedsim->cell_size) - text_y_size) / 2;
839b757b 688 XDrawString(nedsim->dpy, nedsim->panel, nedsim->gc, ((STACK_X_OFFSET + 1 + (STACK_WIDTH / 2)) * nedsim->cell_size + nedsim->origin_x_offset),
84b74595
AT
689 ((STACK_Y_OFFSET+STACK_LABEL_HEIGHT) * nedsim->cell_size + nedsim->origin_y_offset - local_y_offset), stack_size, strlen(stack_size));
690
691 // Draw the heap lights.
692 for (i = 0; i < nedsim->num_data_rows; i++) {
693 draw_wordline_lights(nedsim, ram_r_word(nedsim->nedstate, HEAP_START_ADDRESS+(i*BPW)), HEAP_X_OFFSET, HEAP_Y_OFFSET+HEAP_LABEL_HEIGHT+i);
694 }
695}
696
697/* -------------------------------------------------------------------------- */
698/* Screenhack API Functions */
699/* -------------------------------------------------------------------------- */
700
701static Bool
702NEDsim_event(Display * dpy, Window win, void * closure, XEvent * event)
703{
704 return False;
705}
706
707static void
708NEDsim_free(Display * dpy, Window win, void * closure)
709{
84b74595 710 struct NEDsim * nedsim = closure;
d87b1e06
AT
711
712 if (nedsim->nedstate != NULL) {
713 free(nedsim->nedstate->active_thread->psw);
714 free(nedsim->nedstate->active_thread);
715 free(nedsim->nedstate->hack);
716 free(nedsim->nedstate);
717 }
718
719 // TODO: Replace all this with proper code to free everything related to the screensaver itself.
84b74595 720 XFreeGC(nedsim->dpy, nedsim->gc);
839b757b 721 XFreePixmap(nedsim->dpy, nedsim->panel);
84b74595
AT
722 free(nedsim);
723}
724
725static void *
726NEDsim_init(Display * dpy, Window win)
727{
2c7168ae
AT
728 // =========================================================================
729 // Basic Setup
730 // =========================================================================
731
84b74595 732 struct NEDsim * nedsim;
84b74595
AT
733
734 nedsim = calloc(1, sizeof(*nedsim));
735 if (!nedsim) {
736 fprintf(stderr, "ERROR: Failed to calloc() for NEDsim struct in NEDsim_init().\n");
737 exit(EXIT_FAILURE);
738 }
739
740 nedsim->dpy = dpy;
741 nedsim->win = win;
742
2c7168ae
AT
743 XGCValues gcv;
744 nedsim->gc = XCreateGC(nedsim->dpy, nedsim->win, GCForeground, &gcv);
745
746 XWindowAttributes xgwa;
84b74595
AT
747 XGetWindowAttributes(nedsim->dpy, nedsim->win, &xgwa);
748 nedsim->dpy_width = xgwa.width;
749 nedsim->dpy_height = xgwa.height;
750
2c7168ae
AT
751 nedsim->panel = XCreatePixmap(nedsim->dpy, nedsim->win, nedsim->dpy_width, nedsim->dpy_height, xgwa.depth);
752
753 // =========================================================================
754 // Process User Requests
755 // =========================================================================
756
84b74595
AT
757 nedsim->delay = get_integer_resource(nedsim->dpy, "delay", "Integer");
758 nedsim->delay *= 1000; /* Turn milliseconds into microseconds. */
759
2c7168ae
AT
760 // If the user did not supply a program for execution, randomly select one
761 // of the included programs.
5923644e
AT
762 char * input_file = get_string_resource(nedsim->dpy, "binary", "String");
763 if (input_file == NULL) {
764 // TODO: Need to include some default programs and randomly select one to load into RAM.
765 nedsim->nedstate = init_simulator("./test.out");
766 } else {
767 nedsim->nedstate = init_simulator(input_file);
768 }
84b74595 769
2c7168ae 770 // If the user did not select a color scheme, select one randomly.
f93fc861
AT
771 nedsim->color_index = get_integer_resource(nedsim->dpy, "color", "Integer");
772 if (nedsim->color_index == -1) {
773 nedsim->color_index = random() % sizeof(color_list)/sizeof(color_list[0]);
774 } else if (nedsim->color_index >= sizeof(color_list)/sizeof(color_list[0])) {
775 fprintf(stderr, "WARNING: Color index out of range.\n");
776 nedsim->color_index = 0;
777 }
84b74595 778
2c7168ae
AT
779 // =========================================================================
780 // Scale Panel To Screen
781 // =========================================================================
84b74595 782
2c7168ae
AT
783 // We desire to make the panel as wide as possible while also making the
784 // cell size an integer pixel size.
785 nedsim->cell_size = nedsim->dpy_width / OVERALL_WIDTH_IN_CELLS;
786 // Cell sizes below about 10 pixels result in unreadable fonts. For now,
787 // we'll use that as our cutoff. It also works well with a 1:10 border:cell
788 // ratio.
84b74595
AT
789 if (nedsim->cell_size < 10) {
790 nedsim->suitable_display = False;
791 return nedsim;
792 }
2c7168ae
AT
793 // Center the panel horizontally.
794 nedsim->origin_x_offset = (nedsim->dpy_width -
795 (nedsim->cell_size * OVERALL_WIDTH_IN_CELLS)) / 2;
796
797 // The stack and heap displays are variable height. Size them to fit the
798 // display window.
799 int available_space_for_data_rows = nedsim->dpy_height -
800 (nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + FOOTER_HEIGHT_IN_CELLS));
84b74595
AT
801 for (int i = 0; ; i++) {
802 if ((nedsim->cell_size * (1 << i)) > available_space_for_data_rows) {
803 nedsim->num_data_rows = (1 << --i);
804 break;
805 }
806 }
2c7168ae 807 // Enforce a minimum vertical size, though '4' is arbitrary.
84b74595
AT
808 if (nedsim->num_data_rows < 4) {
809 nedsim->suitable_display = False;
810 return nedsim;
811 }
2c7168ae
AT
812 // Center the panel vertically.
813 nedsim->origin_y_offset = (nedsim->dpy_height -
814 (nedsim->cell_size * (HEADER_HEIGHT_IN_CELLS + nedsim->num_data_rows + FOOTER_HEIGHT_IN_CELLS))) / 2;
84b74595
AT
815
816 // Scale border relative to cell_size in a 1:10 relationship.
817 nedsim->border_size = nedsim->cell_size / 10;
818
2c7168ae
AT
819 // =========================================================================
820 // Draw Initial Panel
821 // =========================================================================
822
84b74595
AT
823 draw_panel(nedsim);
824 draw_logo(nedsim);
825 draw_halt(nedsim);
826 draw_pc(nedsim);
827 draw_sc(nedsim);
828 draw_psw(nedsim);
829 draw_stack(nedsim);
830 draw_heap(nedsim);
831
832 nedsim->suitable_display = True;
833
834 return nedsim;
835}
836
837static unsigned long
838NEDsim_draw(Display * dpy, Window win, void * closure)
839{
840 struct NEDsim * nedsim = closure;
841
2c7168ae 842 // Update the panel display buffer.
84b74595
AT
843 if (nedsim->suitable_display) {
844 nedsim->nedstate = run_simulator(nedsim->nedstate);
845 update_display(nedsim);
846 } else {
847 set_color(nedsim, &color_list[nedsim->color_index].error_on);
839b757b 848 XFillRectangle(nedsim->dpy, nedsim->panel, nedsim->gc, 0, 0, nedsim->dpy_width, nedsim->dpy_height);
84b74595
AT
849 }
850
2c7168ae 851 // Copy panel buffer to display window.
839b757b
AT
852 XCopyArea(nedsim->dpy, nedsim->panel, nedsim->win, nedsim->gc, 0, 0, nedsim->dpy_width, nedsim->dpy_height, 0, 0);
853
84b74595
AT
854 return nedsim->delay;
855}
856
857static void
858NEDsim_reshape(Display * dpy, Window win, void * closure, unsigned int w, unsigned int h)
859{
860 struct NEDsim * nedsim = closure;
2c7168ae
AT
861
862 // Only re-initialize the display if it changed size.
84b74595
AT
863 XWindowAttributes xgwa;
864 XGetWindowAttributes(nedsim->dpy, nedsim->win, &xgwa);
84b74595 865 if (nedsim->dpy_width != xgwa.width || nedsim->dpy_height != xgwa.height) {
2c7168ae
AT
866 // Although we are re-initializing the display, we wish to retain the
867 // in-progress NED simulation. Thus, we retain the NEDstate pointer.
503470d7
AT
868 struct NEDstate * original_nedstate = nedsim->nedstate;
869 nedsim->nedstate = NULL;
870 NEDsim_free(dpy, win, nedsim);
871 struct NEDsim * new_nedsim = NEDsim_init(dpy, win);
872 new_nedsim->nedstate = original_nedstate;
873 closure = new_nedsim;
84b74595
AT
874 }
875}
876
877static const char * NEDsim_defaults[] = {
878 "*delay: 250",
f93fc861 879 "*color: -1",
84b74595
AT
880 0
881};
882
883static XrmOptionDescRec NEDsim_options[] = {
884 { "-delay", ".delay", XrmoptionSepArg, 0 },
5923644e 885 { "-binary", ".binary", XrmoptionSepArg, 0 },
f93fc861 886 { "-color", ".color", XrmoptionSepArg, 0 },
84b74595
AT
887 { 0, 0, 0, 0 }
888};
889
890XSCREENSAVER_MODULE ("Blinken-lights simulator for NED1 CPU architecture.", NEDsim)