4 * Copyright (c) 1997 Sandro Sigala, Brescia, Italy.
5 * Copyright (c) 1997 Chris Shenton
6 * Copyright (c) 1995 S ren Schmidt
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer
14 * in this position and unchanged.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * $FreeBSD: src/sys/modules/syscons/daemon/daemon_saver.c,v 1.18.2.2 2001/05/06 05:44:29 nyan Exp $
31 * $DragonFly: src/sys/dev/misc/syscons/fred/fred_saver.c,v 1.8 2007/08/09 02:27:51 swildner Exp $
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/module.h>
37 #include <sys/malloc.h>
38 #include <sys/kernel.h>
39 #include <sys/sysctl.h>
40 #include <sys/consio.h>
42 #include <sys/thread.h>
44 #include <machine/pc/display.h>
46 #include <dev/video/fb/fbreg.h>
47 #include <dev/video/fb/splashreg.h>
48 #include "../syscons.h"
50 #define FRED_MAX_WIDTH 31
51 #define FRED_MAX_HEIGHT 15
54 static int messagelen;
57 static const char *fred_pic[] = {
60 " `, `-, (/ \\) ,-' ,'",
61 " `-, `-,/ \\,-' ,-'",
63 " ,----------( )----------,",
65 " `-,__,-' \\ / `-,__,-'",
76 static const char *fred_attr[] = {
79 " WW WWW GR RG WWW WW ",
82 " WWWWWWWWWWWR RWWWWWWWWWWW",
84 " WWWWWWWW R R WWWWWWWW",
96 * Reverse a graphics character, or return unaltered if no mirror;
97 * should do alphanumerics too, but I'm too lazy. <cshenton@it.hq.nasa.gov>
101 xflip_symbol(u_char symbol)
103 static const u_char lchars[] = "`'(){}[]\\/<>";
104 static const u_char rchars[] = "'`)(}{][/\\><";
107 for (pos = 0; lchars[pos] != '\0'; pos++)
108 if (lchars[pos] == symbol)
115 clear_fred(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff,
123 for (y = yoff; y < ylen; y++) {
124 sc_vtb_erase(&sc->cur_scp->scr,
125 (ypos + y)*sc->cur_scp->xsize + xpos + xoff,
127 sc->scr_map[0x20], (FG_LIGHTGREY | BG_BLACK) << 8);
132 draw_fred(sc_softc_t *sc, int xpos, int ypos, int dxdir, int xoff, int yoff,
139 for (y = yoff; y < ylen; y++) {
143 px = FRED_MAX_WIDTH - xlen;
144 if (px >= strlen(fred_pic[y]))
146 for (x = xoff; (x < xlen) && (fred_pic[y][px] != '\0'); x++, px++) {
147 switch (fred_attr[y][px]) {
148 case 'R': attr = (FG_LIGHTRED|BG_BLACK)<<8; break;
149 case 'G': attr = (FG_LIGHTGREEN|BG_BLACK)<<8; break;
150 case 'W': attr = (FG_LIGHTGREY|BG_BLACK)<<8; break;
151 default: attr = (FG_WHITE|BG_BLACK)<<8; break;
153 if (dxdir < 0) { /* Moving left */
154 sc_vtb_putc(&sc->cur_scp->scr,
155 (ypos + y)*sc->cur_scp->xsize
157 sc->scr_map[(int)fred_pic[y][px]],
159 } else { /* Moving right */
160 sc_vtb_putc(&sc->cur_scp->scr,
161 (ypos + y)*sc->cur_scp->xsize
162 + xpos + FRED_MAX_WIDTH
164 sc->scr_map[xflip_symbol(fred_pic[y][px])],
172 clear_string(sc_softc_t *sc, int xpos, int ypos, int xoff, char *s, int len)
176 sc_vtb_erase(&sc->cur_scp->scr,
177 ypos*sc->cur_scp->xsize + xpos + xoff, len - xoff,
178 sc->scr_map[0x20], (FG_LIGHTGREY | BG_BLACK) << 8);
182 draw_string(sc_softc_t *sc, int xpos, int ypos, int xoff, char *s, int len)
186 for (x = xoff; x < len; x++) {
187 sc_vtb_putc(&sc->cur_scp->scr,
188 ypos*sc->cur_scp->xsize + xpos + x,
189 sc->scr_map[(int)s[x]], (FG_LIGHTBLUE | BG_BLACK) << 8);
194 fred_saver(video_adapter_t *adp, int blank)
196 static int txpos = 10, typos = 10;
197 static int txdir = -1, tydir = -1;
198 static int dxpos = 0, dypos = 0;
199 static int dxdir = 1, dydir = 1;
200 static int moved_fred = 0;
201 static int xoff, yoff, toff;
202 static int xlen, ylen, tlen;
207 sc = sc_find_softc(adp, NULL);
214 if (adp->va_info.vi_flags & V_INFO_GRAPHICS) {
218 /* clear the screen and set the border color */
219 sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
220 (FG_LIGHTGREY | BG_BLACK) << 8);
221 (*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
222 sc_set_border(scp, 0);
223 xlen = ylen = tlen = 0;
230 clear_fred(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen);
231 clear_string(sc, txpos, typos, toff, message, tlen);
235 * Fred's picture may be off the screen, if
236 * screen size is chagened while the screen
237 * saver is inactive. Make sure the origin of
238 * the picture is between min and max.
240 if (scp->xsize <= FRED_MAX_WIDTH) {
242 * If the screen width is too narrow, we
243 * allow part of the picture go off
244 * the screen so that Fred won't
247 min = scp->xsize - FRED_MAX_WIDTH - 10;
251 max = scp->xsize - FRED_MAX_WIDTH;
256 } else if (dxpos >= max) {
261 if (scp->ysize <= FRED_MAX_HEIGHT) {
262 min = scp->ysize - FRED_MAX_HEIGHT - 10;
266 max = scp->ysize - FRED_MAX_HEIGHT;
271 } else if (dypos >= max) {
277 dxpos += dxdir; dypos += dydir;
279 /* clip the picture */
281 xlen = FRED_MAX_WIDTH;
282 if (dxpos + xlen <= 0)
286 if (dxpos >= scp->xsize)
288 else if (dxpos + xlen > scp->xsize)
289 xlen = scp->xsize - dxpos;
291 ylen = FRED_MAX_HEIGHT;
292 if (dypos + ylen <= 0)
296 if (dypos >= scp->ysize)
298 else if (dypos + ylen > scp->ysize)
299 ylen = scp->ysize - dypos;
302 if (scp->xsize <= messagelen) {
303 min = scp->xsize - messagelen - 10;
307 max = scp->xsize - messagelen;
312 } else if (txpos >= max) {
319 } else if (typos >= scp->ysize - 1) {
320 typos = scp->ysize - 1;
323 txpos += txdir; typos += tydir;
327 if (txpos + tlen <= 0)
331 if (txpos >= scp->xsize)
333 else if (txpos + tlen > scp->xsize)
334 tlen = scp->xsize - txpos;
336 draw_fred(sc, dxpos, dypos, dxdir, xoff, yoff, xlen, ylen);
337 draw_string(sc, txpos, typos, toff, message, tlen);
345 fred_init(video_adapter_t *adp)
347 messagelen = strlen(hostname) + 3 + strlen(ostype) + 1 +
349 message = kmalloc(messagelen + 1, M_SYSCONS, M_WAITOK);
350 ksprintf(message, "%s - %s %s", hostname, ostype, osrelease);
356 fred_term(video_adapter_t *adp)
358 kfree(message, M_SYSCONS);
362 static scrn_saver_t fred_module = {
363 "fred_saver", fred_init, fred_term, fred_saver, NULL,
366 SAVER_MODULE(fred_saver, fred_module);