1*86d7f5d3SJohn Marino /*-
2*86d7f5d3SJohn Marino * Copyright (c) 1999 Brad Forschinger
3*86d7f5d3SJohn Marino * All rights reserved.
4*86d7f5d3SJohn Marino *
5*86d7f5d3SJohn Marino * Redistribution and use in source and binary forms, with or without
6*86d7f5d3SJohn Marino * modification, are permitted provided that the following conditions
7*86d7f5d3SJohn Marino * are met:
8*86d7f5d3SJohn Marino * 1. Redistributions of source code must retain the above copyright
9*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer,
10*86d7f5d3SJohn Marino * without modification, immediately at the beginning of the file.
11*86d7f5d3SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright
12*86d7f5d3SJohn Marino * notice, this list of conditions and the following disclaimer in the
13*86d7f5d3SJohn Marino * documentation and/or other materials provided with the distribution.
14*86d7f5d3SJohn Marino *
15*86d7f5d3SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*86d7f5d3SJohn Marino * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*86d7f5d3SJohn Marino * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*86d7f5d3SJohn Marino * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19*86d7f5d3SJohn Marino * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*86d7f5d3SJohn Marino * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*86d7f5d3SJohn Marino * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*86d7f5d3SJohn Marino * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*86d7f5d3SJohn Marino * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*86d7f5d3SJohn Marino * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*86d7f5d3SJohn Marino *
26*86d7f5d3SJohn Marino * $FreeBSD: src/sys/modules/syscons/fire/fire_saver.c,v 1.6.2.1 2000/05/10 14:01:23 obrien Exp $
27*86d7f5d3SJohn Marino * $DragonFly: src/sys/dev/misc/syscons/fire/fire_saver.c,v 1.4 2006/09/03 18:52:27 dillon Exp $
28*86d7f5d3SJohn Marino */
29*86d7f5d3SJohn Marino
30*86d7f5d3SJohn Marino /*
31*86d7f5d3SJohn Marino * brad forschinger, 19990504 <retch@flag.blackened.net>
32*86d7f5d3SJohn Marino *
33*86d7f5d3SJohn Marino * written with much help from warp_saver.c
34*86d7f5d3SJohn Marino *
35*86d7f5d3SJohn Marino */
36*86d7f5d3SJohn Marino
37*86d7f5d3SJohn Marino #include <sys/param.h>
38*86d7f5d3SJohn Marino #include <sys/systm.h>
39*86d7f5d3SJohn Marino #include <sys/kernel.h>
40*86d7f5d3SJohn Marino #include <sys/module.h>
41*86d7f5d3SJohn Marino #include <sys/syslog.h>
42*86d7f5d3SJohn Marino #include <sys/consio.h>
43*86d7f5d3SJohn Marino #include <sys/fbio.h>
44*86d7f5d3SJohn Marino #include <sys/random.h>
45*86d7f5d3SJohn Marino #include <sys/thread.h>
46*86d7f5d3SJohn Marino
47*86d7f5d3SJohn Marino #include <dev/video/fb/fbreg.h>
48*86d7f5d3SJohn Marino #include <dev/video/fb/splashreg.h>
49*86d7f5d3SJohn Marino #include "../syscons.h"
50*86d7f5d3SJohn Marino
51*86d7f5d3SJohn Marino #define X_SIZE 320
52*86d7f5d3SJohn Marino #define Y_SIZE 200
53*86d7f5d3SJohn Marino
54*86d7f5d3SJohn Marino static int blanked;
55*86d7f5d3SJohn Marino static u_char fire_pal[768];
56*86d7f5d3SJohn Marino static u_char buf[X_SIZE * (Y_SIZE + 1)];
57*86d7f5d3SJohn Marino static u_char *vid;
58*86d7f5d3SJohn Marino
59*86d7f5d3SJohn Marino static int
fire_saver(video_adapter_t * adp,int blank)60*86d7f5d3SJohn Marino fire_saver(video_adapter_t *adp, int blank)
61*86d7f5d3SJohn Marino {
62*86d7f5d3SJohn Marino int x, y;
63*86d7f5d3SJohn Marino
64*86d7f5d3SJohn Marino if (blank) {
65*86d7f5d3SJohn Marino if (blanked <= 0) {
66*86d7f5d3SJohn Marino int red, green, blue;
67*86d7f5d3SJohn Marino int palette_index;
68*86d7f5d3SJohn Marino
69*86d7f5d3SJohn Marino set_video_mode(adp, M_VGA_CG320);
70*86d7f5d3SJohn Marino
71*86d7f5d3SJohn Marino /* build and load palette */
72*86d7f5d3SJohn Marino red = green = blue = 0;
73*86d7f5d3SJohn Marino for (palette_index = 0; palette_index < 256; palette_index++) {
74*86d7f5d3SJohn Marino red++;
75*86d7f5d3SJohn Marino if (red > 128)
76*86d7f5d3SJohn Marino green += 2;
77*86d7f5d3SJohn Marino
78*86d7f5d3SJohn Marino fire_pal[(palette_index * 3) + 0] = red;
79*86d7f5d3SJohn Marino fire_pal[(palette_index * 3) + 1] = green;
80*86d7f5d3SJohn Marino fire_pal[(palette_index * 3) + 2] = blue;
81*86d7f5d3SJohn Marino }
82*86d7f5d3SJohn Marino load_palette(adp, fire_pal);
83*86d7f5d3SJohn Marino
84*86d7f5d3SJohn Marino blanked++;
85*86d7f5d3SJohn Marino vid = (u_char *) adp->va_window;
86*86d7f5d3SJohn Marino }
87*86d7f5d3SJohn Marino /* make a new bottom line */
88*86d7f5d3SJohn Marino for (x = 0, y = Y_SIZE; x < X_SIZE; x++)
89*86d7f5d3SJohn Marino buf[x + (y * X_SIZE)] = krandom() % 160 + 96;
90*86d7f5d3SJohn Marino
91*86d7f5d3SJohn Marino /* fade the flames out */
92*86d7f5d3SJohn Marino for (y = 0; y < Y_SIZE; y++) {
93*86d7f5d3SJohn Marino for (x = 0; x < X_SIZE; x++) {
94*86d7f5d3SJohn Marino buf[x + (y * X_SIZE)] = (buf[(x + 0) + ((y + 0) * X_SIZE)] +
95*86d7f5d3SJohn Marino buf[(x - 1) + ((y + 1) * X_SIZE)] +
96*86d7f5d3SJohn Marino buf[(x + 0) + ((y + 1) * X_SIZE)] +
97*86d7f5d3SJohn Marino buf[(x + 1) + ((y + 1) * X_SIZE)]) / 4;
98*86d7f5d3SJohn Marino if (buf[x + (y * X_SIZE)] > 0)
99*86d7f5d3SJohn Marino buf[x + (y * X_SIZE)]--;
100*86d7f5d3SJohn Marino }
101*86d7f5d3SJohn Marino }
102*86d7f5d3SJohn Marino
103*86d7f5d3SJohn Marino /* blit our buffer into video ram */
104*86d7f5d3SJohn Marino memcpy(vid, buf, X_SIZE * Y_SIZE);
105*86d7f5d3SJohn Marino } else {
106*86d7f5d3SJohn Marino blanked = 0;
107*86d7f5d3SJohn Marino }
108*86d7f5d3SJohn Marino
109*86d7f5d3SJohn Marino return 0;
110*86d7f5d3SJohn Marino }
111*86d7f5d3SJohn Marino
112*86d7f5d3SJohn Marino static int
fire_initialise(video_adapter_t * adp)113*86d7f5d3SJohn Marino fire_initialise(video_adapter_t *adp)
114*86d7f5d3SJohn Marino {
115*86d7f5d3SJohn Marino video_info_t info;
116*86d7f5d3SJohn Marino
117*86d7f5d3SJohn Marino /* check that the console is capable of running in 320x200x256 */
118*86d7f5d3SJohn Marino if (get_mode_info(adp, M_VGA_CG320, &info)) {
119*86d7f5d3SJohn Marino log(LOG_NOTICE, "fire_saver: the console does not support M_VGA_CG320\n");
120*86d7f5d3SJohn Marino return (ENODEV);
121*86d7f5d3SJohn Marino }
122*86d7f5d3SJohn Marino blanked = 0;
123*86d7f5d3SJohn Marino
124*86d7f5d3SJohn Marino return 0;
125*86d7f5d3SJohn Marino }
126*86d7f5d3SJohn Marino
127*86d7f5d3SJohn Marino static int
fire_terminate(video_adapter_t * adp)128*86d7f5d3SJohn Marino fire_terminate(video_adapter_t *adp)
129*86d7f5d3SJohn Marino {
130*86d7f5d3SJohn Marino return 0;
131*86d7f5d3SJohn Marino }
132*86d7f5d3SJohn Marino
133*86d7f5d3SJohn Marino static scrn_saver_t fire_module = {
134*86d7f5d3SJohn Marino "fire_saver", fire_initialise, fire_terminate, fire_saver, NULL
135*86d7f5d3SJohn Marino };
136*86d7f5d3SJohn Marino
137*86d7f5d3SJohn Marino SAVER_MODULE(fire_saver, fire_module);
138