xref: /dragonfly/sys/dev/misc/syscons/logo/logo_saver.c (revision 2d8a3be7)
1 /*-
2  * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer
10  *    in this position and unchanged.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission
16  *
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.
27  *
28  * $FreeBSD: src/sys/modules/syscons/logo/logo_saver.c,v 1.8 1999/08/28 00:47:51 peter Exp $
29  * $DragonFly: src/sys/dev/misc/syscons/logo/logo_saver.c,v 1.3 2003/08/15 08:32:30 dillon Exp $
30  */
31 
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/module.h>
36 #include <sys/syslog.h>
37 #include <sys/consio.h>
38 #include <sys/fbio.h>
39 
40 #include <dev/video/fb/fbreg.h>
41 #include <dev/video/fb/splashreg.h>
42 #include "../syscons.h"
43 
44 static u_char *vid;
45 static int banksize, scrmode, bpsl, scrw, scrh;
46 static int blanked;
47 
48 #include "logo.c"
49 
50 static void
51 logo_blit(video_adapter_t *adp, int x, int y)
52 {
53     int d, l, o, p;
54 
55     for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize)
56 	o += banksize;
57     set_origin(adp, o);
58 
59     for (d = 0; d < sizeof logo_img; d += logo_w) {
60 	if (p + logo_w < banksize) {
61 	    bcopy(logo_img + d, vid + p, logo_w);
62 	    p += bpsl;
63 	} else if (p < banksize) {
64 	    l = banksize - p;
65 	    bcopy(logo_img + d, vid + p, l);
66 	    set_origin(adp, (o += banksize));
67 	    bcopy(logo_img + d + l, vid, logo_w - l);
68 	    p += bpsl - banksize;
69 	} else {
70 	    p -= banksize;
71 	    set_origin(adp, (o += banksize));
72 	    bcopy(logo_img + d, vid + p, logo_w);
73 	    p += bpsl;
74 	}
75     }
76 }
77 
78 static void
79 logo_update(video_adapter_t *adp)
80 {
81     static int xpos = 0, ypos = 0;
82     static int xinc = 1, yinc = 1;
83 
84     /* Turn when you hit the edge */
85     if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0))
86 	xinc = -xinc;
87     if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0))
88 	yinc = -yinc;
89     xpos += xinc;
90     ypos += yinc;
91 
92     /* XXX Relies on margin around logo to erase trail */
93     logo_blit(adp, xpos, ypos);
94 }
95 
96 static int
97 logo_saver(video_adapter_t *adp, int blank)
98 {
99     int i, pl;
100 
101     if (blank) {
102 	/* switch to graphics mode */
103 	if (blanked <= 0) {
104 	    pl = splhigh();
105 	    set_video_mode(adp, scrmode);
106 	    load_palette(adp, logo_pal);
107 #if 0 /* XXX conflict */
108 	    set_border(adp, 0);
109 #endif
110 	    blanked++;
111 	    vid = (u_char *)adp->va_window;
112 	    banksize = adp->va_window_size;
113 	    bpsl = adp->va_line_width;
114 	    splx(pl);
115 	    for (i = 0; i < bpsl*scrh; i += banksize) {
116 		set_origin(adp, i);
117 		bzero(vid, banksize);
118 	    }
119 	}
120 	logo_update(adp);
121     } else {
122 	blanked = 0;
123     }
124     return 0;
125 }
126 
127 static int
128 logo_init(video_adapter_t *adp)
129 {
130     video_info_t info;
131 
132     if (!get_mode_info(adp, M_VESA_CG800x600, &info)) {
133 	scrmode = M_VESA_CG800x600;
134     } else if (!get_mode_info(adp, M_VGA_CG320, &info)) {
135 	scrmode = M_VGA_CG320;
136     } else {
137         log(LOG_NOTICE, "logo_saver: no suitable graphics mode\n");
138 	return ENODEV;
139     }
140 
141     scrw = info.vi_width;
142     scrh = info.vi_height;
143     blanked = 0;
144 
145     return 0;
146 }
147 
148 static int
149 logo_term(video_adapter_t *adp)
150 {
151     return 0;
152 }
153 
154 static scrn_saver_t logo_module = {
155     "logo_saver", logo_init, logo_term, logo_saver, NULL,
156 };
157 
158 SAVER_MODULE(logo_saver, logo_module);
159