e520433ad5cd4f4788d035d9078715dfec3ebfaa
[xscreensaver] / hacks / bsod.c
1 /* xscreensaver, Copyright (c) 1998-2006 Jamie Zawinski <jwz@jwz.org>
2  *
3  * Permission to use, copy, modify, distribute, and sell this software and its
4  * documentation for any purpose is hereby granted without fee, provided that
5  * the above copyright notice appear in all copies and that both that
6  * copyright notice and this permission notice appear in supporting
7  * documentation.  No representations are made about the suitability of this
8  * software for any purpose.  It is provided "as is" without express or 
9  * implied warranty.
10  *
11  * Blue Screen of Death: the finest in personal computer emulation.
12  * Concept cribbed from Stephen Martin <smartin@mks.com>;
13  * this version written by jwz, 4-Jun-98.
14  * Mostly rewritten by jwz, 20-Feb-2006.
15  */
16
17
18 /* To add a new mode:
19
20     - Define a function `new_os(dpy,win)' that returns a `bsod_state' struct.
21     - Draw on the window to set up its frame-zero state.  This must be fast:
22       no sleeping or long loops!
23     - Populate the bsod_state structure with additional actions to take by
24       using the various BSOD_ macros.  Note that you can control the delays
25       when printing text on a per-character or per-line basis.
26     - Insert your function in the `all_modes' table.
27     - Add a `doXXX' entry to `bsod_defaults'.
28     - Add fonts or colors to `bsod_defaults' if necessary.
29
30    Look at windows_31() for a simple example.
31
32    Look at linux_fsck() for a more complicated example with random behavior.
33
34    Or, you can bypass all that: look at nvidia() for a really hairy example.
35  */
36
37
38 #include "screenhack.h"
39 #include "xpm-pixmap.h"
40 #include "apple2.h"
41
42 #include <ctype.h>
43
44 #ifdef HAVE_XSHM_EXTENSION
45 #include "xshm.h"
46 #endif
47
48 #ifdef HAVE_UNAME
49 # include <sys/utsname.h>
50 #endif /* HAVE_UNAME */
51
52 #if defined(HAVE_GDK_PIXBUF) || defined(HAVE_XPM) || defined(HAVE_COCOA)
53 # define DO_XPM
54 #endif
55
56 #ifdef DO_XPM
57 # include "images/amiga.xpm"
58 # include "images/hmac.xpm"
59 # include "images/osx_10_2.xpm"
60 # include "images/osx_10_3.xpm"
61 #endif
62 #include "images/atari.xbm"
63 #include "images/mac.xbm"
64 #include "images/macbomb.xbm"
65 #include "images/atm.xbm"
66
67 #undef countof
68 #define countof(x) (sizeof((x))/sizeof((*x)))
69
70 #undef EOF
71 typedef enum { EOF=0, 
72                LEFT, CENTER, RIGHT, 
73                LEFT_FULL, CENTER_FULL, RIGHT_FULL, 
74                COLOR, INVERT, MOVETO, MARGINS,
75                CURSOR_BLOCK, CURSOR_LINE, RECT, COPY, PIXMAP, IMG,
76                PAUSE, CHAR_DELAY, LINE_DELAY,
77                LOOP
78 } bsod_event_type;
79
80 struct bsod_event {
81   bsod_event_type type;
82   void *arg1, *arg2, *arg3, *arg4, *arg5, *arg6;
83 };
84
85 struct bsod_state {
86   Display *dpy;
87   Window window;
88   XWindowAttributes xgwa;
89   XFontStruct *font;
90   unsigned long fg, bg;
91   GC gc;
92   int left_margin, right_margin;        /* for text wrapping */
93   int top_margin, bottom_margin;        /* for text scrolling */
94   Bool wrap_p;
95   Bool scroll_p;
96
97   Pixmap pixmap;                /* Source image used by BSOD_PIXMAP */
98
99   int x, y;                     /* current text-drawing position */
100   int current_left;             /* don't use this */
101
102   int pos;                      /* position in queue */
103   int queue_size;
104   struct bsod_event *queue;
105
106   unsigned long char_delay;     /* delay between printing characters */
107   unsigned long line_delay;     /* delay between printing lines */
108
109   Bool macx_eol_kludge;
110
111   void *closure;
112   int  (*draw_cb) (struct bsod_state *);
113   void (*free_cb) (struct bsod_state *);
114
115   async_load_state *img_loader;
116 };
117
118
119 # if !defined(__GNUC__) && !defined(__extension__)
120   /* don't warn about "string length is greater than the length ISO C89
121      compilers are required to support" in these string constants... */
122 #  define  __extension__ /**/
123 # endif
124
125
126 /* Draw text at the current position; align is LEFT, CENTER, RIGHT, or *_FULL
127    (meaning to clear the whole line margin to margin).
128  */
129 #define BSOD_TEXT(bst,align,string) do { \
130   ensure_queue (bst); \
131   (bst)->queue[(bst)->pos].type = (align); \
132   (bst)->queue[(bst)->pos].arg1 = (void *) strdup (__extension__ (string)); \
133   (bst)->queue[(bst)->pos].arg2 = (bst)->queue[(bst)->pos].arg1; \
134   (bst)->queue[(bst)->pos].arg3 = (void *) 0; \
135   (bst)->pos++; \
136   } while (0)
137
138 /* Flip the foreground and background colors
139  */
140 #define BSOD_INVERT(bst) do { \
141   ensure_queue (bst); \
142   (bst)->queue[(bst)->pos].type = INVERT; \
143   (bst)->pos++; \
144   } while (0)
145
146 /* Set the foreground and background colors to the given pixels
147  */
148 #define BSOD_COLOR(bst,fg,bg) do { \
149   ensure_queue (bst); \
150   (bst)->queue[(bst)->pos].type = COLOR; \
151   (bst)->queue[(bst)->pos].arg1 = (void *) fg; \
152   (bst)->queue[(bst)->pos].arg2 = (void *) bg; \
153   (bst)->pos++; \
154   } while (0)
155
156 /* Set the position of the next text.
157    Note that this is the baseline: lower left corner of next char printed.
158  */
159 #define BSOD_MOVETO(bst,x,y) do { \
160   ensure_queue (bst); \
161   (bst)->queue[(bst)->pos].type = MOVETO; \
162   (bst)->queue[(bst)->pos].arg1 = (void *) ((long) (x)); \
163   (bst)->queue[(bst)->pos].arg2 = (void *) ((long) (y)); \
164   (bst)->pos++; \
165   } while (0)
166
167 /* Delay for at least the given number of microseconds.
168  */
169 #define BSOD_PAUSE(bst,usec) do { \
170   ensure_queue (bst); \
171   (bst)->queue[(bst)->pos].type = PAUSE; \
172   (bst)->queue[(bst)->pos].arg1 = (void *) ((long) (usec)); \
173   (bst)->pos++; \
174   } while (0)
175
176 /* Set the delay after each character is printed.
177  */
178 #define BSOD_CHAR_DELAY(bst,usec) do { \
179   ensure_queue (bst); \
180   (bst)->queue[(bst)->pos].type = CHAR_DELAY; \
181   (bst)->queue[(bst)->pos].arg1 = (void *) ((long) (usec)); \
182   (bst)->pos++; \
183   } while (0)
184
185 /* Set the delay after each newline.
186  */
187 #define BSOD_LINE_DELAY(bst,usec) do { \
188   ensure_queue (bst); \
189   (bst)->queue[(bst)->pos].type = LINE_DELAY; \
190   (bst)->queue[(bst)->pos].arg1 = (void *) (usec); \
191   (bst)->pos++; \
192   } while (0)
193
194 /* Set the prevailing left/right margins (used when strings have
195    embedded newlines, and when centering or right-justifying text.)
196  */
197 #define BSOD_MARGINS(bst,left,right) do { \
198   ensure_queue (bst); \
199   (bst)->queue[(bst)->pos].type = MARGINS; \
200   (bst)->queue[(bst)->pos].arg1 = (void *) ((long) (left)); \
201   (bst)->queue[(bst)->pos].arg2 = (void *) ((long) (right)); \
202   (bst)->pos++; \
203   } while (0)
204
205 /* Draw a blinking cursor; type is CURSOR_BLOCK or CURSOR_LINE.
206    usec is how long 1/2 of a cycle is.  count is how many times to blink.
207    (You can pass a gigantic number if this is the last thing in your mode.)
208  */
209 #define BSOD_CURSOR(bst,ctype,usec,count) do { \
210   ensure_queue (bst); \
211   (bst)->queue[(bst)->pos].type = (ctype); \
212   (bst)->queue[(bst)->pos].arg1 = (void *) (usec); \
213   (bst)->queue[(bst)->pos].arg2 = (void *) (count); \
214   (bst)->pos++; \
215   } while (0)
216
217 /* Draw or fill a rectangle.  You can set line-width in the GC.
218  */
219 #define BSOD_RECT(bst,fill,x,y,w,h) do { \
220   ensure_queue (bst); \
221   (bst)->queue[(bst)->pos].type = RECT; \
222   (bst)->queue[(bst)->pos].arg1 = (void *) ((long) (fill)); \
223   (bst)->queue[(bst)->pos].arg2 = (void *) ((long) (x)); \
224   (bst)->queue[(bst)->pos].arg3 = (void *) ((long) (y)); \
225   (bst)->queue[(bst)->pos].arg4 = (void *) ((long) (w)); \
226   (bst)->queue[(bst)->pos].arg5 = (void *) ((long) (h)); \
227   (bst)->pos++; \
228   } while (0)
229
230 /* Copy a rect from the window, to the window.
231  */
232 #define BSOD_COPY(bst,srcx,srcy,w,h,tox,toy) do { \
233   ensure_queue (bst); \
234   (bst)->queue[(bst)->pos].type = COPY; \
235   (bst)->queue[(bst)->pos].arg1 = (void *) ((long) (srcx)); \
236   (bst)->queue[(bst)->pos].arg2 = (void *) ((long) (srcy)); \
237   (bst)->queue[(bst)->pos].arg3 = (void *) ((long) (w)); \
238   (bst)->queue[(bst)->pos].arg4 = (void *) ((long) (h)); \
239   (bst)->queue[(bst)->pos].arg5 = (void *) ((long) (tox)); \
240   (bst)->queue[(bst)->pos].arg6 = (void *) ((long) (toy)); \
241   (bst)->pos++; \
242   } while (0)
243
244 /* Copy a rect from bst->pixmap to the window.
245  */
246 #define BSOD_PIXMAP(bst,srcx,srcy,w,h,tox,toy) do { \
247   BSOD_COPY(bst,srcx,srcy,w,h,tox,toy); \
248   (bst)->queue[(bst)->pos-1].type = PIXMAP; \
249   } while (0)
250
251 /* Load a random image (or the desktop) onto the window.
252  */
253 #define BSOD_IMG(bst) do { \
254   ensure_queue (bst); \
255   (bst)->queue[(bst)->pos].type = IMG; \
256   (bst)->pos++; \
257   } while (0)
258
259 /* Jump around in the state table.  You can use this as the last thing 
260    in your state table to repeat the last N elements forever.
261  */
262 #define BSOD_LOOP(bst,off) do { \
263   ensure_queue (bst); \
264   (bst)->queue[(bst)->pos].type = LOOP; \
265   (bst)->queue[(bst)->pos].arg1 = (void *) (off); \
266   (bst)->pos++; \
267   } while (0)
268
269
270 static void
271 ensure_queue (struct bsod_state *bst)
272 {
273   int n;
274   if (bst->pos + 1 < bst->queue_size)
275     return;
276
277   n = bst->queue_size + 10;
278   if (n < 100) n *= 2;
279   n *= 1.2;
280
281   bst->queue = (struct bsod_event *) 
282     realloc (bst->queue, n * sizeof(*bst->queue));
283   if (!bst->queue) abort();
284   memset (bst->queue + bst->queue_size, 0, 
285           (n - bst->queue_size) * sizeof(*bst->queue));
286   bst->queue_size = n;
287 }
288
289
290 static void
291 position_for_text (struct bsod_state *bst, const char *line)
292 {
293   int max_width = 0;
294
295   const char *start = line;
296
297   if (bst->queue[bst->pos].type != LEFT &&
298       bst->queue[bst->pos].type != LEFT_FULL)
299     while (*start)
300       {
301         int dir, ascent, descent;
302         XCharStruct ov;
303         const char *end = start;
304         while (*end && *end != '\r' && *end != '\n')
305           end++;
306
307         XTextExtents (bst->font, start, end-start,
308                       &dir, &ascent, &descent, &ov);
309         if (ov.width > max_width)
310           max_width = ov.width;
311         if (!*end) break;
312         start = end+1;
313       }
314
315   switch (bst->queue[bst->pos].type) {
316   case LEFT:
317   case LEFT_FULL:
318     bst->current_left = bst->left_margin;
319     break;
320   case RIGHT:
321   case RIGHT_FULL:
322     bst->x = max_width - bst->right_margin;
323     bst->current_left = bst->x;
324     break;
325   case CENTER:
326   case CENTER_FULL:
327     {
328       int w = (bst->xgwa.width - bst->left_margin - bst->right_margin -
329                max_width);
330       if (w < 0) w = 0;
331       bst->x = bst->left_margin + (w / 2);
332       bst->current_left = bst->x;
333       break;
334     }
335   default:
336     abort();
337   }
338 }
339
340
341 static void
342 bst_crlf (struct bsod_state *bst)
343 {
344   int lh = bst->font->ascent + bst->font->descent;
345   bst->x = bst->current_left;
346   if (!bst->scroll_p ||
347       bst->y + lh < bst->xgwa.height - bst->bottom_margin)
348     bst->y += lh;
349   else
350     {
351       int w = bst->xgwa.width  - bst->right_margin - bst->left_margin;
352       int h = bst->xgwa.height - bst->top_margin - bst->bottom_margin;
353       XCopyArea (bst->dpy, bst->window, bst->window, bst->gc,
354                  bst->left_margin,
355                  bst->top_margin + lh,
356                  w, h - lh,
357                  bst->left_margin,
358                  bst->top_margin);
359       XClearArea (bst->dpy, bst->window,
360                   bst->left_margin, bst->top_margin + h - lh, w, lh, False);
361     }
362 }
363
364
365 static void
366 draw_char (struct bsod_state *bst, char c)
367 {
368   if (!c)
369     abort();
370   else if (c == '\r')
371     {
372       bst->x = bst->current_left;
373     }
374   else if (c == '\n')
375     {
376       if (bst->macx_eol_kludge)
377         {
378           /* Special case for the weird way OSX crashes print newlines... */
379           XDrawImageString (bst->dpy, bst->window, bst->gc, 
380                             bst->x, bst->y, " ", 1);
381           XDrawImageString (bst->dpy, bst->window, bst->gc, 
382                             bst->x, 
383                             bst->y + bst->font->ascent + bst->font->descent,
384                             " ", 1);
385         }
386       bst_crlf (bst);
387     }
388   else if (c == '\b')   /* backspace */
389     {
390       int cw = (bst->font->per_char
391                 ? bst->font->per_char['n'-bst->font->min_char_or_byte2].width
392                 : bst->font->min_bounds.width);
393       bst->x -= cw;
394       if (bst->x < bst->left_margin)
395         bst->x = bst->left_margin;
396     }
397   else
398     {
399       int dir, ascent, descent;
400       XCharStruct ov;
401       XTextExtents (bst->font, &c, 1, &dir, &ascent, &descent, &ov);
402
403       if (bst->wrap_p && 
404           bst->x + ov.width > bst->xgwa.width - bst->right_margin)
405         bst_crlf (bst);
406
407       XDrawImageString (bst->dpy, bst->window, bst->gc, 
408                         bst->x, bst->y, &c, 1);
409       bst->x += ov.width;
410     }
411 }
412
413
414 static long
415 bsod_pop (struct bsod_state *bst)
416 {
417   bsod_event_type type = bst->queue[bst->pos].type;
418
419   if (bst->draw_cb)
420     return bst->draw_cb (bst);
421
422   if (bst->pos < 0)   /* already done */
423     abort();
424
425   switch (type) {
426
427   case LEFT:   case LEFT_FULL:
428   case CENTER: case CENTER_FULL:
429   case RIGHT:  case RIGHT_FULL:
430     {
431       const char *s = (const char *) bst->queue[bst->pos].arg2;
432       char c;
433
434       if (! *s)
435         {
436           long delay = bst->line_delay;
437           bst->pos++;
438           bst->current_left = bst->left_margin;
439           return delay;
440         }
441
442       if (! bst->queue[bst->pos].arg3)    /* "done once" */
443         {
444           position_for_text (bst, s);
445           bst->queue[bst->pos].type = LEFT;
446
447           if (type == CENTER_FULL ||
448               type == LEFT_FULL ||
449               type == RIGHT_FULL)
450             {
451               XSetForeground (bst->dpy, bst->gc, bst->bg);
452               XFillRectangle (bst->dpy, bst->window, bst->gc,
453                               0,
454                               bst->y - bst->font->ascent,
455                               bst->xgwa.width,
456                               bst->font->ascent + bst->font->descent);
457               XSetForeground (bst->dpy, bst->gc, bst->fg);
458             }
459         }
460
461       c = *s++;
462       draw_char (bst, c);
463       bst->queue[bst->pos].arg2 = (void *) s;
464       bst->queue[bst->pos].arg3 = (void *) 1;  /* "done once" */
465
466       return (c == '\r' || c == '\n'
467               ? bst->line_delay
468               : bst->char_delay);
469     }
470   case INVERT:
471     {
472       unsigned long swap = bst->fg;
473       bst->fg = bst->bg;
474       bst->bg = swap;
475       XSetForeground (bst->dpy, bst->gc, bst->fg);
476       XSetBackground (bst->dpy, bst->gc, bst->bg);
477       bst->pos++;
478       return 0;
479     }
480   case COLOR:
481     {
482       bst->fg = (unsigned long) bst->queue[bst->pos].arg1;
483       bst->bg = (unsigned long) bst->queue[bst->pos].arg2;
484       XSetForeground (bst->dpy, bst->gc, bst->fg);
485       XSetBackground (bst->dpy, bst->gc, bst->bg);
486       bst->pos++;
487       return 0;
488     }
489   case MOVETO:
490     {
491       bst->x = (long) bst->queue[bst->pos].arg1;
492       bst->y = (long) bst->queue[bst->pos].arg2;
493       bst->pos++;
494       return 0;
495     }
496   case RECT:
497     {
498       int f = (long) bst->queue[bst->pos].arg1;
499       int x = (long) bst->queue[bst->pos].arg2;
500       int y = (long) bst->queue[bst->pos].arg3;
501       int w = (long) bst->queue[bst->pos].arg4;
502       int h = (long) bst->queue[bst->pos].arg5;
503       if (f)
504         XFillRectangle (bst->dpy, bst->window, bst->gc, x, y, w, h);
505       else
506         XDrawRectangle (bst->dpy, bst->window, bst->gc, x, y, w, h);
507       bst->pos++;
508       return 0;
509     }
510   case COPY:
511   case PIXMAP:
512     {
513       int srcx = (long) bst->queue[bst->pos].arg1;
514       int srcy = (long) bst->queue[bst->pos].arg2;
515       int w    = (long) bst->queue[bst->pos].arg3;
516       int h    = (long) bst->queue[bst->pos].arg4;
517       int tox  = (long) bst->queue[bst->pos].arg5;
518       int toy  = (long) bst->queue[bst->pos].arg6;
519       XCopyArea (bst->dpy, 
520                  (type == PIXMAP ? bst->pixmap : bst->window), 
521                  bst->window, bst->gc,
522                  srcx, srcy, w, h, tox, toy);
523       bst->pos++;
524       return 0;
525     }
526   case IMG:
527     {
528       if (bst->img_loader) abort();
529       bst->img_loader = load_image_async_simple (0, bst->xgwa.screen, 
530                                                  bst->window, bst->window,
531                                                  0, 0);
532       bst->pos++;
533       return 0;
534     }
535   case PAUSE:
536     {
537       long delay = (long) bst->queue[bst->pos].arg1;
538       bst->pos++;
539       return delay;
540     }
541   case CHAR_DELAY:
542     {
543       bst->char_delay = (long) bst->queue[bst->pos].arg1;
544       bst->pos++;
545       return 0;
546     }
547   case LINE_DELAY:
548     {
549       bst->line_delay = (long) bst->queue[bst->pos].arg1;
550       bst->pos++;
551       return 0;
552     }
553   case MARGINS:
554     {
555       bst->left_margin  = (long) bst->queue[bst->pos].arg1;
556       bst->right_margin = (long) bst->queue[bst->pos].arg2;
557       bst->pos++;
558       return 0;
559     }
560   case CURSOR_BLOCK:
561   case CURSOR_LINE:
562     {
563       long delay = (long) bst->queue[bst->pos].arg1;
564       long count = (long) bst->queue[bst->pos].arg2;
565       int ox = bst->x;
566
567       if (type == CURSOR_BLOCK)
568         {
569           unsigned long swap = bst->fg;
570           bst->fg = bst->bg;
571           bst->bg = swap;
572           XSetForeground (bst->dpy, bst->gc, bst->fg);
573           XSetBackground (bst->dpy, bst->gc, bst->bg);
574           draw_char (bst, ' ');
575         }
576       else
577         {
578           draw_char (bst, (count & 1 ? ' ' : '_'));
579           draw_char (bst, ' ');
580         }
581
582       bst->x = ox;
583
584       count--;
585       bst->queue[bst->pos].arg2 = (void *) count;
586       if (count <= 0)
587         bst->pos++;
588
589       return delay;
590     }
591   case LOOP:
592     {
593       long off = (long) bst->queue[bst->pos].arg1;
594       bst->pos += off;
595       if (bst->pos < 0 || bst->pos >= bst->queue_size)
596         abort();
597       return 0;
598     }
599   case EOF:
600     {
601       bst->pos = -1;
602       return -1;
603     }
604   default:
605     break;
606   }
607   abort();
608 }
609
610
611 static struct bsod_state *
612 make_bsod_state (Display *dpy, Window window,
613                  const char *name, const char *class)
614 {
615   XGCValues gcv;
616   struct bsod_state *bst;
617   char buf1[1024], buf2[1024];
618   char buf3[1024], buf4[1024];
619   const char *font1, *font2;
620
621   bst = (struct bsod_state *) calloc (1, sizeof (*bst));
622   bst->queue_size = 10;
623   bst->queue = (struct bsod_event *) calloc (bst->queue_size,
624                                              sizeof (*bst->queue));
625   bst->dpy = dpy;
626   bst->window = window;
627   XGetWindowAttributes (dpy, window, &bst->xgwa);
628
629   /* If the window is small:
630        use ".font" if it is loadable, else use ".font2".
631
632      If the window is big:
633        use ".bigFont" if it is loadable, else use ".bigFont2".
634    */
635   if (bst->xgwa.height < 640)
636     {
637       sprintf (buf1, "%.100s.font", name);
638       sprintf (buf2, "%.100s.font", class);
639       sprintf (buf3, "%.100s.font2", name);
640       sprintf (buf4, "%.100s.font2", class);
641     }
642   else
643     {
644       sprintf (buf1, "%.100s.bigFont", name);
645       sprintf (buf2, "%.100s.bigFont", class);
646       sprintf (buf3, "%.100s.bigFont2", name);
647       sprintf (buf4, "%.100s.bigFont2", class);
648     }
649
650   font1 = get_string_resource (dpy, buf1, buf2);
651   font2 = get_string_resource (dpy, buf3, buf4);
652
653   if (font1)
654     bst->font = XLoadQueryFont (dpy, font1);
655   if (! bst->font && font2)
656     bst->font = XLoadQueryFont (dpy, font2);
657
658   /* If neither of those worked, try some defaults. */
659
660   if (! bst->font)
661     bst->font = XLoadQueryFont (dpy,"-*-courier-bold-r-*-*-*-120-*-*-m-*-*-*");
662   if (! bst->font)
663     bst->font = XLoadQueryFont (dpy, "fixed");
664   if (! bst->font)
665     abort();
666
667   gcv.font = bst->font->fid;
668
669   sprintf (buf1, "%.100s.foreground", name);
670   sprintf (buf2, "%.100s.Foreground", class);
671   bst->fg = gcv.foreground = get_pixel_resource (dpy, bst->xgwa.colormap,
672                                                  buf1, buf2);
673   sprintf (buf1, "%.100s.background", name);
674   sprintf (buf2, "%.100s.Background", class);
675   bst->bg = gcv.background = get_pixel_resource (dpy, bst->xgwa.colormap,
676                                                  buf1, buf2);
677   bst->gc = XCreateGC (dpy, window, GCFont|GCForeground|GCBackground, &gcv);
678
679 #ifdef HAVE_COCOA
680   jwxyz_XSetAntiAliasing (dpy, bst->gc, False);
681 #endif
682
683   bst->left_margin = bst->right_margin = 10;
684   bst->x = bst->left_margin;
685   bst->y = bst->font->ascent + bst->left_margin;
686
687   XSetWindowBackground (dpy, window, gcv.background);
688   return bst;
689 }
690
691
692 static void
693 free_bsod_state (struct bsod_state *bst)
694 {
695   int i;
696
697   if (bst->free_cb)
698     bst->free_cb (bst);
699   if (bst->pixmap)
700     XFreePixmap(bst->dpy, bst->pixmap);
701
702   XFreeFont (bst->dpy, bst->font);
703   XFreeGC (bst->dpy, bst->gc);
704
705   for (i = 0; i < bst->queue_size; i++)
706     switch (bst->queue[i].type) {
707     case LEFT:   case LEFT_FULL:
708     case RIGHT:  case RIGHT_FULL:
709     case CENTER: case CENTER_FULL:
710       free ((char *) bst->queue[i].arg1);
711       break;
712     default:
713       break;
714     }
715
716   free (bst->queue);
717   free (bst);
718 }
719
720
721 static Pixmap
722 double_pixmap (Display *dpy, GC gc, Visual *visual, int depth, Pixmap pixmap,
723                int pix_w, int pix_h)
724 {
725   int x, y;
726   Pixmap p2 = XCreatePixmap(dpy, pixmap, pix_w*2, pix_h*2, depth);
727   XImage *i1 = XGetImage(dpy, pixmap, 0, 0, pix_w, pix_h, ~0L, ZPixmap);
728   XImage *i2 = XCreateImage(dpy, visual, depth, ZPixmap, 0, 0,
729                             pix_w*2, pix_h*2, 8, 0);
730   i2->data = (char *) calloc(i2->height, i2->bytes_per_line);
731   for (y = 0; y < pix_h; y++)
732     for (x = 0; x < pix_w; x++)
733       {
734         unsigned long p = XGetPixel(i1, x, y);
735         XPutPixel(i2, x*2,   y*2,   p);
736         XPutPixel(i2, x*2+1, y*2,   p);
737         XPutPixel(i2, x*2,   y*2+1, p);
738         XPutPixel(i2, x*2+1, y*2+1, p);
739       }
740   free(i1->data); i1->data = 0;
741   XDestroyImage(i1);
742   XPutImage(dpy, p2, gc, i2, 0, 0, 0, 0, i2->width, i2->height);
743   free(i2->data); i2->data = 0;
744   XDestroyImage(i2);
745   XFreePixmap(dpy, pixmap);
746   return p2;
747 }
748
749
750 /*****************************************************************************
751  *****************************************************************************/
752
753 static struct bsod_state *
754 windows_31 (Display *dpy, Window window)
755 {
756   struct bsod_state *bst = make_bsod_state (dpy, window, "windows", "Windows");
757   BSOD_INVERT (bst);
758   BSOD_TEXT   (bst, CENTER, "Windows\n");
759   BSOD_INVERT (bst);
760   BSOD_TEXT   (bst, CENTER,
761                "A fatal exception 0E has occured at F0AD:42494C4C\n"
762                "the current application will be terminated.\n"
763                "\n"
764                "* Press any key to terminate the current application.\n"
765                "* Press CTRL+ALT+DELETE again to restart your computer.\n"
766                "  You will lose any unsaved information in all applications.\n"
767                "\n"
768                "\n");
769   BSOD_TEXT   (bst, CENTER, "Press any key to continue");
770
771   bst->y = ((bst->xgwa.height -
772              ((bst->font->ascent + bst->font->descent) * 9))
773             / 2);
774
775   XClearWindow (dpy, window);
776   return bst;
777 }
778
779
780 static struct bsod_state *
781 windows_nt (Display *dpy, Window window)
782 {
783   struct bsod_state *bst = make_bsod_state (dpy, window, "windows", "Windows");
784
785   BSOD_TEXT (bst, LEFT,
786    "*** STOP: 0x0000001E (0x80000003,0x80106fc0,0x8025ea21,0xfd6829e8)\n"
787    "Unhandled Kernel exception c0000047 from fa8418b4 (8025ea21,fd6829e8)\n"
788    "\n"
789    "Dll Base Date Stamp - Name             Dll Base Date Stamp - Name\n"
790    "80100000 2be154c9 - ntoskrnl.exe       80400000 2bc153b0 - hal.dll\n"
791    "80258000 2bd49628 - ncrc710.sys        8025c000 2bd49688 - SCSIPORT.SYS \n"
792    "80267000 2bd49683 - scsidisk.sys       802a6000 2bd496b9 - Fastfat.sys\n"
793    "fa800000 2bd49666 - Floppy.SYS         fa810000 2bd496db - Hpfs_Rec.SYS\n"
794    "fa820000 2bd49676 - Null.SYS           fa830000 2bd4965a - Beep.SYS\n"
795    "fa840000 2bdaab00 - i8042prt.SYS       fa850000 2bd5a020 - SERMOUSE.SYS\n"
796    "fa860000 2bd4966f - kbdclass.SYS       fa870000 2bd49671 - MOUCLASS.SYS\n"
797    "fa880000 2bd9c0be - Videoprt.SYS       fa890000 2bd49638 - NCC1701E.SYS\n"
798    "fa8a0000 2bd4a4ce - Vga.SYS            fa8b0000 2bd496d0 - Msfs.SYS\n"
799    "fa8c0000 2bd496c3 - Npfs.SYS           fa8e0000 2bd496c9 - Ntfs.SYS\n"
800    "fa940000 2bd496df - NDIS.SYS           fa930000 2bd49707 - wdlan.sys\n"
801    "fa970000 2bd49712 - TDI.SYS            fa950000 2bd5a7fb - nbf.sys\n"
802    "fa980000 2bd72406 - streams.sys        fa9b0000 2bd4975f - ubnb.sys\n"
803    "fa9c0000 2bd5bfd7 - usbser.sys         fa9d0000 2bd4971d - netbios.sys\n"
804    "fa9e0000 2bd49678 - Parallel.sys       fa9f0000 2bd4969f - serial.SYS\n"
805    "faa00000 2bd49739 - mup.sys            faa40000 2bd4971f - SMBTRSUP.SYS\n"
806    "faa10000 2bd6f2a2 - srv.sys            faa50000 2bd4971a - afd.sys\n"
807    "faa60000 2bd6fd80 - rdr.sys            faaa0000 2bd49735 - bowser.sys\n"
808    "\n"
809    "Address dword dump Dll Base                                      - Name\n"
810    "801afc20 80106fc0 80106fc0 00000000 00000000 80149905 : "
811      "fa840000 - i8042prt.SYS\n"
812    "801afc24 80149905 80149905 ff8e6b8c 80129c2c ff8e6b94 : "
813      "8025c000 - SCSIPORT.SYS\n"
814    "801afc2c 80129c2c 80129c2c ff8e6b94 00000000 ff8e6b94 : "
815      "80100000 - ntoskrnl.exe\n"
816    "801afc34 801240f2 80124f02 ff8e6df4 ff8e6f60 ff8e6c58 : "
817      "80100000 - ntoskrnl.exe\n"
818    "801afc54 80124f16 80124f16 ff8e6f60 ff8e6c3c 8015ac7e : "
819      "80100000 - ntoskrnl.exe\n"
820    "801afc64 8015ac7e 8015ac7e ff8e6df4 ff8e6f60 ff8e6c58 : "
821      "80100000 - ntoskrnl.exe\n"
822    "801afc70 80129bda 80129bda 00000000 80088000 80106fc0 : "
823      "80100000 - ntoskrnl.exe\n"
824    "\n"
825    "Kernel Debugger Using: COM2 (Port 0x2f8, Baud Rate 19200)\n"
826    "Restart and set the recovery options in the system control panel\n"
827    "or the /CRASHDEBUG system start option. If this message reappears,\n"
828    "contact your system administrator or technical support group."
829    );
830
831   bst->line_delay = 750;
832
833   XClearWindow (dpy, window);
834   return bst;
835 }
836
837
838 static struct bsod_state *
839 windows_2k (Display *dpy, Window window)
840 {
841   struct bsod_state *bst = make_bsod_state (dpy, window, "windows", "Windows");
842
843   BSOD_TEXT (bst, LEFT,
844     "*** STOP: 0x000000D1 (0xE1D38000,0x0000001C,0x00000000,0xF09D42DA)\n"
845     "DRIVER_IRQL_NOT_LESS_OR_EQUAL \n"
846     "\n"
847     "*** Address F09D42DA base at F09D4000, DateStamp 39f459ff - CRASHDD.SYS\n"
848     "\n"
849     "Beginning dump of physical memory\n");
850   BSOD_PAUSE (bst, 4000000);
851   BSOD_TEXT (bst, LEFT,
852     "Physical memory dump complete. Contact your system administrator or\n"
853     "technical support group.\n");
854
855   bst->left_margin = 40;
856   bst->y = (bst->font->ascent + bst->font->descent) * 10;
857   bst->line_delay = 750;
858
859   XClearWindow (dpy, window);
860   return bst;
861 }
862
863
864 static struct bsod_state *
865 windows_me (Display *dpy, Window window)
866 {
867   struct bsod_state *bst = make_bsod_state (dpy, window, "windows", "Windows");
868
869   BSOD_TEXT (bst, LEFT,
870     "Windows protection error.  You need to restart your computer.\n\n"
871     "System halted.");
872   BSOD_CURSOR (bst, CURSOR_LINE, 120000, 999999);
873
874   bst->left_margin = 40;
875   bst->y = ((bst->xgwa.height -
876              ((bst->font->ascent + bst->font->descent) * 3))
877             / 2);
878
879   XClearWindow (dpy, window);
880   return bst;
881 }
882
883
884 static struct bsod_state *
885 windows_xp (Display *dpy, Window window)
886 {
887   struct bsod_state *bst = make_bsod_state (dpy, window, "windows", "Windows");
888
889   BSOD_TEXT (bst, LEFT,  /* From Wm. Rhodes <xscreensaver@27.org> */
890       "A problem has been detected and windows has been shut down to prevent "
891       "damage\n"
892       "to your computer.\n"
893       "\n"
894       "If this is the first time you've seen this Stop error screen,\n"
895       "restart your computer. If this screen appears again, follow\n"
896       "these steps:\n"
897       "\n"
898       "Check to be sure you have adequate disk space. If a driver is\n"
899       "identified in the Stop message, disable the driver or check\n"
900       "with the manufacturer for driver updates. Try changing video\n"
901       "adapters.\n"
902       "\n"
903       "Check with your hardware vendor for any BIOS updates. Disable\n"
904       "BIOS memory options such as caching or shadowing. If you need\n"
905       "to use Safe Mode to remove or disable components, restart your\n"
906       "computer, press F8 to select Advanced Startup Options, and then\n"
907       "select Safe Mode.\n"
908       "\n"
909       "Technical information:\n"
910       "\n"
911       "*** STOP: 0x0000007E (0xC0000005,0xF88FF190,0x0xF8975BA0,0xF89758A0)\n"
912       "\n"
913       "\n"
914       "***  EPUSBDSK.sys - Address F88FF190 base at FF88FE000, datestamp "
915       "3b9f3248\n"
916       "\n"
917       "Beginning dump of physical memory\n");
918   BSOD_PAUSE (bst, 4000000);
919   BSOD_TEXT (bst, LEFT,
920       "Physical memory dump complete.\n"
921       "Contact your system administrator or technical support group for "
922       "further\n"
923       "assistance.\n");
924
925   XClearWindow (dpy, window);
926   return bst;
927 }
928
929
930 static struct bsod_state *
931 windows_lh (Display *dpy, Window window)
932 {
933   struct bsod_state *bst = 
934     make_bsod_state (dpy, window, "windowslh", "WindowsLH");
935
936   unsigned long fg = bst->fg;
937   unsigned long bg = bst->bg;
938   unsigned long bg2 = get_pixel_resource (dpy, bst->xgwa.colormap,
939                                           "windowslh.background2",
940                                           "WindowsLH.Background");
941
942   /* The "RSOD" that appeared with "Windows Longhorn 5048.050401-0536_x86fre"
943      As reported by http://joi.ito.com/RedScreen.jpg
944    */
945   BSOD_COLOR (bst, bg, bg2);
946   BSOD_TEXT (bst, CENTER_FULL, "Windows Boot Error\n");
947   BSOD_COLOR (bst, fg, bg);
948   BSOD_TEXT (bst, CENTER,
949      "\n"
950      "Windows Boot Manager has experienced a problem.\n"
951      "\n"
952      "\n"
953      "    Status: 0xc000000f\n"
954      "\n"
955      "\n"
956      "\n"
957      "    Info: An error occurred transferring exectuion."  /* (sic) */
958      "\n"
959      "\n"
960      "\n"
961      "You can try to recover the system with the Microsoft Windows "
962      "System Recovery\n"
963      "Tools. (You might need to restart the system manually.)\n"
964      "\n"
965      "If the problem continues, please contact your system administrator "
966      "or computer\n"
967      "manufacturer.\n"
968      );
969   BSOD_MOVETO (bst, bst->left_margin, bst->xgwa.height - bst->font->descent);
970   BSOD_COLOR (bst, bg, bg2);
971   BSOD_TEXT (bst, LEFT_FULL, " SPACE=Continue\n");
972
973   bst->y = bst->font->ascent;
974
975   XClearWindow (dpy, window);
976   return bst;
977 }
978
979
980 static struct bsod_state *
981 windows_other (Display *dpy, Window window)
982 {
983   /* Lump all of the 2K-ish crashes together and select them randomly...
984    */
985   int which = (random() % 4);
986   switch (which) {
987   case 0: return windows_2k (dpy, window); break;
988   case 1: return windows_me (dpy, window); break;
989   case 2: return windows_xp (dpy, window); break;
990   case 3: return windows_lh (dpy, window); break;
991   default: abort(); break;
992   }
993 }
994
995
996 /* SCO OpenServer 5 panic, by Tom Kelly <tom@ancilla.toronto.on.ca>
997  */
998 static struct bsod_state *
999 sco (Display *dpy, Window window)
1000 {
1001   struct bsod_state *bst = make_bsod_state (dpy, window, "sco", "SCO");
1002
1003   BSOD_TEXT (bst, LEFT,
1004      "Unexpected trap in kernel mode:\n"
1005      "\n"
1006      "cr0 0x80010013     cr2  0x00000014     cr3 0x00000000  tlb  0x00000000\n"
1007      "ss  0x00071054    uesp  0x00012055     efl 0x00080888  ipl  0x00000005\n"
1008      "cs  0x00092585     eip  0x00544a4b     err 0x004d4a47  trap 0x0000000E\n"
1009      "eax 0x0045474b     ecx  0x0042544b     edx 0x57687920  ebx  0x61726520\n"
1010      "esp 0x796f7520     ebp  0x72656164     esi 0x696e6720  edi  0x74686973\n"
1011      "ds  0x3f000000     es   0x43494c48     fs  0x43525343  gs   0x4f4d4b53\n"
1012      "\n"
1013      "PANIC: k_trap - kernel mode trap type 0x0000000E\n"
1014      "Trying to dump 5023 pages to dumpdev hd (1/41), 63 pages per '.'\n"
1015     );
1016   BSOD_CHAR_DELAY (bst, 100000);
1017   BSOD_TEXT (bst, LEFT,
1018     "................................................................."
1019     "..............\n"
1020     );
1021   BSOD_CHAR_DELAY (bst, 0);
1022   BSOD_TEXT (bst, LEFT,
1023      "5023 pages dumped\n"
1024      "\n"
1025      "\n"
1026      );
1027   BSOD_PAUSE (bst, 2000000);
1028   BSOD_TEXT (bst, LEFT,
1029      "**   Safe to Power Off   **\n"
1030      "           - or -\n"
1031      "** Press Any Key to Reboot **\n"
1032     );
1033
1034   bst->y = ((bst->xgwa.height -
1035              ((bst->font->ascent + bst->font->descent) * 18)));
1036
1037   XClearWindow (dpy, window);
1038   return bst;
1039 }
1040
1041
1042 /* Linux (sparc) panic, by Tom Kelly <tom@ancilla.toronto.on.ca>
1043  */
1044 static struct bsod_state *
1045 sparc_linux (Display *dpy, Window window)
1046 {
1047   struct bsod_state *bst = make_bsod_state (dpy, window, "sco", "SCO");
1048   bst->scroll_p = True;
1049   bst->y = bst->xgwa.height - bst->font->ascent - bst->font->descent;
1050
1051   BSOD_TEXT (bst, LEFT,
1052         "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
1053         "Unable to handle kernel paging request at virtual address f0d4a000\n"
1054         "tsk->mm->context = 00000014\n"
1055         "tsk->mm->pgd = f26b0000\n"
1056         "              \\|/ ____ \\|/\n"
1057         "              \"@'/ ,. \\`@\"\n"
1058         "              /_| \\__/ |_\\\n"
1059         "                 \\__U_/\n"
1060         "gawk(22827): Oops\n"
1061         "PSR: 044010c1 PC: f001c2cc NPC: f001c2d0 Y: 00000000\n"
1062         "g0: 00001000 g1: fffffff7 g2: 04401086 g3: 0001eaa0\n"
1063         "g4: 000207dc g5: f0130400 g6: f0d4a018 g7: 00000001\n"
1064         "o0: 00000000 o1: f0d4a298 o2: 00000040 o3: f1380718\n"
1065         "o4: f1380718 o5: 00000200 sp: f1b13f08 ret_pc: f001c2a0\n"
1066         "l0: efffd880 l1: 00000001 l2: f0d4a230 l3: 00000014\n"
1067         "l4: 0000ffff l5: f0131550 l6: f012c000 l7: f0130400\n"
1068         "i0: f1b13fb0 i1: 00000001 i2: 00000002 i3: 0007c000\n"
1069         "i4: f01457c0 i5: 00000004 i6: f1b13f70 i7: f0015360\n"
1070         "Instruction DUMP:\n"
1071     );
1072
1073   XClearWindow (dpy, window);
1074   return bst;
1075 }
1076
1077
1078 /* BSD Panic by greywolf@starwolf.com - modeled after the Linux panic above.
1079    By Grey Wolf <greywolf@siteROCK.com>
1080  */
1081 static struct bsod_state *
1082 bsd (Display *dpy, Window window)
1083 {
1084   struct bsod_state *bst = make_bsod_state (dpy, window, "bsd", "BSD");
1085
1086   const char * const panicstr[] = {
1087     "panic: ifree: freeing free inode\n",
1088     "panic: blkfree: freeing free block\n",
1089     "panic: improbability coefficient below zero\n",
1090     "panic: cgsixmmap\n",
1091     "panic: crazy interrupts\n",
1092     "panic: nmi\n",
1093     "panic: attempted windows install\n",
1094     "panic: don't\n",
1095     "panic: free inode isn't\n",
1096     "panic: cpu_fork: curproc\n",
1097     "panic: malloc: out of space in kmem_map\n",
1098     "panic: vogon starship detected\n",
1099     "panic: teleport chamber: out of order\n",
1100     "panic: Brain fried - core dumped\n"
1101    };
1102   int i, n, b;
1103   char syncing[80], bbuf[5];
1104
1105   for (i = 0; i < sizeof(syncing); i++)
1106     syncing[i] = 0;
1107
1108   i = (random() % (sizeof(panicstr) / sizeof(*panicstr)));
1109   BSOD_TEXT (bst, LEFT, panicstr[i]);
1110   BSOD_TEXT (bst, LEFT, "Syncing disks: ");
1111
1112   b = (random() % 40);
1113   for (n = 0; (n < 20) && (b > 0); n++)
1114     {
1115       if (i)
1116         {
1117           i = (random() & 0x7);
1118           b -= (random() & 0xff) % 20;
1119           if (b < 0)
1120             b = 0;
1121         }
1122       sprintf (bbuf, "%d ", b);
1123       BSOD_TEXT (bst, LEFT, bbuf);
1124       BSOD_PAUSE (bst, 1000000);
1125     }
1126
1127   BSOD_TEXT (bst, LEFT, "\n");
1128   BSOD_TEXT (bst, LEFT, (b ? "damn!" : "sunk!"));
1129   BSOD_TEXT (bst, LEFT, "\nRebooting\n");
1130
1131   bst->y = ((bst->xgwa.height -
1132              ((bst->font->ascent + bst->font->descent) * 4)));
1133
1134   XClearWindow (dpy, window);
1135   return bst;
1136 }
1137
1138
1139 static struct bsod_state *
1140 amiga (Display *dpy, Window window)
1141 {
1142   struct bsod_state *bst = make_bsod_state (dpy, window, "amiga", "Amiga");
1143
1144   Pixmap pixmap = 0;
1145   int pix_w = 0, pix_h = 0;
1146   int height;
1147   int lw = 10;
1148
1149   unsigned long bg2 = get_pixel_resource (dpy, bst->xgwa.colormap,
1150                                           "amiga.background2",
1151                                           "Amiga.Background");
1152
1153 # ifdef DO_XPM
1154   pixmap = xpm_data_to_pixmap (dpy, window, (char **) amiga_hand,
1155                                &pix_w, &pix_h, 0);
1156 # endif /* DO_XPM */
1157
1158   if (pixmap && bst->xgwa.height > 600) /* scale up the bitmap */
1159     {
1160       pixmap = double_pixmap (dpy, bst->gc, bst->xgwa.visual, bst->xgwa.depth,
1161                               pixmap, pix_w, pix_h);
1162       pix_w *= 2;
1163       pix_h *= 2;
1164     }
1165
1166   XSetLineAttributes (dpy, bst->gc, lw, LineSolid, CapButt, JoinMiter);
1167
1168   height = (bst->font->ascent + bst->font->descent) * 6;
1169
1170   BSOD_PAUSE (bst, 2000000);
1171   BSOD_COPY (bst, 0, 0, bst->xgwa.width, bst->xgwa.height - height, 0, height);
1172
1173   BSOD_INVERT (bst);
1174   BSOD_RECT (bst, True, 0, 0, bst->xgwa.width, height);
1175   BSOD_INVERT (bst);
1176   BSOD_TEXT (bst, CENTER,
1177              "\n"
1178              "Software failure.  Press left mouse button to continue.\n"
1179              "Guru Meditation #00000003.00C01570"
1180              );
1181   BSOD_RECT (bst, False, lw/2, lw/2, bst->xgwa.width - lw, height);
1182   BSOD_PAUSE (bst, 1000000);
1183   BSOD_INVERT (bst);
1184   BSOD_LOOP (bst, -3);
1185
1186   XSetWindowBackground (dpy, window, bg2);
1187   XClearWindow (dpy, window);
1188   XSetWindowBackground (dpy, window, bst->bg);
1189
1190   if (pixmap)
1191     {
1192       int x = (bst->xgwa.width - pix_w) / 2;
1193       int y = ((bst->xgwa.height - pix_h) / 2);
1194       XCopyArea (dpy, pixmap, bst->window, bst->gc, 0, 0, pix_w, pix_h, x, y);
1195     }
1196
1197   bst->y += lw;
1198
1199   return bst;
1200 }
1201
1202
1203
1204 /* Atari ST, by Marcus Herbert <rhoenie@nobiscum.de>
1205    Marcus had this to say:
1206
1207         Though I still have my Atari somewhere, I hardly remember
1208         the meaning of the bombs. I think 9 bombs was "bus error" or
1209         something like that.  And you often had a few bombs displayed
1210         quickly and then the next few ones coming up step by step.
1211         Perhaps somebody else can tell you more about it..  its just
1212         a quick hack :-}
1213  */
1214 static struct bsod_state *
1215 atari (Display *dpy, Window window)
1216 {
1217   struct bsod_state *bst = make_bsod_state (dpy, window, "atari", "Atari");
1218
1219   Pixmap pixmap = 0;
1220   int pix_w = atari_width;
1221   int pix_h = atari_height;
1222   int offset;
1223   int i, x, y;
1224
1225   pixmap = XCreatePixmapFromBitmapData (dpy, window, (char *) atari_bits,
1226                                         pix_w, pix_h,
1227                                         bst->fg, bst->bg, bst->xgwa.depth);
1228   pixmap = double_pixmap (dpy, bst->gc, bst->xgwa.visual, bst->xgwa.depth,
1229                           pixmap, pix_w, pix_h);
1230   pix_w *= 2;
1231   pix_h *= 2;
1232
1233   offset = pix_w;
1234   x = 0;
1235   y = bst->xgwa.height/2;
1236   if (y < 0) y = 0;
1237
1238   for (i = 1; i< 7; i++)
1239     BSOD_COPY (bst, x, y, pix_w, pix_h, (x + (i*offset)), y);
1240
1241   for (; i< 10; i++) 
1242     {
1243       BSOD_PAUSE (bst, 1000000);
1244       BSOD_COPY (bst, x, y, pix_w, pix_h, (x + (i*offset)), y);
1245     }
1246
1247   XClearWindow (dpy, window);
1248   XCopyArea (dpy, pixmap, window, bst->gc, 0, 0, pix_w, pix_h, x, y);
1249   XFreePixmap (dpy, pixmap);
1250
1251   return bst;
1252 }
1253
1254
1255 static struct bsod_state *
1256 mac (Display *dpy, Window window)
1257 {
1258   struct bsod_state *bst = make_bsod_state (dpy, window, "mac", "Mac");
1259
1260   Pixmap pixmap = 0;
1261   int pix_w = mac_width;
1262   int pix_h = mac_height;
1263   int offset = mac_height * 4;
1264   int i;
1265
1266   const char *string = ("0 0 0 0 0 0 0 F\n"
1267                         "0 0 0 0 0 0 0 3");
1268
1269   pixmap = XCreatePixmapFromBitmapData(dpy, window, (char *) mac_bits,
1270                                        mac_width, mac_height,
1271                                        bst->fg, bst->bg, bst->xgwa.depth);
1272
1273   for (i = 0; i < 2; i++)
1274     {
1275       pixmap = double_pixmap (dpy, bst->gc, bst->xgwa.visual, bst->xgwa.depth,
1276                               pixmap, pix_w, pix_h);
1277       pix_w *= 2; pix_h *= 2;
1278     }
1279
1280   bst->x = (bst->xgwa.width - pix_w) / 2;
1281   bst->y = (((bst->xgwa.height + offset) / 2) -
1282             pix_h -
1283             (bst->font->ascent + bst->font->descent) * 2);
1284   if (bst->y < 0) bst->y = 0;
1285
1286   XClearWindow (dpy, window);
1287   XCopyArea (dpy, pixmap, window, bst->gc, 0, 0, pix_w, pix_h, bst->x, bst->y);
1288   XFreePixmap (dpy, pixmap);
1289
1290   bst->y += offset + bst->font->ascent + bst->font->descent;
1291   BSOD_TEXT (bst, CENTER, string);
1292
1293   return bst;
1294 }
1295
1296
1297 static struct bsod_state *
1298 macsbug (Display *dpy, Window window)
1299 {
1300   struct bsod_state *bst = make_bsod_state (dpy, window, "macsbug", "MacsBug");
1301
1302   __extension__
1303   const char *left = ("    SP     \n"
1304                       " 04EB0A58  \n"
1305                       "58 00010000\n"
1306                       "5C 00010000\n"
1307                       "   ........\n"
1308                       "60 00000000\n"
1309                       "64 000004EB\n"
1310                       "   ........\n"
1311                       "68 0000027F\n"
1312                       "6C 2D980035\n"
1313                       "   ....-..5\n"
1314                       "70 00000054\n"
1315                       "74 0173003E\n"
1316                       "   ...T.s.>\n"
1317                       "78 04EBDA76\n"
1318                       "7C 04EBDA8E\n"
1319                       "   .S.L.a.U\n"
1320                       "80 00000000\n"
1321                       "84 000004EB\n"
1322                       "   ........\n"
1323                       "88 00010000\n"
1324                       "8C 00010000\n"
1325                       "   ...{3..S\n"
1326                       "\n"
1327                       "\n"
1328                       " CurApName \n"
1329                       "  Finder   \n"
1330                       "\n"
1331                       " 32-bit VM \n"
1332                       "SR Smxnzvc0\n"
1333                       "D0 04EC0062\n"
1334                       "D1 00000053\n"
1335                       "D2 FFFF0100\n"
1336                       "D3 00010000\n"
1337                       "D4 00010000\n"
1338                       "D5 04EBDA76\n"
1339                       "D6 04EBDA8E\n"
1340                       "D7 00000001\n"
1341                       "\n"
1342                       "A0 04EBDA76\n"
1343                       "A1 04EBDA8E\n"
1344                       "A2 A0A00060\n"
1345                       "A3 027F2D98\n"
1346                       "A4 027F2E58\n"
1347                       "A5 04EC04F0\n"
1348                       "A6 04EB0A86\n"
1349                       "A7 04EB0A58");
1350   const char *bottom = ("  _A09D\n"
1351                         "     +00884    40843714     #$0700,SR         "
1352                         "                  ; A973        | A973\n"
1353                         "     +00886    40843765     *+$0400           "
1354                         "                                | 4A1F\n"
1355                         "     +00888    40843718     $0004(A7),([0,A7[)"
1356                         "                  ; 04E8D0AE    | 66B8");
1357   __extension__
1358   const char * body = ("PowerPC unmapped memory exception at 003AFDAC "
1359                                                 "BowelsOfTheMemoryMgr+04F9C\n"
1360                       " Calling chain using A6/R1 links\n"
1361                       "  Back chain  ISA  Caller\n"
1362                       "  00000000    PPC  28C5353C  __start+00054\n"
1363                       "  24DB03C0    PPC  28B9258C  main+0039C\n"
1364                       "  24DB0350    PPC  28B9210C  MainEvent+00494\n"
1365                       "  24DB02B0    PPC  28B91B40  HandleEvent+00278\n"
1366                       "  24DB0250    PPC  28B83DAC  DoAppleEvent+00020\n"
1367                       "  24DB0210    PPC  FFD3E5D0  "
1368                                                 "AEProcessAppleEvent+00020\n"
1369                       "  24DB0132    68K  00589468\n"
1370                       "  24DAFF8C    68K  00589582\n"
1371                       "  24DAFF26    68K  00588F70\n"
1372                       "  24DAFEB3    PPC  00307098  "
1373                                                 "EmToNatEndMoveParams+00014\n"
1374                       "  24DAFE40    PPC  28B9D0B0  DoScript+001C4\n"
1375                       "  24DAFDD0    PPC  28B9C35C  RunScript+00390\n"
1376                       "  24DAFC60    PPC  28BA36D4  run_perl+000E0\n"
1377                       "  24DAFC10    PPC  28BC2904  perl_run+002CC\n"
1378                       "  24DAFA80    PPC  28C18490  Perl_runops+00068\n"
1379                       "  24DAFA30    PPC  28BE6CC0  Perl_pp_backtick+000FC\n"
1380                       "  24DAF9D0    PPC  28BA48B8  Perl_my_popen+00158\n"
1381                       "  24DAF980    PPC  28C5395C  sfclose+00378\n"
1382                       "  24DAF930    PPC  28BA568C  free+0000C\n"
1383                       "  24DAF8F0    PPC  28BA6254  pool_free+001D0\n"
1384                       "  24DAF8A0    PPC  FFD48F14  DisposePtr+00028\n"
1385                       "  24DAF7C9    PPC  00307098  "
1386                                                 "EmToNatEndMoveParams+00014\n"
1387                       "  24DAF780    PPC  003AA180  __DisposePtr+00010");
1388
1389   const char *s;
1390   int body_lines = 1;
1391
1392   int char_width, line_height;
1393   int col_right, row_top, row_bottom, page_right, page_bottom, body_top;
1394   int xoff, yoff;
1395
1396   unsigned long fg = bst->fg;
1397   unsigned long bg = bst->bg;
1398   unsigned long bc = get_pixel_resource (dpy, bst->xgwa.colormap,
1399                                          "macsbug.borderColor",
1400                                          "MacsBug.BorderColor");
1401
1402   for (s = body; *s; s++) if (*s == '\n') body_lines++;
1403
1404   char_width = (bst->font->per_char
1405                 ? bst->font->per_char['n'-bst->font->min_char_or_byte2].width
1406                 : bst->font->min_bounds.width);
1407   line_height = bst->font->ascent + bst->font->descent;
1408
1409   col_right   = char_width  * 12;  /* number of columns in `left' */
1410   page_bottom = line_height * 47;  /* number of lines in `left'   */
1411
1412   if (page_bottom > bst->xgwa.height) 
1413     page_bottom = bst->xgwa.height;
1414
1415   row_bottom = page_bottom - line_height;
1416   row_top    = row_bottom - (line_height * 4);
1417   page_right = col_right + (char_width * 88);
1418   body_top   = row_top - (line_height * body_lines);
1419
1420   page_bottom += 2;
1421   row_bottom += 2;
1422   body_top -= 4;
1423
1424   if (body_top > 4)
1425     body_top = 4;
1426
1427   xoff = (bst->xgwa.width  - page_right)  / 2;
1428   yoff = (bst->xgwa.height - page_bottom) / 2;
1429
1430   if (xoff < 0) xoff = 0;
1431   if (yoff < 0) yoff = 0;
1432
1433   BSOD_MARGINS (bst, xoff, yoff);
1434
1435   BSOD_COLOR (bst, bc, bg);
1436   BSOD_RECT (bst, True, 0, 0, bst->xgwa.width, bst->xgwa.height);
1437   BSOD_COLOR (bst, bg, bg);
1438   BSOD_RECT (bst, True, xoff-2, yoff, page_right+4, page_bottom);
1439   BSOD_COLOR (bst, fg, bg);
1440
1441   BSOD_MOVETO (bst, xoff, yoff + line_height);
1442   BSOD_TEXT (bst, LEFT, left);
1443   BSOD_MOVETO (bst, xoff+col_right, yoff + row_top + line_height);
1444   BSOD_TEXT (bst, LEFT, bottom);
1445
1446   BSOD_RECT (bst, True, xoff + col_right, yoff, 2, page_bottom);
1447   BSOD_RECT (bst, True, xoff + col_right, yoff + row_top, 
1448              page_right - col_right, 1);
1449   BSOD_RECT (bst, True, xoff + col_right, yoff + row_bottom, 
1450              page_right - col_right, 1);
1451   BSOD_RECT (bst, False, xoff-2, yoff, page_right+4, page_bottom);
1452
1453   BSOD_LINE_DELAY (bst, 500);
1454   BSOD_MOVETO (bst, 
1455                xoff + col_right + char_width, 
1456                yoff + body_top + line_height);
1457   BSOD_MARGINS (bst, xoff + col_right + char_width, yoff);
1458   BSOD_TEXT (bst, LEFT, body);
1459
1460   BSOD_RECT (bst, False, xoff-2, yoff, page_right+4, page_bottom); /* again */
1461
1462   BSOD_RECT (bst, False,
1463              xoff + col_right + (char_width/2)+2,
1464              yoff + row_bottom + 2,
1465              0,
1466              page_bottom - row_bottom - 4);
1467
1468   BSOD_PAUSE (bst, 666666);
1469   BSOD_INVERT (bst);
1470   BSOD_LOOP (bst, -3);
1471
1472   XClearWindow (dpy, window);
1473   return bst;
1474 }
1475
1476
1477 static struct bsod_state *
1478 mac1 (Display *dpy, Window window)
1479 {
1480   struct bsod_state *bst = make_bsod_state (dpy, window, "mac1", "Mac1");
1481
1482   Pixmap pixmap = 0;
1483   int pix_w = macbomb_width;
1484   int pix_h = macbomb_height;
1485   int x, y;
1486
1487   pixmap = XCreatePixmapFromBitmapData (dpy, window, (char *) macbomb_bits,
1488                                         macbomb_width, macbomb_height,
1489                                         bst->fg, bst->bg, bst->xgwa.depth);
1490
1491   x = (bst->xgwa.width - pix_w) / 2;
1492   y = (bst->xgwa.height - pix_h) / 2;
1493   if (y < 0) y = 0;
1494
1495   XClearWindow (dpy, window);
1496   XCopyArea (dpy, pixmap, window, bst->gc, 0, 0, pix_w, pix_h, x, y);
1497
1498   return bst;
1499 }
1500
1501
1502 /* This is what kernel panics looked like on MacOS X 10.0 through 10.1.5.
1503    In later releases, it's a graphic of a power button with text in
1504    English, French, German, and Japanese overlayed transparently.
1505  */
1506 static struct bsod_state *
1507 macx_10_0 (Display *dpy, Window window)
1508 {
1509   struct bsod_state *bst = make_bsod_state (dpy, window, "macx", "MacX");
1510
1511   XClearWindow (dpy, window);
1512   XSetForeground (dpy, bst->gc,
1513                   get_pixel_resource (dpy, bst->xgwa.colormap,
1514                                       "macx.textForeground",
1515                                       "MacX.TextForeground"));
1516   XSetBackground (dpy, bst->gc,
1517                   get_pixel_resource (dpy, bst->xgwa.colormap,
1518                                       "macx.textBackground",
1519                                       "MacX.TextBackground"));
1520
1521 # ifdef DO_XPM
1522   {
1523     Pixmap pixmap = 0;
1524     Pixmap mask = 0;
1525     int x, y, pix_w, pix_h;
1526     pixmap = xpm_data_to_pixmap (dpy, window, (char **) happy_mac,
1527                                  &pix_w, &pix_h, &mask);
1528
1529     x = (bst->xgwa.width - pix_w) / 2;
1530     y = (bst->xgwa.height - pix_h) / 2;
1531     if (y < 0) y = 0;
1532     XSetClipMask (dpy, bst->gc, mask);
1533     XSetClipOrigin (dpy, bst->gc, x, y);
1534     XCopyArea (dpy, pixmap, window, bst->gc, 0, 0, pix_w, pix_h, x, y);
1535     XSetClipMask (dpy, bst->gc, None);
1536     XFreePixmap (dpy, pixmap);
1537   }
1538 #endif /* DO_XPM */
1539
1540   bst->left_margin = 0;
1541   bst->right_margin = 0;
1542   bst->y = bst->font->ascent;
1543   bst->macx_eol_kludge = True;
1544   bst->wrap_p = True;
1545
1546   BSOD_PAUSE (bst, 3000000);
1547   BSOD_TEXT (bst, LEFT,
1548     "panic(cpu 0): Unable to find driver for this platform: "
1549     "\"PowerMac 3,5\".\n"
1550     "\n"
1551     "backtrace: 0x0008c2f4 0x0002a7a0 0x001f0204 0x001d4e4c 0x001d4c5c "
1552     "0x001a56cc 0x01d5dbc 0x001c621c 0x00037430 0x00037364\n"
1553     "\n"
1554     "\n"
1555     "\n"
1556     "No debugger configured - dumping debug information\n"
1557     "\n"
1558     "version string : Darwin Kernel Version 1.3:\n"
1559     "Thu Mar  1 06:56:40 PST 2001; root:xnu/xnu-123.5.obj~1/RELEASE_PPC\n"
1560     "\n"
1561     "\n"
1562     "\n"
1563     "\n"
1564     "DBAT0: 00000000 00000000\n"
1565     "DBAT1: 00000000 00000000\n"
1566     "DBAT2: 80001FFE 8000003A\n"
1567     "DBAT3: 90001FFE 9000003A\n"
1568     "MSR=00001030\n"
1569     "backtrace: 0x0008c2f4 0x0002a7a0 0x001f0204 0x001d4e4c 0x001d4c5c "
1570     "0x001a56cc 0x01d5dbc 0x001c621c 0x00037430 0x00037364\n"
1571     "\n"
1572     "panic: We are hanging here...\n");
1573
1574   return bst;
1575 }
1576
1577
1578 # ifdef DO_XPM
1579 static struct bsod_state *
1580 macx_10_2 (Display *dpy, Window window, Bool v10_3_p)
1581 {
1582   struct bsod_state *bst = make_bsod_state (dpy, window, "macx", "MacX");
1583
1584   Pixmap pixmap = 0;
1585   int pix_w = 0, pix_h = 0;
1586   int x, y;
1587
1588   pixmap = xpm_data_to_pixmap (dpy, window, 
1589                                (char **) (v10_3_p ? osx_10_3 : osx_10_2),
1590                                &pix_w, &pix_h, 0);
1591   if (! pixmap) abort();
1592
1593 #if 0
1594   if (bst->xgwa.height > 600)   /* scale up the bitmap */
1595     {
1596       pixmap = double_pixmap (dpy, bst->gc, bst->xgwa.visual, bst->xgwa.depth,
1597                               pixmap, pix_w, pix_h);
1598       if (! pixmap) abort();
1599       pix_w *= 2;
1600       pix_h *= 2;
1601     }
1602 #endif
1603
1604   BSOD_IMG (bst);
1605   BSOD_PAUSE (bst, 2000000);
1606
1607   bst->pixmap = pixmap;
1608
1609   x = (bst->xgwa.width - pix_w) / 2;
1610   y = ((bst->xgwa.height - pix_h) / 2);
1611   BSOD_PIXMAP (bst, 0, 0, pix_w, pix_h, x, y);
1612
1613   return bst;
1614 }
1615 # endif /* DO_XPM */
1616
1617
1618 static struct bsod_state *
1619 macx (Display *dpy, Window window)
1620 {
1621 # ifdef DO_XPM
1622   switch (random() % 3) {
1623   case 0: return macx_10_0 (dpy, window);        break;
1624   case 1: return macx_10_2 (dpy, window, False); break;
1625   case 2: return macx_10_2 (dpy, window, True);  break;
1626   default: abort();
1627   }
1628 # else  /* !DO_XPM */
1629   return macx_10_0 (dpy, window);
1630 # endif /* !DO_XPM */
1631 }
1632
1633
1634 #ifndef HAVE_COCOA /* #### I have no idea how to implement this without
1635                            real plane-masks.  I don't think it would look
1636                            right if done with alpha-transparency... */
1637 /* blit damage
1638  *
1639  * by Martin Pool <mbp@samba.org>, Feb 2000.
1640  *
1641  * This is meant to look like the preferred failure mode of NCD
1642  * Xterms.  The parameters for choosing what to copy where might not
1643  * be quite right, but it looks about ugly enough.
1644  */
1645 static struct bsod_state *
1646 blitdamage (Display *dpy, Window window)
1647 {
1648   struct bsod_state *bst = 
1649     make_bsod_state (dpy, window, "blitdamage", "BlitDamage");
1650
1651   int i;
1652   int delta_x = 0, delta_y = 0;
1653   int w, h;
1654   int chunk_h, chunk_w;
1655   int steps;
1656   long gc_mask = 0;
1657   int src_x, src_y;
1658   int x, y;
1659   
1660   w = bst->xgwa.width;
1661   h = bst->xgwa.height;
1662
1663   gc_mask = GCForeground;
1664   
1665   XSetPlaneMask (dpy, bst->gc, random());
1666
1667   steps = 50;
1668   chunk_w = w / (random() % 1 + 1);
1669   chunk_h = h / (random() % 1 + 1);
1670   if (random() & 0x1000) 
1671     delta_y = random() % 600;
1672   if (!delta_y || (random() & 0x2000))
1673     delta_x = random() % 600;
1674   src_x = 0; 
1675   src_y = 0; 
1676   x = 0;
1677   y = 0;
1678   
1679   BSOD_IMG (bst);
1680   for (i = 0; i < steps; i++) {
1681     if (x + chunk_w > w) 
1682       x -= w;
1683     else
1684       x += delta_x;
1685     
1686     if (y + chunk_h > h)
1687       y -= h;
1688     else
1689       y += delta_y;
1690     
1691     BSOD_COPY (bst, src_x, src_y, chunk_w, chunk_h, x, y);
1692     BSOD_PAUSE (bst, 1000);
1693   }
1694
1695   return bst;
1696 }
1697 #endif /* !HAVE_COCOA */
1698
1699
1700 /*
1701  * OS/2 panics, by Knut St. Osmundsen <bird-xscreensaver@anduin.net>
1702  *
1703  * All but one messages are real ones, some are from my test machines
1704  * and system dumps, others are reconstructed from google results.
1705  * Please, don't be to hard if the formatting of the earlier systems
1706  * aren't 100% correct.
1707  */
1708 static struct bsod_state *
1709 os2 (Display *dpy, Window window)
1710 {
1711   struct bsod_state *bst = make_bsod_state (dpy, window, "os2", "OS2");
1712
1713   __extension__
1714   static const char * const os2_panics[] =
1715     { /* OS/2 2.0 trap - details are bogus (CR0++). */
1716       "TRAP 0002       ERRCD=0000  ERACC=****  ERLIM=********\n"
1717       "EAX=7d240a58  EBX=ff202fdc  ECX=00064423  EDX=00003624\n"
1718       "ESI=fff3272c  EDI=7d240004  EBP=00004a44  FLG=00003202\n"
1719       "CS:EIP=0160:fff702a6  CSACC=c09d  CSLIM=ffffffff\n"
1720       "SS:ESP=0030:00004a38  SSACC=1097  SSLIM=00003fff\n"
1721       "DS=0158  DSACC=c0f3  DSLIM=ffffffff  CR0=fffffffb\n"
1722       "ES=0158  ESACC=c0f3  ESLIM=ffffffff  CR2=1a060014\n"
1723       "FS=0000  FSACC=****  FSLIM=********\n"
1724       "GS=0000  GSACC=****  GSLIM=********\n"
1725       "\n"
1726       "The system detected an internal processing error\n"
1727       "at location ##0160:fff6453f - 000d:a53f\n"
1728       "60000, 9084\n"
1729       "\n"
1730       "038600d1\n"
1731       "Internal revision 6.307, 92/03/01\n"
1732       "\n",
1733
1734       /* warp 3 (early) */
1735       "TRAP 000e       ERRCD=0000  ERACC=****  ERLIM=********\n"
1736       "EAX=ff050c20  EBX=000000bb  ECX=ffff00c1  EDx=fff379b8\n"
1737       "ESI=ffe55a3c  EDI=00000000  EBP=00004eb8  FLG=00013282\n"
1738       "CS:EIP=0160:fff8dbb8  CSACC=c09b  CSLIM=ffffffff\n"
1739       "SS:EIP=0030:00004eb4  SSACC=1097  SSLIM=00003fff\n"
1740       "DS=0158  DSACC=c0f3  DSLIM=ffffffff  CR0=8001001b\n"
1741       "ES=0158  DSACC=c0f3  DSLIM=ffffffff  CR2=000000c7\n"
1742       "FS=0000  FSACC=****  FSLIM=********\n"
1743       "GS=0000  GSACC=****  GSLIM=********\n"
1744       "\n"
1745       "The system detected an internal processing error\n"
1746       "at location ##0160:fff66bf0 - 000d:9bf0.\n"
1747       "60000, 9084\n"
1748       "\n"
1749       "048600b4\n"
1750       "Internal revision 8.125, 94/02/16\n"
1751       "\n"
1752       "The system is stopped.  Record the location number of the error\n"
1753       "and contact your service representative.\n",
1754
1755       /* warp 3 */
1756       "TRAP 000e       ERRCD=0002  ERACC=****  ERLIM=********\n"
1757       "EAX=00000000  EBX=fdef1e0c  ECX=00003824  EDX=0000edf9\n"
1758       "ESI=fdf30e80  EDI=fc8b0000  EBP=00005658  FLG=00012246\n"
1759       "CS:EIP=0160:fff8ada3  CSACC=c09b  CSLIM=ffffffff\n"
1760       "SS:ESP=0030:000055d4  SSACC=1097  SSLIM=0000480f\n"
1761       "DS=0158  DSACC=c093  DSLIM=ffffffff  CR0=8001001b\n"
1762       "ES=0158  ESACC=c093  ESLIM=ffffffff  CR2=fc8b0000\n"
1763       "FS=03b8  FSACC=0093  FSLIM=00000023\n"
1764       "GS=0000  GSACC=****  GSLIM=********\n"
1765       "\n"
1766       "The system detected an internal processing error\n"
1767       "at location ##0160:fff5c364 - 000d:a364.\n"
1768       "60000, 9084\n"
1769       "\n"
1770       "05860526\n"
1771       "Internal revision 8200,94/11/07\n"
1772       "\n"
1773       "The system is stopped. Record all of the above information and\n"
1774       "contact your service representative.\n",
1775
1776       /* warp 3 (late) */
1777       "TRAP 000d       ERRCD=2200  ERACC=1092  ERLIM=00010fff\n"
1778       "EAX=0000802e  EBX=fff001c8  ECX=9bd80000  EDX=00000000\n"
1779       "ESI=fff09bd8  EDI=fdeb001b  EBP=00000000  FLG=00012012\n"
1780       "CS:EIP=0168:fff480a2  CSACC=c09b  CSLIM=ffffffff\n"
1781       "SS:ESP=00e8:00001f32  SSACC=0093  SSLIM=00001fff\n"
1782       "DS=0940  DSACC=0093  DSLIM=00000397  CR0=8001001b\n"
1783       "ES=00e8  ESACC=0093  ESLIM=00001fff  CR2=15760008\n"
1784       "FS=0000  FSACC=****  FSLIM=****\n"
1785       "GS=0000  GSACC=****  GSLIM=****\n"
1786       "\n"
1787       "The system detected an internal processing error\n"
1788       "at location ##0168:fff4b06e - 000e:c06e\n"
1789       "60000, 9084\n"
1790       "\n"
1791       "06860652\n"
1792       "Internal revision 8.259_uni,98/01/07\n"
1793       "\n"
1794       "The system is stopped. Record all of the above information and\n"
1795       "contact your service representative.\n",
1796
1797       /* Warp 4.52+ - the official r0trap.exe from the debugging classes */
1798       "Exception in module: OS2KRNL\n"
1799       "TRAP 000e       ERRCD=0002  ERACC=****  ERLIM=********\n"
1800       "EAX=00000001  EBX=80010002  ECX=ffed4638  EDX=0003f17b\n"
1801       "ESI=00000001  EDI=00000002  EBP=00005408  FLG=00012202\n"
1802       "CS:EIP=0168:fff3cd2e  CSACC=c09b  CSLIM=ffffffff\n"
1803       "SS:ESP=0030:000053ec  SSACC=1097  SSLIM=000044ff\n"
1804       "DS=0160  DSACC=c093  DSLIM=ffffffff  CR0=8001001b\n"
1805       "ES=0160  ESACC=c093  ESLIM=ffffffff  CR2=00000001\n"
1806       "FS=0000  FSACC=****  FSLIM=********\n"
1807       "GS=0000  GSACC=****  GSLIM=********\n"
1808       "\n"
1809       "The system detected an internal processing error at\n"
1810       "location ##0168:fff1e3f3 - 000e:c3f3.\n"
1811       "60000, 9084\n"
1812       "\n"
1813       "068606a0\n"
1814       "Internal revision 14.097_UNI\n"
1815       "\n"
1816       "The system is stopped. Record all of the above information and\n"
1817       "contact your service representative.\n",
1818
1819       /* Warp 4.52+, typical JFS problem. */
1820       "Exeption in module: JFS\n"
1821       "TRAP 0003       ERRCD=0000  ERACC=****  ERLIM=********\n"
1822       "EAX=00000000  EBX=ffffff05  ECX=00000001  EDX=f5cd8010\n"
1823       "ESI=000000e6  EDI=000000e7  EBP=f9c7378e  FLG=00002296\n"
1824       "CS:EIP=0168:f8df3250  CSACC=c09b  CSLIM=ffffffff\n"
1825       "SS:ESP=1550:fdc73778  SSACC=c093  SSLIM=ffffffff\n"
1826       "DS=0160  DSACC=c093  DSLIM=ffffffff  CR0=80010016\n"
1827       "ES=0160  ESACC=c093  DSLIM=ffffffff  CR2=05318000\n"
1828       "FS=03c0  FSACC=0093  DSLIM=00000023\n"
1829       "GS=0160  GSACC=c093  DSLIM=ffffffff\n"
1830       "\n"
1831       "The system detected an internal processing error\n"
1832       "at location ##0168:fff1e2ab - 000e:c2ab.\n"
1833       "60000, 9084\n"
1834       "\n"
1835       "07860695\n"
1836       "\n"
1837       "Internal revision 14.100c_UNI\n"
1838       "\n"
1839       "The system is stopped. Record all of the above information and\n"
1840       "contact your service representative.\n"
1841     };
1842
1843   BSOD_TEXT (bst, LEFT, os2_panics[random() % countof(os2_panics)]);
1844   BSOD_CURSOR (bst, CURSOR_LINE, 240000, 999999);
1845
1846   XClearWindow (dpy, window);
1847   return bst;
1848 }
1849
1850
1851 /* SPARC Solaris panic. Should look pretty authentic on Solaris boxes.
1852  * Anton Solovyev <solovam@earthlink.net>
1853  */ 
1854 static struct bsod_state *
1855 sparc_solaris (Display *dpy, Window window)
1856 {
1857   struct bsod_state *bst = make_bsod_state (dpy, window, "solaris", "Solaris");
1858   int i;
1859
1860   bst->scroll_p = True;
1861   bst->wrap_p = True;
1862   bst->left_margin = bst->right_margin = bst->xgwa.width  * 0.07;
1863   bst->top_margin = bst->bottom_margin = bst->xgwa.height * 0.07;
1864   bst->y = bst->top_margin + bst->font->ascent;
1865
1866   BSOD_IMG (bst);
1867   BSOD_PAUSE (bst, 3000000);
1868
1869   BSOD_INVERT(bst);
1870   BSOD_RECT (bst, True, 
1871              bst->left_margin, bst->top_margin,
1872              bst->xgwa.width - bst->left_margin - bst->right_margin,
1873              bst->xgwa.height - bst->top_margin - bst->bottom_margin);
1874   BSOD_INVERT(bst);
1875
1876   BSOD_TEXT (bst, LEFT,
1877     "BAD TRAP: cpu=0 type=0x31 rp=0x2a10043b5e0 addr=0xf3880 mmu_fsr=0x0\n"
1878     "BAD TRAP occurred in module \"unix\" due to an illegal access to a"
1879     " user address.\n"
1880     "adb: trap type = 0x31\n"
1881     "addr=0xf3880\n"
1882     "pid=307, pc=0x100306e4, sp=0x2a10043ae81, tstate=0x4480001602,"
1883     " context=0x87f\n"
1884     "g1-g7: 1045b000, 32f, 10079440, 180, 300000ebde8, 0, 30000953a20\n"
1885     "Begin traceback... sp = 2a10043ae81\n"
1886     "Called from 100bd060, fp=2a10043af31, args=f3700 300008cc988 f3880 0"
1887     " 1 300000ebde0.\n"
1888     "Called from 101fe1bc, fp=2a10043b011, args=3000045a240 104465a0"
1889     " 300008e47d0 300008e48fa 300008ae350 300008ae410\n"
1890     "Called from 1007c520, fp=2a10043b0c1, args=300008e4878 300003596e8 0"
1891     " 3000045a320 0 3000045a220\n"
1892     "Called from 1007c498, fp=2a10043b171, args=1045a000 300007847f0 20"
1893     " 3000045a240 1 0\n"
1894     "Called from 1007972c, fp=2a10043b221, args=1 300009517c0 30000951e58 1"
1895     " 300007847f0 0\n"
1896     "Called from 10031e10, fp=2a10043b2d1, args=3000095b0c8 0 300009396a8"
1897     " 30000953a20 0 1\n"
1898     "Called from 10000bdd8, fp=ffffffff7ffff1c1, args=0 57 100131480"
1899     " 100131480 10012a6e0 0\n"
1900     "End traceback...\n"
1901     "panic[cpu0]/thread=30000953a20: trap\n"
1902     "syncing file systems...");
1903
1904   BSOD_PAUSE (bst, 3000000);
1905
1906   BSOD_TEXT (bst, LEFT, " 1 done\n");
1907   BSOD_TEXT (bst, LEFT, "dumping to /dev/dsk/c0t0d0s3, offset 26935296\n");
1908   BSOD_PAUSE (bst, 2000000);
1909
1910
1911   for (i = 1; i <= 100; ++i)
1912     {
1913       char buf[100];
1914       sprintf (buf, "\b\b\b\b\b\b\b\b\b\b\b%3d%% done", i);
1915       BSOD_TEXT (bst, LEFT, buf);
1916       BSOD_PAUSE (bst, 100000);
1917     }
1918
1919   BSOD_TEXT (bst, LEFT,
1920     ": 2803 pages dumped, compression ratio 2.88, dump succeeded\n");
1921   BSOD_PAUSE (bst, 2000000);
1922
1923   BSOD_TEXT (bst, LEFT,
1924     "rebooting...\n"
1925     "Resetting ...");
1926
1927   return bst;
1928 }
1929
1930
1931 /* Linux panic and fsck, by jwz
1932  */
1933 static struct bsod_state *
1934 linux_fsck (Display *dpy, Window window)
1935 {
1936   struct bsod_state *bst = make_bsod_state (dpy, window, "linux", "Linux");
1937
1938   int i;
1939   const char *sysname;
1940   char buf[1024];
1941
1942   const char *linux_panic[] = {
1943    " kernel: Unable to handle kernel paging request at virtual "
1944      "address 0000f0ad\n",
1945    " kernel:  printing eip:\n",
1946    " kernel: c01becd7\n",
1947    " kernel: *pde = 00000000\n",
1948    " kernel: Oops: 0000\n",
1949    " kernel: CPU:    0\n",
1950    " kernel: EIP:    0010:[<c01becd7>]    Tainted: P \n",
1951    " kernel: EFLAGS: 00010286\n",
1952    " kernel: eax: 0000ff00   ebx: ca6b7e00   ecx: ce1d7a60   edx: ce1d7a60\n",
1953    " kernel: esi: ca6b7ebc   edi: 00030000   ebp: d3655ca0   esp: ca6b7e5c\n",
1954    " kernel: ds: 0018   es: 0018   ss: 0018\n",
1955    " kernel: Process crond (pid: 1189, stackpage=ca6b7000)\n",
1956    " kernel: Stack: d3655ca0 ca6b7ebc 00030054 ca6b7e7c c01c1e5b "
1957        "00000287 00000020 c01c1fbf \n",
1958    "",
1959    " kernel:        00005a36 000000dc 000001f4 00000000 00000000 "
1960        "ce046d40 00000001 00000000 \n",
1961    "", "", "",
1962    " kernel:        ffffffff d3655ca0 d3655b80 00030054 c01bef93 "
1963        "d3655ca0 ca6b7ebc 00030054 \n",
1964    "", "", "",
1965    " kernel: Call Trace:    [<c01c1e5b>] [<c01c1fbf>] [<c01bef93>] "
1966        "[<c01bf02b>] [<c0134c4f>]\n",
1967    "", "", "",
1968    " kernel:   [<c0142562>] [<c0114f8c>] [<c0134de3>] [<c010891b>]\n",
1969    " kernel: \n",
1970    " kernel: Code: 2a 00 75 08 8b 44 24 2c 85 c0 74 0c 8b 44 24 58 83 48 18 "
1971       "08 \n",
1972    0
1973   };
1974
1975   bst->scroll_p = True;
1976   bst->wrap_p = True;
1977   bst->left_margin = bst->right_margin = 10;
1978   bst->top_margin = bst->bottom_margin = 10;
1979
1980   sysname = "linux";
1981 # ifdef HAVE_UNAME
1982   {
1983     struct utsname uts;
1984     char *s;
1985     if (uname (&uts) >= 0)
1986       sysname = uts.nodename;
1987     s = strchr (sysname, '.');
1988     if (s) *s = 0;
1989   }
1990 # endif /* !HAVE_UNAME */
1991
1992
1993   BSOD_TEXT (bst, LEFT, "waiting for X server to shut down ");
1994   BSOD_PAUSE (bst, 100000);
1995   BSOD_TEXT (bst, LEFT,
1996              "XIO:  fatal IO error 2 (broken pipe) on X server \":0.0\"\n"
1997              "        after 339471 requests (339471 known processed) "
1998              "with 0 events remaining\n");
1999   BSOD_CHAR_DELAY (bst, 300000);
2000   BSOD_TEXT (bst, LEFT, ".........\n");
2001   BSOD_CHAR_DELAY (bst, 0);
2002   BSOD_TEXT (bst, LEFT, 
2003              "xinit:  X server slow to shut down, sending KILL signal.\n"
2004              "waiting for server to die ");
2005   BSOD_CHAR_DELAY (bst, 300000);
2006   BSOD_TEXT (bst, LEFT, "...\n");
2007   BSOD_CHAR_DELAY (bst, 0);
2008   BSOD_TEXT (bst, LEFT, "xinit:  Can't kill server\n");
2009   BSOD_PAUSE (bst, 2000000);
2010
2011   sprintf (buf, "\n%s Login: ", sysname);
2012   BSOD_TEXT (bst, LEFT, buf);
2013   BSOD_PAUSE (bst, 1000000);
2014   BSOD_TEXT (bst, LEFT,
2015     "\n\n"
2016     "Parallelizing fsck version 1.22 (22-Jun-2001)\n"
2017     "e2fsck 1.22, 22-Jun-2001 for EXT2 FS 0.5b, 95/08/09\n"
2018     "Warning!  /dev/hda1 is mounted.\n"
2019     "/dev/hda1 contains a file system with errors, check forced.\n");
2020   BSOD_PAUSE (bst, 1000000);
2021
2022   if (0 == random() % 2)
2023     BSOD_TEXT (bst, LEFT,
2024      "Couldn't find ext2 superblock, trying backup blocks...\n"
2025      "The filesystem size (according to the superblock) is 3644739 blocks\n"
2026      "The physical size of the device is 3636706 blocks\n"
2027      "Either the superblock or the partition table is likely to be corrupt!\n"
2028      "Abort<y>? no\n");
2029   BSOD_PAUSE (bst, 1000000);
2030
2031  AGAIN:
2032
2033   BSOD_TEXT (bst, LEFT, "Pass 1: Checking inodes, blocks, and sizes\n");
2034   BSOD_PAUSE (bst, 2000000);
2035
2036   i = (random() % 60) - 20;
2037   while (--i > 0)
2038     {
2039       int b = random() % 0xFFFF;
2040       sprintf (buf, "Deleted inode %d has zero dtime.  Fix<y>? yes\n\n", b);
2041       BSOD_TEXT (bst, LEFT, buf);
2042       BSOD_PAUSE (bst, 1000);
2043     }
2044
2045   i = (random() % 40) - 10;
2046   if (i > 0)
2047     {
2048       int g = random() % 0xFFFF;
2049       int b = random() % 0xFFFFFFF;
2050
2051       BSOD_PAUSE (bst, 1000000);
2052
2053       sprintf (buf, "Warning: Group %d's copy of the group descriptors "
2054                "has a bad block (%d).\n", g, b);
2055       BSOD_TEXT (bst, LEFT, buf);
2056
2057       b = random() % 0x3FFFFF;
2058       while (--i > 0)
2059         {
2060           b += random() % 0xFFFF;
2061           sprintf (buf,
2062                    "Error reading block %d (Attempt to read block "
2063                    "from filesystem resulted in short read) while doing "
2064                    "inode scan.  Ignore error<y>?",
2065                    b);
2066           BSOD_TEXT (bst, LEFT, buf);
2067           BSOD_PAUSE (bst, 10000);
2068           BSOD_TEXT (bst, LEFT, " yes\n\n");
2069         }
2070     }
2071
2072   if (0 == (random() % 10))
2073     {
2074       BSOD_PAUSE (bst, 1000000);
2075
2076       i = 3 + (random() % 10);
2077       while (--i > 0)
2078         {
2079           BSOD_TEXT (bst, LEFT,
2080                      "Could not allocate 256 block(s) for inode table: "
2081                      "No space left on device\n");
2082           BSOD_PAUSE (bst, 1000);
2083         }
2084       BSOD_TEXT (bst, LEFT, "Restarting e2fsck from the beginning...\n");
2085       BSOD_PAUSE (bst, 2000000);
2086
2087       goto AGAIN;
2088     }
2089
2090   i = (random() % 20) - 5;
2091
2092   if (i > 0)
2093     BSOD_PAUSE (bst, 1000000);
2094
2095   while (--i > 0)
2096     {
2097       int j = 5 + (random() % 10);
2098       int w = random() % 4;
2099
2100       while (--j > 0)
2101         {
2102           int b = random() % 0xFFFFF;
2103           int g = random() % 0xFFF;
2104
2105           if (0 == (random() % 10))
2106             b = 0;
2107           else if (0 == (random() % 10))
2108             b = -1;
2109
2110           if (w == 0)
2111             sprintf (buf,
2112                      "Inode table for group %d not in group.  (block %d)\n"
2113                      "WARNING: SEVERE DATA LOSS POSSIBLE.\n"
2114                      "Relocate<y>?",
2115                      g, b);
2116           else if (w == 1)
2117             sprintf (buf,
2118                      "Block bitmap for group %d not in group.  (block %d)\n"
2119                      "Relocate<y>?",
2120                      g, b);
2121           else if (w == 2)
2122             sprintf (buf,
2123                      "Inode bitmap %d for group %d not in group.\n"
2124                      "Continue<y>?",
2125                      b, g);
2126           else /* if (w == 3) */
2127             sprintf (buf,
2128                      "Bad block %d in group %d's inode table.\n"
2129                      "WARNING: SEVERE DATA LOSS POSSIBLE.\n"
2130                      "Relocate<y>?",
2131                      b, g);
2132
2133           BSOD_TEXT (bst, LEFT, buf);
2134           BSOD_TEXT (bst, LEFT, " yes\n\n");
2135           BSOD_PAUSE (bst, 1000);
2136         }
2137     }
2138
2139
2140   if (0 == random() % 10) goto PANIC;
2141   BSOD_TEXT (bst, LEFT, "Pass 2: Checking directory structure\n");
2142   BSOD_PAUSE (bst, 2000000);
2143
2144   i = (random() % 20) - 5;
2145   while (--i > 0)
2146     {
2147       int n = random() % 0xFFFFF;
2148       int o = random() % 0xFFF;
2149       sprintf (buf, "Directory inode %d, block 0, offset %d: "
2150                "directory corrupted\n"
2151                "Salvage<y>? ",
2152                n, o);
2153       BSOD_TEXT (bst, LEFT, buf);
2154       BSOD_PAUSE (bst, 1000);
2155       BSOD_TEXT (bst, LEFT, " yes\n\n");
2156
2157       if (0 == (random() % 100))
2158         {
2159           sprintf (buf, "Missing '.' in directory inode %d.\nFix<y>?", n);
2160           BSOD_TEXT (bst, LEFT, buf);
2161           BSOD_PAUSE (bst, 1000);
2162           BSOD_TEXT (bst, LEFT, " yes\n\n");
2163         }
2164     }
2165
2166   if (0 == random() % 10)
2167     goto PANIC;
2168
2169   BSOD_TEXT (bst, LEFT, 
2170              "Pass 3: Checking directory connectivity\n"
2171              "/lost+found not found.  Create? yes\n");
2172   BSOD_PAUSE (bst, 2000000);
2173
2174   /* Unconnected directory inode 4949 (/var/spool/squid/06/???)
2175      Connect to /lost+found<y>? yes
2176
2177      '..' in /var/spool/squid/06/08 (20351) is <The NULL inode> (0), should be 
2178      /var/spool/squid/06 (20350).
2179      Fix<y>? yes
2180
2181      Unconnected directory inode 128337 (/var/spool/squid/06/???)
2182      Connect to /lost+found<y>? yes
2183    */
2184
2185
2186   if (0 == random() % 10) goto PANIC;
2187   BSOD_TEXT (bst, LEFT,  "Pass 4: Checking reference counts\n");
2188   BSOD_PAUSE (bst, 2000000);
2189
2190   /* Inode 2 ref count is 19, should be 20.  Fix<y>? yes
2191
2192      Inode 4949 ref count is 3, should be 2.  Fix<y>? yes
2193
2194         ...
2195
2196      Inode 128336 ref count is 3, should be 2.  Fix<y>? yes
2197
2198      Inode 128337 ref count is 3, should be 2.  Fix<y>? yes
2199
2200    */
2201
2202
2203   if (0 == random() % 10) goto PANIC;
2204   BSOD_TEXT (bst, LEFT,  "Pass 5: Checking group summary information\n");
2205   BSOD_PAUSE (bst, 2000000);
2206
2207   i = (random() % 200) - 50;
2208   if (i > 0)
2209     {
2210       BSOD_TEXT (bst, LEFT,  "Block bitmap differences: ");
2211       while (--i > 0)
2212         {
2213           sprintf (buf, " %d", -(random() % 0xFFF));
2214           BSOD_TEXT (bst, LEFT, buf);
2215           BSOD_PAUSE (bst, 1000);
2216         }
2217       BSOD_TEXT (bst, LEFT, "\nFix? yes\n\n");
2218     }
2219
2220
2221   i = (random() % 100) - 50;
2222   if (i > 0)
2223     {
2224       BSOD_TEXT (bst, LEFT,  "Inode bitmap differences: ");
2225       while (--i > 0)
2226         {
2227           sprintf (buf, " %d", -(random() % 0xFFF));
2228           BSOD_TEXT (bst, LEFT, buf);
2229           BSOD_PAUSE (bst, 1000);
2230         }
2231       BSOD_TEXT (bst, LEFT,  "\nFix? yes\n\n");
2232     }
2233
2234   i = (random() % 20) - 5;
2235   while (--i > 0)
2236     {
2237       int g = random() % 0xFFFF;
2238       int c = random() % 0xFFFF;
2239       sprintf (buf,
2240                "Free blocks count wrong for group #0 (%d, counted=%d).\nFix? ",
2241                g, c);
2242       BSOD_TEXT (bst, LEFT, buf);
2243       BSOD_PAUSE (bst, 1000);
2244       BSOD_TEXT (bst, LEFT,  " yes\n\n");
2245     }
2246
2247  PANIC:
2248
2249   i = 0;
2250   BSOD_TEXT (bst, LEFT,  "\n\n");
2251   while (linux_panic[i])
2252     {
2253       time_t t = time ((time_t *) 0);
2254       struct tm *tm = localtime (&t);
2255       char prefix[100];
2256
2257       if (*linux_panic[i])
2258         {
2259           strftime (prefix, sizeof(prefix)-1, "%b %d %H:%M:%S ", tm);
2260           BSOD_TEXT (bst, LEFT,  prefix);
2261           BSOD_TEXT (bst, LEFT,  sysname);
2262           BSOD_TEXT (bst, LEFT,  linux_panic[i]);
2263           BSOD_PAUSE (bst, 1000);
2264         }
2265       else
2266         BSOD_PAUSE (bst, 300000);
2267
2268       i++;
2269     }
2270   BSOD_PAUSE (bst, 4000000);
2271
2272   XClearWindow(dpy, window);
2273   return bst;
2274 }
2275
2276
2277 /*
2278  * Linux (hppa) panic, by Stuart Brady <sdbrady@ntlworld.com>
2279  * Output courtesy of M. Grabert
2280  */
2281 static struct bsod_state *
2282 hppa_linux (Display *dpy, Window window)
2283 {
2284   struct bsod_state *bst = 
2285     make_bsod_state (dpy, window, "hppalinux", "HPPALinux");
2286
2287   int i = 0;
2288   const char *release, *sysname, *gccversion, *version;
2289   long int linedelay = 0;
2290
2291   __extension__
2292   struct { long int delay; const char *string; } linux_panic[] =
2293     {{ 0, "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
2294           "\n\n\n\n\n\n\n\n\n\n\n\n\n" },
2295      { 0, "Linux version %s (root@%s) (gcc version %s) %s\n" },
2296      { 4000, "FP[0] enabled: Rev 1 Model 16\n" },
2297      { 10, "The 32-bit Kernel has started...\n" },
2298      { -1, "Determining PDC firmware type: System Map.\n" },
2299      { -1, "model 00005bb0 00000481 00000000 00000002 7778df9f 100000f0 "
2300            "00000008 000000b2 000000b2\n" },
2301      { -1, "vers  00000203\n" },
2302      { -1, "CPUID vers 17 rev 7 (0x00000227)\n" },
2303      { -1, "capabilities 0x3\n" },
2304      { -1, "model 9000/785/C3000\n" },
2305      { -1, "Total Memory: 1024 Mb\n" },
2306      { -1, "On node 0 totalpages: 262144\n" },
2307      { -1, "  DMA zone: 262144 pages, LIFO batch:16\n" },
2308      { -1, "  Normal zone: 0 pages, LIFO batch:1\n" },
2309      { -1, "  HighMem zone: 0 pages, LIFO batch:1\n" },
2310      { -1, "LCD display at f05d0008,f05d0000 registered\n" },
2311      { -1, "Building zonelist for node : 0\n" },
2312      { -1, "Kernel command line: ide=nodma root=/dev/sda3 HOME=/ ip=off "
2313            "console=ttyS0 TERM=vt102 palo_kernel=2/vmlinux-2.6\n" },
2314      { -1, "ide_setup: ide=nodmaIDE: Prevented DMA\n" },
2315      { -1, "PID hash table entries: 16 (order 4: 128 bytes)\n" },
2316      {500, "Console: colour dummy device 160x64\n" },
2317      { 10, "Memory: 1034036k available\n" },
2318      { -1, "Calibrating delay loop... 796.67 BogoMIPS\n" },
2319      { -1, "Dentry cache hash table entries: 131072 (order: 7, 524288 "
2320            "bytes)\n" },
2321      { -1, "Inode-cache hash table entries: 65536 (order: 6, 262144 "
2322            "bytes)\n" },
2323      { -1, "Mount-cache hash table entries: 512 (order: 0, 4096 bytes)\n" },
2324      { -1, "POSIX conformance testing by UNIFIX\n" },
2325      { -1, "NET: Registered protocol family 16\n" },
2326      { 100, "Searching for devices...\n" },
2327      { 25, "Found devices:\n" },
2328      { 10, "1. Astro BC Runway Port at 0xfed00000 [10] "
2329            "{ 12, 0x0, 0x582, 0x0000b }\n" },
2330      { -1, "2. Elroy PCI Bridge at 0xfed30000 [10/0] "
2331            "{ 13, 0x0, 0x782, 0x0000a }\n" },
2332      { -1, "3. Elroy PCI Bridge at 0xfed32000 [10/1] "
2333            "{ 13, 0x0, 0x782, 0x0000a }\n" },
2334      { -1, "4. Elroy PCI Bridge at 0xfed38000 [10/4] "
2335            "{ 13, 0x0, 0x782, 0x0000a }\n" },
2336      { -1, "5. Elroy PCI Bridge at 0xfed3c000 [10/6] "
2337            "{ 13, 0x0, 0x782, 0x0000a }\n" },
2338      { -1, "6. AllegroHigh W at 0xfffa0000 [32] "
2339            "{ 0, 0x0, 0x5bb, 0x00004 }\n" },
2340      { -1, "7. Memory at 0xfed10200 [49] { 1, 0x0, 0x086, 0x00009 }\n" },
2341      { -1, "CPU(s): 1 x PA8500 (PCX-W) at 400.000000 MHz\n" },
2342      { -1, "SBA found Astro 2.1 at 0xfed00000\n" },
2343      { -1, "lba version TR2.1 (0x2) found at 0xfed30000\n" },
2344      { -1, "lba version TR2.1 (0x2) found at 0xfed32000\n" },
2345      { -1, "lba version TR2.1 (0x2) found at 0xfed38000\n" },
2346      { -1, "lba version TR2.1 (0x2) found at 0xfed3c000\n" },
2347      { 100, "SCSI subsystem initialized\n" },
2348      { 10, "drivers/usb/core/usb.c: registered new driver usbfs\n" },
2349      { -1, "drivers/usb/core/usb.c: registered new driver hub\n" },
2350      { -1, "ikconfig 0.7 with /proc/config*\n" },
2351      { -1, "Initializing Cryptographic API\n" },
2352      { 250, "SuperIO: probe of 0000:00:0e.0 failed with error -1\n" },
2353      { 20, "SuperIO: Found NS87560 Legacy I/O device at 0000:00:0e.1 "
2354            "(IRQ 64)\n" },
2355      { -1, "SuperIO: Serial port 1 at 0x3f8\n" },
2356      { -1, "SuperIO: Serial port 2 at 0x2f8\n" },
2357      { -1, "SuperIO: Parallel port at 0x378\n" },
2358      { -1, "SuperIO: Floppy controller at 0x3f0\n" },
2359      { -1, "SuperIO: ACPI at 0x7e0\n" },
2360      { -1, "SuperIO: USB regulator enabled\n" },
2361      { -1, "SuperIO: probe of 0000:00:0e.2 failed with error -1\n" },
2362      { -1, "Soft power switch enabled, polling @ 0xf0400804.\n" },
2363      { -1, "pty: 256 Unix98 ptys configured\n" },
2364      { -1, "Generic RTC Driver v1.07\n" },
2365      { -1, "Serial: 8250/16550 driver $Revision: 1.90 $ 13 ports, "
2366            "IRQ sharing disabled\n" },
2367      { -1, "ttyS0 at I/O 0x3f8 (irq = 0) is a 16550A\n" },
2368      { -1, "ttyS1 at I/O 0x2f8 (irq = 0) is a 16550A\n" },
2369      { -1, "Linux Tulip driver version 1.1.13 (May 11, 2002)\n" },
2370      { 150, "tulip0: no phy info, aborting mtable build\n" },
2371      { 10, "tulip0:  MII transceiver #1 config 1000 status 782d "
2372            "advertising 01e1.\n" },
2373      { -1, "eth0: Digital DS21143 Tulip rev 65 at 0xf4008000, "
2374            "00:10:83:F9:B4:34, IRQ 66.\n" },
2375      { -1, "Uniform Multi-Platform E-IDE driver Revision: 7.00alpha2\n" },
2376      { -1, "ide: Assuming 33MHz system bus speed for PIO modes; "
2377            "override with idebus=xx\n" },
2378      { 100, "SiI680: IDE controller at PCI slot 0000:01:06.0\n" },
2379      { 10, "SiI680: chipset revision 2\n" },
2380      { -1, "SiI680: BASE CLOCK == 133\n" },
2381      { -1, "SiI680: 100% native mode on irq 128\n" },
2382      { -1, "    ide0: MMIO-DMA at 0xf4800000-0xf4800007 -- "
2383            "Error, MMIO ports already in use.\n" },
2384      { -1, "    ide1: MMIO-DMA at 0xf4800008-0xf480000f -- "
2385            "Error, MMIO ports already in use.\n" },
2386      { 5, "hda: TS130220A2, ATA DISK drive\n" },
2387      { -1, "      _______________________________\n" },
2388      { -1, "     < Your System ate a SPARC! Gah! >\n" },
2389      { -1, "      -------------------------------\n" },
2390      { -1, "             \\   ^__^\n" },
2391      { -1, "              \\  (xx)\\_______\n" },
2392      { -1, "                 (__)\\       )\\/\\\n" },
2393      { -1, "                  U  ||----w |\n" },
2394      { -1, "                     ||     ||\n" },
2395      { -1, "swapper (pid 1): Breakpoint (code 0)\n" },
2396      { -1, "\n" },
2397      { -1, "     YZrvWESTHLNXBCVMcbcbcbcbOGFRQPDI\n" },
2398      { -1, "PSW: 00000000000001001111111100001111 Not tainted\n" },
2399      { -1, "r00-03  4d6f6f21 1032f010 10208f34 103fc2e0\n" },
2400      { -1, "r04-07  103fc230 00000001 00000001 0000000f\n" },
2401      { -1, "r08-11  103454f8 000f41fa 372d3980 103ee404\n" },
2402      { -1, "r12-15  3ccbf700 10344810 103ee010 f0400004\n" },
2403      { -1, "r16-19  f00008c4 f000017c f0000174 00000000\n" },
2404      { -1, "r20-23  fed32840 fed32800 00000000 0000000a\n" },
2405      { -1, "r24-27  0000ffa0 000000ff 103fc2e0 10326010\n" },
2406      { -1, "r28-31  00000000 00061a80 4ff98340 10208f34\n" },
2407      { -1, "sr0-3   00000000 00000000 00000000 00000000\n" },
2408      { -1, "sr4-7   00000000 00000000 00000000 00000000\n" },
2409      { -1, "\n" },
2410      { -1, "IASQ: 00000000 00000000 IAOQ: 00000000 00000004\n" },
2411      { -1, " IIR: 00000000    ISR: 00000000  IOR: 00000000\n" },
2412      { -1, " CPU:        0   CR30: 4ff98000 CR31: 1037c000\n" },
2413      { -1, " ORIG_R28: 55555555\n" },
2414      { -1, " IAOQ[0]: 0x0\n" },
2415      { -1, " IAOQ[1]: 0x4\n" },
2416      { -1, " RP(r2): probe_hwif+0x218/0x44c\n" },
2417      { -1, "Kernel panic: Attempted to kill init!\n" },
2418      { 0, NULL }};
2419
2420   bst->scroll_p = True;
2421   bst->wrap_p = True;
2422   bst->left_margin = bst->right_margin = 10;
2423   bst->top_margin = bst->bottom_margin = 10;
2424
2425   release = "2.6.0-test11-pa2";
2426   sysname = "hppa";
2427   version = "#2 Mon Dec 8 06:09:27 GMT 2003";
2428 # ifdef HAVE_UNAME
2429   {
2430     struct utsname uts;
2431     char *s;
2432     if (uname (&uts) >= 0)
2433       {
2434         sysname = uts.nodename;
2435         if (!strcmp (uts.sysname, "Linux"))
2436           {
2437             release = uts.release;
2438             version = uts.version;
2439           }
2440       }
2441     s = strchr (sysname, '.');
2442     if (s) *s = 0;
2443   }
2444 # endif /* !HAVE_UNAME */
2445
2446 # if (defined (__GNUC__) && defined (__VERSION__))
2447   gccversion = __VERSION__;
2448 # else /* !(defined (__GNUC__) && defined (__VERSION__)) */
2449   gccversion = "3.3.2 (Debian)";
2450 # endif /* !(defined (__GNUC__) && defined (__VERSION__)) */
2451
2452   /* Insert current host name into banner on line 2 */
2453   {
2454     char ss[1024];
2455     snprintf (ss, 1024, linux_panic[1].string, 
2456               release, sysname, gccversion, version);
2457     linux_panic[1].string = ss;
2458   }
2459
2460   BSOD_PAUSE (bst, 100000);
2461   while (linux_panic[i].string)
2462     {
2463       if (linux_panic[i].delay != -1)
2464         linedelay = linux_panic[i].delay * 1000;
2465       BSOD_PAUSE (bst, linedelay);
2466       BSOD_TEXT (bst, LEFT, linux_panic[i].string);
2467       i++;
2468     }
2469
2470   bst->y = bst->xgwa.height - bst->font->ascent - bst->font->descent;
2471
2472   XClearWindow(dpy, window);
2473   return bst;
2474 }
2475
2476
2477 /* VMS by jwz (text sent by Roland Barmettler <roli@barmettler.net>)
2478  */
2479 static struct bsod_state *
2480 vms (Display *dpy, Window window)
2481 {
2482   struct bsod_state *bst = make_bsod_state (dpy, window, "vms", "VMS");
2483
2484   const char *sysname;
2485   int char_delay = 0;
2486   int dot_delay = 40000;
2487   int chunk_delay = 500000;
2488   char *s, *s1;
2489   int i;
2490   int arg_count;
2491
2492   __extension__
2493
2494   const char *lines[] = {
2495     "%CNXMAN,  Lost connection to system #\n"
2496     "%SHADOW-I-VOLPROC, DSA0: shadow master has changed.  "
2497     "Dump file WILL be written if system crashes.\n"
2498     "\n",
2499     "",
2500
2501     "%CNXMAN,  Quorum lost, blocking activity\n"
2502     "%CNXMAN,  Timed-out lost connection to system #\n"
2503     "%CNXMAN,  Timed-out lost connection to system #\n"
2504     "%CNXMAN,  Timed-out lost connection to system #\n"
2505     "%CNXMAN,  Proposing reconfiguration of the VMScluster\n",
2506     "",
2507
2508     "%CNXMAN,  Removed from VMScluster system #\n"
2509     "%CNXMAN,  Removed from VMScluster system #\n"
2510     "%CNXMAN,  Removed from VMScluster system #\n"
2511     "%CNXMAN,  Completing VMScluster state transition\n",
2512
2513     "\n"
2514     "**** OpenVMS (TM) Alpha Operating system V7.3-1   - BUGCHECK ****\n"
2515     "\n"
2516     "** Bugcheck code = 000005DC: CLUEXIT, Node voluntarily exiting "
2517     "VMScluster\n"
2518     "** Crash CPU: 00    Primary CPU: 00    Active CPUs: 00000001\n"
2519     "** Current Process = NULL\n"
2520     "** Current PSB ID = 00000001\n"
2521     "** Image Name =\n"
2522     "\n"
2523     "** Dumping error log buffers to HBVS unit 0\n"
2524     "**** Unable to dump error log buffers to remaining shadow set members\n"
2525     "** Error log buffers not dumped to HBVS unit 200\n"
2526     "\n"
2527     "** Dumping memory to HBVS unit 0\n"
2528     "**** Starting compressed selective memory dump at #...\n",
2529
2530     "...",
2531
2532     "\n"
2533     "**** Memory dump complete - not all processes or global pages saved\n",
2534
2535     "\n"
2536     "halted CPU 0\n",
2537     "",
2538
2539     "\n"
2540     "halt code = 5\n"
2541     "HALT instruction executed\n"
2542     "PC = ffffffff800c3884\n",
2543
2544     "\n"
2545     "CPU 0 booting\n",
2546
2547     "\n"
2548     "resetting all I/O buses\n"
2549     "\n"
2550     "\n"
2551     };
2552   char *args[8];
2553   int ids[3];
2554
2555   bst->scroll_p = True;
2556   bst->wrap_p = True;
2557   bst->left_margin = bst->right_margin = 10;
2558   bst->top_margin = bst->bottom_margin = 10;
2559
2560   sysname = "VMS001";
2561 # ifdef HAVE_UNAME
2562   {
2563     struct utsname uts;
2564     if (uname (&uts) >= 0)
2565       sysname = uts.nodename;
2566     s = strchr (sysname, '.');
2567     if (s) *s = 0;
2568   }
2569 # endif /* !HAVE_UNAME */
2570
2571   args[0] = malloc (strlen(sysname) + 7);
2572   strcpy (args[0], sysname);
2573   args[0][5] = 0;
2574
2575   /* Pick three numbers, 1-9, no overlaps. */
2576   ids[0] = 1 + (random() % 9);
2577   do { ids[1] = 1 + (random() % 9); } while (ids[1]==ids[0]);
2578   do { ids[2] = 1 + (random() % 9); } while (ids[2]==ids[0] || ids[2]==ids[1]);
2579
2580   i = strlen(args[0])-1;
2581   if (i < 6) i++;
2582   args[0][i] = '0' + ids[0];
2583   args[0][i+1] = 0;
2584
2585   for (s = args[0]; *s; s++)
2586     if (isalpha(*s)) *s = toupper (*s);
2587
2588   args[1] = strdup (args[0]);
2589   args[2] = strdup (args[0]); args[2][i] = '0' + ids[1];
2590   args[3] = strdup (args[0]); args[3][i] = '0' + ids[2];
2591
2592   args[4] = strdup (args[1]);
2593   args[5] = strdup (args[2]);
2594   args[6] = strdup (args[3]);
2595
2596   {
2597     time_t t = time ((time_t *) 0);
2598     struct tm *tm = localtime (&t);
2599     args[7] = malloc (30);
2600     strftime (args[7], 29, "%d-%b-%Y %H:%M", tm);
2601     for (s = args[7]; *s; s++)
2602       if (isalpha(*s)) *s = toupper (*s);
2603   }
2604
2605   arg_count = 0;
2606   for (i = 0; i < countof(lines); i++)
2607     {
2608       const char *fmt = lines[i];
2609       if (! strcmp (fmt, "..."))
2610         {
2611           int steps = 180 + (random() % 60);
2612           while (--steps >= 0)
2613             {
2614               BSOD_TEXT (bst, LEFT, ".");
2615               BSOD_PAUSE (bst, dot_delay);
2616             }
2617         }
2618       else
2619         {
2620           char *fmt2 = malloc (strlen (fmt) * 2 + 1);
2621           for (s = (char *) fmt, s1 = fmt2; *s; s++)
2622             {
2623               if (*s == '#')
2624                 {
2625                   strcpy (s1, args[arg_count++]);
2626                   s1 += strlen(s1);
2627                 }
2628               else
2629                 *s1++ = *s;
2630             }
2631           *s1 = 0;
2632           BSOD_CHAR_DELAY (bst, char_delay);
2633           BSOD_TEXT (bst, LEFT, fmt2);
2634           free (fmt2);
2635           BSOD_CHAR_DELAY (bst, 0);
2636           BSOD_PAUSE (bst, chunk_delay);
2637         }
2638     }
2639
2640   for (i = 0; i < countof (args); i++)
2641     free (args[i]);
2642
2643   XClearWindow(dpy, window);
2644   return bst;
2645 }
2646
2647
2648 /* HVX (formerly GCOS6) and TPS6 crash
2649    by Brian Garratt <brian-m.garratt@bull.co.uk>
2650
2651    GCOS6 is a Unix-like operating system developed by Honeywell in the
2652    1970s in collaboration with MIT and AT&T (who called their version
2653    UNIX).  Both are very much like MULTICS which Honeywell got from GE.
2654
2655    HVX ("High-performance Virtual System on Unix") is an AIX application
2656    which emulates GCOS6 hardware on RS6000-like machines.
2657  */
2658 static struct bsod_state *
2659 hvx (Display *dpy, Window window)
2660 {
2661   struct bsod_state *bst = make_bsod_state (dpy, window, "hvx", "HVX");
2662
2663   bst->scroll_p = True;
2664   bst->wrap_p = True;
2665   bst->y = bst->xgwa.height - bst->bottom_margin - bst->font->ascent;
2666
2667   BSOD_CHAR_DELAY (bst, 10000);
2668   BSOD_TEXT (bst, LEFT,
2669      "(TP) Trap no E   Effective address 00000000   Instruction D7DE\n"
2670      "(TP)  Registers :\n"
2671      "(TP)  B1 -> B7  03801B02  00000000  03880D45  038BABDB  0388AFFD"
2672      "  0389B3F8  03972317\n"
2673      "(TP)  R1 -> R7  0001  0007  F10F  090F  0020  0106  0272\n"
2674      "(TP)  P I Z M1  0388A18B  3232  0000 FF00\n"
2675      "(TP) Program counter is at offset 0028 from string YTPAD\n"
2676      "(TP) User id of task which trapped is LT 626\n"
2677      "(TP)?\n"
2678      );
2679   BSOD_PAUSE (bst, 1000000);
2680
2681   BSOD_CHAR_DELAY (bst, 100000);
2682   BSOD_TEXT (bst, LEFT, " TP CLOSE ALL");
2683
2684   BSOD_CHAR_DELAY (bst, 10000);
2685   BSOD_TEXT (bst, LEFT, "\n(TP)?\n");
2686   BSOD_PAUSE (bst, 1000000);
2687
2688   BSOD_CHAR_DELAY (bst, 100000);
2689   BSOD_TEXT (bst, LEFT, " TP ABORT -LT ALL");
2690
2691   BSOD_CHAR_DELAY (bst, 10000);
2692   BSOD_TEXT (bst, LEFT, "\n(TP)?\n");
2693   BSOD_PAUSE (bst, 1000000);
2694
2695   BSOD_CHAR_DELAY (bst, 100000);
2696   BSOD_TEXT (bst, LEFT, "  TP STOP KILL");
2697
2698   BSOD_CHAR_DELAY (bst, 10000);
2699   BSOD_TEXT (bst, LEFT,
2700      "\n"
2701      "(TP)?\n"
2702      "Core dumps initiated for selected HVX processes ...\n"
2703      "Core dumps complete.\n"
2704      "Fri Jul 19 15:53:09 2002\n"
2705      "Live registers for cp 0:\n"
2706      " P    =     7de3  IW=0000     I=32    CI=30000000   S=80006013"
2707      "   IV=aa0      Level=13\n"
2708      " R1-7 =       1f      913       13        4        8        0        0\n"
2709      " B1-7 =   64e71b      a93      50e   64e73c     6c2c     7000      b54\n"
2710      "Memory dump starting to file /var/hvx/dp01/diag/Level2 ...\n"
2711      "Memory dump complete.\n"
2712     );
2713
2714   XClearWindow(dpy, window);
2715   return bst;
2716 }
2717
2718
2719 /* HPUX panic, by Tobias Klausmann <klausman@schwarzvogel.de>
2720  */
2721 static struct bsod_state *
2722 hpux (Display *dpy, Window window)
2723 {
2724   struct bsod_state *bst = make_bsod_state (dpy, window, "hvx", "HVX");
2725   const char *sysname;
2726   char buf[2048];
2727
2728   bst->scroll_p = True;
2729   bst->y = bst->xgwa.height - bst->bottom_margin - bst->font->ascent;
2730
2731   sysname = "HPUX";
2732 # ifdef HAVE_UNAME
2733   {
2734     struct utsname uts;
2735     char *s;
2736     if (uname (&uts) >= 0)
2737       sysname = uts.nodename;
2738     s = strchr (sysname, '.');
2739     if (s) *s = 0;
2740   }
2741 # endif /* !HAVE_UNAME */
2742
2743   BSOD_TEXT (bst, LEFT,
2744              "                                                       "
2745              "                                                       "
2746              "                                                       \n");
2747   sprintf (buf, "%.100s [HP Release B.11.00] (see /etc/issue)\n", sysname);
2748   BSOD_TEXT (bst, LEFT, buf);
2749   BSOD_PAUSE (bst, 1000000);
2750   BSOD_TEXT (bst, LEFT,
2751    "Console Login:\n"
2752    "\n"
2753    "     ******* Unexpected HPMC/TOC. Processor HPA FFFFFFFF'"
2754    "FFFA0000 *******\n"
2755    "                              GENERAL REGISTERS:\n"
2756    "r00/03 00000000'00000000 00000000'00000000 00000000'00000000 00000000'"
2757    "006C76C0\n"
2758    "r04/07 00000000'00000001 00000000'0126E328 00000000'00000000 00000000'"
2759    "0122B640\n"
2760    "r08/11 00000000'00000000 00000000'0198CFC0 00000000'000476FE 00000000'"
2761    "00000001\n"
2762    "r12/15 00000000'40013EE8 00000000'08000080 00000000'4002530C 00000000'"
2763    "4002530C\n"
2764    "r16/19 00000000'7F7F2A00 00000000'00000001 00000000'00000000 00000000'"
2765    "00000000\n"
2766    "r20/23 00000000'006C8048 00000000'00000001 00000000'00000000 00000000'"
2767    "00000000\n"
2768    "r24/27 00000000'00000000 00000000'00000000 00000000'00000000 00000000'"
2769    "00744378\n"
2770    "r28/31 00000000'00000000 00000000'007DD628 00000000'0199F2B0 00000000'"
2771    "00000000\n"
2772    "                              CONTROL REGISTERS:\n"
2773    "sr0/3  00000000'0F3B4000 00000000'0C2A2000 00000000'016FF800 00000000'"
2774    "00000000\n"
2775    "sr4/7  00000000'00000000 00000000'016FF800 00000000'0DBF1400 00000000'"
2776    "00000000\n"
2777    "pcq =  00000000'00000000.00000000'00104950 00000000'00000000.00000000'"
2778    "00104A14\n"
2779    "isr =  00000000'10240006 ior = 00000000'67D9E220 iir = 08000240 rctr = "
2780    "7FF10BB6\n"
2781    "\n"
2782    "pid reg cr8/cr9    00007700'0000B3A9 00000000'0000C5D8\n"
2783    "pid reg cr12/cr13  00000000'00000000 00000000'00000000\n"
2784    "ipsw = 000000FF'080CFF1F iva = 00000000'0002C000 sar = 3A ccr = C0\n"
2785    "tr0/3  00000000'006C76C0 00000000'00000001 00000000'00000000 00000000'"
2786    "7F7CE000\n"
2787    "tr4/7  00000000'03790000 0000000C'4FB68340 00000000'C07EE13F 00000000'"
2788    "0199F2B0\n"
2789    "eiem = FFFFFFF0'FFFFFFFF eirr = 80000000'00000000 itmr = 0000000C'"
2790    "4FD8EDE1\n"
2791    "cr1/4  00000000'00000000 00000000'00000000 00000000'00000000 00000000'"
2792    "00000000\n"
2793    "cr5/7  00000000'00000000 00000000'00000000 00000000'"
2794    "00000000\n"
2795    "                           MACHINE CHECK PARAMETERS:\n"
2796    "Check Type = 00000000 CPU STATE = 9E000001 Cache Check = 00000000\n"
2797    "TLB Check = 00000000 Bus Check = 00000000 PIM State = ? SIU "
2798    "Status = ????????\n"
2799    "Assists = 00000000 Processor = 00000000\n"
2800    "Slave Addr = 00000000'00000000 Master Addr = 00000000'00000000\n"
2801    "\n"
2802    "\n"
2803    "TOC,    pcsq.pcoq = 0'0.0'104950   , isr.ior = 0'10240006.0'67d9e220\n"
2804    "@(#)B2352B/9245XB HP-UX (B.11.00) #1: Wed Nov  5 22:38:19 PST 1997\n"
2805    "Transfer of control: (display==0xd904, flags==0x0)\n"
2806    "\n"
2807    "\n"
2808    "\n"
2809    "*** A system crash has occurred.  (See the above messages for details.)\n"
2810    "*** The system is now preparing to dump physical memory to disk, for use\n"
2811    "*** in debugging the crash.\n"
2812    "\n"
2813    "*** The dump will be a SELECTIVE dump:  40 of 256 megabytes.\n"
2814    "*** To change this dump type, press any key within 10 seconds.\n"
2815    "*** Proceeding with selective dump.\n"
2816    "\n"
2817    "*** The dump may be aborted at any time by pressing ESC.\n");
2818
2819   {
2820     int i;
2821     int steps = 11;
2822     int size = 40;
2823     for (i = 0; i <= steps; i++)
2824       {
2825         if (i > steps) i = steps;
2826         sprintf (buf, 
2827                "*** Dumping: %3d%% complete (%d of 40 MB) (device 64:0x2)\r",
2828                  i * 100 / steps,
2829                  i * size / steps);
2830         BSOD_TEXT (bst, LEFT, buf);
2831         BSOD_PAUSE (bst, 1500000);
2832       }
2833   }
2834
2835   BSOD_TEXT (bst, LEFT, "\n*** System rebooting.\n");
2836
2837   XClearWindow(dpy, window);
2838   return bst;
2839 }
2840
2841
2842 /* IBM OS/390 aka MVS aka z/OS.
2843    Text from Dan Espen <dane@mk.telcordia.com>.
2844    Apparently this isn't actually a crash, just a random session...
2845    But who can tell.
2846  */
2847 static struct bsod_state *
2848 os390 (Display *dpy, Window window)
2849 {
2850   struct bsod_state *bst = make_bsod_state (dpy, window, "os390", "OS390");
2851
2852   bst->scroll_p = True;
2853   bst->y = bst->xgwa.height - bst->bottom_margin - bst->font->ascent;
2854
2855   BSOD_LINE_DELAY (bst, 100000);
2856   BSOD_TEXT (bst, LEFT,
2857    "\n*** System rebooting.\n"
2858    "* ISPF Subtask abend *\n"
2859    "SPF      ENDED DUE TO ERROR+\n"
2860    "READY\n"
2861    "\n"
2862    "IEA995I SYMPTOM DUMP OUTPUT\n"
2863    "  USER COMPLETION CODE=0222\n"
2864    " TIME=23.00.51  SEQ=03210  CPU=0000  ASID=00AE\n"
2865    " PSW AT TIME OF ERROR  078D1000   859DAF18  ILC 2  INTC 0D\n"
2866    "   NO ACTIVE MODULE FOUND\n"
2867    "   NAME=UNKNOWN\n"
2868    "   DATA AT PSW  059DAF12 - 00181610  0A0D9180  70644710\n"
2869    "   AR/GR 0: 00000000/80000000   1: 00000000/800000DE\n"
2870    "         2: 00000000/196504DC   3: 00000000/00037A78\n"
2871    "         4: 00000000/00037B78   5: 00000000/0003351C\n"
2872    "         6: 00000000/0000F0AD   7: 00000000/00012000\n"
2873    "         8: 00000000/059DAF10   9: 00000000/0002D098\n"
2874    "         A: 00000000/059D9F10   B: 00000000/059D8F10\n"
2875    "         C: 00000000/859D7F10   D: 00000000/00032D60\n"
2876    "         E: 00000000/00033005   F: 01000002/00000041\n"
2877    " END OF SYMPTOM DUMP\n"
2878    "ISPS014 - ** Logical screen request failed - abend 0000DE **\n"
2879    "ISPS015 - ** Contact your system programmer or dialog developer.**\n"
2880    "*** ISPF Main task abend ***\n"
2881    "IEA995I SYMPTOM DUMP OUTPUT\n"
2882    "  USER COMPLETION CODE=0222\n"
2883    " TIME=23.00.52  SEQ=03211  CPU=0000  ASID=00AE\n"
2884    " PSW AT TIME OF ERROR  078D1000   8585713C  ILC 2  INTC 0D\n"
2885    "   ACTIVE LOAD MODULE           ADDRESS=05855000  OFFSET=0000213C\n"
2886    "   NAME=ISPMAIN\n"
2887    "   DATA AT PSW  05857136 - 00181610  0A0D9180  D3304770\n"
2888    "   GR 0: 80000000   1: 800000DE\n"
2889    "      2: 00015260   3: 00000038\n"
2890    "      4: 00012508   5: 00000000\n"
2891    "      6: 000173AC   7: FFFFFFF8\n"
2892    "      8: 05858000   9: 00012CA0\n"
2893    "      A: 05857000   B: 05856000\n"
2894    "      C: 85855000   D: 00017020\n"
2895    "      E: 85857104   F: 00000000\n"
2896    " END OF SYMPTOM DUMP\n"
2897    "READY\n"
2898    "***");
2899   BSOD_CURSOR (bst, CURSOR_LINE, 240000, 999999);
2900
2901   XClearWindow(dpy, window);
2902   return bst;
2903 }
2904
2905
2906 /* Compaq Tru64 Unix panic, by jwz as described by
2907    Tobias Klausmann <klausman@schwarzvogel.de>
2908  */
2909 static struct bsod_state *
2910 tru64 (Display *dpy, Window window)
2911 {
2912   struct bsod_state *bst = make_bsod_state (dpy, window, "tru64", "Tru64");
2913   const char *sysname;
2914   char buf[2048];
2915
2916   bst->scroll_p = True;
2917   bst->y = bst->xgwa.height - bst->bottom_margin - bst->font->ascent;
2918
2919   sysname = "127.0.0.1";
2920 # ifdef HAVE_UNAME
2921   {
2922     struct utsname uts;
2923     if (uname (&uts) >= 0)
2924       sysname = uts.nodename;
2925   }
2926 # endif /* !HAVE_UNAME */
2927
2928   sprintf (buf,
2929            "Compaq Tru64 UNIX V5.1B (Rev. 2650) (%.100s) console\n"
2930            "\n"
2931            "login: ",
2932            sysname);
2933   BSOD_TEXT (bst, LEFT, buf);
2934   BSOD_PAUSE (bst, 6000000);
2935
2936   BSOD_TEXT (bst, LEFT,
2937     "panic (cpu 0): trap: illegal instruction\n"
2938     "kernel inst fault=gentrap, ps=0x5, pc=0xfffffc0000593878, inst=0xaa\n"
2939     "kernel inst fault=gentrap, ps=0x5, pc=0xfffffc0000593878, inst=0xaa\n"
2940     "                                                                   \n"
2941     "DUMP: blocks available:  1571600\n"
2942     "DUMP: blocks wanted:      100802 (partial compressed dump) [OKAY]\n"
2943     "DUMP: Device     Disk Blocks Available\n"
2944     "DUMP: ------     ---------------------\n"
2945     "DUMP: 0x1300023  1182795 - 1571597 (of 1571598) [primary swap]\n"
2946     "DUMP.prom: Open: dev 0x5100041, block 2102016: SCSI 0 11 0 2 200 0 0\n"
2947     "DUMP: Writing header... [1024 bytes at dev 0x1300023, block 1571598]\n"
2948     "DUMP: Writing data");
2949
2950   {
2951     int i;
2952     int steps = 4 + (random() % 8);
2953     BSOD_CHAR_DELAY (bst, 1000000);
2954     for (i = 0; i < steps; i++)
2955       BSOD_TEXT (bst, LEFT, ".");
2956     BSOD_CHAR_DELAY (bst, 0);
2957     sprintf (buf, "[%dMB]\n", steps);
2958     BSOD_TEXT (bst, LEFT, buf);
2959   }
2960
2961   BSOD_TEXT (bst, LEFT,
2962     "DUMP: Writing header... [1024 bytes at dev 0x1300023, block 1571598]\n"
2963     "DUMP: crash dump complete.\n"
2964     "kernel inst fault=gentrap, ps=0x5, pc=0xfffffc0000593878, inst=0xaa\n"
2965     "                                                                   \n"
2966     "DUMP: second crash dump skipped: 'dump_savecnt' enforced.\n");
2967   BSOD_PAUSE (bst, 4000000);
2968
2969   BSOD_TEXT (bst, LEFT,
2970     "\n"
2971     "halted CPU 0\n"
2972     "\n"
2973     "halt code = 5\n"
2974     "HALT instruction executed\n"
2975     "PC = fffffc00005863b0\n");
2976   BSOD_PAUSE (bst, 3000000);
2977
2978   BSOD_TEXT (bst, LEFT,
2979     "\n"   
2980     "CPU 0 booting\n"
2981     "\n"
2982     "\n"
2983     "\n");
2984
2985   XClearWindow(dpy, window);
2986   return bst;
2987 }
2988
2989
2990 /* MS-DOS, by jwz
2991  */
2992 static struct bsod_state *
2993 msdos (Display *dpy, Window window)
2994 {
2995   struct bsod_state *bst = make_bsod_state (dpy, window, "msdos", "MSDOS");
2996
2997   BSOD_CHAR_DELAY (bst, 10000);
2998   BSOD_TEXT (bst, LEFT, "C:\\WINDOWS>");
2999   BSOD_CURSOR (bst, CURSOR_LINE, 200000, 8);
3000
3001   BSOD_CHAR_DELAY (bst, 200000);
3002   BSOD_TEXT (bst, LEFT, "dir a:");
3003   BSOD_PAUSE (bst, 1000000);
3004
3005   BSOD_CHAR_DELAY (bst, 10000);
3006   BSOD_TEXT (bst, LEFT, "\nNot ready reading drive A\nAbort, Retry, Fail?");
3007
3008   BSOD_CURSOR (bst, CURSOR_LINE, 200000, 10);
3009   BSOD_CHAR_DELAY (bst, 200000);
3010   BSOD_TEXT (bst, LEFT, "f");
3011   BSOD_PAUSE (bst, 1000000);
3012
3013   BSOD_CHAR_DELAY (bst, 10000);
3014   BSOD_TEXT (bst, LEFT,
3015              "\n\n\nNot ready reading drive A\nAbort, Retry, Fail?");
3016
3017   BSOD_CURSOR (bst, CURSOR_LINE, 200000, 10);
3018   BSOD_CHAR_DELAY (bst, 200000);
3019   BSOD_TEXT (bst, LEFT, "f");
3020   BSOD_PAUSE (bst, 1000000);
3021
3022   BSOD_CHAR_DELAY (bst, 10000);
3023   BSOD_TEXT (bst, LEFT, "\nVolume in drive A has no label\n\n"
3024                   "Not ready reading drive A\nAbort, Retry, Fail?");
3025
3026   BSOD_CURSOR (bst, CURSOR_LINE, 200000, 12);
3027   BSOD_CHAR_DELAY (bst, 200000);
3028   BSOD_TEXT (bst, LEFT, "a");
3029   BSOD_PAUSE (bst, 1000000);
3030
3031   BSOD_CHAR_DELAY (bst, 10000);
3032   BSOD_TEXT (bst, LEFT, "\n\nC:\\WINDOWS>");
3033
3034   BSOD_CURSOR (bst, CURSOR_LINE, 200000, 999999);
3035
3036   XClearWindow(dpy, window);
3037   return bst;
3038 }
3039
3040
3041 /* nvidia, by jwz.
3042  *
3043  * This is what happens if an Nvidia card goes into some crazy text mode.
3044  * Most often seen on the second screen of a dual-head system when the
3045  * proper driver isn't loaded.
3046  */
3047 typedef struct { int fg; int bg; int bit; Bool blink; } nvcell;
3048
3049 static void
3050 nvspatter (nvcell *grid, int rows, int cols, int ncolors, int nbits,
3051            Bool fill_p)
3052 {
3053   int max = rows * cols;
3054   int from = fill_p ?   0 : random() % (max - 1);
3055   int len  = fill_p ? max : random() % (cols * 4);
3056   int to = from + len;
3057   int i;
3058   Bool noisy = ((random() % 4) == 0);
3059   Bool diag = (noisy || fill_p) ? 0 : ((random() % 4) == 0);
3060
3061   int fg = random() % ncolors;
3062   int bg = random() % ncolors;
3063   int blink = ((random() % 4) == 0);
3064   int bit = (random() % nbits);
3065
3066   if (to > max) to = max;
3067
3068   if (diag)
3069     {
3070       int src = random() % (rows * cols);
3071       int len2 = (cols / 2) - (random() % 5);
3072       int j = src;
3073       for (i = from; i < to; i++, j++)
3074         {
3075           if (j > src + len2 || j >= max)
3076             j = src;
3077           if (i >= max) abort();
3078           if (j >= max) abort();
3079           grid[j] = grid[i];
3080         }
3081     }
3082   else
3083     for (i = from; i < to; i++)
3084       {
3085         nvcell *cell = &grid[i];
3086         cell->fg = fg;
3087         cell->bg = bg;
3088         cell->bit = bit;
3089         cell->blink = blink;
3090
3091         if (noisy)
3092           {
3093             fg = random() % ncolors;
3094             bg = random() % ncolors;
3095             blink = ((random() % 8) == 0);
3096           }
3097       }
3098 }
3099
3100 typedef struct {
3101   struct bsod_state *bst;
3102   GC gc1;
3103   Pixmap bits[5];
3104   int rows, cols;
3105   int cellw, cellh;
3106   nvcell *grid;
3107   int ncolors;
3108   unsigned long colors[256];
3109   int tick;
3110 } nvstate;
3111
3112
3113 static void
3114 nvidia_free (struct bsod_state *bst)
3115 {
3116   nvstate *nvs = (nvstate *) bst->closure;
3117   int i;
3118   XFreeColors (bst->dpy, bst->xgwa.colormap, nvs->colors, nvs->ncolors, 0);
3119   for (i = 0; i < countof(nvs->bits); i++)
3120     XFreePixmap (bst->dpy, nvs->bits[i]);
3121   XFreeGC (bst->dpy, nvs->gc1);
3122   free (nvs->grid);
3123   free (nvs);
3124 }
3125
3126 static int
3127 nvidia_draw (struct bsod_state *bst)
3128 {
3129   nvstate *nvs = (nvstate *) bst->closure;
3130   int x, y;
3131
3132   for (y = 0; y < nvs->rows; y++)
3133     for (x = 0; x < nvs->cols; x++)
3134       {
3135         nvcell *cell = &nvs->grid[y * nvs->cols + x];
3136         unsigned long fg = nvs->colors[cell->fg];
3137         unsigned long bg = nvs->colors[cell->bg];
3138         Bool flip = cell->blink && (nvs->tick & 1);
3139         XSetForeground (bst->dpy, bst->gc, flip ? fg : bg);
3140         XSetBackground (bst->dpy, bst->gc, flip ? bg : fg);
3141         XCopyPlane (bst->dpy, nvs->bits[cell->bit], bst->window, bst->gc,
3142                     0, 0, nvs->cellw, nvs->cellh,
3143                     x * nvs->cellw, y * nvs->cellh, 1L);
3144       }
3145
3146   nvs->tick++;
3147   if ((random() % 5) == 0)    /* change the display */
3148     nvspatter (nvs->grid, nvs->rows, nvs->cols, nvs->ncolors, 
3149                countof(nvs->bits), False);
3150
3151   return 250000;
3152 }
3153
3154
3155 static struct bsod_state *
3156 nvidia (Display *dpy, Window window)
3157 {
3158   struct bsod_state *bst = make_bsod_state (dpy, window, "nvidia", "nVidia");
3159   nvstate *nvs = (nvstate *) calloc (1, sizeof (*nvs));
3160
3161   XGCValues gcv;
3162   int i;
3163
3164   nvs->bst = bst;
3165   bst->closure = nvs;
3166   bst->draw_cb = nvidia_draw;
3167   bst->free_cb = nvidia_free;
3168
3169   nvs->cols = 80;
3170   nvs->rows = 25;
3171   nvs->cellw = bst->xgwa.width  / nvs->cols;
3172   nvs->cellh = bst->xgwa.height / nvs->rows;
3173   if (nvs->cellw < 8 || nvs->cellh < 18)
3174     nvs->cellw = 8, nvs->cellh = 18;
3175   nvs->cols = (bst->xgwa.width  / nvs->cellw) + 1;
3176   nvs->rows = (bst->xgwa.height / nvs->cellh) + 1;
3177
3178   nvs->grid = (nvcell *) calloc (sizeof(*nvs->grid), nvs->rows * nvs->cols);
3179
3180   /* Allocate colors
3181    */
3182   nvs->ncolors = 16;
3183   for (i = 0; i < nvs->ncolors; i++)
3184     {
3185       XColor c;
3186       c.red   = random() & 0xFFFF;
3187       c.green = random() & 0xFFFF;
3188       c.blue  = random() & 0xFFFF;
3189       c.flags = DoRed|DoGreen|DoBlue;
3190       XAllocColor (dpy, bst->xgwa.colormap, &c);
3191       nvs->colors[i] = c.pixel;
3192     }
3193
3194   /* Construct corrupted character bitmaps
3195    */
3196   for (i = 0; i < countof(nvs->bits); i++)
3197     {
3198       int j;
3199
3200       nvs->bits[i] = XCreatePixmap (dpy, window, nvs->cellw, nvs->cellh, 1);
3201       if (!nvs->gc1) nvs->gc1 = XCreateGC (dpy, nvs->bits[i], 0, &gcv);
3202
3203       XSetForeground (dpy, nvs->gc1, 0);
3204       XFillRectangle (dpy, nvs->bits[i], nvs->gc1, 0, 0, 
3205                       nvs->cellw, nvs->cellh);
3206       XSetForeground (dpy, nvs->gc1, 1);
3207
3208       if ((random() % 40) != 0)
3209         for (j = 0; j < ((nvs->cellw * nvs->cellh) / 16); j++)
3210           XFillRectangle (dpy, nvs->bits[i], nvs->gc1,
3211                           (random() % (nvs->cellw-2)) & ~1,
3212                           (random() % (nvs->cellh-2)) & ~1,
3213                           2, 2);
3214     }
3215
3216   /* Randomize the grid
3217    */
3218   nvspatter (nvs->grid, nvs->rows, nvs->cols, nvs->ncolors, 
3219              countof(nvs->bits), True);
3220   for (i = 0; i < 20; i++)
3221     nvspatter (nvs->grid, nvs->rows, nvs->cols, nvs->ncolors, 
3222                countof(nvs->bits), False);
3223
3224   return bst;
3225 }
3226
3227
3228 /*
3229  * Simulate various Apple ][ crashes. The memory map encouraged many programs
3230  * to use the primary hi-res video page for various storage, and the secondary
3231  * hi-res page for active display. When it crashed into Applesoft or the
3232  * monitor, it would revert to the primary page and you'd see memory garbage on
3233  * the screen. Also, it was common for copy-protected games to use the primary
3234  * text page for important code, because that made it really hard to
3235  * reverse-engineer them. The result often looked like what this generates.
3236  *
3237  * The Apple ][ logic and video hardware is in apple2.c. The TV is emulated by
3238  * analogtv.c for maximum realism
3239  *
3240  * Trevor Blackwell <tlb@tlb.org> 
3241  */
3242
3243 static const char * const apple2_basic_errors[]={
3244   "BREAK",
3245   "NEXT WITHOUT FOR",
3246   "SYNTAX ERROR",
3247   "RETURN WITHOUT GOSUB",
3248   "ILLEGAL QUANTITY",
3249   "OVERFLOW",
3250   "OUT OF MEMORY",
3251   "BAD SUBSCRIPT ERROR",
3252   "DIVISION BY ZERO",
3253   "STRING TOO LONG",
3254   "FORMULA TOO COMPLEX",
3255   "UNDEF'D FUNCTION",
3256   "OUT OF DATA"
3257 #if 0
3258   ,
3259   "DEFAULT ARGUMENTS ARE NOT ALLOWED IN DECLARATION OF FRIEND "
3260   "TEMPLATE SPECIALIZATION"
3261 #endif
3262
3263 };
3264 static const char * const apple2_dos_errors[]={
3265   "VOLUME MISMATCH",
3266   "I/O ERROR",
3267   "DISK FULL",
3268   "NO BUFFERS AVAILABLE",
3269   "PROGRAM TOO LARGE",
3270 };
3271
3272 static void a2controller_crash(apple2_sim_t *sim, int *stepno,
3273                                double *next_actiontime)
3274 {
3275   apple2_state_t *st=sim->st;
3276   char *s;
3277   int i;
3278
3279   struct mydata {
3280     int fillptr;
3281     int fillbyte;
3282   } *mine;
3283
3284   if (!sim->controller_data)
3285     sim->controller_data = calloc(sizeof(struct mydata),1);
3286   mine=(struct mydata *) sim->controller_data;
3287   
3288   switch(*stepno) {
3289   case 0:
3290     
3291     a2_init_memory_active(sim);
3292     sim->dec->powerup = 1000.0;
3293
3294     if (random()%3==0) {
3295       st->gr_mode=0;
3296       *next_actiontime+=0.4;
3297       *stepno=100;
3298     }
3299     else if (random()%4==0) {
3300       st->gr_mode=A2_GR_LORES;
3301       if (random()%3==0) st->gr_mode |= A2_GR_FULL;
3302       *next_actiontime+=0.4;
3303       *stepno=100;
3304     }
3305     else if (random()%2==0) {
3306       st->gr_mode=A2_GR_HIRES;
3307       *stepno=300;
3308     }
3309     else {
3310       st->gr_mode=A2_GR_HIRES;
3311       *next_actiontime+=0.4;
3312       *stepno=100;
3313     }
3314     break;
3315
3316   case 100:
3317     /* An illegal instruction or a reset caused it to drop into the
3318        assembly language monitor, where you could disassemble code & view
3319        data in hex. */
3320     if (random()%3==0) {
3321       char ibytes[128];
3322       char itext[128];
3323       int addr=0xd000+random()%0x3000;
3324       sprintf(ibytes,
3325               "%02X",random()%0xff);
3326       sprintf(itext,
3327               "???");
3328       sprintf(sim->printing_buf,
3329               "\n\n"
3330               "%04X: %-15s %s\n"
3331               " A=%02X X=%02X Y=%02X S=%02X F=%02X\n"
3332               "*",
3333               addr,ibytes,itext,
3334               random()%0xff, random()%0xff,
3335               random()%0xff, random()%0xff,
3336               random()%0xff);
3337       sim->printing=sim->printing_buf;
3338       a2_goto(st,23,1);
3339       if (st->gr_mode) {
3340         *stepno=180;
3341       } else {
3342         *stepno=200;
3343       }
3344       sim->prompt='*';
3345       *next_actiontime += 2.0 + (random()%1000)*0.0002;
3346     }
3347     else {
3348       /* Lots of programs had at least their main functionality in
3349          Applesoft Basic, which had a lot of limits (memory, string
3350          length, etc) and would sometimes crash unexpectedly. */
3351       sprintf(sim->printing_buf,
3352               "\n"
3353               "\n"
3354               "\n"
3355               "?%s IN %d\n"
3356               "\001]",
3357               apple2_basic_errors[random() %
3358                                   (sizeof(apple2_basic_errors)
3359                                    /sizeof(char *))],
3360               (1000*(random()%(random()%59+1)) +
3361                100*(random()%(random()%9+1)) +
3362                5*(random()%(random()%199+1)) +
3363                1*(random()%(random()%(random()%2+1)+1))));
3364       sim->printing=sim->printing_buf;
3365       a2_goto(st,23,1);
3366       *stepno=110;
3367       sim->prompt=']';
3368       *next_actiontime += 2.0 + (random()%1000)*0.0002;
3369     }
3370     break;
3371
3372   case 110:
3373     if (random()%3==0) {
3374       /* This was how you reset the Basic interpreter. The sort of
3375          incantation you'd have on a little piece of paper taped to the
3376          side of your machine */
3377       sim->typing="CALL -1370";
3378       *stepno=120;
3379     }
3380     else if (random()%2==0) {
3381       sim->typing="CATALOG\n";
3382       *stepno=170;
3383     }
3384     else {
3385       *next_actiontime+=1.0;
3386       *stepno=999;
3387     }
3388     break;
3389
3390   case 120:
3391     *stepno=130;
3392     *next_actiontime += 0.5;
3393     break;
3394
3395   case 130:
3396     st->gr_mode=0;
3397     a2_cls(st);
3398     a2_goto(st,0,16);
3399     for (s="APPLE ]["; *s; s++) a2_printc(st,*s);
3400     a2_goto(st,23,0);
3401     a2_printc(st,']');
3402     *next_actiontime+=1.0;
3403     *stepno=999;
3404     break;
3405
3406   case 170:
3407     if (random()%50==0) {
3408       sprintf(sim->printing_buf,
3409               "\nDISK VOLUME 254\n\n"
3410               " A 002 HELLO\n"
3411               "\n"
3412               "]");
3413       sim->printing=sim->printing_buf;
3414     }
3415     else {
3416       sprintf(sim->printing_buf,"\n?%s\n]",
3417               apple2_dos_errors[random()%
3418                                 (sizeof(apple2_dos_errors) /
3419                                  sizeof(char *))]);
3420       sim->printing=sim->printing_buf;
3421     }
3422     *stepno=999;
3423     *next_actiontime+=1.0;
3424     break;
3425
3426   case 180:
3427     if (random()%2==0) {
3428       /* This was how you went back to text mode in the monitor */
3429       sim->typing="FB4BG";
3430       *stepno=190;
3431     } else {
3432       *next_actiontime+=1.0;
3433       *stepno=999;
3434     }
3435     break;
3436
3437   case 190:
3438     st->gr_mode=0;
3439     a2_invalidate(st);
3440     a2_printc(st,'\n');
3441     a2_printc(st,'*');
3442     *stepno=200;
3443     *next_actiontime+=2.0;
3444     break;
3445
3446   case 200:
3447     /* This reset things into Basic */
3448     if (random()%2==0) {
3449       sim->typing="FAA6G";
3450       *stepno=120;
3451     }
3452     else {
3453       *stepno=999;
3454       *next_actiontime+=sim->delay;
3455     }
3456     break;
3457
3458   case 300:
3459     for (i=0; i<1500; i++) {
3460       a2_poke(st, mine->fillptr, mine->fillbyte);
3461       mine->fillptr++;
3462       mine->fillbyte = (mine->fillbyte+1)&0xff;
3463     }
3464     *next_actiontime += 0.08;
3465     /* When you hit c000, it changed video settings */
3466     if (mine->fillptr>=0xc000) {
3467       a2_invalidate(st);
3468       st->gr_mode=0;
3469     }
3470     /* And it seemed to reset around here, I dunno why */
3471     if (mine->fillptr>=0xcf00) *stepno=130;
3472     break;
3473
3474   case 999:
3475     break;
3476
3477   case A2CONTROLLER_FREE:
3478     free(mine);
3479     break;
3480   }
3481 }
3482
3483 static int
3484 a2_draw (struct bsod_state *bst)
3485 {
3486   apple2_sim_t *sim = (apple2_sim_t *) bst->closure;
3487   if (! sim) {
3488     sim = apple2_start (bst->dpy, bst->window, 9999999, a2controller_crash);
3489     bst->closure = sim;
3490   }
3491
3492   if (! apple2_one_frame (sim)) {
3493     bst->closure = 0;
3494   }
3495
3496   return 10000;
3497 }
3498
3499 static void
3500 a2_free (struct bsod_state *bst)
3501 {
3502   apple2_sim_t *sim = (apple2_sim_t *) bst->closure;
3503   if (sim) {
3504     sim->stepno = A2CONTROLLER_DONE;
3505     a2_draw (bst);              /* finish up */
3506     if (bst->closure) abort();  /* should have been freed by now */
3507   }
3508 }
3509
3510
3511 static struct bsod_state *
3512 apple2crash (Display *dpy, Window window)
3513 {
3514   struct bsod_state *bst = make_bsod_state (dpy, window, "apple2", "Apple2");
3515   bst->draw_cb = a2_draw;
3516   bst->free_cb = a2_free;
3517   return bst;
3518 }
3519
3520
3521 static struct bsod_state *
3522 atm (Display *dpy, Window window)
3523 {
3524   struct bsod_state *bst = make_bsod_state (dpy, window, "atm", "ATM");
3525
3526   Pixmap pixmap = 0;
3527   int pix_w = atm_width;
3528   int pix_h = atm_height;
3529   int x, y, i = 0;
3530   float scale = 0.48;
3531
3532   XClearWindow (dpy, window);
3533
3534   pixmap = XCreatePixmapFromBitmapData (dpy, window, (char *) atm_bits,
3535                                         atm_width, atm_height,
3536                                         bst->fg, bst->bg, bst->xgwa.depth);
3537
3538   while (pix_w <= bst->xgwa.width  * scale && 
3539          pix_h <= bst->xgwa.height * scale)
3540     {
3541       pixmap = double_pixmap (dpy, bst->gc, bst->xgwa.visual, bst->xgwa.depth,
3542                               pixmap, pix_w, pix_h);
3543       pix_w *= 2;
3544       pix_h *= 2;
3545       i++;
3546     }
3547
3548   x = (bst->xgwa.width  - pix_w) / 2;
3549   y = (bst->xgwa.height - pix_h) / 2;
3550   if (y < 0) y = 0;
3551
3552   if (i > 0)
3553     {
3554       int j;
3555       XSetForeground (dpy, bst->gc,
3556                       get_pixel_resource (dpy, bst->xgwa.colormap,
3557                                           "atm.background",
3558                                           "ATM.Background"));
3559       for (j = -1; j < pix_w; j += i+1)
3560         XDrawLine (bst->dpy, pixmap, bst->gc, j, 0, j, pix_h);
3561       for (j = -1; j < pix_h; j += i+1)
3562         XDrawLine (bst->dpy, pixmap, bst->gc, 0, j, pix_w, j);
3563     }
3564
3565   XCopyArea (dpy, pixmap, window, bst->gc, 0, 0, pix_w, pix_h, x, y);
3566
3567   XFreePixmap (dpy, pixmap);
3568
3569   return bst;
3570 }
3571
3572
3573 /*****************************************************************************
3574  *****************************************************************************/
3575
3576
3577 static const struct {
3578   const char *name;
3579   struct bsod_state * (*fn) (Display *, Window);
3580 } all_modes[] = {
3581   { "Windows",          windows_31 },
3582   { "NT",               windows_nt },
3583   { "Win2K",            windows_other },
3584   { "Amiga",            amiga },
3585   { "Mac",              mac },
3586   { "MacsBug",          macsbug },
3587   { "Mac1",             mac1 },
3588   { "MacX",             macx },
3589   { "SCO",              sco },
3590   { "HVX",              hvx },
3591   { "HPPALinux",        hppa_linux },
3592   { "SparcLinux",       sparc_linux },
3593   { "BSD",              bsd },
3594   { "Atari",            atari },
3595 #ifndef HAVE_COCOA
3596   { "BlitDamage",       blitdamage },
3597 #endif
3598   { "Solaris",          sparc_solaris },
3599   { "Linux",            linux_fsck },
3600   { "HPUX",             hpux },
3601   { "OS390",            os390 },
3602   { "Tru64",            tru64 },
3603   { "VMS",              vms },
3604   { "OS2",              os2 },
3605   { "MSDOS",            msdos },
3606   { "Nvidia",           nvidia },
3607   { "Apple2",           apple2crash },
3608   { "ATM",              atm },
3609 };
3610
3611
3612 struct driver_state {
3613   const char *name;
3614   int only, which;
3615   int delay;
3616   time_t start;
3617   Bool debug_p, cycle_p;
3618   struct bsod_state *bst;
3619 };
3620
3621
3622 static void
3623 hack_title (struct driver_state *dst)
3624 {
3625 # ifndef HAVE_COCOA
3626   char *oname = 0;
3627   XFetchName (dst->bst->dpy, dst->bst->window, &oname);
3628   if (oname && !strncmp (oname, "BSOD: ", 6)) {
3629     char *tail = oname + 4;
3630     char *s = strchr (tail+1, ':');
3631     char *nname;
3632     if (s) tail = s;
3633     nname = malloc (strlen (tail) + strlen (dst->name) + 20);
3634     sprintf (nname, "BSOD: %s%s", dst->name, tail);
3635     XStoreName (dst->bst->dpy, dst->bst->window, nname);
3636     free (nname);
3637   }
3638 # endif /* !HAVE_COCOA */
3639 }
3640
3641 static void *
3642 bsod_init (Display *dpy, Window window)
3643 {
3644   struct driver_state *dst = (struct driver_state *) calloc (1, sizeof(*dst));
3645   char *s;
3646
3647   dst->delay = get_integer_resource (dpy, "delay", "Integer");
3648   if (dst->delay < 3) dst->delay = 3;
3649
3650   dst->debug_p = get_boolean_resource (dpy, "debug", "Boolean");
3651
3652   dst->only = -1;
3653   s = get_string_resource(dpy, "doOnly", "DoOnly");
3654   if (s && !strcasecmp (s, "cycle"))
3655     {
3656       dst->which = -1;
3657       dst->cycle_p = True;
3658     }
3659   else if (s && *s)
3660     {
3661       int count = countof(all_modes);
3662       for (dst->only = 0; dst->only < count; dst->only++)
3663         if (!strcasecmp (s, all_modes[dst->only].name))
3664           break;
3665       if (dst->only >= count)
3666         {
3667           fprintf (stderr, "%s: unknown -only mode: \"%s\"\n", progname, s);
3668           dst->only = -1;
3669         }
3670     }
3671   if (s) free (s);
3672
3673   dst->name = "none";
3674   dst->which = -1;
3675   return dst;
3676 }
3677
3678
3679 static unsigned long
3680 bsod_draw (Display *dpy, Window window, void *closure)
3681 {
3682   struct driver_state *dst = (struct driver_state *) closure;
3683   time_t now;
3684   int time_left;
3685
3686  AGAIN:
3687   now = time ((time_t *) 0);
3688   time_left = dst->start + dst->delay - now;
3689
3690   if (dst->bst && dst->bst->img_loader)   /* still loading */
3691     {
3692       dst->bst->img_loader = 
3693         load_image_async_simple (dst->bst->img_loader, 0, 0, 0, 0, 0);
3694       return 100000;
3695     }
3696
3697   if (! dst->bst && time_left > 0)      /* run completed; wait out the delay */
3698     {
3699       if (dst->debug_p)
3700         fprintf (stderr, "%s: %s: %d left\n", progname, dst->name, time_left);
3701       return 500000;
3702     }
3703
3704   else if (dst->bst)                    /* sub-mode currently running */
3705     {
3706       int this_delay = -1;
3707
3708       if (time_left > 0)
3709         this_delay = bsod_pop (dst->bst);
3710
3711       /* XSync (dpy, False);  slows down char drawing too much on HAVE_COCOA */
3712
3713       if (this_delay == 0)
3714         goto AGAIN;                     /* no delay, not expired: stay here */
3715       else if (this_delay >= 0)
3716         return this_delay;              /* return; time to sleep */
3717       else
3718         {                               /* sub-mode run completed or expired */
3719           if (dst->debug_p)
3720             fprintf (stderr, "%s: %s: done\n", progname, dst->name);
3721           free_bsod_state (dst->bst);
3722           dst->bst = 0;
3723           return 0;
3724         }
3725     }
3726   else                                  /* launch a new sub-mode */
3727     {
3728       if (dst->cycle_p)
3729         dst->which = (dst->which + 1) % countof(all_modes);
3730       else if (dst->only >= 0)
3731         dst->which = dst->only;
3732       else
3733         {
3734           int count = countof(all_modes);
3735           int i;
3736
3737           for (i = 0; i < 200; i++)
3738             {
3739               char name[100], class[100];
3740               int new_mode = (random() & 0xFF) % count;
3741
3742               if (i < 100 && new_mode == dst->which)
3743                 continue;
3744
3745               sprintf (name,  "do%s", all_modes[new_mode].name);
3746               sprintf (class, "Do%s", all_modes[new_mode].name);
3747
3748               if (get_boolean_resource (dpy, name, class))
3749                 {
3750                   dst->which = new_mode;
3751                   break;
3752                 }
3753             }
3754
3755           if (i >= 200)
3756             {
3757               fprintf (stderr, "%s: no display modes enabled?\n", progname);
3758               /* exit (-1); */
3759               dst->which = dst->only = 0;
3760             }
3761         }
3762           
3763       if (dst->debug_p)
3764         fprintf (stderr, "%s: %s: launch\n", progname, 
3765                  all_modes[dst->which].name);
3766
3767       /* Run the mode setup routine...
3768        */
3769       if (dst->bst) abort();
3770       dst->name  = all_modes[dst->which].name;
3771       dst->bst   = all_modes[dst->which].fn (dpy, window);
3772       dst->start = (dst->bst ? time ((time_t *) 0) : 0);
3773
3774       /* Reset the structure run state to the beginning,
3775          and do some sanitization of the cursor position
3776          before the first run.
3777        */
3778       if (dst->bst)
3779         {
3780           if (dst->debug_p)
3781             fprintf (stderr, "%s: %s: queue size: %d (%d)\n", progname, 
3782                      dst->name, dst->bst->pos, dst->bst->queue_size);
3783
3784           hack_title (dst);
3785           dst->bst->pos = 0;
3786           dst->bst->x = dst->bst->current_left = dst->bst->left_margin;
3787
3788           if (dst->bst->y < dst->bst->top_margin + dst->bst->font->ascent)
3789             dst->bst->y = dst->bst->top_margin + dst->bst->font->ascent;
3790         }
3791     }
3792
3793   return 0;
3794 }
3795
3796
3797 static void
3798 bsod_reshape (Display *dpy, Window window, void *closure, 
3799               unsigned int w, unsigned int h)
3800 {
3801   struct driver_state *dst = (struct driver_state *) closure;
3802
3803   if (dst->bst &&
3804       w == dst->bst->xgwa.width &&
3805       h == dst->bst->xgwa.height)
3806     return;
3807
3808   if (dst->debug_p)
3809     fprintf (stderr, "%s: %s: reshape reset\n", progname, dst->name);
3810
3811   /* just pick a new mode and restart when the window is resized. */
3812   if (dst->bst)
3813     free_bsod_state (dst->bst);
3814   dst->bst = 0;
3815   dst->start = 0;
3816   dst->name = "none";
3817   XClearWindow (dpy, window);
3818 }
3819
3820
3821 static Bool
3822 bsod_event (Display *dpy, Window window, void *closure, XEvent *event)
3823 {
3824   struct driver_state *dst = (struct driver_state *) closure;
3825   Bool reset_p = False;
3826
3827   /* pick a new mode and restart when mouse clicked, or certain keys typed. */
3828
3829   if (event->type == ButtonPress)
3830     reset_p = True;
3831   else if (event->type == KeyPress)
3832     {
3833       KeySym keysym;
3834       char c = 0;
3835       XLookupString (&event->xkey, &c, 1, &keysym, 0);
3836       if (c == ' ' || c == '\t' || c == '\r' || c == '\n')
3837         reset_p = True;
3838     }
3839
3840   if (reset_p)
3841     {
3842       if (dst->debug_p)
3843         fprintf (stderr, "%s: %s: manual reset\n", progname, dst->name);
3844       if (dst->bst)
3845         free_bsod_state (dst->bst);
3846       dst->bst = 0;
3847       dst->start = 0;
3848       dst->name = "none";
3849       XClearWindow (dpy, window);
3850       return True;
3851     }
3852   else
3853     return False;
3854 }
3855
3856
3857 static void
3858 bsod_free (Display *dpy, Window window, void *closure)
3859 {
3860   struct driver_state *dst = (struct driver_state *) closure;
3861   if (dst->bst)
3862     free_bsod_state (dst->bst);
3863   free (dst);
3864 }
3865
3866
3867 static const char *bsod_defaults [] = {
3868   "*delay:                 30",
3869   "*debug:                 False",
3870
3871   "*doOnly:                ",
3872   "*doWindows:             True",
3873   "*doNT:                  True",
3874   "*doWin2K:               True",
3875   "*doAmiga:               True",
3876   "*doMac:                 True",
3877   "*doMacsBug:             True",
3878   "*doMac1:                True",
3879   "*doMacX:                True",
3880   "*doSCO:                 True",
3881   "*doAtari:               False",      /* boring */
3882   "*doBSD:                 False",      /* boring */
3883   "*doLinux:               True",
3884   "*doSparcLinux:          False",      /* boring */
3885   "*doHPPALinux:           True",
3886   "*doBlitDamage:          True",
3887   "*doSolaris:             True",
3888   "*doHPUX:                True",
3889   "*doTru64:               True",
3890   "*doApple2:              True",
3891   "*doOS390:               True",
3892   "*doVMS:                 True",
3893   "*doHVX:                 True",
3894   "*doMSDOS:               True",
3895   "*doOS2:                 True",
3896   "*doNvidia:              True",
3897   "*doATM:                 True",
3898
3899   "*font:                  9x15bold",
3900   "*font2:                 -*-courier-bold-r-*-*-*-120-*-*-m-*-*-*",
3901   "*bigFont:               -*-courier-bold-r-*-*-*-180-*-*-m-*-*-*",
3902   "*bigFont2:              -*-courier-bold-r-*-*-*-180-*-*-m-*-*-*",
3903
3904   ".foreground:            White",
3905   ".background:            Black",
3906
3907   ".windows.foreground:    White",
3908   ".windows.background:    #0000AA",    /* EGA color 0x01. */
3909
3910   ".windowslh.foreground:  White",
3911   ".windowslh.background:  #AA0000",    /* EGA color 0x04. */
3912   ".windowslh.background2: #AAAAAA",    /* EGA color 0x07. */
3913
3914   ".amiga.foreground:      #FF0000",
3915   ".amiga.background:      Black",
3916   ".amiga.background2:     White",
3917
3918   ".mac.foreground:        #BBFFFF",
3919   ".mac.background:        Black",
3920
3921   ".atari.foreground:      Black",
3922   ".atari.background:      White",
3923
3924   ".macsbug.font:          -*-courier-medium-r-*-*-*-80-*-*-m-*-*-*",
3925   ".macsbug.bigFont:       -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*",
3926   ".macsbug.foreground:    Black",
3927   ".macsbug.background:    White",
3928   ".macsbug.borderColor:   #AAAAAA",
3929
3930   ".mac1.foreground:       Black",
3931   ".mac1.background:       White",
3932
3933   ".macx.foreground:       White",
3934   ".macx.textForeground:   White",
3935   ".macx.textBackground:   Black",
3936   ".macx.background:       #888888",
3937
3938   ".sco.font:              -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*",
3939   ".sco.foreground:        White",
3940   ".sco.background:        Black",
3941
3942   ".hvx.font:              -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*",
3943   ".hvx.foreground:        White",
3944   ".hvx.background:        Black",
3945
3946   ".linux.foreground:      White",
3947   ".linux.background:      Black",
3948
3949   ".hppalinux.bigFont:     -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*",
3950   ".hppalinux.foreground:  White",
3951   ".hppalinux.background:  Black",
3952
3953   ".sparclinux.bigFont:    -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*",
3954   ".sparclinux.foreground: White",
3955   ".sparclinux.background: Black",
3956
3957   ".bsd.font:              vga",
3958   ".bsd.bigFont:           -sun-console-medium-r-*-*-22-*-*-*-m-*-*-*",
3959   ".bsd.bigFont2:          -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*",
3960   ".bsd.foreground:        #c0c0c0",
3961   ".bsd.background:        Black",
3962
3963   ".solaris.font:          -sun-gallant-*-*-*-*-19-*-*-*-*-120-*-*",
3964   ".solaris.foreground:    Black",
3965   ".solaris.background:    White",
3966
3967   ".hpux.bigFont:          -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*",
3968   ".hpux.foreground:       White",
3969   ".hpux.background:       Black",
3970
3971   ".os390.bigFont:         -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*",
3972   ".os390.background:      Black",
3973   ".os390.foreground:      Red",
3974
3975   ".tru64.bigFont:         -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*",
3976   ".tru64.foreground:      White",
3977   ".tru64.background:      #0000AA",    /* EGA color 0x01. */
3978
3979   ".vms.bigFont:           -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*",
3980   ".vms.foreground:        White",
3981   ".vms.background:        Black",
3982
3983   ".msdos.bigFont:         -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*",
3984   ".msdos.foreground:      White",
3985   ".msdos.background:      Black",
3986
3987   ".os2.foreground:        White",
3988   ".os2.background:        Black",
3989
3990   ".atm.foreground:        Black",
3991   ".atm.background:        #FF6600",
3992
3993   "*dontClearRoot:         True",
3994
3995   "*apple2TVColor:         50",
3996   "*apple2TVTint:          5",
3997   "*apple2TVBrightness:    10",
3998   "*apple2TVContrast:      90",
3999   "*apple2SimulateUser:    True",
4000
4001   ANALOGTV_DEFAULTS
4002
4003 #ifdef HAVE_XSHM_EXTENSION
4004   "*useSHM:                True",
4005 #endif
4006   0
4007 };
4008
4009 static const XrmOptionDescRec bsod_options [] = {
4010   { "-delay",           ".delay",               XrmoptionSepArg, 0 },
4011   { "-only",            ".doOnly",              XrmoptionSepArg, 0 },
4012   { "-debug",           ".debug",               XrmoptionNoArg,  "True"  },
4013   { "-windows",         ".doWindows",           XrmoptionNoArg,  "True"  },
4014   { "-no-windows",      ".doWindows",           XrmoptionNoArg,  "False" },
4015   { "-nt",              ".doNT",                XrmoptionNoArg,  "True"  },
4016   { "-no-nt",           ".doNT",                XrmoptionNoArg,  "False" },
4017   { "-2k",              ".doWin2K",             XrmoptionNoArg,  "True"  },
4018   { "-no-2k",           ".doWin2K",             XrmoptionNoArg,  "False" },
4019   { "-amiga",           ".doAmiga",             XrmoptionNoArg,  "True"  },
4020   { "-no-amiga",        ".doAmiga",             XrmoptionNoArg,  "False" },
4021   { "-mac",             ".doMac",               XrmoptionNoArg,  "True"  },
4022   { "-no-mac",          ".doMac",               XrmoptionNoArg,  "False" },
4023   { "-mac1",            ".doMac1",              XrmoptionNoArg,  "True"  },
4024   { "-no-mac1",         ".doMac1",              XrmoptionNoArg,  "False" },
4025   { "-macx",            ".doMacX",              XrmoptionNoArg,  "True"  },
4026   { "-no-macx",         ".doMacX",              XrmoptionNoArg,  "False" },
4027   { "-atari",           ".doAtari",             XrmoptionNoArg,  "True"  },
4028   { "-no-atari",        ".doAtari",             XrmoptionNoArg,  "False" },
4029   { "-macsbug",         ".doMacsBug",           XrmoptionNoArg,  "True"  },
4030   { "-no-macsbug",      ".doMacsBug",           XrmoptionNoArg,  "False" },
4031   { "-apple2",          ".doApple2",            XrmoptionNoArg,  "True"  },
4032   { "-no-apple2",       ".doApple2",            XrmoptionNoArg,  "False" },
4033   { "-sco",             ".doSCO",               XrmoptionNoArg,  "True"  },
4034   { "-no-sco",          ".doSCO",               XrmoptionNoArg,  "False" },
4035   { "-hvx",             ".doHVX",               XrmoptionNoArg,  "True"  },
4036   { "-no-hvx",          ".doHVX",               XrmoptionNoArg,  "False" },
4037   { "-bsd",             ".doBSD",               XrmoptionNoArg,  "True"  },
4038   { "-no-bsd",          ".doBSD",               XrmoptionNoArg,  "False" },
4039   { "-linux",           ".doLinux",             XrmoptionNoArg,  "True"  },
4040   { "-no-linux",        ".doLinux",             XrmoptionNoArg,  "False" },
4041   { "-hppalinux",       ".doHPPALinux",         XrmoptionNoArg,  "True"  },
4042   { "-no-hppalinux",    ".doHPPALinux",         XrmoptionNoArg,  "False" },
4043   { "-sparclinux",      ".doSparcLinux",        XrmoptionNoArg,  "True"  },
4044   { "-no-sparclinux",   ".doSparcLinux",        XrmoptionNoArg,  "False" },
4045   { "-blitdamage",      ".doBlitDamage",        XrmoptionNoArg,  "True"  },
4046   { "-no-blitdamage",   ".doBlitDamage",        XrmoptionNoArg,  "False" },
4047   { "-nvidia",          ".doNvidia",            XrmoptionNoArg,  "True"  },
4048   { "-no-nvidia",       ".doNvidia",            XrmoptionNoArg,  "False" },
4049   { "-solaris",         ".doSolaris",           XrmoptionNoArg,  "True"  },
4050   { "-no-solaris",      ".doSolaris",           XrmoptionNoArg,  "False" },
4051   { "-hpux",            ".doHPUX",              XrmoptionNoArg,  "True"  },
4052   { "-no-hpux",         ".doHPUX",              XrmoptionNoArg,  "False" },
4053   { "-os390",           ".doOS390",             XrmoptionNoArg,  "True"  },
4054   { "-no-os390",        ".doOS390",             XrmoptionNoArg,  "False" },
4055   { "-tru64",           ".doHPUX",              XrmoptionNoArg,  "True"  },
4056   { "-no-tru64",        ".doTru64",             XrmoptionNoArg,  "False" },
4057   { "-vms",             ".doVMS",               XrmoptionNoArg,  "True"  },
4058   { "-no-vms",          ".doVMS",               XrmoptionNoArg,  "False" },
4059   { "-msdos",           ".doMSDOS",             XrmoptionNoArg,  "True"  },
4060   { "-no-msdos",        ".doMSDOS",             XrmoptionNoArg,  "False" },
4061   { "-os2",             ".doOS2",               XrmoptionNoArg,  "True"  },
4062   { "-no-os2",          ".doOS2",               XrmoptionNoArg,  "False" },
4063   { "-atm",             ".doATM",               XrmoptionNoArg,  "True"  },
4064   { "-no-atm",          ".doATM",               XrmoptionNoArg,  "False" },
4065   ANALOGTV_OPTIONS
4066   { 0, 0, 0, 0 }
4067 };
4068
4069
4070 XSCREENSAVER_MODULE ("BSOD", bsod)