adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2002, 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. All advertising materials mentioning features or use of this |
| 15 | * software must display the following acknowledgement: |
| 16 | * This product includes software developed by Adam Dunkels. |
| 17 | * 4. The name of the author may not be used to endorse or promote |
| 18 | * products derived from this software without specific prior |
| 19 | * written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
| 22 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
| 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
| 27 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | * |
| 33 | * This file is part of the Contiki desktop environment |
| 34 | * |
adamdunkels | 2af72c2 | 2003-08-24 22:31:23 +0000 | [diff] [blame^] | 35 | * $Id: ssfire.c,v 1.4 2003/08/24 22:31:23 adamdunkels Exp $ |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 36 | * |
| 37 | */ |
| 38 | |
| 39 | #include <stdlib.h> |
| 40 | |
| 41 | #include "ctk.h" |
| 42 | #include "ctk-draw.h" |
adamdunkels | 7f78282 | 2003-08-09 23:28:49 +0000 | [diff] [blame] | 43 | #include "ctk-mouse.h" |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 44 | #include "dispatcher.h" |
| 45 | #include "loader.h" |
| 46 | |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 47 | |
| 48 | static DISPATCHER_SIGHANDLER(ssfire_sighandler, s, data); |
| 49 | static void ssfire_idle(void); |
| 50 | static struct dispatcher_proc p = |
| 51 | {DISPATCHER_PROC("Fire screensaver", ssfire_idle, |
| 52 | ssfire_sighandler, |
| 53 | NULL)}; |
| 54 | static ek_id_t id; |
| 55 | |
| 56 | |
| 57 | static unsigned char flames[8*17]; |
| 58 | |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 59 | |
| 60 | static const unsigned char flamecolors[16] = |
| 61 | {COLOR_BLACK, COLOR_BLACK, COLOR_BLACK, |
| 62 | COLOR_RED, COLOR_LIGHTRED, COLOR_YELLOW, COLOR_WHITE, |
| 63 | COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, |
| 64 | COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, |
| 65 | COLOR_WHITE}; |
| 66 | |
| 67 | |
adamdunkels | 7f78282 | 2003-08-09 23:28:49 +0000 | [diff] [blame] | 68 | static void fire_init(void); |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 69 | |
| 70 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 2af72c2 | 2003-08-24 22:31:23 +0000 | [diff] [blame^] | 71 | LOADER_INIT_FUNC(ssfire_init, arg) |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 72 | { |
adamdunkels | 2af72c2 | 2003-08-24 22:31:23 +0000 | [diff] [blame^] | 73 | arg_free(arg); |
| 74 | |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 75 | if(id == EK_ID_NONE) { |
| 76 | id = dispatcher_start(&p); |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 77 | dispatcher_listen(ctk_signal_screensaver_stop); |
adamdunkels | 7f78282 | 2003-08-09 23:28:49 +0000 | [diff] [blame] | 78 | ctk_mode_set(CTK_MODE_SCREENSAVER); |
| 79 | ctk_mouse_hide(); |
| 80 | fire_init(); |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | /*-----------------------------------------------------------------------------------*/ |
| 84 | static void |
| 85 | fire_quit(void) |
| 86 | { |
| 87 | dispatcher_exit(&p); |
| 88 | id = EK_ID_NONE; |
| 89 | LOADER_UNLOAD(); |
| 90 | } |
| 91 | /*-----------------------------------------------------------------------------------*/ |
| 92 | static void |
| 93 | fire_init(void) |
| 94 | { |
| 95 | unsigned char *ptr, *cptr; |
| 96 | |
adamdunkels | 2af72c2 | 2003-08-24 22:31:23 +0000 | [diff] [blame^] | 97 | /* Fill screen with inverted spaces. */ |
| 98 | cptr = COLOR_RAM; |
| 99 | for(ptr = (unsigned char *)0x0400; |
| 100 | ptr != (unsigned char *)0x07e8; |
| 101 | ++ptr) { |
| 102 | *ptr = 0xa0; |
| 103 | *cptr++ = 0x00; |
| 104 | } |
| 105 | |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 106 | SID.v3.freq = 0xffff; |
| 107 | SID.v3.ctrl = 0x80; |
| 108 | SID.amp = 0; |
| 109 | |
| 110 | VIC.ctrl1 = 0x1b; /* $D011 */ |
| 111 | VIC.addr = 0x17; /* $D018 */ |
| 112 | VIC.ctrl2 = 0xc8; /* $D016 */ |
| 113 | VIC.bordercolor = 0x00; /* $D020 */ |
| 114 | VIC.bgcolor0 = 0x00; /* $D021 */ |
| 115 | CIA2.pra = 0x03; /* $DD00 */ |
| 116 | |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 117 | } |
| 118 | /*-----------------------------------------------------------------------------------*/ |
| 119 | static |
| 120 | DISPATCHER_SIGHANDLER(ssfire_sighandler, s, data) |
| 121 | { |
| 122 | DISPATCHER_SIGHANDLER_ARGS(s, data); |
| 123 | |
adamdunkels | 7f78282 | 2003-08-09 23:28:49 +0000 | [diff] [blame] | 124 | if(s == ctk_signal_screensaver_stop || |
| 125 | s == dispatcher_signal_quit) { |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 126 | fire_quit(); |
| 127 | ctk_draw_init(); |
adamdunkels | eb4d92a | 2003-07-31 23:34:04 +0000 | [diff] [blame] | 128 | ctk_desktop_redraw(NULL); |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | /*-----------------------------------------------------------------------------------*/ |
adamdunkels | 2af72c2 | 2003-08-24 22:31:23 +0000 | [diff] [blame^] | 132 | static unsigned char *flameptr, *colorptr1, *colorptr2; |
| 133 | static unsigned char x, y; |
| 134 | |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 135 | void |
| 136 | ssfire_idle(void) |
| 137 | { |
adamdunkels | 2af72c2 | 2003-08-24 22:31:23 +0000 | [diff] [blame^] | 138 | |
adamdunkels | 7f78282 | 2003-08-09 23:28:49 +0000 | [diff] [blame] | 139 | if(ctk_mode_get() == CTK_MODE_SCREENSAVER) { |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 140 | |
adamdunkels | 7f78282 | 2003-08-09 23:28:49 +0000 | [diff] [blame] | 141 | /* Calculate new flames. */ |
| 142 | asm("ldx #0"); |
| 143 | asm("loop:"); |
| 144 | asm("lda _flames+7,x"); |
| 145 | asm("clc"); |
| 146 | asm("adc _flames+8,x"); |
| 147 | asm("adc _flames+9,x"); |
| 148 | asm("adc _flames+16,x"); |
| 149 | asm("lsr"); |
| 150 | asm("lsr"); |
| 151 | asm("sta _flames,x"); |
| 152 | asm("inx"); |
| 153 | asm("cpx #(8*15)"); |
| 154 | asm("bne loop"); |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 155 | |
adamdunkels | 7f78282 | 2003-08-09 23:28:49 +0000 | [diff] [blame] | 156 | /* Fill last line with pseudo-random data from noise generator on |
| 157 | voice 3. */ |
| 158 | asm("ldx #$05"); |
| 159 | asm("loop2:"); |
| 160 | asm("ldy #$20"); |
| 161 | asm("delay:"); |
| 162 | asm("dey"); |
| 163 | asm("bne delay"); |
| 164 | asm("lda $d41b"); |
| 165 | asm("and #$0f"); |
| 166 | asm("sta _flames+8*15+1,x"); |
| 167 | asm("dex"); |
| 168 | asm("bpl loop2"); |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 169 | |
adamdunkels | 7f78282 | 2003-08-09 23:28:49 +0000 | [diff] [blame] | 170 | /* Display flames on screen. */ |
| 171 | flameptr = flames; |
| 172 | colorptr1 = COLOR_RAM + 40*10; |
| 173 | colorptr2 = colorptr1 + 0x20; |
| 174 | for(y = 0; y < 15; ++y) { |
| 175 | for(x = 0; x < 8; ++x) { |
adamdunkels | 2af72c2 | 2003-08-24 22:31:23 +0000 | [diff] [blame^] | 176 | colorptr1[x] = colorptr2[x] = flamecolors[flameptr[x]]; |
adamdunkels | 7f78282 | 2003-08-09 23:28:49 +0000 | [diff] [blame] | 177 | } |
adamdunkels | 2af72c2 | 2003-08-24 22:31:23 +0000 | [diff] [blame^] | 178 | colorptr1 += 0x28; |
| 179 | colorptr2 += 0x28; |
| 180 | flameptr += 8; |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 181 | } |
adamdunkels | bc70b4d | 2003-04-24 17:10:32 +0000 | [diff] [blame] | 182 | |
| 183 | } |
| 184 | } |
| 185 | /*-----------------------------------------------------------------------------------*/ |
| 186 | |