kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 1 | /* |
| 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 2006/04/17 15:18:19 kthacker 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 | |
| 44 | static 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 | |
| 79 | static unsigned char sinetab2[256]; |
| 80 | static unsigned char sinetab3[256]; |
| 81 | |
| 82 | static unsigned char colortab[256]; |
| 83 | |
| 84 | static unsigned char colors[16] = |
| 85 | { |
| 86 | 0x00, 0x06, 0x0b, 0x04, |
| 87 | 0x0a, 0x0f, 0x07, 0x01, |
| 88 | 0x07, 0x0f, 0x0a, 0x08, |
| 89 | 0x02, 0x09, 0x00, 0x00, |
| 90 | }; |
| 91 | |
| 92 | #define XSIZE 24 |
| 93 | #define YSIZE 25 |
| 94 | |
| 95 | static unsigned char xplasma[XSIZE], yplasma[YSIZE]; |
| 96 | static unsigned char xcnt, ycnt; |
| 97 | static unsigned char xcnt01, xcnt02, xcnt1, xcnt2; |
| 98 | static unsigned char ycnt01, ycnt02, ycnt1, ycnt2; |
| 99 | |
| 100 | static unsigned char xadd01 = 0xfe; |
| 101 | static unsigned char yadd01 = 0x05; |
| 102 | static unsigned char xadd02 = 0x01; |
| 103 | static unsigned char yadd02 = 0xfb; |
| 104 | |
| 105 | static unsigned char xadd1 = 0x04; |
| 106 | static unsigned char yadd1 = 0x02; |
| 107 | static unsigned char xadd2 = 0xfc; |
| 108 | static unsigned char yadd2 = 0xf9; |
| 109 | |
| 110 | static unsigned char xadd = 0x03; |
| 111 | static unsigned char yadd = 0xfe; |
| 112 | |
| 113 | static unsigned char movcnt; |
| 114 | static unsigned char movadd = 0xfb; |
| 115 | |
| 116 | /*static DISPATCHER_SIGHANDLER(sighandler, s, data); |
| 117 | static void idle(void); |
| 118 | static struct dispatcher_proc p = |
| 119 | {DISPATCHER_PROC("Plasma screensaver", idle, |
| 120 | sighandler, |
| 121 | NULL)}; |
| 122 | static ek_id_t id;*/ |
| 123 | EK_EVENTHANDLER(eventhandler, ev, data); |
| 124 | EK_POLLHANDLER(pollhandler); |
| 125 | EK_PROCESS(p, "Plasma screensaver", EK_PRIO_LOWEST, |
| 126 | eventhandler, pollhandler, NULL); |
| 127 | static ek_id_t id = EK_ID_NONE; |
| 128 | |
| 129 | /*-----------------------------------------------------------------------------------*/ |
| 130 | static void |
| 131 | quit(void) |
| 132 | { |
| 133 | ek_exit(); |
| 134 | id = EK_ID_NONE; |
| 135 | LOADER_UNLOAD(); |
| 136 | } |
| 137 | /*-----------------------------------------------------------------------------------*/ |
| 138 | static void |
| 139 | scrninit(void) |
| 140 | { |
| 141 | unsigned char *ptr, *cptr; |
| 142 | static int i; |
| 143 | |
| 144 | /* Make sine tables */ |
| 145 | for(i = 0; i < 256; ++i) { |
| 146 | sinetab2[(unsigned char)i] = sinetab1[(unsigned char)i] / 2; |
| 147 | sinetab3[(unsigned char)i] = sinetab1[(unsigned char)i] / 4; |
| 148 | } |
| 149 | |
| 150 | /* Make color table */ |
| 151 | for(i = 0; i < 256; ++i) { |
| 152 | colortab[(unsigned char)i] = colors[(unsigned char)i / 16]; |
| 153 | } |
| 154 | |
| 155 | |
| 156 | /* Fill screen with inverted spaces. */ |
| 157 | cptr = COLOR_RAM; |
| 158 | for(ptr = (unsigned char *)0x0400; |
| 159 | ptr != (unsigned char *)0x07e8; |
| 160 | ++ptr) { |
| 161 | *ptr = 0xa0; |
| 162 | *cptr++ = 0x00; |
| 163 | } |
| 164 | |
| 165 | VIC.ctrl1 = 0x1b; /* $D011 */ |
| 166 | VIC.addr = 0x17; /* $D018 */ |
| 167 | VIC.ctrl2 = 0xc8; /* $D016 */ |
| 168 | VIC.bordercolor = 0x00; /* $D020 */ |
| 169 | VIC.bgcolor0 = 0x00; /* $D021 */ |
| 170 | CIA2.pra = 0x03; /* $DD00 */ |
| 171 | |
| 172 | } |
| 173 | /*-----------------------------------------------------------------------------------*/ |
| 174 | EK_POLLHANDLER(pollhandler) |
| 175 | { |
| 176 | static unsigned char i, x, y; |
| 177 | register unsigned char *cptr; |
| 178 | |
| 179 | if(ctk_mode_get() == CTK_MODE_SCREENSAVER) { |
| 180 | |
| 181 | |
| 182 | xcnt1 = xcnt01; |
| 183 | xcnt2 = xcnt02; |
| 184 | |
| 185 | for(i = 0; i < XSIZE; ++i) { |
| 186 | xplasma[i] = sinetab1[xcnt1] + sinetab2[xcnt2]; |
| 187 | xcnt1 += xadd1; |
| 188 | xcnt2 += xadd2; |
| 189 | } |
| 190 | |
| 191 | ycnt1 = ycnt01; |
| 192 | ycnt2 = ycnt02; |
| 193 | |
| 194 | for(i = 0; i < YSIZE; ++i) { |
| 195 | yplasma[i] = sinetab1[ycnt1] + sinetab3[ycnt2]; |
| 196 | ycnt1 += yadd1; |
| 197 | ycnt2 += yadd2; |
| 198 | } |
| 199 | |
| 200 | xcnt01 += xadd01; |
| 201 | xcnt02 += xadd02; |
| 202 | ycnt01 += yadd01; |
| 203 | ycnt02 += yadd02; |
| 204 | |
| 205 | |
| 206 | yadd02 = sinetab3[ycnt] / 4; |
| 207 | xadd02 = sinetab3[xcnt] / 4; |
| 208 | |
| 209 | ycnt += yadd; |
| 210 | xcnt += xadd; |
| 211 | |
| 212 | movcnt += movadd; |
| 213 | cptr = (unsigned char *)(0xd800 + sinetab1[movcnt]/16); |
| 214 | for(y = 0; y < YSIZE; ++y) { |
| 215 | for(x = 0; x < XSIZE; ++x) { |
| 216 | *cptr = colortab[(xplasma[x] + yplasma[y]) & 0xff]; |
| 217 | ++cptr; |
| 218 | } |
| 219 | cptr += 40 - XSIZE; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | /*-----------------------------------------------------------------------------------*/ |
| 224 | /*static |
| 225 | DISPATCHER_SIGHANDLER(sighandler, s, data)*/ |
| 226 | EK_EVENTHANDLER(eventhandler, ev, data) |
| 227 | { |
| 228 | EK_EVENTHANDLER_ARGS(ev, data); |
| 229 | |
| 230 | if(ev == EK_EVENT_INIT) { |
| 231 | ctk_mode_set(CTK_MODE_SCREENSAVER); |
| 232 | ctk_mouse_hide(); |
| 233 | |
| 234 | scrninit(); |
| 235 | |
| 236 | } else if(ev == ctk_signal_screensaver_stop || |
| 237 | ev == EK_EVENT_REQUEST_EXIT) { |
| 238 | ctk_draw_init(); |
| 239 | ctk_desktop_redraw(NULL); |
| 240 | /* ctk_mode_set(CTK_MODE_NORMAL);*/ |
| 241 | quit(); |
| 242 | } |
| 243 | } |
| 244 | /*-----------------------------------------------------------------------------------*/ |
| 245 | LOADER_INIT_FUNC(plasma_init, arg) |
| 246 | { |
| 247 | arg_free(arg); |
| 248 | |
| 249 | if(id == EK_ID_NONE) { |
| 250 | id = ek_start(&p); |
| 251 | } |
| 252 | } |
| 253 | /*-----------------------------------------------------------------------------------*/ |
| 254 | |