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 i, 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 for (i = 0; i < bpsl * scrh; i += banksize) { 122 set_origin(adp, i); 123 bzero(vid, banksize); 124 } 125 } 126 fire_update(adp); 127 } else { 128 blanked = 0; 129 } 130 131 return 0; 132 } 133 134 static int 135 fire_init(video_adapter_t *adp) 136 { 137 video_info_t info; 138 int i, red, green, blue; 139 140 if (!get_mode_info(adp, M_VGA_CG320, &info)) { 141 scrmode = M_VGA_CG320; 142 } else if (!get_mode_info(adp, M_PC98_PEGC640x480, &info)) { 143 scrmode = M_PC98_PEGC640x480; 144 } else if (!get_mode_info(adp, M_PC98_PEGC640x400, &info)) { 145 scrmode = M_PC98_PEGC640x400; 146 } else { 147 log(LOG_NOTICE, 148 "%s: the console does not support M_VGA_CG320\n", 149 SAVER_NAME); 150 return (ENODEV); 151 } 152 153 scrw = info.vi_width; 154 scrh = info.vi_height; 155 156 buf = (u_char *)malloc(scrw * (scrh + 1), M_DEVBUF, M_NOWAIT); 157 if (buf) { 158 bzero(buf, scrw * (scrh + 1)); 159 } else { 160 log(LOG_NOTICE, 161 "%s: buffer allocation is failed\n", 162 SAVER_NAME); 163 return (ENODEV); 164 } 165 166 /* intialize the palette */ 167 red = green = blue = 0; 168 for (i = 0; i < 256; i++) { 169 red++; 170 if (red > 128) 171 green += 2; 172 fire_pal[RED(i)] = red; 173 fire_pal[GREEN(i)] = green; 174 fire_pal[BLUE(i)] = blue; 175 } 176 177 return (0); 178 } 179 180 static int 181 fire_term(video_adapter_t *adp) 182 { 183 free(buf, M_DEVBUF); 184 return (0); 185 } 186 187 static scrn_saver_t fire_module = { 188 SAVER_NAME, 189 fire_init, 190 fire_term, 191 fire_saver, 192 NULL 193 }; 194 195 SAVER_MODULE(fire_saver, fire_module); 196