star_saver.c revision 40885
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 *
2840885Speter *	$Id: star_saver.c,v 1.16 1998/09/17 19:40:30 sos Exp $
296628Ssos */
306628Ssos
316628Ssos#include <sys/param.h>
326628Ssos#include <sys/systm.h>
3340885Speter#include <sys/kernel.h>
3440885Speter#include <sys/module.h>
356628Ssos
3616879Sbde#include <machine/md_var.h>
3732571Sbde#include <machine/pc/display.h>
3816879Sbde
3927427Syokota#include <saver.h>
4016879Sbde
416628Ssos#define NUM_STARS	50
426628Ssos
4339428Ssosstatic u_short *window;
4439428Ssos
456628Ssos/*
466628Ssos * Alternate saver that got its inspiration from a well known utility
476628Ssos * package for an inferior^H^H^H^H^H^Hfamous OS.
486628Ssos */
4912276Sbdestatic void
506628Ssosstar_saver(int blank)
516628Ssos{
526628Ssos	scr_stat	*scp = cur_console;
536628Ssos	int		cell, i;
546628Ssos	char 		pattern[] = {"...........++++***   "};
558871Srgrimes	char		colors[] = {FG_DARKGREY, FG_LIGHTGREY,
566628Ssos				    FG_WHITE, FG_LIGHTCYAN};
576628Ssos	static u_short 	stars[NUM_STARS][2];
588871Srgrimes
596628Ssos	if (blank) {
6039428Ssos		if (!ISTEXTSC(scp))
6139428Ssos			return;
6227427Syokota		if (scrn_blanked <= 0) {
6339428Ssos			scp->status |= SAVER_RUNNING;
6439428Ssos			window = (u_short *)(*biosvidsw.adapter)(scp->adp)->va_window;
656628Ssos			scrn_blanked = 1;
6639428Ssos			fillw((FG_LIGHTGREY|BG_BLACK)<<8|scr_map[0x20], window,
676628Ssos			      scp->xsize * scp->ysize);
6839287Ssos			set_border(scp, 0);
696628Ssos			for(i=0; i<NUM_STARS; i++) {
708871Srgrimes				stars[i][0] =
716628Ssos					random() % (scp->xsize*scp->ysize);
726628Ssos				stars[i][1] = 0;
736628Ssos			}
746628Ssos		}
756628Ssos		cell = random() % NUM_STARS;
7639428Ssos		*((u_short*)(window + stars[cell][0])) =
778871Srgrimes			scr_map[pattern[stars[cell][1]]] |
786628Ssos				colors[random()%sizeof(colors)] << 8;
796628Ssos		if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) {
806628Ssos			stars[cell][0] = random() % (scp->xsize*scp->ysize);
816628Ssos			stars[cell][1] = 0;
826628Ssos		}
836628Ssos	}
846628Ssos	else {
8527427Syokota		if (scrn_blanked > 0) {
8639287Ssos			set_border(scp, scp->border);
876628Ssos			scrn_blanked = 0;
8839428Ssos			scp->status &= ~SAVER_RUNNING;
896628Ssos		}
906628Ssos	}
916628Ssos}
926628Ssos
9312276Sbdestatic int
9440885Speterstar_saver_load(void)
956628Ssos{
9627427Syokota	return add_scrn_saver(star_saver);
976628Ssos}
986628Ssos
9912276Sbdestatic int
10040885Speterstar_saver_unload(void)
1016628Ssos{
10227427Syokota	return remove_scrn_saver(star_saver);
1036628Ssos}
1046628Ssos
10540885SpeterSAVER_MODULE(star_saver);
106