star_saver.c revision 24674
16628Ssos/*-
26628Ssos * Copyright (c) 1995 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
98871Srgrimes *    notice, this list of conditions and the following disclaimer
106628Ssos *    in this position and unchanged.
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
156628Ssos *    derived from this software withough 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 *
2824674Sdufault *	$Id: star_saver.c,v 1.10 1997/02/22 12:49:22 peter Exp $
296628Ssos */
306628Ssos
316628Ssos#include <sys/param.h>
326628Ssos#include <sys/systm.h>
336628Ssos#include <sys/conf.h>
346628Ssos#include <sys/exec.h>
356628Ssos#include <sys/sysent.h>
366628Ssos#include <sys/lkm.h>
376628Ssos#include <sys/errno.h>
386628Ssos
3916879Sbde#include <machine/md_var.h>
4016879Sbde
4116879Sbde#include "saver.h"
4216879Sbde
4312276SbdeMOD_MISC(star_saver);
446628Ssos
4512276Sbdevoid (*current_saver)(int blank);
4612276Sbdevoid (*old_saver)(int blank);
476628Ssos
486628Ssos#define NUM_STARS	50
496628Ssos
506628Ssos/*
516628Ssos * Alternate saver that got its inspiration from a well known utility
526628Ssos * package for an inferior^H^H^H^H^H^Hfamous OS.
536628Ssos */
5412276Sbdestatic void
556628Ssosstar_saver(int blank)
566628Ssos{
576628Ssos	scr_stat	*scp = cur_console;
586628Ssos	int		cell, i;
596628Ssos	char 		pattern[] = {"...........++++***   "};
608871Srgrimes	char		colors[] = {FG_DARKGREY, FG_LIGHTGREY,
616628Ssos				    FG_WHITE, FG_LIGHTCYAN};
626628Ssos	static u_short 	stars[NUM_STARS][2];
638871Srgrimes
646628Ssos	if (blank) {
656628Ssos		if (!scrn_blanked) {
666628Ssos			scrn_blanked = 1;
678871Srgrimes			fillw((FG_LIGHTGREY|BG_BLACK)<<8|scr_map[0x20], Crtat,
686628Ssos			      scp->xsize * scp->ysize);
696628Ssos			set_border(0);
706628Ssos			for(i=0; i<NUM_STARS; i++) {
718871Srgrimes				stars[i][0] =
726628Ssos					random() % (scp->xsize*scp->ysize);
736628Ssos				stars[i][1] = 0;
746628Ssos			}
756628Ssos		}
766628Ssos		cell = random() % NUM_STARS;
778871Srgrimes		*((u_short*)(Crtat + stars[cell][0])) =
788871Srgrimes			scr_map[pattern[stars[cell][1]]] |
796628Ssos				colors[random()%sizeof(colors)] << 8;
806628Ssos		if ((stars[cell][1]+=(random()%4)) >= sizeof(pattern)-1) {
816628Ssos			stars[cell][0] = random() % (scp->xsize*scp->ysize);
826628Ssos			stars[cell][1] = 0;
836628Ssos		}
846628Ssos	}
856628Ssos	else {
866628Ssos		if (scrn_blanked) {
876628Ssos			set_border(scp->border);
886628Ssos			scrn_blanked = 0;
897500Ssos			scp->start = 0;
907500Ssos			scp->end = scp->xsize * scp->ysize;
916628Ssos		}
926628Ssos	}
936628Ssos}
946628Ssos
9512276Sbdestatic int
9611857Speterstar_saver_load(struct lkm_table *lkmtp, int cmd)
976628Ssos{
986628Ssos	(*current_saver)(0);
996628Ssos	old_saver = current_saver;
1006628Ssos	current_saver = star_saver;
1016628Ssos	return 0;
1026628Ssos}
1036628Ssos
10412276Sbdestatic int
10511857Speterstar_saver_unload(struct lkm_table *lkmtp, int cmd)
1066628Ssos{
1076628Ssos	(*current_saver)(0);
1086628Ssos	current_saver = old_saver;
1096628Ssos	return 0;
1106628Ssos}
1116628Ssos
11212276Sbdeint
11311857Speterstar_saver_mod(struct lkm_table *lkmtp, int cmd, int ver)
1146628Ssos{
11524674Sdufault	MOD_DISPATCH(star_saver, lkmtp, cmd, ver,
11624674Sdufault		star_saver_load, star_saver_unload, lkm_nullcmd);
1176628Ssos}
118