xref: /dflybsd-src/sys/dev/misc/syscons/fire/fire_saver.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino /*-
286d7f5d3SJohn Marino  * Copyright (c) 1999 Brad Forschinger
386d7f5d3SJohn Marino  * All rights reserved.
486d7f5d3SJohn Marino  *
586d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
686d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
786d7f5d3SJohn Marino  * are met:
886d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
986d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer,
1086d7f5d3SJohn Marino  *    without modification, immediately at the beginning of the file.
1186d7f5d3SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
1286d7f5d3SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
1386d7f5d3SJohn Marino  *    documentation and/or other materials provided with the distribution.
1486d7f5d3SJohn Marino  *
1586d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1686d7f5d3SJohn Marino  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1786d7f5d3SJohn Marino  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1886d7f5d3SJohn Marino  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1986d7f5d3SJohn Marino  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2086d7f5d3SJohn Marino  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2186d7f5d3SJohn Marino  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2286d7f5d3SJohn Marino  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2386d7f5d3SJohn Marino  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2486d7f5d3SJohn Marino  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2586d7f5d3SJohn Marino  *
2686d7f5d3SJohn Marino  * $FreeBSD: src/sys/modules/syscons/fire/fire_saver.c,v 1.6.2.1 2000/05/10 14:01:23 obrien Exp $
2786d7f5d3SJohn Marino  * $DragonFly: src/sys/dev/misc/syscons/fire/fire_saver.c,v 1.4 2006/09/03 18:52:27 dillon Exp $
2886d7f5d3SJohn Marino  */
2986d7f5d3SJohn Marino 
3086d7f5d3SJohn Marino /*
3186d7f5d3SJohn Marino  * brad forschinger, 19990504 <retch@flag.blackened.net>
3286d7f5d3SJohn Marino  *
3386d7f5d3SJohn Marino  * written with much help from warp_saver.c
3486d7f5d3SJohn Marino  *
3586d7f5d3SJohn Marino  */
3686d7f5d3SJohn Marino 
3786d7f5d3SJohn Marino #include <sys/param.h>
3886d7f5d3SJohn Marino #include <sys/systm.h>
3986d7f5d3SJohn Marino #include <sys/kernel.h>
4086d7f5d3SJohn Marino #include <sys/module.h>
4186d7f5d3SJohn Marino #include <sys/syslog.h>
4286d7f5d3SJohn Marino #include <sys/consio.h>
4386d7f5d3SJohn Marino #include <sys/fbio.h>
4486d7f5d3SJohn Marino #include <sys/random.h>
4586d7f5d3SJohn Marino #include <sys/thread.h>
4686d7f5d3SJohn Marino 
4786d7f5d3SJohn Marino #include <dev/video/fb/fbreg.h>
4886d7f5d3SJohn Marino #include <dev/video/fb/splashreg.h>
4986d7f5d3SJohn Marino #include "../syscons.h"
5086d7f5d3SJohn Marino 
5186d7f5d3SJohn Marino #define X_SIZE 320
5286d7f5d3SJohn Marino #define Y_SIZE 200
5386d7f5d3SJohn Marino 
5486d7f5d3SJohn Marino static int      blanked;
5586d7f5d3SJohn Marino static u_char   fire_pal[768];
5686d7f5d3SJohn Marino static u_char   buf[X_SIZE * (Y_SIZE + 1)];
5786d7f5d3SJohn Marino static u_char  *vid;
5886d7f5d3SJohn Marino 
5986d7f5d3SJohn Marino static int
fire_saver(video_adapter_t * adp,int blank)6086d7f5d3SJohn Marino fire_saver(video_adapter_t *adp, int blank)
6186d7f5d3SJohn Marino {
6286d7f5d3SJohn Marino     int             x, y;
6386d7f5d3SJohn Marino 
6486d7f5d3SJohn Marino     if (blank) {
6586d7f5d3SJohn Marino 	if (blanked <= 0) {
6686d7f5d3SJohn Marino 	    int             red, green, blue;
6786d7f5d3SJohn Marino 	    int             palette_index;
6886d7f5d3SJohn Marino 
6986d7f5d3SJohn Marino 	    set_video_mode(adp, M_VGA_CG320);
7086d7f5d3SJohn Marino 
7186d7f5d3SJohn Marino 	    /* build and load palette */
7286d7f5d3SJohn Marino 	    red = green = blue = 0;
7386d7f5d3SJohn Marino 	    for (palette_index = 0; palette_index < 256; palette_index++) {
7486d7f5d3SJohn Marino 		red++;
7586d7f5d3SJohn Marino 		if (red > 128)
7686d7f5d3SJohn Marino 		    green += 2;
7786d7f5d3SJohn Marino 
7886d7f5d3SJohn Marino 		fire_pal[(palette_index * 3) + 0] = red;
7986d7f5d3SJohn Marino 		fire_pal[(palette_index * 3) + 1] = green;
8086d7f5d3SJohn Marino 		fire_pal[(palette_index * 3) + 2] = blue;
8186d7f5d3SJohn Marino 	    }
8286d7f5d3SJohn Marino 	    load_palette(adp, fire_pal);
8386d7f5d3SJohn Marino 
8486d7f5d3SJohn Marino 	    blanked++;
8586d7f5d3SJohn Marino 	    vid = (u_char *) adp->va_window;
8686d7f5d3SJohn Marino 	}
8786d7f5d3SJohn Marino 	/* make a new bottom line */
8886d7f5d3SJohn Marino 	for (x = 0, y = Y_SIZE; x < X_SIZE; x++)
8986d7f5d3SJohn Marino 	    buf[x + (y * X_SIZE)] = krandom() % 160 + 96;
9086d7f5d3SJohn Marino 
9186d7f5d3SJohn Marino 	/* fade the flames out */
9286d7f5d3SJohn Marino 	for (y = 0; y < Y_SIZE; y++) {
9386d7f5d3SJohn Marino 	    for (x = 0; x < X_SIZE; x++) {
9486d7f5d3SJohn Marino 		buf[x + (y * X_SIZE)] = (buf[(x + 0) + ((y + 0) * X_SIZE)] +
9586d7f5d3SJohn Marino 					 buf[(x - 1) + ((y + 1) * X_SIZE)] +
9686d7f5d3SJohn Marino 					 buf[(x + 0) + ((y + 1) * X_SIZE)] +
9786d7f5d3SJohn Marino 				     buf[(x + 1) + ((y + 1) * X_SIZE)]) / 4;
9886d7f5d3SJohn Marino 		if (buf[x + (y * X_SIZE)] > 0)
9986d7f5d3SJohn Marino 		    buf[x + (y * X_SIZE)]--;
10086d7f5d3SJohn Marino 	    }
10186d7f5d3SJohn Marino 	}
10286d7f5d3SJohn Marino 
10386d7f5d3SJohn Marino 	/* blit our buffer into video ram */
10486d7f5d3SJohn Marino 	memcpy(vid, buf, X_SIZE * Y_SIZE);
10586d7f5d3SJohn Marino     } else {
10686d7f5d3SJohn Marino 	blanked = 0;
10786d7f5d3SJohn Marino     }
10886d7f5d3SJohn Marino 
10986d7f5d3SJohn Marino     return 0;
11086d7f5d3SJohn Marino }
11186d7f5d3SJohn Marino 
11286d7f5d3SJohn Marino static int
fire_initialise(video_adapter_t * adp)11386d7f5d3SJohn Marino fire_initialise(video_adapter_t *adp)
11486d7f5d3SJohn Marino {
11586d7f5d3SJohn Marino     video_info_t    info;
11686d7f5d3SJohn Marino 
11786d7f5d3SJohn Marino     /* check that the console is capable of running in 320x200x256 */
11886d7f5d3SJohn Marino     if (get_mode_info(adp, M_VGA_CG320, &info)) {
11986d7f5d3SJohn Marino 	log(LOG_NOTICE, "fire_saver: the console does not support M_VGA_CG320\n");
12086d7f5d3SJohn Marino 	return (ENODEV);
12186d7f5d3SJohn Marino     }
12286d7f5d3SJohn Marino     blanked = 0;
12386d7f5d3SJohn Marino 
12486d7f5d3SJohn Marino     return 0;
12586d7f5d3SJohn Marino }
12686d7f5d3SJohn Marino 
12786d7f5d3SJohn Marino static int
fire_terminate(video_adapter_t * adp)12886d7f5d3SJohn Marino fire_terminate(video_adapter_t *adp)
12986d7f5d3SJohn Marino {
13086d7f5d3SJohn Marino     return 0;
13186d7f5d3SJohn Marino }
13286d7f5d3SJohn Marino 
13386d7f5d3SJohn Marino static scrn_saver_t fire_module = {
13486d7f5d3SJohn Marino     "fire_saver", fire_initialise, fire_terminate, fire_saver, NULL
13586d7f5d3SJohn Marino };
13686d7f5d3SJohn Marino 
13786d7f5d3SJohn Marino SAVER_MODULE(fire_saver, fire_module);
138