blob: 193636362d5ff6e6081826374581ad65272d8da0 [file] [log] [blame]
oliverschmidtd1c833f2005-05-12 21:12:43 +00001/*
2 * Copyright (c) 2002-2004, Adam Dunkels.
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 * 2. Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * 3. The name of the author may not be used to endorse or promote
15 * products derived from this software without specific prior
16 * written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * This file is part of the Contiki desktop environment
31 *
32 * $Id: plasma.c,v 1.1 2005/05/12 21:12:43 oliverschmidt Exp $
33 *
34 */
35
36#include <stdlib.h>
37
38#include "ctk.h"
39#include "ctk-draw.h"
40#include "ctk-mouse.h"
41#include "ek.h"
42#include "loader.h"
43
44static unsigned char sinetab1[256] = {
45 128, 131, 134, 137, 140, 143, 146, 149,
46 152, 156, 159, 162, 165, 168, 171, 174,
47 176, 179, 182, 185, 188, 191, 193, 196,
48 199, 201, 204, 206, 209, 211, 213, 216,
49 218, 220, 222, 224, 226, 228, 230, 232,
50 234, 236, 237, 239, 240, 242, 243, 245,
51 246, 247, 248, 249, 250, 251, 252, 252,
52 253, 254, 254, 255, 255, 255, 255, 255,
53 255, 255, 255, 255, 255, 255, 254, 254,
54 253, 252, 252, 251, 250, 249, 248, 247,
55 246, 245, 243, 242, 240, 239, 237, 236,
56 234, 232, 230, 228, 226, 224, 222, 220,
57 218, 216, 213, 211, 209, 206, 204, 201,
58 199, 196, 193, 191, 188, 185, 182, 179,
59 176, 174, 171, 168, 165, 162, 159, 156,
60 152, 149, 146, 143, 140, 137, 134, 131,
61 128, 124, 121, 118, 115, 112, 109, 106,
62 103, 99, 96, 93, 90, 87, 84, 81,
63 79, 76, 73, 70, 67, 64, 62, 59,
64 56, 54, 51, 49, 46, 44, 42, 39,
65 37, 35, 33, 31, 29, 27, 25, 23,
66 21, 19, 18, 16, 15, 13, 12, 10,
67 9, 8, 7, 6, 5, 4, 3, 3,
68 2, 1, 1, 0, 0, 0, 0, 0,
69 0, 0, 0, 0, 0, 0, 1, 1,
70 2, 3, 3, 4, 5, 6, 7, 8,
71 9, 10, 12, 13, 15, 16, 18, 19,
72 21, 23, 25, 27, 29, 31, 33, 35,
73 37, 39, 42, 44, 46, 49, 51, 54,
74 56, 59, 62, 64, 67, 70, 73, 76,
75 78, 81, 84, 87, 90, 93, 96, 99,
76 103, 106, 109, 112, 115, 118, 121, 124,
77};
78
79static unsigned char sinetab2[256];
80static unsigned char sinetab3[256];
81
82static unsigned char colortab[256];
83
84static unsigned char colors[16] =
85 {
86 0x00, 0x22, 0x55, 0x33,
87 0xBB, 0xAA, 0xDD, 0xFF,
88 0xDD, 0xAA, 0xBB, 0x99,
89 0x11, 0x88, 0x00, 0x00
90 };
91
92#define XSIZE 25
93#define YSIZE 24
94
95#define XADD01 0xfe
96#define YADD01 0x05
97
98#define XADD1 0x04
99#define YADD1 0x02
100#define XADD2 0xfc
101#define YADD2 0xf9
102
103#define XADD 0x03
104#define YADD 0xfe
105
106#define MOVADD 0xfb
107
108static unsigned char xplasma[XSIZE], yplasma[YSIZE];
109static unsigned char xcnt, ycnt;
110static unsigned char xcnt01, xcnt02, xcnt1, xcnt2;
111static unsigned char ycnt01, ycnt02, ycnt1, ycnt2;
112
113static unsigned char xadd02 = 0x01;
114static unsigned char yadd02 = 0xfb;
115
116static unsigned char movcnt;
117
118/*static DISPATCHER_SIGHANDLER(sighandler, s, data);
119static void idle(void);
120static struct dispatcher_proc p =
121 {DISPATCHER_PROC("Plasma screensaver", idle,
122 sighandler,
123 NULL)};
124 static ek_id_t id;*/
125EK_EVENTHANDLER(eventhandler, ev, data);
126EK_POLLHANDLER(pollhandler);
127EK_PROCESS(p, "Plasma screensaver", EK_PRIO_LOWEST,
128 eventhandler, pollhandler, NULL);
129static ek_id_t id = EK_ID_NONE;
130
131/*-----------------------------------------------------------------------------------*/
132static void
133quit(void)
134{
135 *(char *)0xC051 = 0;
136
137 ek_exit();
138 id = EK_ID_NONE;
139 LOADER_UNLOAD();
140}
141/*-----------------------------------------------------------------------------------*/
142static void
143scrninit(void)
144{
145 static int i;
146
147 /* Make sine tables */
148 for(i = 0; i < 256; ++i) {
149 sinetab2[(unsigned char)i] = sinetab1[(unsigned char)i] / 2;
150 sinetab3[(unsigned char)i] = sinetab1[(unsigned char)i] / 4;
151 }
152
153 /* Make color table */
154 for(i = 0; i < 256; ++i) {
155 colortab[(unsigned char)i] = colors[(unsigned char)i / 16];
156 }
157
158 *(char *)0xC056 = 0;
159 *(char *)0xC054 = 0;
160 *(char *)0xC052 = 0;
161 *(char *)0xC050 = 0;
162
163 for(ycnt = 0; ycnt < 24; ++ycnt) {
164 gotoy(ycnt);
165 for(xcnt = 0; xcnt < 40; ++xcnt) {
166 (*(unsigned char **)0x28)[xcnt] = 0x00;
167 }
168 }
169}
170/*-----------------------------------------------------------------------------------*/
171EK_POLLHANDLER(pollhandler)
172{
173 static unsigned char i, x, y, xofs;
174
175 if(ctk_mode_get() == CTK_MODE_SCREENSAVER) {
176
177 xcnt1 = xcnt01;
178 xcnt2 = xcnt02;
179
180 for(i = 0; i < XSIZE; ++i) {
181 xplasma[i] = sinetab1[xcnt1] + sinetab2[xcnt2];
182 xcnt1 += XADD1;
183 xcnt2 += XADD2;
184 }
185
186 ycnt1 = ycnt01;
187 ycnt2 = ycnt02;
188
189 for(i = 0; i < YSIZE; ++i) {
190 yplasma[i] = sinetab1[ycnt1] + sinetab3[ycnt2];
191 ycnt1 += YADD1;
192 ycnt2 += YADD2;
193 }
194
195 xcnt01 += XADD01;
196 xcnt02 += xadd02;
197 ycnt01 += YADD01;
198 ycnt02 += yadd02;
199
200
201 yadd02 = sinetab3[ycnt] / 4;
202 xadd02 = sinetab3[xcnt] / 4;
203
204 ycnt += YADD;
205 xcnt += XADD;
206
207 movcnt += MOVADD;
208 xofs = sinetab1[movcnt]/16;
209
210 for(y = 0; y < YSIZE; ++y) {
211 gotoy(y);
212 for(x = 0; x < XSIZE; ++x) {
213 (*(unsigned char **)0x28)[x + xofs] = colortab[(xplasma[x] + yplasma[y]) & 0xff];
214 }
215 }
216 }
217}
218/*-----------------------------------------------------------------------------------*/
219/*static
220 DISPATCHER_SIGHANDLER(sighandler, s, data)*/
221EK_EVENTHANDLER(eventhandler, ev, data)
222{
223 EK_EVENTHANDLER_ARGS(ev, data);
224
225 if(ev == EK_EVENT_INIT) {
226 ctk_mode_set(CTK_MODE_SCREENSAVER);
227 ctk_mouse_hide();
228
229 scrninit();
230
231 } else if(ev == ctk_signal_screensaver_stop ||
232 ev == EK_EVENT_REQUEST_EXIT) {
233 ctk_draw_init();
234 ctk_desktop_redraw(NULL);
235 /* ctk_mode_set(CTK_MODE_NORMAL);*/
236 quit();
237 }
238}
239/*-----------------------------------------------------------------------------------*/
240LOADER_INIT_FUNC(plasma_init, arg)
241{
242 arg_free(arg);
243
244 if(id == EK_ID_NONE) {
245 id = ek_start(&p);
246 }
247}
248/*-----------------------------------------------------------------------------------*/
249