2 * Copyright (c) 1999 Brad Forschinger
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 * brad forschinger, 19990504 <retch@flag.blackened.net>
32 * written with much help from warp_saver.c
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>
45 #include <dev/fb/fbreg.h>
46 #include <dev/fb/splashreg.h>
47 #include <dev/syscons/syscons.h>
49 #define SAVER_NAME "fire_saver"
51 #define RED(n) ((n) * 3 + 0)
52 #define GREEN(n) ((n) * 3 + 1)
53 #define BLUE(n) ((n) * 3 + 2)
55 #define SET_ORIGIN(adp, o) do { \
57 if (oo != last_origin) \
58 vidd_set_win_org(adp, last_origin = oo); \
63 static int banksize, scrmode, bpsl, scrw, scrh;
64 static u_char fire_pal[768];
68 fire_update(video_adapter_t *adp)
74 /* make a new bottom line */
75 for (x = 0, y = scrh; x < scrw; x++)
76 buf[x + (y * bpsl)] = random() % 160 + 96;
78 /* fade the flames out */
79 for (y = 0; y < scrh; y++) {
80 for (x = 0; x < scrw; x++) {
82 (buf[(x + 0) + ((y + 0) * scrw)] +
83 buf[(x - 1) + ((y + 1) * scrw)] +
84 buf[(x + 0) + ((y + 1) * scrw)] +
85 buf[(x + 1) + ((y + 1) * scrw)]) / 4;
86 if (buf[x + (y * scrw)] > 0)
87 buf[x + (y * scrw)]--;
91 /* blit our buffer into video ram */
92 for (y = 0, p = 0, o = 0; y < scrh; y++, p += bpsl) {
93 while (p > banksize) {
98 if (p + scrw < banksize) {
99 bcopy(buf + y * scrw, vid + p, scrw);
101 bcopy(buf + y * scrw, vid + p, banksize - p);
102 SET_ORIGIN(adp, o + banksize);
103 bcopy(buf + y * scrw + (banksize - p), vid,
104 scrw - (banksize - p));
113 fire_saver(video_adapter_t *adp, int blank)
118 /* switch to graphics mode */
121 vidd_set_mode(adp, scrmode);
122 vidd_load_palette(adp, fire_pal);
124 vid = (u_char *)adp->va_window;
125 banksize = adp->va_window_size;
126 bpsl = adp->va_line_width;
139 fire_init(video_adapter_t *adp)
142 int i, red, green, blue;
144 if (!vidd_get_info(adp, M_VGA_CG320, &info)) {
145 scrmode = M_VGA_CG320;
146 } else if (!vidd_get_info(adp, M_PC98_PEGC640x480, &info)) {
147 scrmode = M_PC98_PEGC640x480;
148 } else if (!vidd_get_info(adp, M_PC98_PEGC640x400, &info)) {
149 scrmode = M_PC98_PEGC640x400;
152 "%s: the console does not support M_VGA_CG320\n",
157 scrw = info.vi_width;
158 scrh = info.vi_height;
160 buf = (u_char *)malloc(scrw * (scrh + 1), M_DEVBUF, M_NOWAIT);
162 bzero(buf, scrw * (scrh + 1));
165 "%s: buffer allocation is failed\n",
170 /* intialize the palette */
171 red = green = blue = 0;
172 for (i = 0; i < 256; i++) {
176 fire_pal[RED(i)] = red;
177 fire_pal[GREEN(i)] = green;
178 fire_pal[BLUE(i)] = blue;
185 fire_term(video_adapter_t *adp)
191 static scrn_saver_t fire_module = {
199 SAVER_MODULE(fire_saver, fire_module);