1 /*- 2 * Copyright (c) 1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software withough specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * $Id: snake_saver.c,v 1.16 1998/01/16 17:58:50 bde Exp $ 29 */ 30 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/exec.h> 34 #include <sys/sysent.h> 35 #include <sys/lkm.h> 36 #include <sys/malloc.h> 37 #include <sys/kernel.h> 38 #include <sys/sysctl.h> 39 40 #include <machine/md_var.h> 41 #include <machine/pc/display.h> 42 43 #include <saver.h> 44 45 MOD_MISC(snake_saver); 46 47 static char *message; 48 static u_char **messagep; 49 static int messagelen; 50 51 static void 52 snake_saver(int blank) 53 { 54 static int dirx, diry; 55 int f; 56 scr_stat *scp = cur_console; 57 58 /* XXX hack for minimal changes. */ 59 #define save message 60 #define savs messagep 61 62 if (blank) { 63 if (scrn_blanked <= 0) { 64 fillw((FG_LIGHTGREY|BG_BLACK)<<8 | scr_map[0x20], 65 Crtat, scp->xsize * scp->ysize); 66 set_border(0); 67 dirx = (scp->xpos ? 1 : -1); 68 diry = (scp->ypos ? 69 scp->xsize : -scp->xsize); 70 for (f=0; f< messagelen; f++) 71 savs[f] = (u_char *)Crtat + 2 * 72 (scp->xpos+scp->ypos*scp->xsize); 73 *(savs[0]) = scr_map[*save]; 74 f = scp->ysize * scp->xsize + 5; 75 outb(crtc_addr, 14); 76 outb(crtc_addr+1, f >> 8); 77 outb(crtc_addr, 15); 78 outb(crtc_addr+1, f & 0xff); 79 scrn_blanked = 1; 80 } 81 if (scrn_blanked++ < 4) 82 return; 83 scrn_blanked = 1; 84 *(savs[messagelen-1]) = scr_map[0x20]; 85 for (f=messagelen-1; f > 0; f--) 86 savs[f] = savs[f-1]; 87 f = (savs[0] - (u_char *)Crtat) / 2; 88 if ((f % scp->xsize) == 0 || 89 (f % scp->xsize) == scp->xsize - 1 || 90 (random() % 50) == 0) 91 dirx = -dirx; 92 if ((f / scp->xsize) == 0 || 93 (f / scp->xsize) == scp->ysize - 1 || 94 (random() % 20) == 0) 95 diry = -diry; 96 savs[0] += 2*dirx + 2*diry; 97 for (f=messagelen-1; f>=0; f--) 98 *(savs[f]) = scr_map[save[f]]; 99 } 100 else { 101 if (scrn_blanked > 0) { 102 set_border(scp->border); 103 scrn_blanked = 0; 104 } 105 } 106 } 107 108 static int 109 snake_saver_load(struct lkm_table *lkmtp, int cmd) 110 { 111 int err; 112 113 if (cur_console->mode >= M_VESA_BASE) 114 return ENODEV; 115 116 messagelen = strlen(ostype) + 1 + strlen(osrelease); 117 message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK); 118 sprintf(message, "%s %s", ostype, osrelease); 119 messagep = malloc(messagelen * sizeof *messagep, M_DEVBUF, M_WAITOK); 120 121 err = add_scrn_saver(snake_saver); 122 if (err != 0) { 123 free(message, M_DEVBUF); 124 free(messagep, M_DEVBUF); 125 } 126 return err; 127 } 128 129 static int 130 snake_saver_unload(struct lkm_table *lkmtp, int cmd) 131 { 132 int err; 133 134 err = remove_scrn_saver(snake_saver); 135 if (err == 0) { 136 free(message, M_DEVBUF); 137 free(messagep, M_DEVBUF); 138 } 139 return err; 140 } 141 142 int 143 snake_saver_mod(struct lkm_table *lkmtp, int cmd, int ver) 144 { 145 MOD_DISPATCH(snake_saver, lkmtp, cmd, ver, 146 snake_saver_load, snake_saver_unload, lkm_nullcmd); 147 } 148