xref: /freebsd/sys/dev/syscons/warp/warp_saver.c (revision b52b9d56d4e96089873a75f9e29062eec19fabba)
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	 "warp_saver"
44 #define SPP		 15
45 #define STARS		 (SPP * (1 + 2 + 4 + 8))
46 
47 static u_char		*vid;
48 static int		 banksize, scrmode, bpsl, scrw, scrh;
49 static int		 blanked;
50 static int		 star[STARS];
51 static u_char		 warp_pal[768] = {
52 	0x00, 0x00, 0x00,
53 	0x66, 0x66, 0x66,
54 	0x99, 0x99, 0x99,
55 	0xcc, 0xcc, 0xcc,
56 	0xff, 0xff, 0xff
57 	/* the rest is zero-filled by the compiler */
58 };
59 
60 static void
61 warp_update(video_adapter_t *adp)
62 {
63 	int i, j, k, n, o, p;
64 
65 	for (i = 1, k = 0, n = SPP*8; i < 5; i++, n /= 2) {
66 		for (j = 0; j < n; j++, k++) {
67 			p = (star[k] / scrw) *  bpsl + (star[k] % scrw);
68 			o = 0;
69 			while (p > banksize) {
70 				p -= banksize;
71 				o += banksize;
72 			}
73 			set_origin(adp, o);
74 			vid[p] = 0;
75 			star[k] += i;
76 			if (star[k] > scrw*scrh)
77 				star[k] -= scrw*scrh;
78 			p = (star[k] / scrw) *  bpsl + (star[k] % scrw);
79 			o = 0;
80 			while (p > banksize) {
81 				p -= banksize;
82 				o += banksize;
83 			}
84 			set_origin(adp, o);
85 			vid[p] = i;
86 		}
87 	}
88 }
89 
90 static int
91 warp_saver(video_adapter_t *adp, int blank)
92 {
93 	int i, pl;
94 
95 	if (blank) {
96 		/* switch to graphics mode */
97 		if (blanked <= 0) {
98 			pl = splhigh();
99 			set_video_mode(adp, scrmode);
100 			load_palette(adp, warp_pal);
101 			set_border(adp, 0);
102 			blanked++;
103 			vid = (u_char *)adp->va_window;
104 			banksize = adp->va_window_size;
105 			bpsl = adp->va_line_width;
106 			splx(pl);
107 			for (i = 0; i < bpsl * scrh; i += banksize) {
108 				set_origin(adp, i);
109 				bzero(vid, banksize);
110 			}
111 		}
112 		/* update display */
113 		warp_update(adp);
114 	} else {
115 		blanked = 0;
116 	}
117 	return (0);
118 }
119 
120 static int
121 warp_init(video_adapter_t *adp)
122 {
123 	video_info_t info;
124 	int i;
125 
126 	if (!get_mode_info(adp, M_VGA_CG320, &info)) {
127 		scrmode = M_VGA_CG320;
128 	} else if (!get_mode_info(adp, M_PC98_PEGC640x480, &info)) {
129 		scrmode = M_PC98_PEGC640x480;
130 	} else if (!get_mode_info(adp, M_PC98_PEGC640x400, &info)) {
131 		scrmode = M_PC98_PEGC640x400;
132 	} else {
133 		log(LOG_NOTICE,
134 		    "%s: the console does not support M_VGA_CG320\n",
135 		    SAVER_NAME);
136 		return (ENODEV);
137 	}
138 
139 	scrw = info.vi_width;
140 	scrh = info.vi_height;
141 
142 	/* randomize the star field */
143 	for (i = 0; i < STARS; i++)
144 		star[i] = random() % (scrw * scrh);
145 
146 	return (0);
147 }
148 
149 static int
150 warp_term(video_adapter_t *adp)
151 {
152 	return (0);
153 }
154 
155 static scrn_saver_t warp_module = {
156 	SAVER_NAME,
157 	warp_init,
158 	warp_term,
159 	warp_saver,
160 	NULL
161 };
162 
163 SAVER_MODULE(warp_saver, warp_module);
164