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: ssfire.c,v 1.1 2006/04/17 15:18:20 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 | |
| 45 | /*static DISPATCHER_SIGHANDLER(ssfire_sighandler, s, data); |
| 46 | static void ssfire_idle(void); |
| 47 | static struct dispatcher_proc p = |
| 48 | {DISPATCHER_PROC("Fire screensaver", ssfire_idle, |
| 49 | ssfire_sighandler, |
| 50 | NULL)}; |
| 51 | static ek_id_t id;*/ |
| 52 | |
| 53 | EK_EVENTHANDLER(ssfire_eventhandler, ev, data); |
| 54 | EK_POLLHANDLER(ssfire_pollhandler); |
| 55 | EK_PROCESS(p, "Fire screensaver", EK_PRIO_LOWEST, |
| 56 | ssfire_eventhandler, ssfire_pollhandler, NULL); |
| 57 | static ek_id_t id = EK_ID_NONE; |
| 58 | |
| 59 | static unsigned char flames[8*17]; |
| 60 | |
| 61 | |
| 62 | static const unsigned char flamecolors[16] = |
| 63 | {COLOR_BLACK, COLOR_BLACK, COLOR_BLACK, |
| 64 | COLOR_RED, COLOR_LIGHTRED, COLOR_YELLOW, COLOR_WHITE, |
| 65 | COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, |
| 66 | COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, |
| 67 | COLOR_WHITE}; |
| 68 | |
| 69 | |
| 70 | static void fire_init(void); |
| 71 | |
| 72 | /*-----------------------------------------------------------------------------------*/ |
| 73 | LOADER_INIT_FUNC(ssfire_init, arg) |
| 74 | { |
| 75 | arg_free(arg); |
| 76 | |
| 77 | if(id == EK_ID_NONE) { |
| 78 | id = ek_start(&p); |
| 79 | } |
| 80 | } |
| 81 | /*-----------------------------------------------------------------------------------*/ |
| 82 | static void |
| 83 | fire_quit(void) |
| 84 | { |
| 85 | ek_exit(); |
| 86 | id = EK_ID_NONE; |
| 87 | LOADER_UNLOAD(); |
| 88 | } |
| 89 | /*-----------------------------------------------------------------------------------*/ |
| 90 | static void |
| 91 | fire_init(void) |
| 92 | { |
| 93 | unsigned char *ptr, *cptr; |
| 94 | |
| 95 | /* Fill screen with inverted spaces. */ |
| 96 | cptr = COLOR_RAM; |
| 97 | for(ptr = (unsigned char *)0x0400; |
| 98 | ptr != (unsigned char *)0x07e8; |
| 99 | ++ptr) { |
| 100 | *ptr = 0xa0; |
| 101 | *cptr++ = 0x00; |
| 102 | } |
| 103 | |
| 104 | SID.v3.freq = 0xffff; |
| 105 | SID.v3.ctrl = 0x80; |
| 106 | SID.amp = 0; |
| 107 | |
| 108 | VIC.ctrl1 = 0x1b; /* $D011 */ |
| 109 | VIC.addr = 0x17; /* $D018 */ |
| 110 | VIC.ctrl2 = 0xc8; /* $D016 */ |
| 111 | VIC.bordercolor = 0x00; /* $D020 */ |
| 112 | VIC.bgcolor0 = 0x00; /* $D021 */ |
| 113 | CIA2.pra = 0x03; /* $DD00 */ |
| 114 | |
| 115 | } |
| 116 | /*-----------------------------------------------------------------------------------*/ |
| 117 | EK_EVENTHANDLER(ssfire_eventhandler, ev, data) |
| 118 | { |
| 119 | EK_EVENTHANDLER_ARGS(ev, data); |
| 120 | |
| 121 | if(ev == EK_EVENT_INIT) { |
| 122 | ctk_mode_set(CTK_MODE_SCREENSAVER); |
| 123 | ctk_mouse_hide(); |
| 124 | fire_init(); |
| 125 | } else if(ev == ctk_signal_screensaver_stop || |
| 126 | ev == EK_EVENT_REQUEST_EXIT) { |
| 127 | fire_quit(); |
| 128 | ctk_draw_init(); |
| 129 | ctk_desktop_redraw(NULL); |
| 130 | } |
| 131 | } |
| 132 | /*-----------------------------------------------------------------------------------*/ |
| 133 | static unsigned char *flameptr, *colorptr1, *colorptr2; |
| 134 | static unsigned char x, y; |
| 135 | |
| 136 | #pragma optimize(push, off) |
| 137 | EK_POLLHANDLER(ssfire_pollhandler) |
| 138 | { |
| 139 | |
| 140 | if(ctk_mode_get() == CTK_MODE_SCREENSAVER) { |
| 141 | |
| 142 | /* Calculate new flames. */ |
| 143 | asm("ldx #0"); |
| 144 | asm("loop:"); |
| 145 | asm("lda _flames+7,x"); |
| 146 | asm("clc"); |
| 147 | asm("adc _flames+8,x"); |
| 148 | asm("adc _flames+9,x"); |
| 149 | asm("adc _flames+16,x"); |
| 150 | asm("lsr"); |
| 151 | asm("lsr"); |
| 152 | asm("sta _flames,x"); |
| 153 | asm("inx"); |
| 154 | asm("cpx #(8*15)"); |
| 155 | asm("bne loop"); |
| 156 | |
| 157 | /* Fill last line with pseudo-random data from noise generator on |
| 158 | voice 3. */ |
| 159 | asm("ldx #$05"); |
| 160 | asm("loop2:"); |
| 161 | asm("ldy #$20"); |
| 162 | asm("delay:"); |
| 163 | asm("dey"); |
| 164 | asm("bne delay"); |
| 165 | asm("lda $d41b"); |
| 166 | asm("and #$0f"); |
| 167 | asm("sta _flames+8*15+1,x"); |
| 168 | asm("dex"); |
| 169 | asm("bpl loop2"); |
| 170 | |
| 171 | /* Display flames on screen. */ |
| 172 | flameptr = flames; |
| 173 | colorptr1 = COLOR_RAM + 40*10; |
| 174 | colorptr2 = colorptr1 + 0x20; |
| 175 | for(y = 0; y < 15; ++y) { |
| 176 | for(x = 0; x < 8; ++x) { |
| 177 | colorptr1[x] = colorptr2[x] = flamecolors[flameptr[x]]; |
| 178 | } |
| 179 | colorptr1 += 0x28; |
| 180 | colorptr2 += 0x28; |
| 181 | flameptr += 8; |
| 182 | } |
| 183 | |
| 184 | } |
| 185 | } |
| 186 | #pragma optimize(pop) |
| 187 | /*-----------------------------------------------------------------------------------*/ |
| 188 | |