2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1999 Brad Forschinger
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
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.
32 * brad forschinger, 19990504 <retch@flag.blackened.net>
34 * written with much help from warp_saver.c
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/module.h>
42 #include <sys/syslog.h>
43 #include <sys/consio.h>
44 #include <sys/malloc.h>
47 #include <dev/fb/fbreg.h>
48 #include <dev/fb/splashreg.h>
49 #include <dev/syscons/syscons.h>
51 #define SAVER_NAME "fire_saver"
53 #define RED(n) ((n) * 3 + 0)
54 #define GREEN(n) ((n) * 3 + 1)
55 #define BLUE(n) ((n) * 3 + 2)
57 #define SET_ORIGIN(adp, o) do { \
59 if (oo != last_origin) \
60 vidd_set_win_org(adp, last_origin = oo); \
65 static int banksize, scrmode, bpsl, scrw, scrh;
66 static u_char fire_pal[768];
70 fire_update(video_adapter_t *adp)
76 /* make a new bottom line */
77 for (x = 0, y = scrh; x < scrw; x++)
78 buf[x + (y * bpsl)] = random() % 160 + 96;
80 /* fade the flames out */
81 for (y = 0; y < scrh; y++) {
82 for (x = 0; x < scrw; x++) {
84 (buf[(x + 0) + ((y + 0) * scrw)] +
85 buf[(x - 1) + ((y + 1) * scrw)] +
86 buf[(x + 0) + ((y + 1) * scrw)] +
87 buf[(x + 1) + ((y + 1) * scrw)]) / 4;
88 if (buf[x + (y * scrw)] > 0)
89 buf[x + (y * scrw)]--;
93 /* blit our buffer into video ram */
94 for (y = 0, p = 0, o = 0; y < scrh; y++, p += bpsl) {
95 while (p > banksize) {
100 if (p + scrw < banksize) {
101 bcopy(buf + y * scrw, vid + p, scrw);
103 bcopy(buf + y * scrw, vid + p, banksize - p);
104 SET_ORIGIN(adp, o + banksize);
105 bcopy(buf + y * scrw + (banksize - p), vid,
106 scrw - (banksize - p));
115 fire_saver(video_adapter_t *adp, int blank)
120 /* switch to graphics mode */
123 vidd_set_mode(adp, scrmode);
124 vidd_load_palette(adp, fire_pal);
126 vid = (u_char *)adp->va_window;
127 banksize = adp->va_window_size;
128 bpsl = adp->va_line_width;
141 fire_init(video_adapter_t *adp)
144 int i, red, green, blue;
146 if (!vidd_get_info(adp, M_VGA_CG320, &info)) {
147 scrmode = M_VGA_CG320;
150 "%s: the console does not support M_VGA_CG320\n",
155 scrw = info.vi_width;
156 scrh = info.vi_height;
158 buf = (u_char *)malloc(scrw * (scrh + 1), M_DEVBUF, M_NOWAIT);
160 bzero(buf, scrw * (scrh + 1));
163 "%s: buffer allocation is failed\n",
168 /* intialize the palette */
169 red = green = blue = 0;
170 for (i = 0; i < 256; i++) {
174 fire_pal[RED(i)] = red;
175 fire_pal[GREEN(i)] = green;
176 fire_pal[BLUE(i)] = blue;
183 fire_term(video_adapter_t *adp)
189 static scrn_saver_t fire_module = {
197 SAVER_MODULE(fire_saver, fire_module);