oliverschmidt | d1c833f | 2005-05-12 21:12:43 +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 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 | |
| 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 | static const unsigned char flamecolors[16] = |
| 62 | {0x00, 0x00, 0x00, 0x11, 0x99, 0xDD, 0xFF, 0xFF, |
| 63 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
| 64 | |
| 65 | static unsigned char *flameptr; |
| 66 | static unsigned char x, y; |
| 67 | |
| 68 | |
| 69 | /*-----------------------------------------------------------------------------------*/ |
| 70 | LOADER_INIT_FUNC(ssfire_init, arg) |
| 71 | { |
| 72 | arg_free(arg); |
| 73 | |
| 74 | if(id == EK_ID_NONE) { |
| 75 | id = ek_start(&p); |
| 76 | } |
| 77 | } |
| 78 | /*-----------------------------------------------------------------------------------*/ |
| 79 | static void |
| 80 | fire_quit(void) |
| 81 | { |
| 82 | *(char *)0xC051 = 0; |
| 83 | |
| 84 | ek_exit(); |
| 85 | id = EK_ID_NONE; |
| 86 | LOADER_UNLOAD(); |
| 87 | } |
| 88 | /*-----------------------------------------------------------------------------------*/ |
| 89 | static void |
| 90 | fire_init(void) |
| 91 | { |
| 92 | *(char *)0xC056 = 0; |
| 93 | *(char *)0xC054 = 0; |
| 94 | *(char *)0xC052 = 0; |
| 95 | *(char *)0xC050 = 0; |
| 96 | |
| 97 | for(y = 0; y < 24; ++y) { |
| 98 | gotoy(y); |
| 99 | for(x = 0; x < 40; ++x) { |
| 100 | (*(unsigned char **)0x28)[x] = 0x00; |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | /*-----------------------------------------------------------------------------------*/ |
| 105 | EK_EVENTHANDLER(ssfire_eventhandler, ev, data) |
| 106 | { |
| 107 | EK_EVENTHANDLER_ARGS(ev, data); |
| 108 | |
| 109 | if(ev == EK_EVENT_INIT) { |
| 110 | ctk_mode_set(CTK_MODE_SCREENSAVER); |
| 111 | ctk_mouse_hide(); |
| 112 | fire_init(); |
| 113 | } else if(ev == ctk_signal_screensaver_stop || |
| 114 | ev == EK_EVENT_REQUEST_EXIT) { |
| 115 | fire_quit(); |
| 116 | ctk_draw_init(); |
| 117 | ctk_desktop_redraw(NULL); |
| 118 | } |
| 119 | } |
| 120 | /*-----------------------------------------------------------------------------------*/ |
| 121 | #pragma optimize(push, off) |
| 122 | static void |
| 123 | fire_burn(void) |
| 124 | { |
| 125 | /* Calculate new flames. */ |
| 126 | asm("ldy #$00"); |
| 127 | loop1: |
| 128 | asm("lda %v+7,y", flames); |
| 129 | asm("clc"); |
| 130 | asm("adc %v+8,y", flames); |
| 131 | asm("adc %v+9,y", flames); |
| 132 | asm("adc %v+16,y", flames); |
| 133 | asm("lsr"); |
| 134 | asm("lsr"); |
| 135 | asm("sta %v,y", flames); |
| 136 | asm("iny"); |
| 137 | asm("cpy #(8*15)"); |
| 138 | asm("bne %g", loop1); |
| 139 | |
| 140 | /* Fill last line with pseudo-random data. */ |
| 141 | asm("ldy #$05"); |
| 142 | loop2: |
| 143 | asm("jsr %v", rand); |
| 144 | asm("and #$0F"); |
| 145 | asm("sta %v+8*15+1,y", flames); |
| 146 | asm("dey"); |
| 147 | asm("bpl %g", loop2); |
| 148 | } |
| 149 | #pragma optimize(pop) |
| 150 | /*-----------------------------------------------------------------------------------*/ |
| 151 | EK_POLLHANDLER(ssfire_pollhandler) |
| 152 | { |
| 153 | if(ctk_mode_get() == CTK_MODE_SCREENSAVER) { |
| 154 | |
| 155 | fire_burn(); |
| 156 | |
| 157 | /* Display flames on screen. */ |
| 158 | flameptr = flames; |
| 159 | for(y = 9; y < 24; ++y) { |
| 160 | gotoy(y); |
| 161 | for(x = 0; x < 8; ++x) { |
| 162 | (*(unsigned char **)0x28)[x ] = |
| 163 | (*(unsigned char **)0x28)[x+32] = flamecolors[flameptr[x]]; |
| 164 | } |
| 165 | flameptr += 8; |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | /*-----------------------------------------------------------------------------------*/ |
| 170 | |