2 * Copyright (c) 1998 Dag-Erling Coïdan Smørgrav
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 * in this position and unchanged.
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 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
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.
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/syslog.h>
36 #include <sys/consio.h>
39 #include <dev/fb/fbreg.h>
40 #include <dev/fb/splashreg.h>
41 #include <dev/syscons/syscons.h>
43 #define SAVER_NAME "rain_saver"
47 #define MAX 63 /* number of colors (in addition to black) */
48 #define INCREMENT 4 /* increment between colors */
50 #define RED(n) ((n) * 3 + 0)
51 #define GREEN(n) ((n) * 3 + 1)
52 #define BLUE(n) ((n) * 3 + 2)
54 #define SET_ORIGIN(adp, o) do { \
56 if (oo != last_origin) \
57 vidd_set_win_org(adp, last_origin = oo); \
61 static int banksize, scrmode, bpsl, scrw, scrh;
62 static u_char rain_pal[768];
66 rain_update(video_adapter_t *adp)
70 t = rain_pal[BLUE(MAX)];
71 for (i = MAX; i > 1; i--)
72 rain_pal[BLUE(i)] = rain_pal[BLUE(i - 1)];
73 rain_pal[BLUE(1)] = t;
74 vidd_load_palette(adp, rain_pal);
78 rain_saver(video_adapter_t *adp, int blank)
85 /* switch to graphics mode */
88 vidd_set_mode(adp, scrmode);
89 vidd_load_palette(adp, rain_pal);
90 vidd_set_border(adp, 0);
92 vid = (u_char *)adp->va_window;
93 banksize = adp->va_window_size;
94 bpsl = adp->va_line_width;
96 for (i = 0; i < bpsl*scrh; i += banksize) {
98 if ((bpsl * scrh - i) < banksize)
99 bzero(vid, bpsl * scrh - i);
101 bzero(vid, banksize);
104 for (i = 0, o = 0, p = 0; i < scrw; i += 2, p += 2) {
110 vid[p] = 1 + (random() % MAX);
113 for (j = 1; j < scrh; j++)
114 for (i = 0, p = bpsl * (j - 1) - o; i < scrw; i += 2, p+= 2) {
115 while (p > banksize) {
120 temp = (vid[p] < MAX) ? 1 + vid[p] : 1;
121 if (p + bpsl < banksize) {
122 vid[p + bpsl] = temp;
124 SET_ORIGIN(adp, o + banksize);
125 vid[p + bpsl - banksize] = temp;
139 rain_init(video_adapter_t *adp)
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 /* intialize the palette */
161 for (i = 1; i < MAX; i++)
162 rain_pal[BLUE(i)] = rain_pal[BLUE(i - 1)] + INCREMENT;
168 rain_term(video_adapter_t *adp)
173 static scrn_saver_t rain_module = {
181 SAVER_MODULE(rain_saver, rain_module);