2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 2000 Chiharu Shibata
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
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>
41 #include <sys/random.h>
43 #include <dev/fb/fbreg.h>
44 #include <dev/fb/splashreg.h>
45 #include <dev/syscons/syscons.h>
47 #define SAVER_NAME "dragon_saver"
52 #define VIDEO_MODE M_VGA_CG320
53 #define VIDEO_MODE_NAME "M_VGA_CG320"
60 static int cur_x, cur_y;
62 static u_char dragon_pal[3*256]; /* zero-filled by the compiler */
65 gpset(int x, int y, int val)
67 if (x < 0 || y < 0 || SCRW <= x || SCRH <= y) {
70 vid[x + y * SCRW] = val;
75 gdraw(int dx, int dy, int val)
88 for (; dx >= 0; --dx, ++i) {
89 set |= gpset(i, cur_y, val);
100 for (; dy >= 0; --dy, ++i) {
101 set |= gpset(cur_x, i, val);
108 dragon_update(video_adapter_t *adp)
111 static int order, mul, out;
112 static int org_x, org_y;
114 static unsigned char fold[1 << (ORDER - 3)];
115 #define GET_FOLD(x) (fold[(x) >> 3] & (1 << ((x) & 7)))
116 #define SET_FOLD(x) (fold[(x) >> 3] |= (1 << ((x) & 7)))
117 #define CLR_FOLD(x) (fold[(x) >> 3] &= ~(1 << ((x) & 7)))
123 /* set palette of each curves */
124 for (tmp = 0; tmp < 3*CURVE; ++tmp) {
125 dragon_pal[3+tmp] = (u_char)random();
127 vidd_load_palette(adp, dragon_pal);
129 mul = ((random() & 7) + 1) * (SCRW / 320);
130 org_x = random() % SCRW; org_y = random() % SCRH;
136 if (order >= ORDER) {
139 cur_x = org_x; cur_y = org_y;
152 (void)gdraw(dx, dy, curve); out = 0;
155 q = p = 0; i = q + 1;
159 SET_FOLD(p); q = p * 2;
165 if (GET_FOLD(q-i) != 0) {
167 tmp = dx; dx = dy; dy = -tmp; /* turn right */
171 tmp = dx; dx = -dy; dy = tmp; /* turn left */
173 if (gdraw(dx, dy, curve)) {
178 order = ORDER; /* force to terminate this curve */
185 dragon_saver(video_adapter_t *adp, int blank)
190 /* switch to graphics mode */
193 vidd_set_mode(adp, VIDEO_MODE);
194 vid = (u_char *)adp->va_window;
210 dragon_init(video_adapter_t *adp)
214 /* check that the console is capable of running in 320x200x256 */
215 if (vidd_get_info(adp, VIDEO_MODE, &info)) {
217 "%s: the console does not support " VIDEO_MODE_NAME "\n",
227 dragon_term(video_adapter_t *adp)
232 static scrn_saver_t dragon_module = {
240 SAVER_MODULE(dragon_saver, dragon_module);