xref: /freebsd/sys/dev/syscons/star/star_saver.c (revision 2ad872c5794e4c26fdf6ed219ad3f09ca0d5304a)
117ee9d00SSøren Schmidt /*-
2a8445737SSøren Schmidt  * Copyright (c) 1995-1998 S�ren Schmidt
317ee9d00SSøren Schmidt  * All rights reserved.
417ee9d00SSøren Schmidt  *
517ee9d00SSøren Schmidt  * Redistribution and use in source and binary forms, with or without
617ee9d00SSøren Schmidt  * modification, are permitted provided that the following conditions
717ee9d00SSøren Schmidt  * are met:
817ee9d00SSøren Schmidt  * 1. Redistributions of source code must retain the above copyright
9a8445737SSøren Schmidt  *    notice, this list of conditions and the following disclaimer,
10a8445737SSøren Schmidt  *    without modification, immediately at the beginning of the file.
1117ee9d00SSøren Schmidt  * 2. Redistributions in binary form must reproduce the above copyright
1217ee9d00SSøren Schmidt  *    notice, this list of conditions and the following disclaimer in the
1317ee9d00SSøren Schmidt  *    documentation and/or other materials provided with the distribution.
1417ee9d00SSøren Schmidt  * 3. The name of the author may not be used to endorse or promote products
15a8445737SSøren Schmidt  *    derived from this software without specific prior written permission.
1617ee9d00SSøren Schmidt  *
1717ee9d00SSøren Schmidt  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1817ee9d00SSøren Schmidt  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1917ee9d00SSøren Schmidt  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2017ee9d00SSøren Schmidt  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2117ee9d00SSøren Schmidt  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2217ee9d00SSøren Schmidt  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2317ee9d00SSøren Schmidt  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2417ee9d00SSøren Schmidt  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2517ee9d00SSøren Schmidt  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2617ee9d00SSøren Schmidt  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2717ee9d00SSøren Schmidt  *
282ad872c5SKazutaka YOKOTA  *	$Id: star_saver.c,v 1.17 1998/11/04 03:49:39 peter Exp $
2917ee9d00SSøren Schmidt  */
3017ee9d00SSøren Schmidt 
3117ee9d00SSøren Schmidt #include <sys/param.h>
3217ee9d00SSøren Schmidt #include <sys/systm.h>
330640d357SPeter Wemm #include <sys/kernel.h>
340640d357SPeter Wemm #include <sys/module.h>
35f6b4ae3cSBruce Evans 
36f6b4ae3cSBruce Evans #include <machine/md_var.h>
3733b77e2dSBruce Evans #include <machine/pc/display.h>
38f6b4ae3cSBruce Evans 
39ce834215SKazutaka YOKOTA #include <saver.h>
4017ee9d00SSøren Schmidt 
4117ee9d00SSøren Schmidt #define NUM_STARS	50
4217ee9d00SSøren Schmidt 
43d74e86d9SSøren Schmidt static u_short *window;
442ad872c5SKazutaka YOKOTA static int blanked;
45d74e86d9SSøren Schmidt 
4617ee9d00SSøren Schmidt /*
4717ee9d00SSøren Schmidt  * Alternate saver that got its inspiration from a well known utility
4817ee9d00SSøren Schmidt  * package for an inferior^H^H^H^H^H^Hfamous OS.
4917ee9d00SSøren Schmidt  */
502ad872c5SKazutaka YOKOTA static int
512ad872c5SKazutaka YOKOTA star_saver(video_adapter_t *adp, int blank)
5217ee9d00SSøren Schmidt {
5317ee9d00SSøren Schmidt 	scr_stat	*scp = cur_console;
5417ee9d00SSøren Schmidt 	int		cell, i;
5517ee9d00SSøren Schmidt 	char 		pattern[] = {"...........++++***   "};
5617ee9d00SSøren Schmidt 	char		colors[] = {FG_DARKGREY, FG_LIGHTGREY,
5717ee9d00SSøren Schmidt 				    FG_WHITE, FG_LIGHTCYAN};
5817ee9d00SSøren Schmidt 	static u_short 	stars[NUM_STARS][2];
5917ee9d00SSøren Schmidt 
6017ee9d00SSøren Schmidt 	if (blank) {
612ad872c5SKazutaka YOKOTA 		if (adp->va_mode_flags & V_INFO_GRAPHICS)
622ad872c5SKazutaka YOKOTA 			return ENODEV;
632ad872c5SKazutaka YOKOTA 		if (!blanked) {
642ad872c5SKazutaka YOKOTA 			window = (u_short *)adp->va_window;
652ad872c5SKazutaka YOKOTA 			/* clear the screen and set the border color */
662ad872c5SKazutaka YOKOTA 			fillw(((FG_LIGHTGREY|BG_BLACK) << 8) | scr_map[0x20],
672ad872c5SKazutaka YOKOTA 			      window, scp->xsize * scp->ysize);
68a8445737SSøren Schmidt 			set_border(scp, 0);
692ad872c5SKazutaka YOKOTA 			blanked = TRUE;
7017ee9d00SSøren Schmidt 			for(i=0; i<NUM_STARS; i++) {
7117ee9d00SSøren Schmidt 				stars[i][0] =
7217ee9d00SSøren Schmidt 					random() % (scp->xsize*scp->ysize);
7317ee9d00SSøren Schmidt 				stars[i][1] = 0;
7417ee9d00SSøren Schmidt 			}
7517ee9d00SSøren Schmidt 		}
7617ee9d00SSøren Schmidt 		cell = random() % NUM_STARS;
77d74e86d9SSøren Schmidt 		*((u_short*)(window + stars[cell][0])) =
7817ee9d00SSøren Schmidt 			scr_map[pattern[stars[cell][1]]] |
7917ee9d00SSøren Schmidt 				colors[random()%sizeof(colors)] << 8;
8017ee9d00SSøren Schmidt 		if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) {
8117ee9d00SSøren Schmidt 			stars[cell][0] = random() % (scp->xsize*scp->ysize);
8217ee9d00SSøren Schmidt 			stars[cell][1] = 0;
8317ee9d00SSøren Schmidt 		}
8417ee9d00SSøren Schmidt 	}
8517ee9d00SSøren Schmidt 	else {
862ad872c5SKazutaka YOKOTA 		blanked = FALSE;
8717ee9d00SSøren Schmidt 	}
882ad872c5SKazutaka YOKOTA 	return 0;
8917ee9d00SSøren Schmidt }
9017ee9d00SSøren Schmidt 
91b3e24f9cSBruce Evans static int
922ad872c5SKazutaka YOKOTA star_init(video_adapter_t *adp)
9317ee9d00SSøren Schmidt {
942ad872c5SKazutaka YOKOTA 	blanked = FALSE;
952ad872c5SKazutaka YOKOTA 	return 0;
9617ee9d00SSøren Schmidt }
9717ee9d00SSøren Schmidt 
98b3e24f9cSBruce Evans static int
992ad872c5SKazutaka YOKOTA star_term(video_adapter_t *adp)
10017ee9d00SSøren Schmidt {
1012ad872c5SKazutaka YOKOTA 	return 0;
10217ee9d00SSøren Schmidt }
10317ee9d00SSøren Schmidt 
1042ad872c5SKazutaka YOKOTA static scrn_saver_t star_module = {
1052ad872c5SKazutaka YOKOTA 	"star_saver", star_init, star_term, star_saver, NULL,
1062ad872c5SKazutaka YOKOTA };
1072ad872c5SKazutaka YOKOTA 
1082ad872c5SKazutaka YOKOTA SAVER_MODULE(star_saver, star_module);
109