xref: /freebsd/sys/dev/syscons/star/star_saver.c (revision 6e8394b8baa7d5d9153ab90de6824bcd19b3b4e1)
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  *
286e8394b8SKazutaka YOKOTA  *	$Id: star_saver.c,v 1.20 1999/02/05 12:40:16 des 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>
356e8394b8SKazutaka YOKOTA #include <sys/consio.h>
366e8394b8SKazutaka YOKOTA #include <sys/fbio.h>
37f6b4ae3cSBruce Evans 
3833b77e2dSBruce Evans #include <machine/pc/display.h>
39f6b4ae3cSBruce Evans 
406e8394b8SKazutaka YOKOTA #include <dev/fb/fbreg.h>
416e8394b8SKazutaka YOKOTA #include <dev/fb/splashreg.h>
426e8394b8SKazutaka YOKOTA #include <dev/syscons/syscons.h>
4317ee9d00SSøren Schmidt 
4417ee9d00SSøren Schmidt #define NUM_STARS	50
4517ee9d00SSøren Schmidt 
462ad872c5SKazutaka YOKOTA static int blanked;
47d74e86d9SSøren Schmidt 
4817ee9d00SSøren Schmidt /*
4917ee9d00SSøren Schmidt  * Alternate saver that got its inspiration from a well known utility
5017ee9d00SSøren Schmidt  * package for an inferior^H^H^H^H^H^Hfamous OS.
5117ee9d00SSøren Schmidt  */
522ad872c5SKazutaka YOKOTA static int
532ad872c5SKazutaka YOKOTA star_saver(video_adapter_t *adp, int blank)
5417ee9d00SSøren Schmidt {
556e8394b8SKazutaka YOKOTA 	sc_softc_t	*sc;
566e8394b8SKazutaka YOKOTA 	scr_stat	*scp;
5717ee9d00SSøren Schmidt 	int		cell, i;
5817ee9d00SSøren Schmidt 	char 		pattern[] = {"...........++++***   "};
596e8394b8SKazutaka YOKOTA #ifndef PC98
6017ee9d00SSøren Schmidt 	char		colors[] = {FG_DARKGREY, FG_LIGHTGREY,
6117ee9d00SSøren Schmidt 				    FG_WHITE, FG_LIGHTCYAN};
626e8394b8SKazutaka YOKOTA #else
636e8394b8SKazutaka YOKOTA 	char		colors[] = {FG_BLUE, FG_LIGHTGREY,
646e8394b8SKazutaka YOKOTA 				    FG_LIGHTGREY, FG_CYAN};
656e8394b8SKazutaka YOKOTA #endif /* PC98 */
6617ee9d00SSøren Schmidt 	static u_short 	stars[NUM_STARS][2];
6717ee9d00SSøren Schmidt 
686e8394b8SKazutaka YOKOTA 	sc = sc_find_softc(adp, NULL);
696e8394b8SKazutaka YOKOTA 	if (sc == NULL)
706e8394b8SKazutaka YOKOTA 		return EAGAIN;
716e8394b8SKazutaka YOKOTA 	scp = sc->cur_scp;
726e8394b8SKazutaka YOKOTA 
7317ee9d00SSøren Schmidt 	if (blank) {
742da199daSDag-Erling Smørgrav 		if (adp->va_info.vi_flags & V_INFO_GRAPHICS)
75f9e730bbSKazutaka YOKOTA 			return EAGAIN;
762ad872c5SKazutaka YOKOTA 		if (!blanked) {
776e8394b8SKazutaka YOKOTA #ifdef PC98
786e8394b8SKazutaka YOKOTA 			if (epson_machine_id == 0x20) {
796e8394b8SKazutaka YOKOTA 				outb(0x43f, 0x42);
806e8394b8SKazutaka YOKOTA 				outb(0x0c17, inb(0xc17) & ~0x08);
816e8394b8SKazutaka YOKOTA 				outb(0x43f, 0x40);
826e8394b8SKazutaka YOKOTA 			}
836e8394b8SKazutaka YOKOTA #endif /* PC98 */
842ad872c5SKazutaka YOKOTA 			/* clear the screen and set the border color */
856e8394b8SKazutaka YOKOTA 			sc_vtb_clear(&scp->scr, sc->scr_map[0x20],
866e8394b8SKazutaka YOKOTA 				     (FG_LIGHTGREY | BG_BLACK) << 8);
876e8394b8SKazutaka YOKOTA 			(*vidsw[adp->va_index]->set_hw_cursor)(adp, -1, -1);
88a8445737SSøren Schmidt 			set_border(scp, 0);
892ad872c5SKazutaka YOKOTA 			blanked = TRUE;
9017ee9d00SSøren Schmidt 			for(i=0; i<NUM_STARS; i++) {
9117ee9d00SSøren Schmidt 				stars[i][0] =
9217ee9d00SSøren Schmidt 					random() % (scp->xsize*scp->ysize);
9317ee9d00SSøren Schmidt 				stars[i][1] = 0;
9417ee9d00SSøren Schmidt 			}
9517ee9d00SSøren Schmidt 		}
9617ee9d00SSøren Schmidt 		cell = random() % NUM_STARS;
976e8394b8SKazutaka YOKOTA 		sc_vtb_putc(&scp->scr, stars[cell][0],
986e8394b8SKazutaka YOKOTA 			    sc->scr_map[pattern[stars[cell][1]]],
996e8394b8SKazutaka YOKOTA 			    colors[random()%sizeof(colors)] << 8);
10017ee9d00SSøren Schmidt 		if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) {
10117ee9d00SSøren Schmidt 			stars[cell][0] = random() % (scp->xsize*scp->ysize);
10217ee9d00SSøren Schmidt 			stars[cell][1] = 0;
10317ee9d00SSøren Schmidt 		}
10417ee9d00SSøren Schmidt 	}
10517ee9d00SSøren Schmidt 	else {
1066e8394b8SKazutaka YOKOTA #ifdef PC98
1076e8394b8SKazutaka YOKOTA 		if (epson_machine_id == 0x20) {
1086e8394b8SKazutaka YOKOTA 			outb(0x43f, 0x42);
1096e8394b8SKazutaka YOKOTA 			outb(0x0c17, inb(0xc17) | 0x08);
1106e8394b8SKazutaka YOKOTA 			outb(0x43f, 0x40);
1116e8394b8SKazutaka YOKOTA 		}
1126e8394b8SKazutaka YOKOTA #endif /* PC98 */
1132ad872c5SKazutaka YOKOTA 		blanked = FALSE;
11417ee9d00SSøren Schmidt 	}
1152ad872c5SKazutaka YOKOTA 	return 0;
11617ee9d00SSøren Schmidt }
11717ee9d00SSøren Schmidt 
118b3e24f9cSBruce Evans static int
1192ad872c5SKazutaka YOKOTA star_init(video_adapter_t *adp)
12017ee9d00SSøren Schmidt {
1212ad872c5SKazutaka YOKOTA 	blanked = FALSE;
1222ad872c5SKazutaka YOKOTA 	return 0;
12317ee9d00SSøren Schmidt }
12417ee9d00SSøren Schmidt 
125b3e24f9cSBruce Evans static int
1262ad872c5SKazutaka YOKOTA star_term(video_adapter_t *adp)
12717ee9d00SSøren Schmidt {
1282ad872c5SKazutaka YOKOTA 	return 0;
12917ee9d00SSøren Schmidt }
13017ee9d00SSøren Schmidt 
1312ad872c5SKazutaka YOKOTA static scrn_saver_t star_module = {
1322ad872c5SKazutaka YOKOTA 	"star_saver", star_init, star_term, star_saver, NULL,
1332ad872c5SKazutaka YOKOTA };
1342ad872c5SKazutaka YOKOTA 
1352ad872c5SKazutaka YOKOTA SAVER_MODULE(star_saver, star_module);
136