1 /*- 2 * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav 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 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$ 29 */ 30 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/kernel.h> 34 #include <sys/module.h> 35 #include <sys/syslog.h> 36 37 #include <machine/md_var.h> 38 #include <machine/random.h> 39 40 #include <saver.h> 41 42 static u_char *vid; 43 44 #define SCRW 320 45 #define SCRH 200 46 #define MAX 63 47 48 static u_char save_pal[768]; 49 static u_char rain_pal[768]; 50 51 static void 52 rain_update(void) 53 { 54 int i, t; 55 56 t = rain_pal[(MAX*3+2)]; 57 for (i = (MAX*3+2); i > 5; i -= 3) 58 rain_pal[i] = rain_pal[i-3]; 59 rain_pal[5] = t; 60 load_palette(cur_console, rain_pal); 61 } 62 63 static void 64 rain_saver(int blank) 65 { 66 scr_stat *scp = cur_console; 67 static int saved_mode; 68 int i, j, k, pl; 69 70 if (blank) { 71 /* switch to graphics mode */ 72 if (scrn_blanked <= 0) { 73 pl = splhigh(); 74 saved_mode = scp->mode; 75 scp->mode = M_VGA_CG320; 76 scp->status |= SAVER_RUNNING|GRAPHICS_MODE; 77 save_palette(scp, save_pal); 78 set_mode(scp); 79 load_palette(scp, rain_pal); 80 scrn_blanked++; 81 vid = (u_char *)Crtat; 82 splx(pl); 83 bzero(vid, SCRW*SCRH); 84 for (i = 0; i < SCRW; i += 2) 85 vid[i] = 1 + (random() % MAX); 86 for (j = 1, k = SCRW; j < SCRH; j++) 87 for (i = 0; i < SCRW; i += 2, k += 2) 88 vid[k] = (vid[k-SCRW] < MAX) ? 1 + vid[k-SCRW] : 1; 89 } 90 91 /* update display */ 92 rain_update(); 93 94 } else { 95 /* return to previous video mode */ 96 if (scrn_blanked > 0) { 97 if (saved_mode) { 98 pl = splhigh(); 99 scrn_blanked = 0; 100 scp->mode = saved_mode; 101 scp->status &= ~(SAVER_RUNNING|GRAPHICS_MODE); 102 set_mode(scp); 103 load_palette(scp, save_pal); 104 saved_mode = 0; 105 splx(pl); 106 } 107 } 108 } 109 } 110 111 static int 112 rain_saver_load(void) 113 { 114 video_info_t info; 115 int i; 116 117 /* check that the console is capable of running in 320x200x256 */ 118 if ((*biosvidsw.get_info)(cur_console->adp, M_VGA_CG320, &info)) { 119 log(LOG_NOTICE, "rain_saver: the console does not support M_VGA_CG320\n"); 120 return ENODEV; 121 } 122 123 /* intialize the palette */ 124 for (i = 3; i < (MAX+1)*3; i += 3) 125 rain_pal[i+2] = rain_pal[i-1] + 4; 126 127 return add_scrn_saver(rain_saver); 128 } 129 130 static int 131 rain_saver_unload(void) 132 { 133 return remove_scrn_saver(rain_saver); 134 } 135 136 SAVER_MODULE(rain_saver); 137