1e8adebf2SKazutaka YOKOTA /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
4e8adebf2SKazutaka YOKOTA * Copyright (c) 1997 Sandro Sigala, Brescia, Italy.
5068eabc6SKazutaka YOKOTA * Copyright (c) 1997 Chris Shenton
6a1ff3f20SXin LI * Copyright (c) 1995 Søren Schmidt
7e8adebf2SKazutaka YOKOTA * All rights reserved.
8e8adebf2SKazutaka YOKOTA *
9e8adebf2SKazutaka YOKOTA * Redistribution and use in source and binary forms, with or without
10e8adebf2SKazutaka YOKOTA * modification, are permitted provided that the following conditions
11e8adebf2SKazutaka YOKOTA * are met:
12e8adebf2SKazutaka YOKOTA * 1. Redistributions of source code must retain the above copyright
13e8adebf2SKazutaka YOKOTA * notice, this list of conditions and the following disclaimer
14e8adebf2SKazutaka YOKOTA * in this position and unchanged.
15e8adebf2SKazutaka YOKOTA * 2. Redistributions in binary form must reproduce the above copyright
16e8adebf2SKazutaka YOKOTA * notice, this list of conditions and the following disclaimer in the
17e8adebf2SKazutaka YOKOTA * documentation and/or other materials provided with the distribution.
18e8adebf2SKazutaka YOKOTA *
19e8adebf2SKazutaka YOKOTA * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20e8adebf2SKazutaka YOKOTA * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21e8adebf2SKazutaka YOKOTA * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22e8adebf2SKazutaka YOKOTA * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23e8adebf2SKazutaka YOKOTA * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24e8adebf2SKazutaka YOKOTA * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25e8adebf2SKazutaka YOKOTA * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26e8adebf2SKazutaka YOKOTA * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27e8adebf2SKazutaka YOKOTA * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28e8adebf2SKazutaka YOKOTA * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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>
3576ca6f88SJamie Gritton #include <sys/jail.h>
36f4863d1aSKazutaka YOKOTA #include <sys/kernel.h>
37f4863d1aSKazutaka YOKOTA #include <sys/sysctl.h>
386e8394b8SKazutaka YOKOTA #include <sys/consio.h>
396e8394b8SKazutaka YOKOTA #include <sys/fbio.h>
40e8adebf2SKazutaka YOKOTA
4133b77e2dSBruce Evans #include <machine/pc/display.h>
42e8adebf2SKazutaka YOKOTA
436e8394b8SKazutaka YOKOTA #include <dev/fb/fbreg.h>
446e8394b8SKazutaka YOKOTA #include <dev/fb/splashreg.h>
456e8394b8SKazutaka YOKOTA #include <dev/syscons/syscons.h>
46068eabc6SKazutaka YOKOTA
47e8adebf2SKazutaka YOKOTA #define DAEMON_MAX_WIDTH 32
48e8adebf2SKazutaka YOKOTA #define DAEMON_MAX_HEIGHT 19
49e8adebf2SKazutaka YOKOTA
502eb8169aSYoshihiro Takahashi static u_char *message;
51ce834215SKazutaka YOKOTA static int messagelen;
522ad872c5SKazutaka YOKOTA static int blanked;
538763b97dSYoshihiro Takahashi static int attr_mask;
548763b97dSYoshihiro Takahashi
558763b97dSYoshihiro Takahashi #define ATTR(attr) (((attr) & attr_mask) << 8)
56068eabc6SKazutaka YOKOTA
57068eabc6SKazutaka YOKOTA /* Who is the author of this ASCII pic? */
58e8adebf2SKazutaka YOKOTA
592eb8169aSYoshihiro Takahashi static u_char *daemon_pic[] = {
60e8adebf2SKazutaka YOKOTA " , ,",
61e8adebf2SKazutaka YOKOTA " /( )`",
62e8adebf2SKazutaka YOKOTA " \\ \\___ / |",
63e8adebf2SKazutaka YOKOTA " /- _ `-/ '",
64e8adebf2SKazutaka YOKOTA " (/\\/ \\ \\ /\\",
65e8adebf2SKazutaka YOKOTA " / / | ` \\",
66e8adebf2SKazutaka YOKOTA " O O ) / |",
67e8adebf2SKazutaka YOKOTA " `-^--'`< '",
68e8adebf2SKazutaka YOKOTA " (_.) _ ) /",
69e8adebf2SKazutaka YOKOTA " `.___/` /",
70e8adebf2SKazutaka YOKOTA " `-----' /",
71e8adebf2SKazutaka YOKOTA "<----. __ / __ \\",
72e8adebf2SKazutaka YOKOTA "<----|====O)))==) \\) /====",
73e8adebf2SKazutaka YOKOTA "<----' `--' `.__,' \\",
74e8adebf2SKazutaka YOKOTA " | |",
75e8adebf2SKazutaka YOKOTA " \\ / /\\",
76e8adebf2SKazutaka YOKOTA " ______( (_ / \\______/",
77e8adebf2SKazutaka YOKOTA " ,' ,-----' |",
78e8adebf2SKazutaka YOKOTA " `--{__________)",
79e8adebf2SKazutaka YOKOTA NULL
80e8adebf2SKazutaka YOKOTA };
81e8adebf2SKazutaka YOKOTA
822eb8169aSYoshihiro Takahashi static u_char *daemon_attr[] = {
83e8adebf2SKazutaka YOKOTA " R R",
84e8adebf2SKazutaka YOKOTA " RR RR",
85e8adebf2SKazutaka YOKOTA " R RRRR R R",
86e8adebf2SKazutaka YOKOTA " RR W RRR R",
87e8adebf2SKazutaka YOKOTA " RWWW W R RR",
88e8adebf2SKazutaka YOKOTA " W W W R R",
89e8adebf2SKazutaka YOKOTA " B B W R R",
90e8adebf2SKazutaka YOKOTA " WWWWWWRR R",
91e8adebf2SKazutaka YOKOTA " RRRR R R R",
92e8adebf2SKazutaka YOKOTA " RRRRRRR R",
93e8adebf2SKazutaka YOKOTA " RRRRRRR R",
94e8adebf2SKazutaka YOKOTA "YYYYYY RR R RR R",
95e8adebf2SKazutaka YOKOTA "YYYYYYYYYYRRRRYYR RR RYYYY",
96e8adebf2SKazutaka YOKOTA "YYYYYY RRRR RRRRRR R",
97e8adebf2SKazutaka YOKOTA " R R",
98e8adebf2SKazutaka YOKOTA " R R RR",
99e8adebf2SKazutaka YOKOTA " CCCCCCR RR R RRRRRRRR",
100e8adebf2SKazutaka YOKOTA " CC CCCCCCC C",
101e8adebf2SKazutaka YOKOTA " CCCCCCCCCCCCCCC",
102e8adebf2SKazutaka YOKOTA NULL
103e8adebf2SKazutaka YOKOTA };
104e8adebf2SKazutaka YOKOTA
105068eabc6SKazutaka YOKOTA /*
106068eabc6SKazutaka YOKOTA * Reverse a graphics character, or return unaltered if no mirror;
107068eabc6SKazutaka YOKOTA * should do alphanumerics too, but I'm too lazy. <cshenton@it.hq.nasa.gov>
108068eabc6SKazutaka YOKOTA */
109068eabc6SKazutaka YOKOTA
1102eb8169aSYoshihiro Takahashi static u_char
xflip_symbol(u_char symbol)1112eb8169aSYoshihiro Takahashi xflip_symbol(u_char symbol)
112068eabc6SKazutaka YOKOTA {
1132eb8169aSYoshihiro Takahashi static const u_char lchars[] = "`'(){}[]\\/<>";
1142eb8169aSYoshihiro Takahashi static const u_char rchars[] = "'`)(}{][/\\><";
115068eabc6SKazutaka YOKOTA int pos;
116068eabc6SKazutaka YOKOTA
117068eabc6SKazutaka YOKOTA for (pos = 0; lchars[pos] != '\0'; pos++)
118068eabc6SKazutaka YOKOTA if (lchars[pos] == symbol)
119068eabc6SKazutaka YOKOTA return rchars[pos];
120068eabc6SKazutaka YOKOTA
121068eabc6SKazutaka YOKOTA return symbol;
122068eabc6SKazutaka YOKOTA }
123e8adebf2SKazutaka YOKOTA
124e8adebf2SKazutaka YOKOTA static void
clear_daemon(sc_softc_t * sc,int xpos,int ypos,int dxdir,int xoff,int yoff,int xlen,int ylen)1256e8394b8SKazutaka YOKOTA clear_daemon(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff,
12602f2e93bSKazutaka YOKOTA int xlen, int ylen)
12702f2e93bSKazutaka YOKOTA {
12802f2e93bSKazutaka YOKOTA int y;
12902f2e93bSKazutaka YOKOTA
13002f2e93bSKazutaka YOKOTA if (xlen <= 0)
13102f2e93bSKazutaka YOKOTA return;
1326e8394b8SKazutaka YOKOTA for (y = yoff; y < ylen; y++) {
1336e8394b8SKazutaka YOKOTA sc_vtb_erase(&sc->cur_scp->scr,
1346e8394b8SKazutaka YOKOTA (ypos + y)*sc->cur_scp->xsize + xpos + xoff,
1356e8394b8SKazutaka YOKOTA xlen - xoff,
1368763b97dSYoshihiro Takahashi sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK));
1376e8394b8SKazutaka YOKOTA }
13802f2e93bSKazutaka YOKOTA }
13902f2e93bSKazutaka YOKOTA
14002f2e93bSKazutaka YOKOTA static void
draw_daemon(sc_softc_t * sc,int xpos,int ypos,int dxdir,int xoff,int yoff,int xlen,int ylen)1416e8394b8SKazutaka YOKOTA draw_daemon(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff,
14202f2e93bSKazutaka YOKOTA int xlen, int ylen)
143e8adebf2SKazutaka YOKOTA {
144e8adebf2SKazutaka YOKOTA int x, y;
14502f2e93bSKazutaka YOKOTA int px;
146e8adebf2SKazutaka YOKOTA int attr;
147e8adebf2SKazutaka YOKOTA
14802f2e93bSKazutaka YOKOTA for (y = yoff; y < ylen; y++) {
14902f2e93bSKazutaka YOKOTA if (dxdir < 0)
15002f2e93bSKazutaka YOKOTA px = xoff;
15102f2e93bSKazutaka YOKOTA else
15202f2e93bSKazutaka YOKOTA px = DAEMON_MAX_WIDTH - xlen;
15302f2e93bSKazutaka YOKOTA if (px >= strlen(daemon_pic[y]))
15402f2e93bSKazutaka YOKOTA continue;
15502f2e93bSKazutaka YOKOTA for (x = xoff; (x < xlen) && (daemon_pic[y][px] != '\0'); x++, px++) {
15602f2e93bSKazutaka YOKOTA switch (daemon_attr[y][px]) {
1578763b97dSYoshihiro Takahashi case 'R': attr = FG_LIGHTRED | BG_BLACK; break;
1588763b97dSYoshihiro Takahashi case 'Y': attr = FG_YELLOW | BG_BLACK; break;
1598763b97dSYoshihiro Takahashi case 'B': attr = FG_LIGHTBLUE | BG_BLACK; break;
1608763b97dSYoshihiro Takahashi case 'W': attr = FG_LIGHTGREY | BG_BLACK; break;
1618763b97dSYoshihiro Takahashi case 'C': attr = FG_CYAN | BG_BLACK; break;
1628763b97dSYoshihiro Takahashi default: attr = FG_WHITE | BG_BLACK; break;
163e8adebf2SKazutaka YOKOTA }
164068eabc6SKazutaka YOKOTA if (dxdir < 0) { /* Moving left */
1656e8394b8SKazutaka YOKOTA sc_vtb_putc(&sc->cur_scp->scr,
1666e8394b8SKazutaka YOKOTA (ypos + y)*sc->cur_scp->xsize
1676e8394b8SKazutaka YOKOTA + xpos + x,
1686e8394b8SKazutaka YOKOTA sc->scr_map[daemon_pic[y][px]],
1698763b97dSYoshihiro Takahashi ATTR(attr));
170068eabc6SKazutaka YOKOTA } else { /* Moving right */
1716e8394b8SKazutaka YOKOTA sc_vtb_putc(&sc->cur_scp->scr,
1726e8394b8SKazutaka YOKOTA (ypos + y)*sc->cur_scp->xsize
1736e8394b8SKazutaka YOKOTA + xpos + DAEMON_MAX_WIDTH
1746e8394b8SKazutaka YOKOTA - px - 1,
1756e8394b8SKazutaka YOKOTA sc->scr_map[xflip_symbol(daemon_pic[y][px])],
1768763b97dSYoshihiro Takahashi ATTR(attr));
17702f2e93bSKazutaka YOKOTA }
178068eabc6SKazutaka YOKOTA }
179e8adebf2SKazutaka YOKOTA }
180e8adebf2SKazutaka YOKOTA }
181e8adebf2SKazutaka YOKOTA
182e8adebf2SKazutaka YOKOTA static void
clear_string(sc_softc_t * sc,int xpos,int ypos,int xoff,char * s,int len)1836e8394b8SKazutaka YOKOTA clear_string(sc_softc_t *sc, int xpos, int ypos, int xoff, char *s, int len)
18402f2e93bSKazutaka YOKOTA {
18502f2e93bSKazutaka YOKOTA if (len <= 0)
18602f2e93bSKazutaka YOKOTA return;
1876e8394b8SKazutaka YOKOTA sc_vtb_erase(&sc->cur_scp->scr,
1886e8394b8SKazutaka YOKOTA ypos*sc->cur_scp->xsize + xpos + xoff, len - xoff,
1898763b97dSYoshihiro Takahashi sc->scr_map[0x20], ATTR(FG_LIGHTGREY | BG_BLACK));
19002f2e93bSKazutaka YOKOTA }
19102f2e93bSKazutaka YOKOTA
19202f2e93bSKazutaka YOKOTA static void
draw_string(sc_softc_t * sc,int xpos,int ypos,int xoff,u_char * s,int len)1932eb8169aSYoshihiro Takahashi draw_string(sc_softc_t *sc, int xpos, int ypos, int xoff, u_char *s, int len)
194e8adebf2SKazutaka YOKOTA {
195e8adebf2SKazutaka YOKOTA int x;
196e8adebf2SKazutaka YOKOTA
1978763b97dSYoshihiro Takahashi for (x = xoff; x < len; x++)
198b95b56c7SYoshihiro Takahashi sc_vtb_putc(&sc->cur_scp->scr,
199b95b56c7SYoshihiro Takahashi ypos*sc->cur_scp->xsize + xpos + x,
2008763b97dSYoshihiro Takahashi sc->scr_map[s[x]], ATTR(FG_LIGHTGREEN | BG_BLACK));
201e8adebf2SKazutaka YOKOTA }
202e8adebf2SKazutaka YOKOTA
2032ad872c5SKazutaka YOKOTA static int
daemon_saver(video_adapter_t * adp,int blank)2042ad872c5SKazutaka YOKOTA daemon_saver(video_adapter_t *adp, int blank)
205e8adebf2SKazutaka YOKOTA {
206e8adebf2SKazutaka YOKOTA static int txpos = 10, typos = 10;
207e8adebf2SKazutaka YOKOTA static int txdir = -1, tydir = -1;
208068eabc6SKazutaka YOKOTA static int dxpos = 0, dypos = 0;
209068eabc6SKazutaka YOKOTA static int dxdir = 1, dydir = 1;
210e8adebf2SKazutaka YOKOTA static int moved_daemon = 0;
21102f2e93bSKazutaka YOKOTA static int xoff, yoff, toff;
21202f2e93bSKazutaka YOKOTA static int xlen, ylen, tlen;
2136e8394b8SKazutaka YOKOTA sc_softc_t *sc;
2146e8394b8SKazutaka YOKOTA scr_stat *scp;
21502f2e93bSKazutaka YOKOTA int min, max;
216e8adebf2SKazutaka YOKOTA
2176e8394b8SKazutaka YOKOTA sc = sc_find_softc(adp, NULL);
2186e8394b8SKazutaka YOKOTA if (sc == NULL)
2196e8394b8SKazutaka YOKOTA return EAGAIN;
2206e8394b8SKazutaka YOKOTA scp = sc->cur_scp;
2216e8394b8SKazutaka YOKOTA
222e8adebf2SKazutaka YOKOTA if (blank) {
2232da199daSDag-Erling Smørgrav if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
224f9e730bbSKazutaka YOKOTA return EAGAIN;
2252ad872c5SKazutaka YOKOTA if (blanked == 0) {
22602f2e93bSKazutaka YOKOTA /* clear the screen and set the border color */
2276e8394b8SKazutaka YOKOTA sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
2288763b97dSYoshihiro Takahashi ATTR(FG_LIGHTGREY | BG_BLACK));
2299336e069SWojciech A. Koszek vidd_set_hw_cursor(adp, -1, -1);
2302b944ee2SKazutaka YOKOTA sc_set_border(scp, 0);
23102f2e93bSKazutaka YOKOTA xlen = ylen = tlen = 0;
23202f2e93bSKazutaka YOKOTA }
2332ad872c5SKazutaka YOKOTA if (blanked++ < 2)
2342ad872c5SKazutaka YOKOTA return 0;
2352ad872c5SKazutaka YOKOTA blanked = 1;
236e8adebf2SKazutaka YOKOTA
2376e8394b8SKazutaka YOKOTA clear_daemon(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen);
2382eb8169aSYoshihiro Takahashi clear_string(sc, txpos, typos, toff, message, tlen);
23902f2e93bSKazutaka YOKOTA
240e8adebf2SKazutaka YOKOTA if (++moved_daemon) {
24102f2e93bSKazutaka YOKOTA /*
24202f2e93bSKazutaka YOKOTA * The daemon picture may be off the screen, if
24302f2e93bSKazutaka YOKOTA * screen size is chagened while the screen
24402f2e93bSKazutaka YOKOTA * saver is inactive. Make sure the origin of
24502f2e93bSKazutaka YOKOTA * the picture is between min and max.
24602f2e93bSKazutaka YOKOTA */
24702f2e93bSKazutaka YOKOTA if (scp->xsize <= DAEMON_MAX_WIDTH) {
24802f2e93bSKazutaka YOKOTA /*
24902f2e93bSKazutaka YOKOTA * If the screen width is too narrow, we
25002f2e93bSKazutaka YOKOTA * allow part of the picture go off
25102f2e93bSKazutaka YOKOTA * the screen so that the daemon won't
25202f2e93bSKazutaka YOKOTA * flip too often.
25302f2e93bSKazutaka YOKOTA */
25402f2e93bSKazutaka YOKOTA min = scp->xsize - DAEMON_MAX_WIDTH - 10;
25502f2e93bSKazutaka YOKOTA max = 10;
25602f2e93bSKazutaka YOKOTA } else {
25702f2e93bSKazutaka YOKOTA min = 0;
25802f2e93bSKazutaka YOKOTA max = scp->xsize - DAEMON_MAX_WIDTH;
25902f2e93bSKazutaka YOKOTA }
26002f2e93bSKazutaka YOKOTA if (dxpos <= min) {
26102f2e93bSKazutaka YOKOTA dxpos = min;
26202f2e93bSKazutaka YOKOTA dxdir = 1;
26302f2e93bSKazutaka YOKOTA } else if (dxpos >= max) {
26402f2e93bSKazutaka YOKOTA dxpos = max;
265e8adebf2SKazutaka YOKOTA dxdir = -1;
266e8adebf2SKazutaka YOKOTA }
267e8adebf2SKazutaka YOKOTA
26802f2e93bSKazutaka YOKOTA if (scp->ysize <= DAEMON_MAX_HEIGHT) {
26902f2e93bSKazutaka YOKOTA min = scp->ysize - DAEMON_MAX_HEIGHT - 10;
27002f2e93bSKazutaka YOKOTA max = 10;
271e8adebf2SKazutaka YOKOTA } else {
27202f2e93bSKazutaka YOKOTA min = 0;
27302f2e93bSKazutaka YOKOTA max = scp->ysize - DAEMON_MAX_HEIGHT;
274e8adebf2SKazutaka YOKOTA }
27502f2e93bSKazutaka YOKOTA if (dypos <= min) {
27602f2e93bSKazutaka YOKOTA dypos = min;
27702f2e93bSKazutaka YOKOTA dydir = 1;
27802f2e93bSKazutaka YOKOTA } else if (dypos >= max) {
27902f2e93bSKazutaka YOKOTA dypos = max;
28002f2e93bSKazutaka YOKOTA dydir = -1;
28102f2e93bSKazutaka YOKOTA }
28202f2e93bSKazutaka YOKOTA
28302f2e93bSKazutaka YOKOTA moved_daemon = -1;
28402f2e93bSKazutaka YOKOTA dxpos += dxdir; dypos += dydir;
28502f2e93bSKazutaka YOKOTA
28602f2e93bSKazutaka YOKOTA /* clip the picture */
28702f2e93bSKazutaka YOKOTA xoff = 0;
28802f2e93bSKazutaka YOKOTA xlen = DAEMON_MAX_WIDTH;
28902f2e93bSKazutaka YOKOTA if (dxpos + xlen <= 0)
29002f2e93bSKazutaka YOKOTA xlen = 0;
29102f2e93bSKazutaka YOKOTA else if (dxpos < 0)
29202f2e93bSKazutaka YOKOTA xoff = -dxpos;
29302f2e93bSKazutaka YOKOTA if (dxpos >= scp->xsize)
29402f2e93bSKazutaka YOKOTA xlen = 0;
29502f2e93bSKazutaka YOKOTA else if (dxpos + xlen > scp->xsize)
29602f2e93bSKazutaka YOKOTA xlen = scp->xsize - dxpos;
29702f2e93bSKazutaka YOKOTA yoff = 0;
29802f2e93bSKazutaka YOKOTA ylen = DAEMON_MAX_HEIGHT;
29902f2e93bSKazutaka YOKOTA if (dypos + ylen <= 0)
30002f2e93bSKazutaka YOKOTA ylen = 0;
30102f2e93bSKazutaka YOKOTA else if (dypos < 0)
30202f2e93bSKazutaka YOKOTA yoff = -dypos;
30302f2e93bSKazutaka YOKOTA if (dypos >= scp->ysize)
30402f2e93bSKazutaka YOKOTA ylen = 0;
30502f2e93bSKazutaka YOKOTA else if (dypos + ylen > scp->ysize)
30602f2e93bSKazutaka YOKOTA ylen = scp->ysize - dypos;
30702f2e93bSKazutaka YOKOTA }
30802f2e93bSKazutaka YOKOTA
30902f2e93bSKazutaka YOKOTA if (scp->xsize <= messagelen) {
31002f2e93bSKazutaka YOKOTA min = scp->xsize - messagelen - 10;
31102f2e93bSKazutaka YOKOTA max = 10;
312e8adebf2SKazutaka YOKOTA } else {
31302f2e93bSKazutaka YOKOTA min = 0;
31402f2e93bSKazutaka YOKOTA max = scp->xsize - messagelen;
31502f2e93bSKazutaka YOKOTA }
31602f2e93bSKazutaka YOKOTA if (txpos <= min) {
31702f2e93bSKazutaka YOKOTA txpos = min;
31802f2e93bSKazutaka YOKOTA txdir = 1;
31902f2e93bSKazutaka YOKOTA } else if (txpos >= max) {
32002f2e93bSKazutaka YOKOTA txpos = max;
32102f2e93bSKazutaka YOKOTA txdir = -1;
32202f2e93bSKazutaka YOKOTA }
32302f2e93bSKazutaka YOKOTA if (typos <= 0) {
32402f2e93bSKazutaka YOKOTA typos = 0;
32502f2e93bSKazutaka YOKOTA tydir = 1;
32602f2e93bSKazutaka YOKOTA } else if (typos >= scp->ysize - 1) {
32702f2e93bSKazutaka YOKOTA typos = scp->ysize - 1;
32802f2e93bSKazutaka YOKOTA tydir = -1;
329e8adebf2SKazutaka YOKOTA }
330e8adebf2SKazutaka YOKOTA txpos += txdir; typos += tydir;
331e8adebf2SKazutaka YOKOTA
33202f2e93bSKazutaka YOKOTA toff = 0;
33302f2e93bSKazutaka YOKOTA tlen = messagelen;
33402f2e93bSKazutaka YOKOTA if (txpos + tlen <= 0)
33502f2e93bSKazutaka YOKOTA tlen = 0;
33602f2e93bSKazutaka YOKOTA else if (txpos < 0)
33702f2e93bSKazutaka YOKOTA toff = -txpos;
33802f2e93bSKazutaka YOKOTA if (txpos >= scp->xsize)
33902f2e93bSKazutaka YOKOTA tlen = 0;
34002f2e93bSKazutaka YOKOTA else if (txpos + tlen > scp->xsize)
34102f2e93bSKazutaka YOKOTA tlen = scp->xsize - txpos;
34202f2e93bSKazutaka YOKOTA
3436e8394b8SKazutaka YOKOTA draw_daemon(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen);
3442eb8169aSYoshihiro Takahashi draw_string(sc, txpos, typos, toff, message, tlen);
3458763b97dSYoshihiro Takahashi } else
3462ad872c5SKazutaka YOKOTA blanked = 0;
3478763b97dSYoshihiro Takahashi
3482ad872c5SKazutaka YOKOTA return 0;
349e8adebf2SKazutaka YOKOTA }
350e8adebf2SKazutaka YOKOTA
351e8adebf2SKazutaka YOKOTA static int
daemon_init(video_adapter_t * adp)3522ad872c5SKazutaka YOKOTA daemon_init(video_adapter_t *adp)
353e8adebf2SKazutaka YOKOTA {
3549425bee7SJohn Baldwin size_t hostlen;
3554f7d1876SRobert Watson
35676ca6f88SJamie Gritton mtx_lock(&prison0.pr_mtx);
3579425bee7SJohn Baldwin for (;;) {
3589425bee7SJohn Baldwin hostlen = strlen(prison0.pr_hostname);
3599425bee7SJohn Baldwin mtx_unlock(&prison0.pr_mtx);
3609425bee7SJohn Baldwin
3619425bee7SJohn Baldwin messagelen = hostlen + 3 + strlen(ostype) + 1 +
362ce834215SKazutaka YOKOTA strlen(osrelease);
363a163d034SWarner Losh message = malloc(messagelen + 1, M_DEVBUF, M_WAITOK);
3649425bee7SJohn Baldwin mtx_lock(&prison0.pr_mtx);
3659425bee7SJohn Baldwin if (hostlen < strlen(prison0.pr_hostname)) {
3669425bee7SJohn Baldwin free(message, M_DEVBUF);
3679425bee7SJohn Baldwin continue;
3689425bee7SJohn Baldwin }
3699425bee7SJohn Baldwin break;
3709425bee7SJohn Baldwin }
371c1f19219SJamie Gritton sprintf(message, "%s - %s %s", prison0.pr_hostname, ostype, osrelease);
37276ca6f88SJamie Gritton mtx_unlock(&prison0.pr_mtx);
3732ad872c5SKazutaka YOKOTA blanked = 0;
3748763b97dSYoshihiro Takahashi attr_mask = ~0;
3758763b97dSYoshihiro Takahashi
3762ad872c5SKazutaka YOKOTA return 0;
377e8adebf2SKazutaka YOKOTA }
378e8adebf2SKazutaka YOKOTA
379e8adebf2SKazutaka YOKOTA static int
daemon_term(video_adapter_t * adp)3802ad872c5SKazutaka YOKOTA daemon_term(video_adapter_t *adp)
381e8adebf2SKazutaka YOKOTA {
382f4863d1aSKazutaka YOKOTA free(message, M_DEVBUF);
3832ad872c5SKazutaka YOKOTA return 0;
384e8adebf2SKazutaka YOKOTA }
385e8adebf2SKazutaka YOKOTA
3862ad872c5SKazutaka YOKOTA static scrn_saver_t daemon_module = {
3872ad872c5SKazutaka YOKOTA "daemon_saver", daemon_init, daemon_term, daemon_saver, NULL,
3882ad872c5SKazutaka YOKOTA };
3892ad872c5SKazutaka YOKOTA
3902ad872c5SKazutaka YOKOTA SAVER_MODULE(daemon_saver, daemon_module);
391