Deleted Added
full compact
fire_saver.c (46899) fire_saver.c (48104)
1/*-
2 * Copyright (c) 1999 Brad Forschinger
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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 1999 Brad Forschinger
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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *
26 * $Id: fire_saver.c,v 1.2.2.1 1999/05/10 15:20:30 des Exp $
26 * $Id: fire_saver.c,v 1.4 1999/05/10 15:25:50 des Exp $
27 */
28
29/*
30 * brad forschinger, 19990504 <retch@flag.blackened.net>
31 *
32 * written with much help from warp_saver.c
33 *
34 */
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/kernel.h>
39#include <sys/module.h>
40#include <sys/syslog.h>
27 */
28
29/*
30 * brad forschinger, 19990504 <retch@flag.blackened.net>
31 *
32 * written with much help from warp_saver.c
33 *
34 */
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/kernel.h>
39#include <sys/module.h>
40#include <sys/syslog.h>
41#include <sys/consio.h>
42#include <sys/fbio.h>
41
43
42#include <machine/md_var.h>
43#include <machine/random.h>
44
44#include <machine/random.h>
45
45#include <saver.h>
46#include <dev/fb/fbreg.h>
47#include <dev/fb/splashreg.h>
48#include <dev/syscons/syscons.h>
46
47#define X_SIZE 320
48#define Y_SIZE 200
49
50static int blanked;
51static u_char fire_pal[768];
52static u_char buf[X_SIZE * (Y_SIZE + 1)];
53static u_char *vid;
54
55static int
56fire_saver(video_adapter_t *adp, int blank)
57{
58 int x, y;
59
60 if (blank) {
61 if (blanked <= 0) {
62 int red, green, blue;
63 int palette_index;
64
65 set_video_mode(adp, M_VGA_CG320);
66
67 /* build and load palette */
68 red = green = blue = 0;
69 for (palette_index = 0; palette_index < 256; palette_index++) {
70 red++;
71 if (red > 128)
72 green += 2;
73
74 fire_pal[(palette_index * 3) + 0] = red;
75 fire_pal[(palette_index * 3) + 1] = green;
76 fire_pal[(palette_index * 3) + 2] = blue;
77 }
78 load_palette(adp, fire_pal);
79
80 blanked++;
81 vid = (u_char *) adp->va_window;
82 }
83 /* make a new bottom line */
84 for (x = 0, y = Y_SIZE; x < X_SIZE; x++)
85 buf[x + (y * X_SIZE)] = random() % 160 + 96;
86
87 /* fade the flames out */
88 for (y = 0; y < Y_SIZE; y++) {
89 for (x = 0; x < X_SIZE; x++) {
90 buf[x + (y * X_SIZE)] = (buf[(x + 0) + ((y + 0) * X_SIZE)] +
91 buf[(x - 1) + ((y + 1) * X_SIZE)] +
92 buf[(x + 0) + ((y + 1) * X_SIZE)] +
93 buf[(x + 1) + ((y + 1) * X_SIZE)]) / 4;
94 if (buf[x + (y * X_SIZE)] > 0)
95 buf[x + (y * X_SIZE)]--;
96 }
97 }
98
99 /* blit our buffer into video ram */
100 memcpy(vid, buf, X_SIZE * Y_SIZE);
101 } else {
102 blanked = 0;
103 }
104
105 return 0;
106}
107
108static int
109fire_initialise(video_adapter_t *adp)
110{
111 video_info_t info;
112
113 /* check that the console is capable of running in 320x200x256 */
114 if (get_mode_info(adp, M_VGA_CG320, &info)) {
115 log(LOG_NOTICE, "fire_saver: the console does not support M_VGA_CG320\n");
116 return (ENODEV);
117 }
118 blanked = 0;
119
120 return 0;
121}
122
123static int
124fire_terminate(video_adapter_t *adp)
125{
126 return 0;
127}
128
129static scrn_saver_t fire_module = {
130 "fire_saver", fire_initialise, fire_terminate, fire_saver, NULL
131};
132
133SAVER_MODULE(fire_saver, fire_module);
49
50#define X_SIZE 320
51#define Y_SIZE 200
52
53static int blanked;
54static u_char fire_pal[768];
55static u_char buf[X_SIZE * (Y_SIZE + 1)];
56static u_char *vid;
57
58static int
59fire_saver(video_adapter_t *adp, int blank)
60{
61 int x, y;
62
63 if (blank) {
64 if (blanked <= 0) {
65 int red, green, blue;
66 int palette_index;
67
68 set_video_mode(adp, M_VGA_CG320);
69
70 /* build and load palette */
71 red = green = blue = 0;
72 for (palette_index = 0; palette_index < 256; palette_index++) {
73 red++;
74 if (red > 128)
75 green += 2;
76
77 fire_pal[(palette_index * 3) + 0] = red;
78 fire_pal[(palette_index * 3) + 1] = green;
79 fire_pal[(palette_index * 3) + 2] = blue;
80 }
81 load_palette(adp, fire_pal);
82
83 blanked++;
84 vid = (u_char *) adp->va_window;
85 }
86 /* make a new bottom line */
87 for (x = 0, y = Y_SIZE; x < X_SIZE; x++)
88 buf[x + (y * X_SIZE)] = random() % 160 + 96;
89
90 /* fade the flames out */
91 for (y = 0; y < Y_SIZE; y++) {
92 for (x = 0; x < X_SIZE; x++) {
93 buf[x + (y * X_SIZE)] = (buf[(x + 0) + ((y + 0) * X_SIZE)] +
94 buf[(x - 1) + ((y + 1) * X_SIZE)] +
95 buf[(x + 0) + ((y + 1) * X_SIZE)] +
96 buf[(x + 1) + ((y + 1) * X_SIZE)]) / 4;
97 if (buf[x + (y * X_SIZE)] > 0)
98 buf[x + (y * X_SIZE)]--;
99 }
100 }
101
102 /* blit our buffer into video ram */
103 memcpy(vid, buf, X_SIZE * Y_SIZE);
104 } else {
105 blanked = 0;
106 }
107
108 return 0;
109}
110
111static int
112fire_initialise(video_adapter_t *adp)
113{
114 video_info_t info;
115
116 /* check that the console is capable of running in 320x200x256 */
117 if (get_mode_info(adp, M_VGA_CG320, &info)) {
118 log(LOG_NOTICE, "fire_saver: the console does not support M_VGA_CG320\n");
119 return (ENODEV);
120 }
121 blanked = 0;
122
123 return 0;
124}
125
126static int
127fire_terminate(video_adapter_t *adp)
128{
129 return 0;
130}
131
132static scrn_saver_t fire_module = {
133 "fire_saver", fire_initialise, fire_terminate, fire_saver, NULL
134};
135
136SAVER_MODULE(fire_saver, fire_module);