X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fbsod.c;h=2e45e6d82bdfbd95dbe5db9dfb94091d433347cf;hb=14627f4038ada5d11456f3770090f3c39740d70f;hp=2fd27c0eee092c20a18ca61111ad93103a716fe4;hpb=59ac4e9a0de290e4275a7bbb890ad16abd09d68f;p=xscreensaver diff --git a/hacks/bsod.c b/hacks/bsod.c index 2fd27c0e..2e45e6d8 100644 --- a/hacks/bsod.c +++ b/hacks/bsod.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1998 Jamie Zawinski +/* xscreensaver, Copyright (c) 1998, 2000 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -158,6 +158,11 @@ static Bool bsod_sleep(Display *dpy, int seconds) { int q = seconds * 4; + int quantum = 250000; + + if (seconds == -1) + q = 1, quantum = 100000; + do { XSync(dpy, False); @@ -165,6 +170,8 @@ bsod_sleep(Display *dpy, int seconds) { XEvent event; XNextEvent (dpy, &event); + if (event.xany.type == ButtonPress) + return True; if (event.xany.type == KeyPress) { KeySym keysym; @@ -179,7 +186,7 @@ bsod_sleep(Display *dpy, int seconds) if (q > 0) { q--; - usleep(250000); + usleep(quantum); } } while (q > 0); @@ -210,7 +217,7 @@ windows (Display *dpy, Window window, int delay, Bool w95p) "\n" "_Press any key to continue"); - const char *wnt = + const char *wnt = /* from Jim Niemira */ ("*** STOP: 0x0000001E (0x80000003,0x80106fc0,0x8025ea21,0xfd6829e8)\n" "Unhandled Kernel exception c0000047 from fa8418b4 (8025ea21,fd6829e8)\n" "\n" @@ -317,10 +324,10 @@ sco (Display *dpy, Window window, int delay) const char *def_font = "fixed"; XFontStruct *font; GC gc; - int lines = 1; + int lines_1 = 0, lines_2 = 0, lines_3 = 0, lines_4 = 0; const char *s; - const char *sco_panic = + const char *sco_panic_1 = ("Unexpected trap in kernel mode:\n" "\n" "cr0 0x80010013 cr2 0x00000014 cr3 0x00000000 tlb 0x00000000\n" @@ -332,11 +339,17 @@ sco (Display *dpy, Window window, int delay) "\n" "PANIC: k_trap - kernel mode trap type 0x0000000E\n" "Trying to dump 5023 pages to dumpdev hd (1/41), 63 pages per '.'\n" - "...............................................................................\n" - "5023 pages dumped\n" + ); + const char *sco_panic_2 = + ("...............................................................................\n" + ); + const char *sco_panic_3 = + ("5023 pages dumped\n" "\n" "\n" - "** Safe to Power Off **\n" + ); + const char *sco_panic_4 = + ("** Safe to Power Off **\n" " - or -\n" "** Press Any Key to Reboot **\n" ); @@ -344,7 +357,10 @@ sco (Display *dpy, Window window, int delay) if (!get_boolean_resource("doSCO", "DoSCO")) return False; - for (s = sco_panic; *s; s++) if (*s == '\n') lines++; + for (s = sco_panic_1; *s; s++) if (*s == '\n') lines_1++; + for (s = sco_panic_2; *s; s++) if (*s == '\n') lines_2++; + for (s = sco_panic_3; *s; s++) if (*s == '\n') lines_3++; + for (s = sco_panic_4; *s; s++) if (*s == '\n') lines_4++; XGetWindowAttributes (dpy, window, &xgwa); @@ -372,13 +388,45 @@ sco (Display *dpy, Window window, int delay) gc = XCreateGC(dpy, window, GCFont|GCForeground|GCBackground, &gcv); draw_string(dpy, window, gc, &gcv, font, - 10, xgwa.height - (lines * (font->ascent + font->descent + 1)), + 10, xgwa.height - ((lines_1 + lines_2 + lines_3 + lines_4 + 1) * + (font->ascent + font->descent + 1)), 10, 10, - sco_panic, 0); - XFreeGC(dpy, gc); + sco_panic_1, 0); + XSync(dpy, False); + for (s = sco_panic_2; *s; s++) + { + char *ss = strdup(sco_panic_2); + ss[s - sco_panic_2] = 0; + draw_string(dpy, window, gc, &gcv, font, + 10, xgwa.height - ((lines_2 + lines_3 + lines_4 + 1) * + (font->ascent + font->descent + 1)), + 10, 10, + ss, 0); + XSync(dpy, False); + free(ss); + if (bsod_sleep (dpy, -1)) + goto DONE; + } + + draw_string(dpy, window, gc, &gcv, font, + 10, xgwa.height - ((lines_3 + lines_4 + 1) * + (font->ascent + font->descent + 1)), + 10, 10, + sco_panic_3, 0); XSync(dpy, False); + if (bsod_sleep(dpy, 1)) + goto DONE; + draw_string(dpy, window, gc, &gcv, font, + 10, xgwa.height - ((lines_4 + 1) * + (font->ascent + font->descent + 1)), + 10, 10, + sco_panic_4, 0); + XSync(dpy, False); + bsod_sleep(dpy, delay); + DONE: XClearWindow(dpy, window); + XFreeGC(dpy, gc); XFreeFont(dpy, font); return True; } @@ -462,6 +510,150 @@ sparc_linux (Display *dpy, Window window, int delay) return True; } +/* BSD Panic by greywolf@starwolf.com - modeled after the Linux panic above. + By Grey Wolf + */ +static Bool +bsd (Display *dpy, Window window, int delay) +{ + XGCValues gcv; + XWindowAttributes xgwa; + char *fontname; + const char *def_font = "fixed"; + XFontStruct *font; + GC gc; + int lines = 1; + int i, n, b; + const char *rbstr, *panicking; + char syncing[80], bbuf[5], *bp; + + const char *panicstr[] = + {"panic: ifree: freeing free inode", + "panic: blkfree: freeing free block", + "panic: improbability coefficient below zero", + "panic: cgsixmmap", + "panic: crazy interrupts", + "panic: nmi", + "panic: attempted windows install", + "panic: don't", + "panic: free inode isn't", + "panic: cpu_fork: curproc", + "panic: malloc: out of space in kmem_map", + "panic: vogon starship detected", + "panic: teleport chamber: out of order", + "panic: Brain fried - core dumped"}; + + if (!get_boolean_resource("doBSD", "DoBSD")) + return False; + + for (i = 0; i < sizeof(syncing); i++) + syncing[i] = 0; + + i = (random() & 0xffff) % (sizeof(panicstr) / sizeof(*panicstr)); + + panicking = panicstr[i]; + strcpy(syncing, "Syncing disks: "); + + b = (random() & 0xff) % 40; + for (n = 0; (n < 20) && (b > 0); n++) + { + if (i) + { + i = (random() & 0x7); + b -= (random() & 0xff) % 20; + if (b < 0) + b = 0; + } + sprintf (bbuf, "%d ", b); + strcat (syncing, bbuf); + } + + if (b) + rbstr = "damn!"; + else + rbstr = "sunk!"; + + lines = 5; + + XGetWindowAttributes (dpy, window, &xgwa); + + fontname = get_string_resource ((xgwa.height > 600 + ? "bsd.font2" + : "bsd.font"), + "BSD.Font"); + if (!fontname || !*fontname) fontname = (char *)def_font; + font = XLoadQueryFont (dpy, fontname); + if (!font) font = XLoadQueryFont (dpy, def_font); + if (!font) exit(-1); + if (fontname && fontname != def_font) + free (fontname); + + gcv.font = font->fid; + gcv.foreground = get_pixel_resource(("bsd.foreground"), + "BSD.Foreground", + dpy, xgwa.colormap); + gcv.background = get_pixel_resource(("bsd.background"), + "BSD.Background", + dpy, xgwa.colormap); + XSetWindowBackground(dpy, window, gcv.background); + XClearWindow(dpy, window); + + gc = XCreateGC(dpy, window, GCFont|GCForeground|GCBackground, &gcv); + + draw_string(dpy, window, gc, &gcv, font, + 10, xgwa.height - (lines * (font->ascent + font->descent + 1)), + 10, 10, + panicking, 0); + XSync(dpy, False); + lines--; + + for (bp = syncing; *bp;) + { + char *bsd_bufs, oc = 0; + for (;*bp && (*bp != ' '); bp++) + ; + if (*bp == ' ') + { + oc = *bp; + *bp = 0; + } + bsd_bufs = strdup(syncing); + draw_string(dpy, window, gc, &gcv, font, + 10, + xgwa.height - (lines * (font->ascent + font->descent + 1)), + 10, 10, + bsd_bufs, 0); + XSync(dpy, False); + free(bsd_bufs); + if (oc) + *bp = oc; + if (bsod_sleep(dpy, -1)) + goto DONE; + bp++; + } + + lines--; + + draw_string(dpy, window, gc, &gcv, font, + 10, xgwa.height - (lines * (font->ascent + font->descent + 1)), + 10, 10, + rbstr, 0); + lines--; + draw_string(dpy, window, gc, &gcv, font, + 10, xgwa.height - (lines * (font->ascent + font->descent + 1)), + 10, 10, + "Rebooting", 0); + + XFreeGC(dpy, gc); + XSync(dpy, False); + bsod_sleep(dpy, delay); + +DONE: + XClearWindow(dpy, window); + XFreeFont(dpy, font); + return True; +} + static Bool amiga (Display *dpy, Window window, int delay) { @@ -661,15 +853,17 @@ atari (Display *dpy, Window window, int delay) } for (i=7 ; i<10 ; i++) { - bsod_sleep(dpy, 1); + if (bsod_sleep(dpy, 1)) + goto DONE; XCopyArea(dpy, pixmap, window, gc, 0, 0, pix_w, pix_h, (x + (i*offset)), y); } + bsod_sleep(dpy, delay); + DONE: XFreePixmap(dpy, pixmap); XFreeGC(dpy, gc); XSync(dpy, False); - bsod_sleep(dpy, delay); XClearWindow(dpy, window); XFreeFont(dpy, font); return True; @@ -969,6 +1163,85 @@ macsbug (Display *dpy, Window window, int delay) return True; } + +/* blit damage + * + * by Martin Pool , Feb 2000. + * + * This is meant to look like the preferred failure mode of NCD + * Xterms. The parameters for choosing what to copy where might not + * be quite right, but it looks about ugly enough. + */ +static Bool +blitdamage (Display *dpy, Window window, int delay) +{ + XGCValues gcv; + XWindowAttributes xwa; + GC gc0; + int i; + int delta_x = 0, delta_y = 0; + int w, h; + int chunk_h, chunk_w; + int steps; + long gc_mask = 0; + int src_x, src_y; + int x, y; + + if (!get_boolean_resource("doBlitDamage", "DoBlitDamage")) + return False; + + XGetWindowAttributes(dpy, window, &xwa); + + grab_screen_image(xwa.screen, window); + + w = xwa.width; + h = xwa.height; + + gc_mask = GCForeground; + + gcv.plane_mask = random(); + gc_mask |= GCPlaneMask; + + gc0 = XCreateGC(dpy, window, gc_mask, &gcv); + + steps = 50; + chunk_w = w / (random() % 1 + 1); + chunk_h = h / (random() % 1 + 1); + if (random() & 0x1000) + delta_y = random() % 600; + if (!delta_y || (random() & 0x2000)) + delta_x = random() % 600; + src_x = 0; + src_y = 0; + x = 0; + y = 0; + + for (i = 0; i < steps; i++) { + if (x + chunk_w > w) + x -= w; + else + x += delta_x; + + if (y + chunk_h > h) + y -= h; + else + y += delta_y; + + XCopyArea(dpy, window, window, gc0, + src_x, src_y, + chunk_w, chunk_h, + x, y); + + bsod_sleep(dpy, 0); + } + + bsod_sleep(dpy, delay); + + XFreeGC(dpy, gc0); + + return True; +} + char *progclass = "BSOD"; @@ -983,7 +1256,9 @@ char *defaults [] = { "*doAtari: False", /* boring */ "*doMacsBug: True", "*doSCO: True", + "*doBSD: False", /* boring */ "*doSparcLinux: False", /* boring */ + "*doBlitDamage: True", ".Windows.font: -*-courier-bold-r-*-*-*-120-*-*-m-*-*-*", ".Windows.font2: -*-courier-bold-r-*-*-*-180-*-*-m-*-*-*", @@ -1019,6 +1294,13 @@ char *defaults [] = { ".SparcLinux.font2: -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*", ".SparcLinux.foreground: White", ".SparcLinux.background: Black", + + ".BSD.font: vga", + ".BSD.font: -*-courier-bold-r-*-*-*-120-*-*-m-*-*-*", + ".BSD.font2: -*-courier-bold-r-*-*-*-140-*-*-m-*-*-*", +/* ".BSD.font2: -sun-console-medium-r-*-*-22-*-*-*-m-*-*-*", */ + ".BSD.foreground: #c0c0c0", + ".BSD.background: Black", 0 }; @@ -1048,7 +1330,7 @@ screenhack (Display *dpy, Window window) while (1) { Bool did; - do { i = (random() & 0xFF) % 8; } while (i == j); + do { i = (random() & 0xFF) % 10; } while (i == j); switch (i) { case 0: did = windows(dpy, window, delay, True); break; @@ -1058,7 +1340,9 @@ screenhack (Display *dpy, Window window) case 4: did = macsbug(dpy, window, delay); break; case 5: did = sco(dpy, window, delay); break; case 6: did = sparc_linux(dpy, window, delay); break; - case 7: did = atari(dpy, window, delay); break; + case 7: did = bsd(dpy, window, delay); break; + case 8: did = atari(dpy, window, delay); break; + case 9: did = blitdamage(dpy, window, delay); break; default: abort(); break; } loop++;