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