xref: /freebsd/sys/dev/syscons/star/star_saver.c (revision e627b39baccd1ec9129690167cf5e6d860509655)
1 /*-
2  * Copyright (c) 1995 S�ren Schmidt
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  *    in this position and unchanged.
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  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software withough specific prior written permission
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  *	$Id: star_saver.c,v 1.7 1995/11/29 20:10:33 wollman Exp $
29  */
30 
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <sys/conf.h>
34 #include <sys/exec.h>
35 #include <sys/sysent.h>
36 #include <sys/lkm.h>
37 #include <sys/errno.h>
38 
39 #include <machine/md_var.h>
40 
41 #include "saver.h"
42 
43 MOD_MISC(star_saver);
44 
45 void (*current_saver)(int blank);
46 void (*old_saver)(int blank);
47 
48 #define NUM_STARS	50
49 
50 /*
51  * Alternate saver that got its inspiration from a well known utility
52  * package for an inferior^H^H^H^H^H^Hfamous OS.
53  */
54 static void
55 star_saver(int blank)
56 {
57 	scr_stat	*scp = cur_console;
58 	int		cell, i;
59 	char 		pattern[] = {"...........++++***   "};
60 	char		colors[] = {FG_DARKGREY, FG_LIGHTGREY,
61 				    FG_WHITE, FG_LIGHTCYAN};
62 	static u_short 	stars[NUM_STARS][2];
63 
64 	if (blank) {
65 		if (!scrn_blanked) {
66 			scrn_blanked = 1;
67 			fillw((FG_LIGHTGREY|BG_BLACK)<<8|scr_map[0x20], Crtat,
68 			      scp->xsize * scp->ysize);
69 			set_border(0);
70 			for(i=0; i<NUM_STARS; i++) {
71 				stars[i][0] =
72 					random() % (scp->xsize*scp->ysize);
73 				stars[i][1] = 0;
74 			}
75 		}
76 		cell = random() % NUM_STARS;
77 		*((u_short*)(Crtat + stars[cell][0])) =
78 			scr_map[pattern[stars[cell][1]]] |
79 				colors[random()%sizeof(colors)] << 8;
80 		if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) {
81 			stars[cell][0] = random() % (scp->xsize*scp->ysize);
82 			stars[cell][1] = 0;
83 		}
84 	}
85 	else {
86 		if (scrn_blanked) {
87 			set_border(scp->border);
88 			scrn_blanked = 0;
89 			scp->start = 0;
90 			scp->end = scp->xsize * scp->ysize;
91 		}
92 	}
93 }
94 
95 static int
96 star_saver_load(struct lkm_table *lkmtp, int cmd)
97 {
98 	(*current_saver)(0);
99 	old_saver = current_saver;
100 	current_saver = star_saver;
101 	return 0;
102 }
103 
104 static int
105 star_saver_unload(struct lkm_table *lkmtp, int cmd)
106 {
107 	(*current_saver)(0);
108 	current_saver = old_saver;
109 	return 0;
110 }
111 
112 int
113 star_saver_mod(struct lkm_table *lkmtp, int cmd, int ver)
114 {
115 	DISPATCH(lkmtp, cmd, ver, star_saver_load, star_saver_unload,
116 		 lkm_nullcmd);
117 }
118