1 /*- 2 * Copyright (c) 1995-1998 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 * without modification, immediately at the beginning of the file. 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 without 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.22 1999/01/17 14:25:19 yokota Exp $ 29 */ 30 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/module.h> 34 #include <sys/malloc.h> 35 #include <sys/kernel.h> 36 #include <sys/sysctl.h> 37 38 #include <machine/md_var.h> 39 #include <machine/pc/display.h> 40 41 #include <saver.h> 42 43 static char *message; 44 static u_char **messagep; 45 static int messagelen; 46 static u_short *window; 47 static int blanked; 48 49 static int 50 snake_saver(video_adapter_t *adp, int blank) 51 { 52 static int dirx, diry; 53 int f; 54 scr_stat *scp = cur_console; 55 56 /* XXX hack for minimal changes. */ 57 #define save message 58 #define savs messagep 59 60 if (blank) { 61 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) 62 return EAGAIN; 63 if (blanked <= 0) { 64 window = (u_short *)adp->va_window; 65 fillw(((FG_LIGHTGREY|BG_BLACK)<<8) | scr_map[0x20], 66 window, scp->xsize * scp->ysize); 67 set_border(scp, 0); 68 dirx = (scp->xpos ? 1 : -1); 69 diry = (scp->ypos ? 70 scp->xsize : -scp->xsize); 71 for (f=0; f< messagelen; f++) 72 savs[f] = (u_char *)window + 2 * 73 (scp->xpos+scp->ypos*scp->xsize); 74 *(savs[0]) = scr_map[*save]; 75 blanked = 1; 76 } 77 if (blanked++ < 4) 78 return 0; 79 blanked = 1; 80 *(savs[messagelen-1]) = scr_map[0x20]; 81 for (f=messagelen-1; f > 0; f--) 82 savs[f] = savs[f-1]; 83 f = (savs[0] - (u_char *)window) / 2; 84 if ((f % scp->xsize) == 0 || 85 (f % scp->xsize) == scp->xsize - 1 || 86 (random() % 50) == 0) 87 dirx = -dirx; 88 if ((f / scp->xsize) == 0 || 89 (f / scp->xsize) == scp->ysize - 1 || 90 (random() % 20) == 0) 91 diry = -diry; 92 savs[0] += 2*dirx + 2*diry; 93 for (f=messagelen-1; f>=0; f--) 94 *(savs[f]) = scr_map[save[f]]; 95 } 96 else { 97 blanked = 0; 98 } 99 return 0; 100 } 101 102 static int 103 snake_init(video_adapter_t *adp) 104 { 105 messagelen = strlen(ostype) + 1 + strlen(osrelease); 106 message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK); 107 sprintf(message, "%s %s", ostype, osrelease); 108 messagep = malloc(messagelen * sizeof *messagep, M_DEVBUF, M_WAITOK); 109 return 0; 110 } 111 112 static int 113 snake_term(video_adapter_t *adp) 114 { 115 free(message, M_DEVBUF); 116 free(messagep, M_DEVBUF); 117 return 0; 118 } 119 120 static scrn_saver_t snake_module = { 121 "snake_saver", snake_init, snake_term, snake_saver, NULL, 122 }; 123 124 SAVER_MODULE(snake_saver, snake_module); 125