]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/syscons/logo/logo_saver.c
zfs: merge openzfs/zfs@c4c162c1e (master) into main
[FreeBSD/FreeBSD.git] / sys / dev / syscons / logo / logo_saver.c
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1998 Dag-Erling Coïdan Smørgrav
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer
12  *    in this position and unchanged.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/syslog.h>
38 #include <sys/consio.h>
39 #include <sys/fbio.h>
40
41 #include <dev/fb/fbreg.h>
42 #include <dev/fb/splashreg.h>
43 #include <dev/syscons/syscons.h>
44
45 #define SAVER_NAME       "logo_saver"
46
47 #define SET_ORIGIN(adp, o) do {                         \
48         int oo = o;                                     \
49         if (oo != last_origin)                          \
50             vidd_set_win_org(adp, last_origin = oo);    \
51         } while (0)
52
53 extern unsigned int      logo_w;
54 extern unsigned int      logo_h;
55 extern unsigned char     logo_pal[];
56 extern unsigned char     logo_img[];
57 extern unsigned int      logo_img_size;
58
59 static u_char           *vid;
60 static int               banksize, scrmode, bpsl, scrw, scrh;
61 static int               blanked;
62
63 static void
64 logo_blit(video_adapter_t *adp, int x, int y)
65 {
66         int d, l, o, p;
67         int last_origin = -1;
68
69         for (o = 0, p = y * bpsl + x; p > banksize; p -= banksize)
70                 o += banksize;
71         SET_ORIGIN(adp, o);
72
73         for (d = 0; d < logo_img_size; d += logo_w) {
74                 if (p + logo_w < banksize) {
75                         bcopy(logo_img + d, vid + p, logo_w);
76                         p += bpsl;
77                 } else if (p < banksize) {
78                         l = banksize - p;
79                         bcopy(logo_img + d, vid + p, l);
80                         SET_ORIGIN(adp, (o += banksize));
81                         bcopy(logo_img + d + l, vid, logo_w - l);
82                         p += bpsl - banksize;
83                 } else {
84                         p -= banksize;
85                         SET_ORIGIN(adp, (o += banksize));
86                         bcopy(logo_img + d, vid + p, logo_w);
87                         p += bpsl;
88                 }
89         }
90 }
91
92 static void
93 logo_update(video_adapter_t *adp)
94 {
95         static int xpos = 0, ypos = 0;
96         static int xinc = 1, yinc = 1;
97
98         /* Turn when you hit the edge */
99         if ((xpos + logo_w + xinc > scrw) || (xpos + xinc < 0))
100                 xinc = -xinc;
101         if ((ypos + logo_h + yinc > scrh) || (ypos + yinc < 0))
102                 yinc = -yinc;
103         xpos += xinc;
104         ypos += yinc;
105
106         /* XXX Relies on margin around logo to erase trail */
107         logo_blit(adp, xpos, ypos);
108 }
109
110 static int
111 logo_saver(video_adapter_t *adp, int blank)
112 {
113         int pl;
114
115         if (blank) {
116                 /* switch to graphics mode */
117                 if (blanked <= 0) {
118                         pl = splhigh();
119                         vidd_set_mode(adp, scrmode);
120                         vidd_load_palette(adp, logo_pal);
121                         vidd_set_border(adp, 0);
122                         blanked++;
123                         vid = (u_char *)adp->va_window;
124                         banksize = adp->va_window_size;
125                         bpsl = adp->va_line_width;
126                         splx(pl);
127                         vidd_clear(adp);
128                 }
129                 logo_update(adp);
130         } else {
131                 blanked = 0;
132         }
133         return (0);
134 }
135
136 static int
137 logo_init(video_adapter_t *adp)
138 {
139         video_info_t info;
140
141         if (!vidd_get_info(adp, M_VESA_CG800x600, &info)) {
142                 scrmode = M_VESA_CG800x600;
143         } else if (!vidd_get_info(adp, M_VGA_CG320, &info)) {
144                 scrmode = M_VGA_CG320;
145         } else {
146                 log(LOG_NOTICE,
147                     "%s: the console does not support M_VGA_CG320\n",
148                     SAVER_NAME);
149                 return (ENODEV);
150         }
151
152         scrw = info.vi_width;
153         scrh = info.vi_height;
154
155         return (0);
156 }
157
158 static int
159 logo_term(video_adapter_t *adp)
160 {
161         return (0);
162 }
163
164 static scrn_saver_t logo_module = {
165         SAVER_NAME,
166         logo_init,
167         logo_term,
168         logo_saver,
169         NULL
170 };
171
172 #ifdef BEASTIE_LOGO
173 SAVER_MODULE(beastie_saver, logo_module);
174 #else
175 SAVER_MODULE(logo_saver, logo_module);
176 #endif