xref: /freebsd/sys/dev/syscons/fire/fire_saver.c (revision 5521ff5a4d1929056e7ffc982fac3341ca54df7c)
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$
27  */
28 
29 /*
30  * brad forschinger, 19990504 <retch@flag.blackened.net>
31  *
32  * written with much help from warp_saver.c
33  *
34  */
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/module.h>
40 #include <sys/syslog.h>
41 #include <sys/consio.h>
42 #include <sys/fbio.h>
43 
44 #include <dev/fb/fbreg.h>
45 #include <dev/fb/splashreg.h>
46 #include <dev/syscons/syscons.h>
47 
48 #define X_SIZE 320
49 #define Y_SIZE 200
50 
51 static int      blanked;
52 static u_char   fire_pal[768];
53 static u_char   buf[X_SIZE * (Y_SIZE + 1)];
54 static u_char  *vid;
55 
56 static int
57 fire_saver(video_adapter_t *adp, int blank)
58 {
59     int             x, y;
60 
61     if (blank) {
62 	if (blanked <= 0) {
63 	    int             red, green, blue;
64 	    int             palette_index;
65 
66 	    set_video_mode(adp, M_VGA_CG320);
67 
68 	    /* build and load palette */
69 	    red = green = blue = 0;
70 	    for (palette_index = 0; palette_index < 256; palette_index++) {
71 		red++;
72 		if (red > 128)
73 		    green += 2;
74 
75 		fire_pal[(palette_index * 3) + 0] = red;
76 		fire_pal[(palette_index * 3) + 1] = green;
77 		fire_pal[(palette_index * 3) + 2] = blue;
78 	    }
79 	    load_palette(adp, fire_pal);
80 
81 	    blanked++;
82 	    vid = (u_char *) adp->va_window;
83 	}
84 	/* make a new bottom line */
85 	for (x = 0, y = Y_SIZE; x < X_SIZE; x++)
86 	    buf[x + (y * X_SIZE)] = random() % 160 + 96;
87 
88 	/* fade the flames out */
89 	for (y = 0; y < Y_SIZE; y++) {
90 	    for (x = 0; x < X_SIZE; x++) {
91 		buf[x + (y * X_SIZE)] = (buf[(x + 0) + ((y + 0) * X_SIZE)] +
92 					 buf[(x - 1) + ((y + 1) * X_SIZE)] +
93 					 buf[(x + 0) + ((y + 1) * X_SIZE)] +
94 				     buf[(x + 1) + ((y + 1) * X_SIZE)]) / 4;
95 		if (buf[x + (y * X_SIZE)] > 0)
96 		    buf[x + (y * X_SIZE)]--;
97 	    }
98 	}
99 
100 	/* blit our buffer into video ram */
101 	memcpy(vid, buf, X_SIZE * Y_SIZE);
102     } else {
103 	blanked = 0;
104     }
105 
106     return 0;
107 }
108 
109 static int
110 fire_initialise(video_adapter_t *adp)
111 {
112     video_info_t    info;
113 
114     /* check that the console is capable of running in 320x200x256 */
115     if (get_mode_info(adp, M_VGA_CG320, &info)) {
116 	log(LOG_NOTICE, "fire_saver: the console does not support M_VGA_CG320\n");
117 	return (ENODEV);
118     }
119     blanked = 0;
120 
121     return 0;
122 }
123 
124 static int
125 fire_terminate(video_adapter_t *adp)
126 {
127     return 0;
128 }
129 
130 static scrn_saver_t fire_module = {
131     "fire_saver", fire_initialise, fire_terminate, fire_saver, NULL
132 };
133 
134 SAVER_MODULE(fire_saver, fire_module);
135