xref: /freebsd/sys/dev/syscons/daemon/daemon_saver.c (revision 8763b97d37e05a2b7950c6b4feea6353e4685d42)
1e8adebf2SKazutaka YOKOTA /*-
2e8adebf2SKazutaka YOKOTA  * Copyright (c) 1997 Sandro Sigala, Brescia, Italy.
3068eabc6SKazutaka YOKOTA  * Copyright (c) 1997 Chris Shenton
4e8adebf2SKazutaka YOKOTA  * Copyright (c) 1995 S ren Schmidt
5e8adebf2SKazutaka YOKOTA  * All rights reserved.
6e8adebf2SKazutaka YOKOTA  *
7e8adebf2SKazutaka YOKOTA  * Redistribution and use in source and binary forms, with or without
8e8adebf2SKazutaka YOKOTA  * modification, are permitted provided that the following conditions
9e8adebf2SKazutaka YOKOTA  * are met:
10e8adebf2SKazutaka YOKOTA  * 1. Redistributions of source code must retain the above copyright
11e8adebf2SKazutaka YOKOTA  *    notice, this list of conditions and the following disclaimer
12e8adebf2SKazutaka YOKOTA  *    in this position and unchanged.
13e8adebf2SKazutaka YOKOTA  * 2. Redistributions in binary form must reproduce the above copyright
14e8adebf2SKazutaka YOKOTA  *    notice, this list of conditions and the following disclaimer in the
15e8adebf2SKazutaka YOKOTA  *    documentation and/or other materials provided with the distribution.
16e8adebf2SKazutaka YOKOTA  *
17e8adebf2SKazutaka YOKOTA  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18e8adebf2SKazutaka YOKOTA  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19e8adebf2SKazutaka YOKOTA  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20e8adebf2SKazutaka YOKOTA  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21e8adebf2SKazutaka YOKOTA  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22e8adebf2SKazutaka YOKOTA  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23e8adebf2SKazutaka YOKOTA  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24e8adebf2SKazutaka YOKOTA  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25e8adebf2SKazutaka YOKOTA  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26e8adebf2SKazutaka YOKOTA  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27e8adebf2SKazutaka YOKOTA  *
28c3aac50fSPeter Wemm  * $FreeBSD$
29e8adebf2SKazutaka YOKOTA  */
30e8adebf2SKazutaka YOKOTA 
31e8adebf2SKazutaka YOKOTA #include <sys/param.h>
32e8adebf2SKazutaka YOKOTA #include <sys/systm.h>
330640d357SPeter Wemm #include <sys/module.h>
34ce834215SKazutaka YOKOTA #include <sys/malloc.h>
35f4863d1aSKazutaka YOKOTA #include <sys/kernel.h>
36f4863d1aSKazutaka YOKOTA #include <sys/sysctl.h>
376e8394b8SKazutaka YOKOTA #include <sys/consio.h>
386e8394b8SKazutaka YOKOTA #include <sys/fbio.h>
39e8adebf2SKazutaka YOKOTA 
4033b77e2dSBruce Evans #include <machine/pc/display.h>
41e8adebf2SKazutaka YOKOTA 
426e8394b8SKazutaka YOKOTA #include <dev/fb/fbreg.h>
436e8394b8SKazutaka YOKOTA #include <dev/fb/splashreg.h>
446e8394b8SKazutaka YOKOTA #include <dev/syscons/syscons.h>
45068eabc6SKazutaka YOKOTA 
46e8adebf2SKazutaka YOKOTA #define DAEMON_MAX_WIDTH	32
47e8adebf2SKazutaka YOKOTA #define DAEMON_MAX_HEIGHT	19
48e8adebf2SKazutaka YOKOTA 
492eb8169aSYoshihiro Takahashi static u_char *message;
50ce834215SKazutaka YOKOTA static int messagelen;
512ad872c5SKazutaka YOKOTA static int blanked;
528763b97dSYoshihiro Takahashi static int attr_mask;
538763b97dSYoshihiro Takahashi 
548763b97dSYoshihiro Takahashi #define	ATTR(attr)	(((attr) & attr_mask) << 8)
55068eabc6SKazutaka YOKOTA 
56068eabc6SKazutaka YOKOTA /* Who is the author of this ASCII pic? */
57e8adebf2SKazutaka YOKOTA 
582eb8169aSYoshihiro Takahashi static u_char *daemon_pic[] = {
59e8adebf2SKazutaka YOKOTA         "             ,        ,",
60e8adebf2SKazutaka YOKOTA 	"            /(        )`",
61e8adebf2SKazutaka YOKOTA 	"            \\ \\___   / |",
62e8adebf2SKazutaka YOKOTA 	"            /- _  `-/  '",
63e8adebf2SKazutaka YOKOTA 	"           (/\\/ \\ \\   /\\",
64e8adebf2SKazutaka YOKOTA 	"           / /   | `    \\",
65e8adebf2SKazutaka YOKOTA 	"           O O   ) /    |",
66e8adebf2SKazutaka YOKOTA 	"           `-^--'`<     '",
67e8adebf2SKazutaka YOKOTA 	"          (_.)  _  )   /",
68e8adebf2SKazutaka YOKOTA 	"           `.___/`    /",
69e8adebf2SKazutaka YOKOTA 	"             `-----' /",
70e8adebf2SKazutaka YOKOTA 	"<----.     __ / __   \\",
71e8adebf2SKazutaka YOKOTA 	"<----|====O)))==) \\) /====",
72e8adebf2SKazutaka YOKOTA 	"<----'    `--' `.__,' \\",
73e8adebf2SKazutaka YOKOTA 	"             |        |",
74e8adebf2SKazutaka YOKOTA 	"              \\       /       /\\",
75e8adebf2SKazutaka YOKOTA 	"         ______( (_  / \\______/",
76e8adebf2SKazutaka YOKOTA 	"       ,'  ,-----'   |",
77e8adebf2SKazutaka YOKOTA 	"       `--{__________)",
78e8adebf2SKazutaka YOKOTA 	NULL
79e8adebf2SKazutaka YOKOTA };
80e8adebf2SKazutaka YOKOTA 
812eb8169aSYoshihiro Takahashi static u_char *daemon_attr[] = {
82e8adebf2SKazutaka YOKOTA         "             R        R",
83e8adebf2SKazutaka YOKOTA 	"            RR        RR",
84e8adebf2SKazutaka YOKOTA 	"            R RRRR   R R",
85e8adebf2SKazutaka YOKOTA 	"            RR W  RRR  R",
86e8adebf2SKazutaka YOKOTA 	"           RWWW W R   RR",
87e8adebf2SKazutaka YOKOTA 	"           W W   W R    R",
88e8adebf2SKazutaka YOKOTA 	"           B B   W R    R",
89e8adebf2SKazutaka YOKOTA 	"           WWWWWWRR     R",
90e8adebf2SKazutaka YOKOTA 	"          RRRR  R  R   R",
91e8adebf2SKazutaka YOKOTA 	"           RRRRRRR    R",
92e8adebf2SKazutaka YOKOTA 	"             RRRRRRR R",
93e8adebf2SKazutaka YOKOTA 	"YYYYYY     RR R RR   R",
94e8adebf2SKazutaka YOKOTA 	"YYYYYYYYYYRRRRYYR RR RYYYY",
95e8adebf2SKazutaka YOKOTA 	"YYYYYY    RRRR RRRRRR R",
96e8adebf2SKazutaka YOKOTA 	"             R        R",
97e8adebf2SKazutaka YOKOTA 	"              R       R       RR",
98e8adebf2SKazutaka YOKOTA 	"         CCCCCCR RR  R RRRRRRRR",
99e8adebf2SKazutaka YOKOTA 	"       CC  CCCCCCC   C",
100e8adebf2SKazutaka YOKOTA 	"       CCCCCCCCCCCCCCC",
101e8adebf2SKazutaka YOKOTA 	NULL
102e8adebf2SKazutaka YOKOTA };
103e8adebf2SKazutaka YOKOTA 
104068eabc6SKazutaka YOKOTA /*
105068eabc6SKazutaka YOKOTA  * Reverse a graphics character, or return unaltered if no mirror;
106068eabc6SKazutaka YOKOTA  * should do alphanumerics too, but I'm too lazy. <cshenton@it.hq.nasa.gov>
107068eabc6SKazutaka YOKOTA  */
108068eabc6SKazutaka YOKOTA 
1092eb8169aSYoshihiro Takahashi static u_char
1102eb8169aSYoshihiro Takahashi xflip_symbol(u_char symbol)
111068eabc6SKazutaka YOKOTA {
1122eb8169aSYoshihiro Takahashi 	static const u_char lchars[] = "`'(){}[]\\/<>";
1132eb8169aSYoshihiro Takahashi 	static const u_char rchars[] = "'`)(}{][/\\><";
114068eabc6SKazutaka YOKOTA 	int pos;
115068eabc6SKazutaka YOKOTA 
116068eabc6SKazutaka YOKOTA 	for (pos = 0; lchars[pos] != '\0'; pos++)
117068eabc6SKazutaka YOKOTA 		if (lchars[pos] == symbol)
118068eabc6SKazutaka YOKOTA 			return rchars[pos];
119068eabc6SKazutaka YOKOTA 
120068eabc6SKazutaka YOKOTA 	return symbol;
121068eabc6SKazutaka YOKOTA }
122e8adebf2SKazutaka YOKOTA 
123e8adebf2SKazutaka YOKOTA static void
1246e8394b8SKazutaka YOKOTA clear_daemon(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff,
12502f2e93bSKazutaka YOKOTA 	    int xlen, int ylen)
12602f2e93bSKazutaka YOKOTA {
12702f2e93bSKazutaka YOKOTA 	int y;
12802f2e93bSKazutaka YOKOTA 
12902f2e93bSKazutaka YOKOTA 	if (xlen <= 0)
13002f2e93bSKazutaka YOKOTA 		return;
1316e8394b8SKazutaka YOKOTA 	for (y = yoff; y < ylen; y++) {
1326e8394b8SKazutaka YOKOTA 		sc_vtb_erase(&sc->cur_scp->scr,
1336e8394b8SKazutaka YOKOTA 			     (ypos + y)*sc->cur_scp->xsize + xpos + xoff,
1346e8394b8SKazutaka YOKOTA 			     xlen - xoff,
1358763b97dSYoshihiro Takahashi 			     sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK));
1366e8394b8SKazutaka YOKOTA 	}
13702f2e93bSKazutaka YOKOTA }
13802f2e93bSKazutaka YOKOTA 
13902f2e93bSKazutaka YOKOTA static void
1406e8394b8SKazutaka YOKOTA draw_daemon(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff,
14102f2e93bSKazutaka YOKOTA 	    int xlen, int ylen)
142e8adebf2SKazutaka YOKOTA {
143e8adebf2SKazutaka YOKOTA 	int x, y;
14402f2e93bSKazutaka YOKOTA 	int px;
145e8adebf2SKazutaka YOKOTA 	int attr;
146e8adebf2SKazutaka YOKOTA 
14702f2e93bSKazutaka YOKOTA 	for (y = yoff; y < ylen; y++) {
14802f2e93bSKazutaka YOKOTA 		if (dxdir < 0)
14902f2e93bSKazutaka YOKOTA 			px = xoff;
15002f2e93bSKazutaka YOKOTA 		else
15102f2e93bSKazutaka YOKOTA 			px = DAEMON_MAX_WIDTH - xlen;
15202f2e93bSKazutaka YOKOTA 		if (px >= strlen(daemon_pic[y]))
15302f2e93bSKazutaka YOKOTA 			continue;
15402f2e93bSKazutaka YOKOTA 		for (x = xoff; (x < xlen) && (daemon_pic[y][px] != '\0'); x++, px++) {
15502f2e93bSKazutaka YOKOTA 			switch (daemon_attr[y][px]) {
1568763b97dSYoshihiro Takahashi 			case 'R': attr = FG_LIGHTRED | BG_BLACK; break;
1578763b97dSYoshihiro Takahashi 			case 'Y': attr = FG_YELLOW | BG_BLACK; break;
1588763b97dSYoshihiro Takahashi 			case 'B': attr = FG_LIGHTBLUE | BG_BLACK; break;
1598763b97dSYoshihiro Takahashi 			case 'W': attr = FG_LIGHTGREY | BG_BLACK; break;
1608763b97dSYoshihiro Takahashi 			case 'C': attr = FG_CYAN | BG_BLACK; break;
1618763b97dSYoshihiro Takahashi 			default: attr = FG_WHITE | BG_BLACK; break;
162e8adebf2SKazutaka YOKOTA 			}
163068eabc6SKazutaka YOKOTA 			if (dxdir < 0) {	/* Moving left */
1646e8394b8SKazutaka YOKOTA 				sc_vtb_putc(&sc->cur_scp->scr,
1656e8394b8SKazutaka YOKOTA 					    (ypos + y)*sc->cur_scp->xsize
1666e8394b8SKazutaka YOKOTA 						 + xpos + x,
1676e8394b8SKazutaka YOKOTA 					    sc->scr_map[daemon_pic[y][px]],
1688763b97dSYoshihiro Takahashi 					    ATTR(attr));
169068eabc6SKazutaka YOKOTA 			} else {		/* Moving right */
1706e8394b8SKazutaka YOKOTA 				sc_vtb_putc(&sc->cur_scp->scr,
1716e8394b8SKazutaka YOKOTA 					    (ypos + y)*sc->cur_scp->xsize
1726e8394b8SKazutaka YOKOTA 						+ xpos + DAEMON_MAX_WIDTH
1736e8394b8SKazutaka YOKOTA 						- px - 1,
1746e8394b8SKazutaka YOKOTA 					    sc->scr_map[xflip_symbol(daemon_pic[y][px])],
1758763b97dSYoshihiro Takahashi 					    ATTR(attr));
17602f2e93bSKazutaka YOKOTA 			}
177068eabc6SKazutaka YOKOTA 		}
178e8adebf2SKazutaka YOKOTA 	}
179e8adebf2SKazutaka YOKOTA }
180e8adebf2SKazutaka YOKOTA 
181e8adebf2SKazutaka YOKOTA static void
1826e8394b8SKazutaka YOKOTA clear_string(sc_softc_t *sc, int xpos, int ypos, int xoff, char *s, int len)
18302f2e93bSKazutaka YOKOTA {
18402f2e93bSKazutaka YOKOTA 	if (len <= 0)
18502f2e93bSKazutaka YOKOTA 		return;
1866e8394b8SKazutaka YOKOTA 	sc_vtb_erase(&sc->cur_scp->scr,
1876e8394b8SKazutaka YOKOTA 		     ypos*sc->cur_scp->xsize + xpos + xoff, len - xoff,
1888763b97dSYoshihiro Takahashi 		     sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK));
18902f2e93bSKazutaka YOKOTA }
19002f2e93bSKazutaka YOKOTA 
19102f2e93bSKazutaka YOKOTA static void
1922eb8169aSYoshihiro Takahashi draw_string(sc_softc_t *sc, int xpos, int ypos, int xoff, u_char *s, int len)
193e8adebf2SKazutaka YOKOTA {
194e8adebf2SKazutaka YOKOTA 	int x;
195e8adebf2SKazutaka YOKOTA 
1968763b97dSYoshihiro Takahashi 	for (x = xoff; x < len; x++)
197b95b56c7SYoshihiro Takahashi 		sc_vtb_putc(&sc->cur_scp->scr,
198b95b56c7SYoshihiro Takahashi 			    ypos*sc->cur_scp->xsize + xpos + x,
1998763b97dSYoshihiro Takahashi 			    sc->scr_map[s[x]], ATTR(FG_LIGHTGREEN | BG_BLACK));
200e8adebf2SKazutaka YOKOTA }
201e8adebf2SKazutaka YOKOTA 
2022ad872c5SKazutaka YOKOTA static int
2032ad872c5SKazutaka YOKOTA daemon_saver(video_adapter_t *adp, int blank)
204e8adebf2SKazutaka YOKOTA {
205e8adebf2SKazutaka YOKOTA 	static int txpos = 10, typos = 10;
206e8adebf2SKazutaka YOKOTA 	static int txdir = -1, tydir = -1;
207068eabc6SKazutaka YOKOTA 	static int dxpos = 0, dypos = 0;
208068eabc6SKazutaka YOKOTA 	static int dxdir = 1, dydir = 1;
209e8adebf2SKazutaka YOKOTA 	static int moved_daemon = 0;
21002f2e93bSKazutaka YOKOTA 	static int xoff, yoff, toff;
21102f2e93bSKazutaka YOKOTA 	static int xlen, ylen, tlen;
2126e8394b8SKazutaka YOKOTA 	sc_softc_t *sc;
2136e8394b8SKazutaka YOKOTA 	scr_stat *scp;
21402f2e93bSKazutaka YOKOTA 	int min, max;
215e8adebf2SKazutaka YOKOTA 
2166e8394b8SKazutaka YOKOTA 	sc = sc_find_softc(adp, NULL);
2176e8394b8SKazutaka YOKOTA 	if (sc == NULL)
2186e8394b8SKazutaka YOKOTA 		return EAGAIN;
2196e8394b8SKazutaka YOKOTA 	scp = sc->cur_scp;
2206e8394b8SKazutaka YOKOTA 
221e8adebf2SKazutaka YOKOTA 	if (blank) {
2222da199daSDag-Erling Smørgrav 		if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
223f9e730bbSKazutaka YOKOTA 			return EAGAIN;
2242ad872c5SKazutaka YOKOTA 		if (blanked == 0) {
22502f2e93bSKazutaka YOKOTA 			/* clear the screen and set the border color */
2266e8394b8SKazutaka YOKOTA 			sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
2278763b97dSYoshihiro Takahashi 				     ATTR(FG_LIGHTGREY | BG_BLACK));
2286e8394b8SKazutaka YOKOTA 			(*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
2292b944ee2SKazutaka YOKOTA 			sc_set_border(scp, 0);
23002f2e93bSKazutaka YOKOTA 			xlen = ylen = tlen = 0;
23102f2e93bSKazutaka YOKOTA 		}
2322ad872c5SKazutaka YOKOTA 		if (blanked++ < 2)
2332ad872c5SKazutaka YOKOTA 			return 0;
2342ad872c5SKazutaka YOKOTA 		blanked = 1;
235e8adebf2SKazutaka YOKOTA 
2366e8394b8SKazutaka YOKOTA  		clear_daemon(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen);
2372eb8169aSYoshihiro Takahashi 		clear_string(sc, txpos, typos, toff, message, tlen);
23802f2e93bSKazutaka YOKOTA 
239e8adebf2SKazutaka YOKOTA 		if (++moved_daemon) {
24002f2e93bSKazutaka YOKOTA 			/*
24102f2e93bSKazutaka YOKOTA 			 * The daemon picture may be off the screen, if
24202f2e93bSKazutaka YOKOTA 			 * screen size is chagened while the screen
24302f2e93bSKazutaka YOKOTA 			 * saver is inactive. Make sure the origin of
24402f2e93bSKazutaka YOKOTA 			 * the picture is between min and max.
24502f2e93bSKazutaka YOKOTA 			 */
24602f2e93bSKazutaka YOKOTA 			if (scp->xsize <= DAEMON_MAX_WIDTH) {
24702f2e93bSKazutaka YOKOTA 				/*
24802f2e93bSKazutaka YOKOTA 				 * If the screen width is too narrow, we
24902f2e93bSKazutaka YOKOTA 				 * allow part of the picture go off
25002f2e93bSKazutaka YOKOTA 				 * the screen so that the daemon won't
25102f2e93bSKazutaka YOKOTA 				 * flip too often.
25202f2e93bSKazutaka YOKOTA 				 */
25302f2e93bSKazutaka YOKOTA 				min = scp->xsize - DAEMON_MAX_WIDTH - 10;
25402f2e93bSKazutaka YOKOTA 				max = 10;
25502f2e93bSKazutaka YOKOTA 			} else {
25602f2e93bSKazutaka YOKOTA 				min = 0;
25702f2e93bSKazutaka YOKOTA 				max = scp->xsize - DAEMON_MAX_WIDTH;
25802f2e93bSKazutaka YOKOTA 			}
25902f2e93bSKazutaka YOKOTA 			if (dxpos <= min) {
26002f2e93bSKazutaka YOKOTA 				dxpos = min;
26102f2e93bSKazutaka YOKOTA 				dxdir = 1;
26202f2e93bSKazutaka YOKOTA 			} else if (dxpos >= max) {
26302f2e93bSKazutaka YOKOTA 				dxpos = max;
264e8adebf2SKazutaka YOKOTA 				dxdir = -1;
265e8adebf2SKazutaka YOKOTA 			}
266e8adebf2SKazutaka YOKOTA 
26702f2e93bSKazutaka YOKOTA 			if (scp->ysize <= DAEMON_MAX_HEIGHT) {
26802f2e93bSKazutaka YOKOTA 				min = scp->ysize - DAEMON_MAX_HEIGHT - 10;
26902f2e93bSKazutaka YOKOTA 				max = 10;
270e8adebf2SKazutaka YOKOTA 			} else {
27102f2e93bSKazutaka YOKOTA 				min = 0;
27202f2e93bSKazutaka YOKOTA 				max = scp->ysize - DAEMON_MAX_HEIGHT;
273e8adebf2SKazutaka YOKOTA 			}
27402f2e93bSKazutaka YOKOTA 			if (dypos <= min) {
27502f2e93bSKazutaka YOKOTA 				dypos = min;
27602f2e93bSKazutaka YOKOTA 				dydir = 1;
27702f2e93bSKazutaka YOKOTA 			} else if (dypos >= max) {
27802f2e93bSKazutaka YOKOTA 				dypos = max;
27902f2e93bSKazutaka YOKOTA 				dydir = -1;
28002f2e93bSKazutaka YOKOTA 			}
28102f2e93bSKazutaka YOKOTA 
28202f2e93bSKazutaka YOKOTA 			moved_daemon = -1;
28302f2e93bSKazutaka YOKOTA 			dxpos += dxdir; dypos += dydir;
28402f2e93bSKazutaka YOKOTA 
28502f2e93bSKazutaka YOKOTA 			/* clip the picture */
28602f2e93bSKazutaka YOKOTA 			xoff = 0;
28702f2e93bSKazutaka YOKOTA 			xlen = DAEMON_MAX_WIDTH;
28802f2e93bSKazutaka YOKOTA 			if (dxpos + xlen <= 0)
28902f2e93bSKazutaka YOKOTA 				xlen = 0;
29002f2e93bSKazutaka YOKOTA 			else if (dxpos < 0)
29102f2e93bSKazutaka YOKOTA 				xoff = -dxpos;
29202f2e93bSKazutaka YOKOTA 			if (dxpos >= scp->xsize)
29302f2e93bSKazutaka YOKOTA 				xlen = 0;
29402f2e93bSKazutaka YOKOTA 			else if (dxpos + xlen > scp->xsize)
29502f2e93bSKazutaka YOKOTA 				xlen = scp->xsize - dxpos;
29602f2e93bSKazutaka YOKOTA 			yoff = 0;
29702f2e93bSKazutaka YOKOTA 			ylen = DAEMON_MAX_HEIGHT;
29802f2e93bSKazutaka YOKOTA 			if (dypos + ylen <= 0)
29902f2e93bSKazutaka YOKOTA 				ylen = 0;
30002f2e93bSKazutaka YOKOTA 			else if (dypos < 0)
30102f2e93bSKazutaka YOKOTA 				yoff = -dypos;
30202f2e93bSKazutaka YOKOTA 			if (dypos >= scp->ysize)
30302f2e93bSKazutaka YOKOTA 				ylen = 0;
30402f2e93bSKazutaka YOKOTA 			else if (dypos + ylen > scp->ysize)
30502f2e93bSKazutaka YOKOTA 				ylen = scp->ysize - dypos;
30602f2e93bSKazutaka YOKOTA 		}
30702f2e93bSKazutaka YOKOTA 
30802f2e93bSKazutaka YOKOTA 		if (scp->xsize <= messagelen) {
30902f2e93bSKazutaka YOKOTA 			min = scp->xsize - messagelen - 10;
31002f2e93bSKazutaka YOKOTA 			max = 10;
311e8adebf2SKazutaka YOKOTA 		} else {
31202f2e93bSKazutaka YOKOTA 			min = 0;
31302f2e93bSKazutaka YOKOTA 			max = scp->xsize - messagelen;
31402f2e93bSKazutaka YOKOTA 		}
31502f2e93bSKazutaka YOKOTA 		if (txpos <= min) {
31602f2e93bSKazutaka YOKOTA 			txpos = min;
31702f2e93bSKazutaka YOKOTA 			txdir = 1;
31802f2e93bSKazutaka YOKOTA 		} else if (txpos >= max) {
31902f2e93bSKazutaka YOKOTA 			txpos = max;
32002f2e93bSKazutaka YOKOTA 			txdir = -1;
32102f2e93bSKazutaka YOKOTA 		}
32202f2e93bSKazutaka YOKOTA 		if (typos <= 0) {
32302f2e93bSKazutaka YOKOTA 			typos = 0;
32402f2e93bSKazutaka YOKOTA 			tydir = 1;
32502f2e93bSKazutaka YOKOTA 		} else if (typos >= scp->ysize - 1) {
32602f2e93bSKazutaka YOKOTA 			typos = scp->ysize - 1;
32702f2e93bSKazutaka YOKOTA 			tydir = -1;
328e8adebf2SKazutaka YOKOTA 		}
329e8adebf2SKazutaka YOKOTA 		txpos += txdir; typos += tydir;
330e8adebf2SKazutaka YOKOTA 
33102f2e93bSKazutaka YOKOTA 		toff = 0;
33202f2e93bSKazutaka YOKOTA 		tlen = messagelen;
33302f2e93bSKazutaka YOKOTA 		if (txpos + tlen <= 0)
33402f2e93bSKazutaka YOKOTA 			tlen = 0;
33502f2e93bSKazutaka YOKOTA 		else if (txpos < 0)
33602f2e93bSKazutaka YOKOTA 			toff = -txpos;
33702f2e93bSKazutaka YOKOTA 		if (txpos >= scp->xsize)
33802f2e93bSKazutaka YOKOTA 			tlen = 0;
33902f2e93bSKazutaka YOKOTA 		else if (txpos + tlen > scp->xsize)
34002f2e93bSKazutaka YOKOTA 			tlen = scp->xsize - txpos;
34102f2e93bSKazutaka YOKOTA 
3426e8394b8SKazutaka YOKOTA  		draw_daemon(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen);
3432eb8169aSYoshihiro Takahashi 		draw_string(sc, txpos, typos, toff, message, tlen);
3448763b97dSYoshihiro Takahashi 	} else
3452ad872c5SKazutaka YOKOTA 		blanked = 0;
3468763b97dSYoshihiro Takahashi 
3472ad872c5SKazutaka YOKOTA 	return 0;
348e8adebf2SKazutaka YOKOTA }
349e8adebf2SKazutaka YOKOTA 
350e8adebf2SKazutaka YOKOTA static int
3512ad872c5SKazutaka YOKOTA daemon_init(video_adapter_t *adp)
352e8adebf2SKazutaka YOKOTA {
353ce834215SKazutaka YOKOTA 	messagelen = strlen(hostname) + 3 + strlen(ostype) + 1 +
354ce834215SKazutaka YOKOTA 	    strlen(osrelease);
355a163d034SWarner Losh 	message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK);
356ce834215SKazutaka YOKOTA 	sprintf(message, "%s - %s %s", hostname, ostype, osrelease);
3572ad872c5SKazutaka YOKOTA 	blanked = 0;
3588763b97dSYoshihiro Takahashi 	switch (adp->va_mode) {
3598763b97dSYoshihiro Takahashi 	case M_PC98_80x25:
3608763b97dSYoshihiro Takahashi 	case M_PC98_80x30:
3618763b97dSYoshihiro Takahashi 		attr_mask = ~FG_UNDERLINE;
3628763b97dSYoshihiro Takahashi 		break;
3638763b97dSYoshihiro Takahashi 	default:
3648763b97dSYoshihiro Takahashi 		attr_mask = ~0;
3658763b97dSYoshihiro Takahashi 		break;
3668763b97dSYoshihiro Takahashi 	}
3678763b97dSYoshihiro Takahashi 
3682ad872c5SKazutaka YOKOTA 	return 0;
369e8adebf2SKazutaka YOKOTA }
370e8adebf2SKazutaka YOKOTA 
371e8adebf2SKazutaka YOKOTA static int
3722ad872c5SKazutaka YOKOTA daemon_term(video_adapter_t *adp)
373e8adebf2SKazutaka YOKOTA {
374f4863d1aSKazutaka YOKOTA 	free(message, M_DEVBUF);
3752ad872c5SKazutaka YOKOTA 	return 0;
376e8adebf2SKazutaka YOKOTA }
377e8adebf2SKazutaka YOKOTA 
3782ad872c5SKazutaka YOKOTA static scrn_saver_t daemon_module = {
3792ad872c5SKazutaka YOKOTA 	"daemon_saver", daemon_init, daemon_term, daemon_saver, NULL,
3802ad872c5SKazutaka YOKOTA };
3812ad872c5SKazutaka YOKOTA 
3822ad872c5SKazutaka YOKOTA SAVER_MODULE(daemon_saver, daemon_module);
383