2 * Copyright (c) 2000 Chiharu Shibata
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
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>
39 #include <sys/random.h>
41 #include <dev/fb/fbreg.h>
42 #include <dev/fb/splashreg.h>
43 #include <dev/syscons/syscons.h>
45 #define SAVER_NAME "dragon_saver"
51 #define VIDEO_MODE M_PC98_EGC640x400
52 #define VIDEO_MODE_NAME "M_PC98_EGC640x400"
56 #define VIDEO_MODE M_VGA_CG320
57 #define VIDEO_MODE_NAME "M_VGA_CG320"
65 static int cur_x, cur_y;
67 static u_char dragon_pal[3*256]; /* zero-filled by the compiler */
70 gpset(int x, int y, int val)
72 if (x < 0 || y < 0 || SCRW <= x || SCRH <= y) {
76 vid[(x + y * SCRW) >> 3] = (0x80 >> (x & 7)); /* write new dot */
78 vid[x + y * SCRW] = val;
84 gdraw(int dx, int dy, int val)
90 outb(0x7c, 0xcc); /* GRCG on & RMW mode(disable planeI,G) */
91 outb(0x7e, (val & 1) ? 0xff: 0); /* tile B */
92 outb(0x7e, (val & 2) ? 0xff: 0); /* tile R */
101 /* horizontal line */
102 for (; dx >= 0; --dx, ++i) {
103 set |= gpset(i, cur_y, val);
114 for (; dy >= 0; --dy, ++i) {
115 set |= gpset(cur_x, i, val);
119 outb(0x7c, 0); /* GRCG off */
125 dragon_update(video_adapter_t *adp)
128 static int order, mul, out;
129 static int org_x, org_y;
131 static unsigned char fold[1 << (ORDER - 3)];
132 #define GET_FOLD(x) (fold[(x) >> 3] & (1 << ((x) & 7)))
133 #define SET_FOLD(x) (fold[(x) >> 3] |= (1 << ((x) & 7)))
134 #define CLR_FOLD(x) (fold[(x) >> 3] &= ~(1 << ((x) & 7)))
140 /* set palette of each curves */
141 for (tmp = 0; tmp < 3*CURVE; ++tmp) {
142 dragon_pal[3+tmp] = (u_char)random();
144 vidd_load_palette(adp, dragon_pal);
146 mul = ((random() & 7) + 1) * (SCRW / 320);
147 org_x = random() % SCRW; org_y = random() % SCRH;
153 if (order >= ORDER) {
156 cur_x = org_x; cur_y = org_y;
169 (void)gdraw(dx, dy, curve); out = 0;
172 q = p = 0; i = q + 1;
176 SET_FOLD(p); q = p * 2;
182 if (GET_FOLD(q-i) != 0) {
184 tmp = dx; dx = dy; dy = -tmp; /* turn right */
188 tmp = dx; dx = -dy; dy = tmp; /* turn left */
190 if (gdraw(dx, dy, curve)) {
195 order = ORDER; /* force to terminate this curve */
202 dragon_saver(video_adapter_t *adp, int blank)
207 /* switch to graphics mode */
210 vidd_set_mode(adp, VIDEO_MODE);
211 vid = (u_char *)adp->va_window;
227 dragon_init(video_adapter_t *adp)
231 /* check that the console is capable of running in 320x200x256 */
232 if (vidd_get_info(adp, VIDEO_MODE, &info)) {
234 "%s: the console does not support " VIDEO_MODE_NAME "\n",
244 dragon_term(video_adapter_t *adp)
249 static scrn_saver_t dragon_module = {
257 SAVER_MODULE(dragon_saver, dragon_module);