xref: /freebsd/sys/dev/syscons/logo/logo_saver.c (revision 39ee7a7a6bdd1557b1c3532abf60d139798ac88b)
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$
29  */
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/syslog.h>
36 #include <sys/consio.h>
37 #include <sys/fbio.h>
38 
39 #include <dev/fb/fbreg.h>
40 #include <dev/fb/splashreg.h>
41 #include <dev/syscons/syscons.h>
42 
43 #define SAVER_NAME	 "logo_saver"
44 
45 #define SET_ORIGIN(adp, o) do {				\
46 	int oo = o;					\
47 	if (oo != last_origin)				\
48 	    vidd_set_win_org(adp, last_origin = oo);	\
49 	} while (0)
50 
51 extern unsigned int	 logo_w;
52 extern unsigned int	 logo_h;
53 extern unsigned char	 logo_pal[];
54 extern unsigned char	 logo_img[];
55 extern unsigned int	 logo_img_size;
56 
57 static u_char		*vid;
58 static int		 banksize, scrmode, bpsl, scrw, scrh;
59 static int		 blanked;
60 
61 static void
62 logo_blit(video_adapter_t *adp, int x, int y)
63 {
64 	int d, l, o, p;
65 	int last_origin = -1;
66 
67 	for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize)
68 		o += banksize;
69 	SET_ORIGIN(adp, o);
70 
71 	for (d = 0; d < logo_img_size; d += logo_w) {
72 		if (p + logo_w < banksize) {
73 			bcopy(logo_img + d, vid + p, logo_w);
74 			p += bpsl;
75 		} else if (p < banksize) {
76 			l = banksize - p;
77 			bcopy(logo_img + d, vid + p, l);
78 			SET_ORIGIN(adp, (o += banksize));
79 			bcopy(logo_img + d + l, vid, logo_w - l);
80 			p += bpsl - banksize;
81 		} else {
82 			p -= banksize;
83 			SET_ORIGIN(adp, (o += banksize));
84 			bcopy(logo_img + d, vid + p, logo_w);
85 			p += bpsl;
86 		}
87 	}
88 }
89 
90 static void
91 logo_update(video_adapter_t *adp)
92 {
93 	static int xpos = 0, ypos = 0;
94 	static int xinc = 1, yinc = 1;
95 
96 	/* Turn when you hit the edge */
97 	if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0))
98 		xinc = -xinc;
99 	if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0))
100 		yinc = -yinc;
101 	xpos += xinc;
102 	ypos += yinc;
103 
104 	/* XXX Relies on margin around logo to erase trail */
105 	logo_blit(adp, xpos, ypos);
106 }
107 
108 static int
109 logo_saver(video_adapter_t *adp, int blank)
110 {
111 	int pl;
112 
113 	if (blank) {
114 		/* switch to graphics mode */
115 		if (blanked <= 0) {
116 			pl = splhigh();
117 			vidd_set_mode(adp, scrmode);
118 			vidd_load_palette(adp, logo_pal);
119 			vidd_set_border(adp, 0);
120 			blanked++;
121 			vid = (u_char *)adp->va_window;
122 			banksize = adp->va_window_size;
123 			bpsl = adp->va_line_width;
124 			splx(pl);
125 			vidd_clear(adp);
126 		}
127 		logo_update(adp);
128 	} else {
129 		blanked = 0;
130 	}
131 	return (0);
132 }
133 
134 static int
135 logo_init(video_adapter_t *adp)
136 {
137 	video_info_t info;
138 
139 	if (!vidd_get_info(adp, M_VESA_CG800x600, &info)) {
140 		scrmode = M_VESA_CG800x600;
141 	} else if (!vidd_get_info(adp, M_VGA_CG320, &info)) {
142 		scrmode = M_VGA_CG320;
143 	} else if (!vidd_get_info(adp, M_PC98_PEGC640x480, &info)) {
144 		scrmode = M_PC98_PEGC640x480;
145 	} else if (!vidd_get_info(adp, M_PC98_PEGC640x400, &info)) {
146 		scrmode = M_PC98_PEGC640x400;
147 	} else {
148 		log(LOG_NOTICE,
149 		    "%s: the console does not support M_VGA_CG320\n",
150 		    SAVER_NAME);
151 		return (ENODEV);
152 	}
153 
154 	scrw = info.vi_width;
155 	scrh = info.vi_height;
156 
157 	return (0);
158 }
159 
160 static int
161 logo_term(video_adapter_t *adp)
162 {
163 	return (0);
164 }
165 
166 static scrn_saver_t logo_module = {
167 	SAVER_NAME,
168 	logo_init,
169 	logo_term,
170 	logo_saver,
171 	NULL
172 };
173 
174 #ifdef BEASTIE_LOGO
175 SAVER_MODULE(beastie_saver, logo_module);
176 #else
177 SAVER_MODULE(logo_saver, logo_module);
178 #endif
179