1 /*- 2 * Copyright (c) 1999 Brad Forschinger 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 * 15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * 26 * $FreeBSD$ 27 */ 28 29 /* 30 * brad forschinger, 19990504 <retch@flag.blackened.net> 31 * 32 * written with much help from warp_saver.c 33 * 34 */ 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/kernel.h> 39 #include <sys/module.h> 40 #include <sys/syslog.h> 41 #include <sys/consio.h> 42 #include <sys/malloc.h> 43 #include <sys/fbio.h> 44 45 #include <dev/fb/fbreg.h> 46 #include <dev/fb/splashreg.h> 47 #include <dev/syscons/syscons.h> 48 49 #define SAVER_NAME "fire_saver" 50 51 #define RED(n) ((n) * 3 + 0) 52 #define GREEN(n) ((n) * 3 + 1) 53 #define BLUE(n) ((n) * 3 + 2) 54 55 static u_char *buf; 56 static u_char *vid; 57 static int banksize, scrmode, bpsl, scrw, scrh; 58 static u_char fire_pal[768]; 59 static int blanked; 60 61 static void 62 fire_update(video_adapter_t *adp) 63 { 64 int x, y; 65 int o, p; 66 67 /* make a new bottom line */ 68 for (x = 0, y = scrh; x < scrw; x++) 69 buf[x + (y * bpsl)] = random() % 160 + 96; 70 71 /* fade the flames out */ 72 for (y = 0; y < scrh; y++) { 73 for (x = 0; x < scrw; x++) { 74 buf[x + (y * scrw)] = 75 (buf[(x + 0) + ((y + 0) * scrw)] + 76 buf[(x - 1) + ((y + 1) * scrw)] + 77 buf[(x + 0) + ((y + 1) * scrw)] + 78 buf[(x + 1) + ((y + 1) * scrw)]) / 4; 79 if (buf[x + (y * scrw)] > 0) 80 buf[x + (y * scrw)]--; 81 } 82 } 83 84 /* blit our buffer into video ram */ 85 for (y = 0, p = 0, o = 0; y < scrh; y++, p += bpsl) { 86 while (p > banksize) { 87 p -= banksize; 88 o += banksize; 89 } 90 set_origin(adp, o); 91 if (p + scrw < banksize) { 92 bcopy(buf + y * scrw, vid + p, scrw); 93 } else { 94 bcopy(buf + y * scrw, vid + p, banksize - p); 95 set_origin(adp, o + banksize); 96 bcopy(buf + y * scrw + (banksize - p), vid, 97 scrw - (banksize - p)); 98 p -= banksize; 99 o += banksize; 100 } 101 } 102 103 } 104 105 static int 106 fire_saver(video_adapter_t *adp, int blank) 107 { 108 int pl; 109 110 if (blank) { 111 /* switch to graphics mode */ 112 if (blanked <= 0) { 113 pl = splhigh(); 114 set_video_mode(adp, scrmode); 115 load_palette(adp, fire_pal); 116 blanked++; 117 vid = (u_char *)adp->va_window; 118 banksize = adp->va_window_size; 119 bpsl = adp->va_line_width; 120 splx(pl); 121 (*vidsw[adp->va_index]->clear)(adp); 122 } 123 fire_update(adp); 124 } else { 125 blanked = 0; 126 } 127 128 return 0; 129 } 130 131 static int 132 fire_init(video_adapter_t *adp) 133 { 134 video_info_t info; 135 int i, red, green, blue; 136 137 if (!get_mode_info(adp, M_VGA_CG320, &info)) { 138 scrmode = M_VGA_CG320; 139 } else if (!get_mode_info(adp, M_PC98_PEGC640x480, &info)) { 140 scrmode = M_PC98_PEGC640x480; 141 } else if (!get_mode_info(adp, M_PC98_PEGC640x400, &info)) { 142 scrmode = M_PC98_PEGC640x400; 143 } else { 144 log(LOG_NOTICE, 145 "%s: the console does not support M_VGA_CG320\n", 146 SAVER_NAME); 147 return (ENODEV); 148 } 149 150 scrw = info.vi_width; 151 scrh = info.vi_height; 152 153 buf = (u_char *)malloc(scrw * (scrh + 1), M_DEVBUF, M_NOWAIT); 154 if (buf) { 155 bzero(buf, scrw * (scrh + 1)); 156 } else { 157 log(LOG_NOTICE, 158 "%s: buffer allocation is failed\n", 159 SAVER_NAME); 160 return (ENODEV); 161 } 162 163 /* intialize the palette */ 164 red = green = blue = 0; 165 for (i = 0; i < 256; i++) { 166 red++; 167 if (red > 128) 168 green += 2; 169 fire_pal[RED(i)] = red; 170 fire_pal[GREEN(i)] = green; 171 fire_pal[BLUE(i)] = blue; 172 } 173 174 return (0); 175 } 176 177 static int 178 fire_term(video_adapter_t *adp) 179 { 180 free(buf, M_DEVBUF); 181 return (0); 182 } 183 184 static scrn_saver_t fire_module = { 185 SAVER_NAME, 186 fire_init, 187 fire_term, 188 fire_saver, 189 NULL 190 }; 191 192 SAVER_MODULE(fire_saver, fire_module); 193