2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1998 Dag-Erling Coïdan Smørgrav
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 * in this position and unchanged.
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.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/syslog.h>
38 #include <sys/consio.h>
41 #include <dev/fb/fbreg.h>
42 #include <dev/fb/splashreg.h>
43 #include <dev/syscons/syscons.h>
45 #define SAVER_NAME "rain_saver"
49 #define MAX 63 /* number of colors (in addition to black) */
50 #define INCREMENT 4 /* increment between colors */
52 #define RED(n) ((n) * 3 + 0)
53 #define GREEN(n) ((n) * 3 + 1)
54 #define BLUE(n) ((n) * 3 + 2)
56 #define SET_ORIGIN(adp, o) do { \
58 if (oo != last_origin) \
59 vidd_set_win_org(adp, last_origin = oo); \
63 static int banksize, scrmode, bpsl, scrw, scrh;
64 static u_char rain_pal[768];
68 rain_update(video_adapter_t *adp)
72 t = rain_pal[BLUE(MAX)];
73 for (i = MAX; i > 1; i--)
74 rain_pal[BLUE(i)] = rain_pal[BLUE(i - 1)];
75 rain_pal[BLUE(1)] = t;
76 vidd_load_palette(adp, rain_pal);
80 rain_saver(video_adapter_t *adp, int blank)
87 /* switch to graphics mode */
90 vidd_set_mode(adp, scrmode);
91 vidd_load_palette(adp, rain_pal);
92 vidd_set_border(adp, 0);
94 vid = (u_char *)adp->va_window;
95 banksize = adp->va_window_size;
96 bpsl = adp->va_line_width;
98 for (i = 0; i < bpsl*scrh; i += banksize) {
100 if ((bpsl * scrh - i) < banksize)
101 bzero(vid, bpsl * scrh - i);
103 bzero(vid, banksize);
106 for (i = 0, o = 0, p = 0; i < scrw; i += 2, p += 2) {
112 vid[p] = 1 + (random() % MAX);
115 for (j = 1; j < scrh; j++)
116 for (i = 0, p = bpsl * (j - 1) - o; i < scrw; i += 2, p+= 2) {
117 while (p > banksize) {
122 temp = (vid[p] < MAX) ? 1 + vid[p] : 1;
123 if (p + bpsl < banksize) {
124 vid[p + bpsl] = temp;
126 SET_ORIGIN(adp, o + banksize);
127 vid[p + bpsl - banksize] = temp;
141 rain_init(video_adapter_t *adp)
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 /* intialize the palette */
159 for (i = 1; i < MAX; i++)
160 rain_pal[BLUE(i)] = rain_pal[BLUE(i - 1)] + INCREMENT;
166 rain_term(video_adapter_t *adp)
171 static scrn_saver_t rain_module = {
179 SAVER_MODULE(rain_saver, rain_module);