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$ 29 */ 30 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/conf.h> 34 #include <sys/exec.h> 35 #include <sys/sysent.h> 36 #include <sys/lkm.h> 37 #include <sys/errno.h> 38 39 #include <machine/md_var.h> 40 41 #include "saver.h" 42 43 MOD_MISC(snake_saver); 44 45 void (*current_saver)(int blank); 46 void (*old_saver)(int blank); 47 48 static void 49 snake_saver(int blank) 50 { 51 const char saves[] = {"FreeBSD-3.0-CURRENT"}; 52 static u_char *savs[sizeof(saves)-1]; 53 static int dirx, diry; 54 int f; 55 scr_stat *scp = cur_console; 56 57 if (blank) { 58 if (!scrn_blanked) { 59 fillw((FG_LIGHTGREY|BG_BLACK)<<8 | scr_map[0x20], 60 Crtat, scp->xsize * scp->ysize); 61 set_border(0); 62 dirx = (scp->xpos ? 1 : -1); 63 diry = (scp->ypos ? 64 scp->xsize : -scp->xsize); 65 for (f=0; f< sizeof(saves)-1; f++) 66 savs[f] = (u_char *)Crtat + 2 * 67 (scp->xpos+scp->ypos*scp->xsize); 68 *(savs[0]) = scr_map[*saves]; 69 f = scp->ysize * scp->xsize + 5; 70 outb(crtc_addr, 14); 71 outb(crtc_addr+1, f >> 8); 72 outb(crtc_addr, 15); 73 outb(crtc_addr+1, f & 0xff); 74 scrn_blanked = 1; 75 } 76 if (scrn_blanked++ < 4) 77 return; 78 scrn_blanked = 1; 79 *(savs[sizeof(saves)-2]) = scr_map[0x20]; 80 for (f=sizeof(saves)-2; f > 0; f--) 81 savs[f] = savs[f-1]; 82 f = (savs[0] - (u_char *)Crtat) / 2; 83 if ((f % scp->xsize) == 0 || 84 (f % scp->xsize) == scp->xsize - 1 || 85 (random() % 50) == 0) 86 dirx = -dirx; 87 if ((f / scp->xsize) == 0 || 88 (f / scp->xsize) == scp->ysize - 1 || 89 (random() % 20) == 0) 90 diry = -diry; 91 savs[0] += 2*dirx + 2*diry; 92 for (f=sizeof(saves)-2; f>=0; f--) 93 *(savs[f]) = scr_map[saves[f]]; 94 } 95 else { 96 if (scrn_blanked) { 97 set_border(scp->border); 98 scrn_blanked = 0; 99 scp->start = 0; 100 scp->end = scp->xsize * scp->ysize; 101 } 102 } 103 } 104 105 static int 106 snake_saver_load(struct lkm_table *lkmtp, int cmd) 107 { 108 (*current_saver)(0); 109 old_saver = current_saver; 110 current_saver = snake_saver; 111 return 0; 112 } 113 114 static int 115 snake_saver_unload(struct lkm_table *lkmtp, int cmd) 116 { 117 (*current_saver)(0); 118 current_saver = old_saver; 119 return 0; 120 } 121 122 int 123 snake_saver_mod(struct lkm_table *lkmtp, int cmd, int ver) 124 { 125 DISPATCH(lkmtp, cmd, ver, snake_saver_load, snake_saver_unload, 126 lkm_nullcmd); 127 } 128