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