fade_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: fade_saver.c,v 1.14 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>
3527427Syokota
3627427Syokota#include <i386/isa/isa.h>
3727427Syokota
386628Ssos#include <saver.h>
396628Ssos
408871Srgrimesstatic void
416628Ssosfade_saver(int blank)
426628Ssos{
436628Ssos	static int count = 0;
4439428Ssos	u_char pal[256*3];
456628Ssos	int i;
466628Ssos
476628Ssos	if (blank) {
486628Ssos		scrn_blanked = 1;
4939428Ssos		cur_console->status |= SAVER_RUNNING;
5030095Syokota		switch (crtc_type) {
5130095Syokota		case KD_VGA:
5230095Syokota			if (count < 64) {
5339428Ssos				pal[0] = pal[1] = pal[2] = 0;
5439428Ssos				for (i = 3; i < 256*3; i++) {
5539428Ssos					if (palette[i] - count > 60)
5639428Ssos						pal[i] = palette[i] - count;
5730095Syokota					else
5839428Ssos						pal[i] = 60;
5930095Syokota				}
6039428Ssos				load_palette(cur_console, pal);
6130095Syokota				count++;
626628Ssos			}
6330095Syokota			break;
6430095Syokota		case KD_EGA:
6530095Syokota			/* not yet done XXX */
6630095Syokota			break;
6730095Syokota		case KD_CGA:
6830095Syokota			outb(crtc_addr + 4, 0x25);
6930095Syokota			break;
7030095Syokota		case KD_MONO:
7130095Syokota		case KD_HERCULES:
7230095Syokota			outb(crtc_addr + 4, 0x21);
7330095Syokota			break;
7430095Syokota		default:
7530095Syokota			break;
766628Ssos		}
776628Ssos	}
786628Ssos	else {
7930095Syokota		switch (crtc_type) {
8030095Syokota		case KD_VGA:
8139287Ssos			load_palette(cur_console, palette);
8230095Syokota			count = 0;
8330095Syokota			break;
8430095Syokota		case KD_EGA:
8530095Syokota			/* not yet done XXX */
8630095Syokota			break;
8730095Syokota		case KD_CGA:
8830095Syokota			outb(crtc_addr + 4, 0x2d);
8930095Syokota			break;
9030095Syokota		case KD_MONO:
9130095Syokota		case KD_HERCULES:
9230095Syokota			outb(crtc_addr + 4, 0x29);
9330095Syokota			break;
9430095Syokota		default:
9530095Syokota			break;
9630095Syokota		}
9739428Ssos		cur_console->status &= ~SAVER_RUNNING;
9830095Syokota		scrn_blanked = 0;
996628Ssos	}
1006628Ssos}
1016628Ssos
10212276Sbdestatic int
10340885Speterfade_saver_load(void)
1046628Ssos{
10530095Syokota	switch (crtc_type) {
10630095Syokota	case KD_MONO:
10730095Syokota	case KD_HERCULES:
10830095Syokota	case KD_CGA:
10930095Syokota		/*
11030095Syokota		 * `fade' saver is not fully implemented for MDA and CGA.
11130095Syokota		 * It simply blanks the display instead.
11230095Syokota		 */
11330095Syokota	case KD_VGA:
11430095Syokota		break;
11530095Syokota	case KD_EGA:
11630095Syokota		/* EGA is yet to be supported */
11730095Syokota	default:
11830095Syokota		return ENODEV;
11930095Syokota	}
12027427Syokota	return add_scrn_saver(fade_saver);
1216628Ssos}
1226628Ssos
12312276Sbdestatic int
12440885Speterfade_saver_unload(void)
1256628Ssos{
12627427Syokota	return remove_scrn_saver(fade_saver);
1276628Ssos}
1286628Ssos
12940885SpeterSAVER_MODULE(fade_saver);
130