spl->critical section conversions.
[dragonfly.git] / sys / dev / misc / syscons / bsdlogo / logo_saver.c
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/bsdlogo/Attic/logo_saver.c,v 1.4 2005/06/11 00:26:46 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 #include <sys/thread2.h>
40
41 #include <dev/video/fb/fbreg.h>
42 #include <dev/video/fb/splashreg.h>
43 #include "../syscons.h"
44
45 static u_char *vid;
46 static int banksize, scrmode, bpsl, scrw, scrh;
47 static int blanked;
48
49 #include "logo.c"
50
51 static void
52 logo_blit(video_adapter_t *adp, int x, int y)
53 {
54     int d, l, o, p;
55     
56     for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize)
57         o += banksize;
58     set_origin(adp, o);
59
60     for (d = 0; d < sizeof logo_img; d += logo_w) {
61         if (p + logo_w < banksize) {
62             bcopy(logo_img + d, vid + p, logo_w);
63             p += bpsl;
64         } else if (p < banksize) {
65             l = banksize - p;
66             bcopy(logo_img + d, vid + p, l);
67             set_origin(adp, (o += banksize));
68             bcopy(logo_img + d + l, vid, logo_w - l);
69             p += bpsl - banksize;
70         } else {
71             p -= banksize;
72             set_origin(adp, (o += banksize));
73             bcopy(logo_img + d, vid + p, logo_w);
74             p += bpsl;
75         }
76     }
77 }
78
79 static void
80 logo_update(video_adapter_t *adp)
81 {
82     static int xpos = 0, ypos = 0;
83     static int xinc = 1, yinc = 1;
84
85     /* Turn when you hit the edge */
86     if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0))
87         xinc = -xinc;
88     if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0))
89         yinc = -yinc;
90     xpos += xinc;
91     ypos += yinc;
92         
93     /* XXX Relies on margin around logo to erase trail */
94     logo_blit(adp, xpos, ypos);
95 }
96
97 static int
98 logo_saver(video_adapter_t *adp, int blank)
99 {
100     int i;
101
102     if (blank) {
103         /* switch to graphics mode */
104         if (blanked <= 0) {
105             crit_enter();
106             set_video_mode(adp, scrmode);
107             load_palette(adp, logo_pal);
108 #if 0 /* XXX conflict */
109             set_border(adp, 0);
110 #endif
111             blanked++;
112             vid = (u_char *)adp->va_window;
113             banksize = adp->va_window_size;
114             bpsl = adp->va_line_width;
115             crit_exit();
116             for (i = 0; i < bpsl*scrh; i += banksize) {
117                 set_origin(adp, i);
118                 bzero(vid, banksize);
119             }
120         }
121         logo_update(adp);
122     } else {
123         blanked = 0;
124     }
125     return 0;
126 }
127
128 static int
129 logo_init(video_adapter_t *adp)
130 {
131     video_info_t info;
132     
133     if (!get_mode_info(adp, M_VESA_CG800x600, &info)) {
134         scrmode = M_VESA_CG800x600;
135     } else if (!get_mode_info(adp, M_VGA_CG320, &info)) {
136         scrmode = M_VGA_CG320;
137     } else {
138         log(LOG_NOTICE, "logo_saver: no suitable graphics mode\n");
139         return ENODEV;
140     }
141     
142     scrw = info.vi_width;
143     scrh = info.vi_height;
144     blanked = 0;
145     
146     return 0;
147 }
148
149 static int
150 logo_term(video_adapter_t *adp)
151 {
152     return 0;
153 }
154
155 static scrn_saver_t logo_module = {
156     "logo_saver", logo_init, logo_term, logo_saver, NULL,
157 };
158
159 SAVER_MODULE(logo_saver, logo_module);