xref: /freebsd/sys/dev/syscons/logo/logo_saver.c (revision 42c159fe388a3765f69860c84183700af37aca8a)
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 extern unsigned int	 logo_w;
46 extern unsigned int	 logo_h;
47 extern unsigned char	 logo_pal[];
48 extern unsigned char	 logo_img[];
49 extern unsigned int	 logo_img_size;
50 
51 static u_char		*vid;
52 static int		 banksize, scrmode, bpsl, scrw, scrh;
53 static int		 blanked;
54 
55 static void
56 logo_blit(video_adapter_t *adp, int x, int y)
57 {
58 	int d, l, o, p;
59 
60 	for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize)
61 		o += banksize;
62 	set_origin(adp, o);
63 
64 	for (d = 0; d < logo_img_size; d += logo_w) {
65 		if (p + logo_w < banksize) {
66 			bcopy(logo_img + d, vid + p, logo_w);
67 			p += bpsl;
68 		} else if (p < banksize) {
69 			l = banksize - p;
70 			bcopy(logo_img + d, vid + p, l);
71 			set_origin(adp, (o += banksize));
72 			bcopy(logo_img + d + l, vid, logo_w - l);
73 			p += bpsl - banksize;
74 		} else {
75 			p -= banksize;
76 			set_origin(adp, (o += banksize));
77 			bcopy(logo_img + d, vid + p, logo_w);
78 			p += bpsl;
79 		}
80 	}
81 }
82 
83 static void
84 logo_update(video_adapter_t *adp)
85 {
86 	static int xpos = 0, ypos = 0;
87 	static int xinc = 1, yinc = 1;
88 
89 	/* Turn when you hit the edge */
90 	if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0))
91 		xinc = -xinc;
92 	if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0))
93 		yinc = -yinc;
94 	xpos += xinc;
95 	ypos += yinc;
96 
97 	/* XXX Relies on margin around logo to erase trail */
98 	logo_blit(adp, xpos, ypos);
99 }
100 
101 static int
102 logo_saver(video_adapter_t *adp, int blank)
103 {
104 	int i, pl;
105 
106 	if (blank) {
107 		/* switch to graphics mode */
108 		if (blanked <= 0) {
109 			pl = splhigh();
110 			set_video_mode(adp, scrmode);
111 			load_palette(adp, logo_pal);
112 			set_border(adp, 0);
113 			blanked++;
114 			vid = (u_char *)adp->va_window;
115 			banksize = adp->va_window_size;
116 			bpsl = adp->va_line_width;
117 			splx(pl);
118 			for (i = 0; i < bpsl * scrh; i += banksize) {
119 				set_origin(adp, i);
120 				bzero(vid, banksize);
121 			}
122 		}
123 		logo_update(adp);
124 	} else {
125 		blanked = 0;
126 	}
127 	return (0);
128 }
129 
130 static int
131 logo_init(video_adapter_t *adp)
132 {
133 	video_info_t info;
134 
135 	if (!get_mode_info(adp, M_VESA_CG800x600, &info)) {
136 		scrmode = M_VESA_CG800x600;
137 	} else if (!get_mode_info(adp, M_VGA_CG320, &info)) {
138 		scrmode = M_VGA_CG320;
139 	} else if (!get_mode_info(adp, M_PC98_PEGC640x480, &info)) {
140 		scrmode = M_PC98_PEGC640x480;
141 	} else if (!get_mode_info(adp, M_PC98_PEGC640x400, &info)) {
142 		scrmode = M_PC98_PEGC640x400;
143 	} else {
144 		log(LOG_NOTICE,
145 		    "%s: the console does not support M_VGA_CG320\n",
146 		    SAVER_NAME);
147 		return (ENODEV);
148 	}
149 
150 	scrw = info.vi_width;
151 	scrh = info.vi_height;
152 
153 	return (0);
154 }
155 
156 static int
157 logo_term(video_adapter_t *adp)
158 {
159 	return (0);
160 }
161 
162 static scrn_saver_t logo_module = {
163 	SAVER_NAME,
164 	logo_init,
165 	logo_term,
166 	logo_saver,
167 	NULL
168 };
169 
170 SAVER_MODULE(logo_saver, logo_module);
171