fade_saver.c revision 42504
1/*-
2 * Copyright (c) 1995-1998 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 *    without modification, immediately at the beginning of the file.
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 without 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: fade_saver.c,v 1.15 1998/11/04 03:49:38 peter Exp $
29 */
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/module.h>
35
36#include <i386/isa/isa.h>
37
38#include <saver.h>
39
40static u_char palette[256*3];
41static int blanked;
42
43static int
44fade_saver(video_adapter_t *adp, int blank)
45{
46	static int count = 0;
47	u_char pal[256*3];
48	int i;
49
50	if (blank) {
51		blanked = TRUE;
52		switch (adp->va_type) {
53		case KD_VGA:
54			if (count <= 0)
55				save_palette(adp, palette);
56			if (count < 64) {
57				pal[0] = pal[1] = pal[2] = 0;
58				for (i = 3; i < 256*3; i++) {
59					if (palette[i] - count > 60)
60						pal[i] = palette[i] - count;
61					else
62						pal[i] = 60;
63				}
64				load_palette(adp, pal);
65				count++;
66			}
67			break;
68		case KD_EGA:
69			/* not yet done XXX */
70			break;
71		case KD_CGA:
72			outb(adp->va_crtc_addr + 4, 0x25);
73			break;
74		case KD_MONO:
75		case KD_HERCULES:
76			outb(adp->va_crtc_addr + 4, 0x21);
77			break;
78		default:
79			break;
80		}
81	}
82	else {
83		switch (adp->va_type) {
84		case KD_VGA:
85			load_palette(adp, palette);
86			count = 0;
87			break;
88		case KD_EGA:
89			/* not yet done XXX */
90			break;
91		case KD_CGA:
92			outb(adp->va_crtc_addr + 4, 0x2d);
93			break;
94		case KD_MONO:
95		case KD_HERCULES:
96			outb(adp->va_crtc_addr + 4, 0x29);
97			break;
98		default:
99			break;
100		}
101		blanked = FALSE;
102	}
103	return 0;
104}
105
106static int
107fade_init(video_adapter_t *adp)
108{
109	switch (adp->va_type) {
110	case KD_MONO:
111	case KD_HERCULES:
112	case KD_CGA:
113		/*
114		 * `fade' saver is not fully implemented for MDA and CGA.
115		 * It simply blanks the display instead.
116		 */
117	case KD_VGA:
118		break;
119	case KD_EGA:
120		/* EGA is yet to be supported */
121	default:
122		return ENODEV;
123	}
124	blanked = FALSE;
125	return 0;
126}
127
128static int
129fade_term(video_adapter_t *adp)
130{
131	return 0;
132}
133
134static scrn_saver_t fade_module = {
135	"fade_saver", fade_init, fade_term, fade_saver, NULL,
136};
137
138SAVER_MODULE(fade_saver, fade_module);
139