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