xref: /freebsd/sys/dev/syscons/logo/logo_saver.c (revision 2ad872c5794e4c26fdf6ed219ad3f09ca0d5304a)
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  *	$Id: logo_saver.c,v 1.2 1999/01/01 14:40:49 des Exp $
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 
37 #include <saver.h>
38 
39 static u_char *vid;
40 static int banksize, scrmode, scrw, scrh;
41 static int blanked;
42 
43 #include "logo.c"
44 
45 #define set_origin(adp, o) (*vidsw[(adp)->va_index]->set_win_org)(adp, o)
46 
47 static void
48 logo_blit(video_adapter_t *adp, int x, int y)
49 {
50     int d, l, o, p;
51 
52     for (o = 0, p = y * scrw + x; p > banksize; p -= banksize)
53 	o += banksize;
54     set_origin(adp, o);
55 
56     for (d = 0; d < sizeof logo_img; d += logo_w) {
57 	if (p + logo_w < banksize) {
58 	    bcopy(logo_img + d, vid + p, logo_w);
59 	    p += scrw;
60 	} else if (p < banksize) {
61 	    l = banksize - p;
62 	    bcopy(logo_img + d, vid + p, l);
63 	    set_origin(adp, (o += banksize));
64 	    bcopy(logo_img + d + l, vid, logo_w - l);
65 	    p += scrw - banksize;
66 	} else {
67 	    p -= banksize;
68 	    set_origin(adp, (o += banksize));
69 	    bcopy(logo_img + d, vid + p, logo_w);
70 	    p += scrw;
71 	}
72     }
73 }
74 
75 static void
76 logo_update(video_adapter_t *adp)
77 {
78     static int xpos = 0, ypos = 0;
79     static int xinc = 1, yinc = 1;
80 
81     /* Turn when you hit the edge */
82     if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0))
83 	xinc = -xinc;
84     if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0))
85 	yinc = -yinc;
86     xpos += xinc;
87     ypos += yinc;
88 
89     /* XXX Relies on margin around logo to erase trail */
90     logo_blit(adp, xpos, ypos);
91 }
92 
93 static int
94 logo_saver(video_adapter_t *adp, int blank)
95 {
96     int i, pl;
97 
98     if (blank) {
99 	/* switch to graphics mode */
100 	if (blanked <= 0) {
101 	    pl = splhigh();
102 	    set_video_mode(adp, scrmode, logo_pal, 0);
103 	    blanked++;
104 	    vid = (u_char *)adp->va_window;
105 	    splx(pl);
106 	    for (i = 0; i < scrw*scrh; i += banksize) {
107 		set_origin(adp, i);
108 		bzero(vid, banksize);
109 	    }
110 	}
111 	logo_update(adp);
112     } else {
113 	blanked = 0;
114     }
115     return 0;
116 }
117 
118 static int
119 logo_init(video_adapter_t *adp)
120 {
121     video_info_t info;
122 
123     if (!get_mode_info(adp, M_VESA_CG800x600, &info)) {
124 	scrmode = M_VESA_CG800x600;
125     } else if (!get_mode_info(adp, M_VGA_CG320, &info)) {
126 	scrmode = M_VGA_CG320;
127     } else {
128         log(LOG_NOTICE, "logo_saver: no suitable graphics mode\n");
129 	return ENODEV;
130     }
131 
132     banksize = info.vi_window_size;
133     scrw = info.vi_width;
134     scrh = info.vi_height;
135     blanked = 0;
136 
137     return 0;
138 }
139 
140 static int
141 logo_term(video_adapter_t *adp)
142 {
143     return 0;
144 }
145 
146 static scrn_saver_t logo_module = {
147     "logo_saver", logo_init, logo_term, logo_saver, NULL,
148 };
149 
150 SAVER_MODULE(logo_saver, logo_module);
151