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>
36 #include <sys/kernel.h>
37 #include <sys/sysctl.h>
38 #include <sys/consio.h>
41 #include <machine/pc/display.h>
43 #include <dev/fb/fbreg.h>
44 #include <dev/fb/splashreg.h>
45 #include <dev/syscons/syscons.h>
47 #define DAEMON_MAX_WIDTH 32
48 #define DAEMON_MAX_HEIGHT 19
50 static u_char *message;
51 static int messagelen;
55 #define ATTR(attr) (((attr) & attr_mask) << 8)
57 /* Who is the author of this ASCII pic? */
59 static u_char *daemon_pic[] = {
72 "<----|====O)))==) \\) /====",
73 "<----' `--' `.__,' \\",
76 " ______( (_ / \\______/",
82 static u_char *daemon_attr[] = {
95 "YYYYYYYYYYRRRRYYR RR RYYYY",
96 "YYYYYY RRRR RRRRRR R",
99 " CCCCCCR RR R RRRRRRRR",
106 * Reverse a graphics character, or return unaltered if no mirror;
107 * should do alphanumerics too, but I'm too lazy. <cshenton@it.hq.nasa.gov>
111 xflip_symbol(u_char symbol)
113 static const u_char lchars[] = "`'(){}[]\\/<>";
114 static const u_char rchars[] = "'`)(}{][/\\><";
117 for (pos = 0; lchars[pos] != '\0'; pos++)
118 if (lchars[pos] == symbol)
125 clear_daemon(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff,
132 for (y = yoff; y < ylen; y++) {
133 sc_vtb_erase(&sc->cur_scp->scr,
134 (ypos + y)*sc->cur_scp->xsize + xpos + xoff,
136 sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK));
141 draw_daemon(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff,
148 for (y = yoff; y < ylen; y++) {
152 px = DAEMON_MAX_WIDTH - xlen;
153 if (px >= strlen(daemon_pic[y]))
155 for (x = xoff; (x < xlen) && (daemon_pic[y][px] != '\0'); x++, px++) {
156 switch (daemon_attr[y][px]) {
157 case 'R': attr = FG_LIGHTRED | BG_BLACK; break;
158 case 'Y': attr = FG_YELLOW | BG_BLACK; break;
159 case 'B': attr = FG_LIGHTBLUE | BG_BLACK; break;
160 case 'W': attr = FG_LIGHTGREY | BG_BLACK; break;
161 case 'C': attr = FG_CYAN | BG_BLACK; break;
162 default: attr = FG_WHITE | BG_BLACK; break;
164 if (dxdir < 0) { /* Moving left */
165 sc_vtb_putc(&sc->cur_scp->scr,
166 (ypos + y)*sc->cur_scp->xsize
168 sc->scr_map[daemon_pic[y][px]],
170 } else { /* Moving right */
171 sc_vtb_putc(&sc->cur_scp->scr,
172 (ypos + y)*sc->cur_scp->xsize
173 + xpos + DAEMON_MAX_WIDTH
175 sc->scr_map[xflip_symbol(daemon_pic[y][px])],
183 clear_string(sc_softc_t *sc, int xpos, int ypos, int xoff, char *s, int len)
187 sc_vtb_erase(&sc->cur_scp->scr,
188 ypos*sc->cur_scp->xsize + xpos + xoff, len - xoff,
189 sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK));
193 draw_string(sc_softc_t *sc, int xpos, int ypos, int xoff, u_char *s, int len)
197 for (x = xoff; x < len; x++)
198 sc_vtb_putc(&sc->cur_scp->scr,
199 ypos*sc->cur_scp->xsize + xpos + x,
200 sc->scr_map[s[x]], ATTR(FG_LIGHTGREEN | BG_BLACK));
204 daemon_saver(video_adapter_t *adp, int blank)
206 static int txpos = 10, typos = 10;
207 static int txdir = -1, tydir = -1;
208 static int dxpos = 0, dypos = 0;
209 static int dxdir = 1, dydir = 1;
210 static int moved_daemon = 0;
211 static int xoff, yoff, toff;
212 static int xlen, ylen, tlen;
217 sc = sc_find_softc(adp, NULL);
223 if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
226 /* clear the screen and set the border color */
227 sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
228 ATTR(FG_LIGHTGREY | BG_BLACK));
229 vidd_set_hw_cursor(adp, -1, -1);
230 sc_set_border(scp, 0);
231 xlen = ylen = tlen = 0;
237 clear_daemon(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen);
238 clear_string(sc, txpos, typos, toff, message, tlen);
240 if (++moved_daemon) {
242 * The daemon picture may be off the screen, if
243 * screen size is chagened while the screen
244 * saver is inactive. Make sure the origin of
245 * the picture is between min and max.
247 if (scp->xsize <= DAEMON_MAX_WIDTH) {
249 * If the screen width is too narrow, we
250 * allow part of the picture go off
251 * the screen so that the daemon won't
254 min = scp->xsize - DAEMON_MAX_WIDTH - 10;
258 max = scp->xsize - DAEMON_MAX_WIDTH;
263 } else if (dxpos >= max) {
268 if (scp->ysize <= DAEMON_MAX_HEIGHT) {
269 min = scp->ysize - DAEMON_MAX_HEIGHT - 10;
273 max = scp->ysize - DAEMON_MAX_HEIGHT;
278 } else if (dypos >= max) {
284 dxpos += dxdir; dypos += dydir;
286 /* clip the picture */
288 xlen = DAEMON_MAX_WIDTH;
289 if (dxpos + xlen <= 0)
293 if (dxpos >= scp->xsize)
295 else if (dxpos + xlen > scp->xsize)
296 xlen = scp->xsize - dxpos;
298 ylen = DAEMON_MAX_HEIGHT;
299 if (dypos + ylen <= 0)
303 if (dypos >= scp->ysize)
305 else if (dypos + ylen > scp->ysize)
306 ylen = scp->ysize - dypos;
309 if (scp->xsize <= messagelen) {
310 min = scp->xsize - messagelen - 10;
314 max = scp->xsize - messagelen;
319 } else if (txpos >= max) {
326 } else if (typos >= scp->ysize - 1) {
327 typos = scp->ysize - 1;
330 txpos += txdir; typos += tydir;
334 if (txpos + tlen <= 0)
338 if (txpos >= scp->xsize)
340 else if (txpos + tlen > scp->xsize)
341 tlen = scp->xsize - txpos;
343 draw_daemon(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen);
344 draw_string(sc, txpos, typos, toff, message, tlen);
352 daemon_init(video_adapter_t *adp)
356 mtx_lock(&prison0.pr_mtx);
358 hostlen = strlen(prison0.pr_hostname);
359 mtx_unlock(&prison0.pr_mtx);
361 messagelen = hostlen + 3 + strlen(ostype) + 1 +
363 message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK);
364 mtx_lock(&prison0.pr_mtx);
365 if (hostlen < strlen(prison0.pr_hostname)) {
366 free(message, M_DEVBUF);
371 sprintf(message, "%s - %s %s", prison0.pr_hostname, ostype, osrelease);
372 mtx_unlock(&prison0.pr_mtx);
380 daemon_term(video_adapter_t *adp)
382 free(message, M_DEVBUF);
386 static scrn_saver_t daemon_module = {
387 "daemon_saver", daemon_init, daemon_term, daemon_saver, NULL,
390 SAVER_MODULE(daemon_saver, daemon_module);