xref: /freebsd/sys/dev/syscons/logo/logo_saver.c (revision daf1cffce2e07931f27c6c6998652e90df6ba87e)
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 static u_char *vid;
44 static int banksize, scrmode, bpsl, scrw, scrh;
45 static int blanked;
46 
47 #include "logo.c"
48 
49 static void
50 logo_blit(video_adapter_t *adp, int x, int y)
51 {
52     int d, l, o, p;
53 
54     for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize)
55 	o += banksize;
56     set_origin(adp, o);
57 
58     for (d = 0; d < sizeof logo_img; d += logo_w) {
59 	if (p + logo_w < banksize) {
60 	    bcopy(logo_img + d, vid + p, logo_w);
61 	    p += bpsl;
62 	} else if (p < banksize) {
63 	    l = banksize - p;
64 	    bcopy(logo_img + d, vid + p, l);
65 	    set_origin(adp, (o += banksize));
66 	    bcopy(logo_img + d + l, vid, logo_w - l);
67 	    p += bpsl - banksize;
68 	} else {
69 	    p -= banksize;
70 	    set_origin(adp, (o += banksize));
71 	    bcopy(logo_img + d, vid + p, logo_w);
72 	    p += bpsl;
73 	}
74     }
75 }
76 
77 static void
78 logo_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 
95 static int
96 logo_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 
126 static int
127 logo_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 
147 static int
148 logo_term(video_adapter_t *adp)
149 {
150     return 0;
151 }
152 
153 static scrn_saver_t logo_module = {
154     "logo_saver", logo_init, logo_term, logo_saver, NULL,
155 };
156 
157 SAVER_MODULE(logo_saver, logo_module);
158