annotate src/dsarm7.c @ 3:17286938e22a

change DS alt. rotate key to rotate twice
author paulo@localhost
date Wed, 08 Apr 2009 21:50:13 -0700
parents
children
rev   line source
paulo@0 1 /*---------------------------------------------------------------------------------
paulo@0 2
paulo@0 3 LOCKJAW Tetromino Game: ARM7 core
paulo@0 4
paulo@0 5 Copyright (C) 2005-2007
paulo@0 6 Damian Yerrick (tepples)
paulo@0 7
paulo@0 8 based on
paulo@0 9 default ARM7 core
paulo@0 10
paulo@0 11 Copyright (C) 2005-2007
paulo@0 12 Michael Noland (joat)
paulo@0 13 Jason Rogers (dovoto)
paulo@0 14 Dave Murphy (WinterMute)
paulo@0 15
paulo@0 16 This software is provided 'as-is', without any express or implied
paulo@0 17 warranty. In no event will the authors be held liable for any
paulo@0 18 damages arising from the use of this software.
paulo@0 19
paulo@0 20 Permission is granted to anyone to use this software for any
paulo@0 21 purpose, including commercial applications, and to alter it and
paulo@0 22 redistribute it freely, subject to the following restrictions:
paulo@0 23
paulo@0 24 1. The origin of this software must not be misrepresented; you
paulo@0 25 must not claim that you wrote the original software. If you use
paulo@0 26 this software in a product, an acknowledgment in the product
paulo@0 27 documentation would be appreciated but is not required.
paulo@0 28 2. Altered source versions must be plainly marked as such, and
paulo@0 29 must not be misrepresented as being the original software.
paulo@0 30 3. This notice may not be removed or altered from any source
paulo@0 31 distribution.
paulo@0 32
paulo@0 33 ---------------------------------------------------------------------------------*/
paulo@0 34 #include <stdlib.h>
paulo@0 35 #include <nds.h>
paulo@0 36 #include "talkback.h" // custom talkback
paulo@0 37
paulo@0 38 void ljSoundEffects(unsigned long int sounds,
paulo@0 39 int countdown);
paulo@0 40 void ljMusic(void);
paulo@0 41 extern int order;
paulo@0 42 extern char ticksLeft;
paulo@0 43 extern char row;
paulo@0 44 extern char musicPaused;
paulo@0 45
paulo@0 46
paulo@0 47
paulo@0 48
paulo@0 49 void powerOffDS(void)
paulo@0 50 {
paulo@0 51 writePowerManagement(PM_CONTROL_REG, 1 << 6);//6 DS power (0: on, 1: shut down!)
paulo@0 52 }
paulo@0 53
paulo@0 54 void doSleep(void) {
paulo@0 55
paulo@0 56 // Check if the lid has been closed.
paulo@0 57 if(IPC->buttons & BIT(7)) {
paulo@0 58 // Save the current interrupt sate.
paulo@0 59 u32 ie_save = REG_IE;
paulo@0 60 // Turn the speaker down.
paulo@0 61 swiChangeSoundBias(0,0x400);
paulo@0 62 // Save current power state.
paulo@0 63 int power = readPowerManagement(PM_CONTROL_REG);
paulo@0 64 // Set sleep LED.
paulo@0 65 writePowerManagement(PM_CONTROL_REG, PM_LED_CONTROL(1));
paulo@0 66 // Register for the lid interrupt.
paulo@0 67 REG_IE = IRQ_LID;
paulo@0 68
paulo@0 69 // Power down till we get our interrupt.
paulo@0 70 swiSleep(); //waits for PM (lid open) interrupt
paulo@0 71
paulo@0 72 REG_IF = ~0;
paulo@0 73 // Restore the interrupt state.
paulo@0 74 REG_IE = ie_save;
paulo@0 75 // Restore power state.
paulo@0 76 writePowerManagement(PM_CONTROL_REG, power);
paulo@0 77
paulo@0 78 // Turn the speaker up.
paulo@0 79 swiChangeSoundBias(1,0x400);
paulo@0 80 IPC->buttons &= ~BIT(7);
paulo@0 81 }
paulo@0 82 }
paulo@0 83
paulo@0 84 void VblankHandler(void) {
paulo@0 85
paulo@0 86 doSleep();
paulo@0 87
paulo@0 88 volatile P8A7Talkback *tb = (P8A7Talkback *)IPC->soundData;
paulo@0 89 if (tb) {
paulo@0 90 int cmd = tb->cmd;
paulo@0 91 tb->cmd = 0;
paulo@0 92
paulo@0 93 switch (cmd) {
paulo@0 94 case TALKBACK_POWER_OFF:
paulo@0 95 powerOFF(POWER_SOUND);
paulo@0 96 powerOffDS();
paulo@0 97 swiWaitForVBlank();
paulo@0 98 break;
paulo@0 99 case TALKBACK_PLAY_MUSIC:
paulo@0 100 musicPaused = 0;
paulo@0 101 break;
paulo@0 102 case TALKBACK_STOP_MUSIC:
paulo@0 103 musicPaused = 1;
paulo@0 104 order = 0;
paulo@0 105 row = 0;
paulo@0 106 ticksLeft = 1;
paulo@0 107 break;
paulo@0 108 case TALKBACK_PAUSE_MUSIC:
paulo@0 109 musicPaused = 1;
paulo@0 110 }
paulo@0 111 unsigned long int fx = tb->sounds;
paulo@0 112 tb->sounds = 0;
paulo@0 113
paulo@0 114 ljSoundEffects(fx, tb->countdown);
paulo@0 115 }
paulo@0 116
paulo@0 117 ljMusic();
paulo@0 118
paulo@0 119 }
paulo@0 120
paulo@0 121
paulo@0 122
paulo@0 123 // All below this is wintermute's and may need to be replaced
paulo@0 124 // with new versions of libnds
paulo@0 125
paulo@0 126
paulo@0 127 touchPosition first,tempPos;
paulo@0 128
paulo@0 129 //---------------------------------------------------------------------------------
paulo@0 130 void VcountHandler() {
paulo@0 131 //---------------------------------------------------------------------------------
paulo@0 132 static int lastbut = -1;
paulo@0 133
paulo@0 134 uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0;
paulo@0 135
paulo@0 136 but = REG_KEYXY;
paulo@0 137
paulo@0 138 if (!( (but ^ lastbut) & (1<<6))) {
paulo@0 139
paulo@0 140 tempPos = touchReadXY();
paulo@0 141
paulo@0 142 if ( tempPos.x == 0 || tempPos.y == 0 ) {
paulo@0 143 but |= (1 <<6);
paulo@0 144 lastbut = but;
paulo@0 145 } else {
paulo@0 146 x = tempPos.x;
paulo@0 147 y = tempPos.y;
paulo@0 148 xpx = tempPos.px;
paulo@0 149 ypx = tempPos.py;
paulo@0 150 z1 = tempPos.z1;
paulo@0 151 z2 = tempPos.z2;
paulo@0 152 }
paulo@0 153
paulo@0 154 } else {
paulo@0 155 lastbut = but;
paulo@0 156 but |= (1 <<6);
paulo@0 157 }
paulo@0 158
paulo@0 159 IPC->touchX = x;
paulo@0 160 IPC->touchY = y;
paulo@0 161 IPC->touchXpx = xpx;
paulo@0 162 IPC->touchYpx = ypx;
paulo@0 163 IPC->touchZ1 = z1;
paulo@0 164 IPC->touchZ2 = z2;
paulo@0 165 IPC->buttons = but;
paulo@0 166
paulo@0 167 }
paulo@0 168
paulo@0 169
paulo@0 170
paulo@0 171 //---------------------------------------------------------------------------------
paulo@0 172 int main(int argc, char ** argv) {
paulo@0 173 //---------------------------------------------------------------------------------
paulo@0 174
paulo@0 175 // set up custom ipc struct
paulo@0 176 IPC->soundData = 0;
paulo@0 177
paulo@0 178 // read User Settings from firmware
paulo@0 179 readUserSettings();
paulo@0 180
paulo@0 181 //enable sound
paulo@0 182 powerON(POWER_SOUND);
paulo@0 183 writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE & ~(1 << 6) ) | PM_SOUND_AMP );
paulo@0 184 SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F);
paulo@0 185
paulo@0 186 irqInit();
paulo@0 187
paulo@0 188 // Start the RTC tracking IRQ
paulo@0 189 initClockIRQ();
paulo@0 190
paulo@0 191 SetYtrigger(80);
paulo@0 192 irqSet(IRQ_VCOUNT, VcountHandler);
paulo@0 193 irqSet(IRQ_VBLANK, VblankHandler);
paulo@0 194
paulo@0 195
paulo@0 196 irqEnable( IRQ_VBLANK | IRQ_VCOUNT);
paulo@0 197
paulo@0 198 // Keep the ARM7 mostly idle
paulo@0 199 while (1) swiWaitForVBlank();
paulo@0 200 }