2 * Copyright (c) 1997 Sandro Sigala, Brescia, Italy.
3 * Copyright (c) 1997 Chris Shenton
4 * Copyright (c) 1995 S ren Schmidt
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.
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/module.h>
34 #include <sys/malloc.h>
35 #include <sys/kernel.h>
36 #include <sys/sysctl.h>
37 #include <sys/consio.h>
40 #include <machine/pc/display.h>
42 #include <dev/fb/fbreg.h>
43 #include <dev/fb/splashreg.h>
44 #include <dev/syscons/syscons.h>
46 #define DAEMON_MAX_WIDTH 32
47 #define DAEMON_MAX_HEIGHT 19
49 static u_char *message;
50 static int messagelen;
54 #define ATTR(attr) (((attr) & attr_mask) << 8)
56 /* Who is the author of this ASCII pic? */
58 static u_char *daemon_pic[] = {
71 "<----|====O)))==) \\) /====",
72 "<----' `--' `.__,' \\",
75 " ______( (_ / \\______/",
81 static u_char *daemon_attr[] = {
94 "YYYYYYYYYYRRRRYYR RR RYYYY",
95 "YYYYYY RRRR RRRRRR R",
98 " CCCCCCR RR R RRRRRRRR",
105 * Reverse a graphics character, or return unaltered if no mirror;
106 * should do alphanumerics too, but I'm too lazy. <cshenton@it.hq.nasa.gov>
110 xflip_symbol(u_char symbol)
112 static const u_char lchars[] = "`'(){}[]\\/<>";
113 static const u_char rchars[] = "'`)(}{][/\\><";
116 for (pos = 0; lchars[pos] != '\0'; pos++)
117 if (lchars[pos] == symbol)
124 clear_daemon(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff,
131 for (y = yoff; y < ylen; y++) {
132 sc_vtb_erase(&sc->cur_scp->scr,
133 (ypos + y)*sc->cur_scp->xsize + xpos + xoff,
135 sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK));
140 draw_daemon(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff,
147 for (y = yoff; y < ylen; y++) {
151 px = DAEMON_MAX_WIDTH - xlen;
152 if (px >= strlen(daemon_pic[y]))
154 for (x = xoff; (x < xlen) && (daemon_pic[y][px] != '\0'); x++, px++) {
155 switch (daemon_attr[y][px]) {
156 case 'R': attr = FG_LIGHTRED | BG_BLACK; break;
157 case 'Y': attr = FG_YELLOW | BG_BLACK; break;
158 case 'B': attr = FG_LIGHTBLUE | BG_BLACK; break;
159 case 'W': attr = FG_LIGHTGREY | BG_BLACK; break;
160 case 'C': attr = FG_CYAN | BG_BLACK; break;
161 default: attr = FG_WHITE | BG_BLACK; break;
163 if (dxdir < 0) { /* Moving left */
164 sc_vtb_putc(&sc->cur_scp->scr,
165 (ypos + y)*sc->cur_scp->xsize
167 sc->scr_map[daemon_pic[y][px]],
169 } else { /* Moving right */
170 sc_vtb_putc(&sc->cur_scp->scr,
171 (ypos + y)*sc->cur_scp->xsize
172 + xpos + DAEMON_MAX_WIDTH
174 sc->scr_map[xflip_symbol(daemon_pic[y][px])],
182 clear_string(sc_softc_t *sc, int xpos, int ypos, int xoff, char *s, int len)
186 sc_vtb_erase(&sc->cur_scp->scr,
187 ypos*sc->cur_scp->xsize + xpos + xoff, len - xoff,
188 sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK));
192 draw_string(sc_softc_t *sc, int xpos, int ypos, int xoff, u_char *s, int len)
196 for (x = xoff; x < len; x++)
197 sc_vtb_putc(&sc->cur_scp->scr,
198 ypos*sc->cur_scp->xsize + xpos + x,
199 sc->scr_map[s[x]], ATTR(FG_LIGHTGREEN | BG_BLACK));
203 daemon_saver(video_adapter_t *adp, int blank)
205 static int txpos = 10, typos = 10;
206 static int txdir = -1, tydir = -1;
207 static int dxpos = 0, dypos = 0;
208 static int dxdir = 1, dydir = 1;
209 static int moved_daemon = 0;
210 static int xoff, yoff, toff;
211 static int xlen, ylen, tlen;
216 sc = sc_find_softc(adp, NULL);
222 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
225 /* clear the screen and set the border color */
226 sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
227 ATTR(FG_LIGHTGREY | BG_BLACK));
228 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
229 sc_set_border(scp, 0);
230 xlen = ylen = tlen = 0;
236 clear_daemon(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen);
237 clear_string(sc, txpos, typos, toff, message, tlen);
239 if (++moved_daemon) {
241 * The daemon picture may be off the screen, if
242 * screen size is chagened while the screen
243 * saver is inactive. Make sure the origin of
244 * the picture is between min and max.
246 if (scp->xsize <= DAEMON_MAX_WIDTH) {
248 * If the screen width is too narrow, we
249 * allow part of the picture go off
250 * the screen so that the daemon won't
253 min = scp->xsize - DAEMON_MAX_WIDTH - 10;
257 max = scp->xsize - DAEMON_MAX_WIDTH;
262 } else if (dxpos >= max) {
267 if (scp->ysize <= DAEMON_MAX_HEIGHT) {
268 min = scp->ysize - DAEMON_MAX_HEIGHT - 10;
272 max = scp->ysize - DAEMON_MAX_HEIGHT;
277 } else if (dypos >= max) {
283 dxpos += dxdir; dypos += dydir;
285 /* clip the picture */
287 xlen = DAEMON_MAX_WIDTH;
288 if (dxpos + xlen <= 0)
292 if (dxpos >= scp->xsize)
294 else if (dxpos + xlen > scp->xsize)
295 xlen = scp->xsize - dxpos;
297 ylen = DAEMON_MAX_HEIGHT;
298 if (dypos + ylen <= 0)
302 if (dypos >= scp->ysize)
304 else if (dypos + ylen > scp->ysize)
305 ylen = scp->ysize - dypos;
308 if (scp->xsize <= messagelen) {
309 min = scp->xsize - messagelen - 10;
313 max = scp->xsize - messagelen;
318 } else if (txpos >= max) {
325 } else if (typos >= scp->ysize - 1) {
326 typos = scp->ysize - 1;
329 txpos += txdir; typos += tydir;
333 if (txpos + tlen <= 0)
337 if (txpos >= scp->xsize)
339 else if (txpos + tlen > scp->xsize)
340 tlen = scp->xsize - txpos;
342 draw_daemon(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen);
343 draw_string(sc, txpos, typos, toff, message, tlen);
351 daemon_init(video_adapter_t *adp)
353 messagelen = strlen(hostname) + 3 + strlen(ostype) + 1 +
355 message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK);
356 sprintf(message, "%s - %s %s", hostname, ostype, osrelease);
358 switch (adp->va_mode) {
361 attr_mask = ~FG_UNDERLINE;
372 daemon_term(video_adapter_t *adp)
374 free(message, M_DEVBUF);
378 static scrn_saver_t daemon_module = {
379 "daemon_saver", daemon_init, daemon_term, daemon_saver, NULL,
382 SAVER_MODULE(daemon_saver, daemon_module);