star_saver.c revision 39428
16628Ssos/*-
239287Ssos * Copyright (c) 1995-1998 S�ren Schmidt
36628Ssos * All rights reserved.
46628Ssos *
56628Ssos * Redistribution and use in source and binary forms, with or without
66628Ssos * modification, are permitted provided that the following conditions
76628Ssos * are met:
86628Ssos * 1. Redistributions of source code must retain the above copyright
939287Ssos *    notice, this list of conditions and the following disclaimer,
1039287Ssos *    without modification, immediately at the beginning of the file.
116628Ssos * 2. Redistributions in binary form must reproduce the above copyright
126628Ssos *    notice, this list of conditions and the following disclaimer in the
136628Ssos *    documentation and/or other materials provided with the distribution.
146628Ssos * 3. The name of the author may not be used to endorse or promote products
1539287Ssos *    derived from this software without specific prior written permission.
166628Ssos *
176628Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
186628Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
196628Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
206628Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
216628Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
226628Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236628Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246628Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256628Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
266628Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276628Ssos *
2839428Ssos *	$Id: star_saver.c,v 1.15 1998/09/15 18:16:39 sos Exp $
296628Ssos */
306628Ssos
316628Ssos#include <sys/param.h>
326628Ssos#include <sys/systm.h>
336628Ssos#include <sys/exec.h>
346628Ssos#include <sys/sysent.h>
356628Ssos#include <sys/lkm.h>
366628Ssos
3716879Sbde#include <machine/md_var.h>
3832571Sbde#include <machine/pc/display.h>
3916879Sbde
4027427Syokota#include <saver.h>
4116879Sbde
4212276SbdeMOD_MISC(star_saver);
436628Ssos
446628Ssos#define NUM_STARS	50
456628Ssos
4639428Ssosstatic u_short *window;
4739428Ssos
486628Ssos/*
496628Ssos * Alternate saver that got its inspiration from a well known utility
506628Ssos * package for an inferior^H^H^H^H^H^Hfamous OS.
516628Ssos */
5212276Sbdestatic void
536628Ssosstar_saver(int blank)
546628Ssos{
556628Ssos	scr_stat	*scp = cur_console;
566628Ssos	int		cell, i;
576628Ssos	char 		pattern[] = {"...........++++***   "};
588871Srgrimes	char		colors[] = {FG_DARKGREY, FG_LIGHTGREY,
596628Ssos				    FG_WHITE, FG_LIGHTCYAN};
606628Ssos	static u_short 	stars[NUM_STARS][2];
618871Srgrimes
626628Ssos	if (blank) {
6339428Ssos		if (!ISTEXTSC(scp))
6439428Ssos			return;
6527427Syokota		if (scrn_blanked <= 0) {
6639428Ssos			scp->status |= SAVER_RUNNING;
6739428Ssos			window = (u_short *)(*biosvidsw.adapter)(scp->adp)->va_window;
686628Ssos			scrn_blanked = 1;
6939428Ssos			fillw((FG_LIGHTGREY|BG_BLACK)<<8|scr_map[0x20], window,
706628Ssos			      scp->xsize * scp->ysize);
7139287Ssos			set_border(scp, 0);
726628Ssos			for(i=0; i<NUM_STARS; i++) {
738871Srgrimes				stars[i][0] =
746628Ssos					random() % (scp->xsize*scp->ysize);
756628Ssos				stars[i][1] = 0;
766628Ssos			}
776628Ssos		}
786628Ssos		cell = random() % NUM_STARS;
7939428Ssos		*((u_short*)(window + stars[cell][0])) =
808871Srgrimes			scr_map[pattern[stars[cell][1]]] |
816628Ssos				colors[random()%sizeof(colors)] << 8;
826628Ssos		if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) {
836628Ssos			stars[cell][0] = random() % (scp->xsize*scp->ysize);
846628Ssos			stars[cell][1] = 0;
856628Ssos		}
866628Ssos	}
876628Ssos	else {
8827427Syokota		if (scrn_blanked > 0) {
8939287Ssos			set_border(scp, scp->border);
906628Ssos			scrn_blanked = 0;
9139428Ssos			scp->status &= ~SAVER_RUNNING;
926628Ssos		}
936628Ssos	}
946628Ssos}
956628Ssos
9612276Sbdestatic int
9711857Speterstar_saver_load(struct lkm_table *lkmtp, int cmd)
986628Ssos{
9927427Syokota	return add_scrn_saver(star_saver);
1006628Ssos}
1016628Ssos
10212276Sbdestatic int
10311857Speterstar_saver_unload(struct lkm_table *lkmtp, int cmd)
1046628Ssos{
10527427Syokota	return remove_scrn_saver(star_saver);
1066628Ssos}
1076628Ssos
10812276Sbdeint
10911857Speterstar_saver_mod(struct lkm_table *lkmtp, int cmd, int ver)
1106628Ssos{
11124674Sdufault	MOD_DISPATCH(star_saver, lkmtp, cmd, ver,
11224674Sdufault		star_saver_load, star_saver_unload, lkm_nullcmd);
1136628Ssos}
114