logo_saver.c revision 50477
1218885Sdim/*-
2218885Sdim * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav
3218885Sdim * All rights reserved.
4218885Sdim *
5218885Sdim * Redistribution and use in source and binary forms, with or without
6218885Sdim * modification, are permitted provided that the following conditions
7218885Sdim * are met:
8218885Sdim * 1. Redistributions of source code must retain the above copyright
9218885Sdim *    notice, this list of conditions and the following disclaimer
10218885Sdim *    in this position and unchanged.
11218885Sdim * 2. Redistributions in binary form must reproduce the above copyright
12218885Sdim *    notice, this list of conditions and the following disclaimer in the
13218885Sdim *    documentation and/or other materials provided with the distribution.
14218885Sdim * 3. The name of the author may not be used to endorse or promote products
15218885Sdim *    derived from this software without specific prior written permission
16218885Sdim *
17218885Sdim * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18218885Sdim * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19218885Sdim * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20218885Sdim * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21218885Sdim * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22234353Sdim * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23218885Sdim * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24234353Sdim * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25218885Sdim * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26239462Sdim * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27234353Sdim *
28234353Sdim * $FreeBSD: head/sys/dev/syscons/logo/logo_saver.c 50477 1999-08-28 01:08:13Z peter $
29234353Sdim */
30234353Sdim
31218885Sdim#include <sys/param.h>
32218885Sdim#include <sys/systm.h>
33218885Sdim#include <sys/kernel.h>
34218885Sdim#include <sys/module.h>
35218885Sdim#include <sys/syslog.h>
36218885Sdim#include <sys/consio.h>
37234353Sdim#include <sys/fbio.h>
38226633Sdim
39234353Sdim#include <dev/fb/fbreg.h>
40234353Sdim#include <dev/fb/splashreg.h>
41234353Sdim#include <dev/syscons/syscons.h>
42218885Sdim
43218885Sdimstatic u_char *vid;
44218885Sdimstatic int banksize, scrmode, bpsl, scrw, scrh;
45218885Sdimstatic int blanked;
46218885Sdim
47234353Sdim#include "logo.c"
48218885Sdim
49218885Sdimstatic void
50218885Sdimlogo_blit(video_adapter_t *adp, int x, int y)
51218885Sdim{
52218885Sdim    int d, l, o, p;
53234353Sdim
54218885Sdim    for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize)
55218885Sdim	o += banksize;
56224145Sdim    set_origin(adp, o);
57218885Sdim
58218885Sdim    for (d = 0; d < sizeof logo_img; d += logo_w) {
59218885Sdim	if (p + logo_w < banksize) {
60218885Sdim	    bcopy(logo_img + d, vid + p, logo_w);
61234353Sdim	    p += bpsl;
62234353Sdim	} else if (p < banksize) {
63218885Sdim	    l = banksize - p;
64234353Sdim	    bcopy(logo_img + d, vid + p, l);
65218885Sdim	    set_origin(adp, (o += banksize));
66218885Sdim	    bcopy(logo_img + d + l, vid, logo_w - l);
67218885Sdim	    p += bpsl - banksize;
68239462Sdim	} else {
69218885Sdim	    p -= banksize;
70239462Sdim	    set_origin(adp, (o += banksize));
71218885Sdim	    bcopy(logo_img + d, vid + p, logo_w);
72218885Sdim	    p += bpsl;
73218885Sdim	}
74218885Sdim    }
75218885Sdim}
76
77static void
78logo_update(video_adapter_t *adp)
79{
80    static int xpos = 0, ypos = 0;
81    static int xinc = 1, yinc = 1;
82
83    /* Turn when you hit the edge */
84    if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0))
85	xinc = -xinc;
86    if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0))
87	yinc = -yinc;
88    xpos += xinc;
89    ypos += yinc;
90
91    /* XXX Relies on margin around logo to erase trail */
92    logo_blit(adp, xpos, ypos);
93}
94
95static int
96logo_saver(video_adapter_t *adp, int blank)
97{
98    int i, pl;
99
100    if (blank) {
101	/* switch to graphics mode */
102	if (blanked <= 0) {
103	    pl = splhigh();
104	    set_video_mode(adp, scrmode);
105	    load_palette(adp, logo_pal);
106#if 0 /* XXX conflict */
107	    set_border(adp, 0);
108#endif
109	    blanked++;
110	    vid = (u_char *)adp->va_window;
111	    banksize = adp->va_window_size;
112	    bpsl = adp->va_line_width;
113	    splx(pl);
114	    for (i = 0; i < bpsl*scrh; i += banksize) {
115		set_origin(adp, i);
116		bzero(vid, banksize);
117	    }
118	}
119	logo_update(adp);
120    } else {
121	blanked = 0;
122    }
123    return 0;
124}
125
126static int
127logo_init(video_adapter_t *adp)
128{
129    video_info_t info;
130
131    if (!get_mode_info(adp, M_VESA_CG800x600, &info)) {
132	scrmode = M_VESA_CG800x600;
133    } else if (!get_mode_info(adp, M_VGA_CG320, &info)) {
134	scrmode = M_VGA_CG320;
135    } else {
136        log(LOG_NOTICE, "logo_saver: no suitable graphics mode\n");
137	return ENODEV;
138    }
139
140    scrw = info.vi_width;
141    scrh = info.vi_height;
142    blanked = 0;
143
144    return 0;
145}
146
147static int
148logo_term(video_adapter_t *adp)
149{
150    return 0;
151}
152
153static scrn_saver_t logo_module = {
154    "logo_saver", logo_init, logo_term, logo_saver, NULL,
155};
156
157SAVER_MODULE(logo_saver, logo_module);
158