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