warp_saver.c revision 42203
1/*-
2 * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav
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 *    in this position and unchanged.
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: warp_saver.c,v 1.2 1998/12/28 14:20:13 des Exp $
29 */
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/kernel.h>
34#include <sys/module.h>
35#include <sys/syslog.h>
36
37#include <machine/md_var.h>
38#include <machine/random.h>
39
40#include <saver.h>
41
42static u_char *vid;
43
44#define SCRW 320
45#define SCRH 200
46#define SPP 15
47#define STARS (SPP*(1+2+4+8))
48
49static int star[STARS];
50static u_char save_pal[768];
51static u_char warp_pal[768] = {
52    0x00, 0x00, 0x00,
53    0x66, 0x66, 0x66,
54    0x99, 0x99, 0x99,
55    0xcc, 0xcc, 0xcc,
56    0xff, 0xff, 0xff
57    /* the rest is zero-filled by the compiler */
58};
59
60static void
61warp_update(void)
62{
63    int i, j, k, n;
64
65    for (i = 1, k = 0, n = SPP*8; i < 5; i++, n /= 2)
66	for (j = 0; j < n; j++, k++) {
67	    vid[star[k]] = 0;
68	    star[k] += i;
69	    if (star[k] > SCRW*SCRH)
70		star[k] -= SCRW*SCRH;
71	    vid[star[k]] = i;
72	}
73}
74
75static void
76warp_saver(int blank)
77{
78    scr_stat *scp = cur_console;
79    static int saved_mode;
80    int pl;
81
82    if (blank) {
83	/* switch to graphics mode */
84	if (scrn_blanked <= 0) {
85	    pl = splhigh();
86	    saved_mode = scp->mode;
87	    scp->mode = M_VGA_CG320;
88	    scp->status |= SAVER_RUNNING|GRAPHICS_MODE;
89	    save_palette(scp, save_pal);
90	    set_mode(scp);
91	    load_palette(scp, warp_pal);
92	    scrn_blanked++;
93	    vid = (u_char *)Crtat;
94	    splx(pl);
95	    bzero(vid, SCRW*SCRH);
96	}
97
98	/* update display */
99	warp_update();
100
101    } else {
102	/* return to previous video mode */
103	if (scrn_blanked > 0) {
104	    if (saved_mode) {
105		pl = splhigh();
106		scrn_blanked = 0;
107		scp->mode = saved_mode;
108		scp->status &= ~(SAVER_RUNNING|GRAPHICS_MODE);
109		set_mode(scp);
110		load_palette(scp, save_pal);
111		saved_mode = 0;
112		splx(pl);
113	    }
114	}
115    }
116}
117
118static int
119warp_saver_load(void)
120{
121    video_info_t info;
122    int i;
123
124    /* check that the console is capable of running in 320x200x256 */
125    if ((*biosvidsw.get_info)(cur_console->adp, M_VGA_CG320, &info)) {
126        log(LOG_NOTICE, "warp_saver: the console does not support M_VGA_CG320\n");
127	return ENODEV;
128    }
129
130    /* randomize the star field */
131    for (i = 0; i < STARS; i++) {
132	star[i] = random() % (SCRW*SCRH);
133    }
134
135    return add_scrn_saver(warp_saver);
136}
137
138static int
139warp_saver_unload(void)
140{
141    return remove_scrn_saver(warp_saver);
142}
143
144SAVER_MODULE(warp_saver);
145