view src/dsarm7.c @ 1:38c62fded078

initial builds (linux and lj.nds)
author paulo@localhost
date Fri, 13 Mar 2009 01:10:13 -0700
parents
children
line source
1 /*---------------------------------------------------------------------------------
3 LOCKJAW Tetromino Game: ARM7 core
5 Copyright (C) 2005-2007
6 Damian Yerrick (tepples)
8 based on
9 default ARM7 core
11 Copyright (C) 2005-2007
12 Michael Noland (joat)
13 Jason Rogers (dovoto)
14 Dave Murphy (WinterMute)
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.
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:
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.
33 ---------------------------------------------------------------------------------*/
34 #include <stdlib.h>
35 #include <nds.h>
36 #include "talkback.h" // custom talkback
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;
49 void powerOffDS(void)
50 {
51 writePowerManagement(PM_CONTROL_REG, 1 << 6);//6 DS power (0: on, 1: shut down!)
52 }
54 void doSleep(void) {
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;
69 // Power down till we get our interrupt.
70 swiSleep(); //waits for PM (lid open) interrupt
72 REG_IF = ~0;
73 // Restore the interrupt state.
74 REG_IE = ie_save;
75 // Restore power state.
76 writePowerManagement(PM_CONTROL_REG, power);
78 // Turn the speaker up.
79 swiChangeSoundBias(1,0x400);
80 IPC->buttons &= ~BIT(7);
81 }
82 }
84 void VblankHandler(void) {
86 doSleep();
88 volatile P8A7Talkback *tb = (P8A7Talkback *)IPC->soundData;
89 if (tb) {
90 int cmd = tb->cmd;
91 tb->cmd = 0;
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;
114 ljSoundEffects(fx, tb->countdown);
115 }
117 ljMusic();
119 }
123 // All below this is wintermute's and may need to be replaced
124 // with new versions of libnds
127 touchPosition first,tempPos;
129 //---------------------------------------------------------------------------------
130 void VcountHandler() {
131 //---------------------------------------------------------------------------------
132 static int lastbut = -1;
134 uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0;
136 but = REG_KEYXY;
138 if (!( (but ^ lastbut) & (1<<6))) {
140 tempPos = touchReadXY();
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 }
154 } else {
155 lastbut = but;
156 but |= (1 <<6);
157 }
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;
167 }
171 //---------------------------------------------------------------------------------
172 int main(int argc, char ** argv) {
173 //---------------------------------------------------------------------------------
175 // set up custom ipc struct
176 IPC->soundData = 0;
178 // read User Settings from firmware
179 readUserSettings();
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);
186 irqInit();
188 // Start the RTC tracking IRQ
189 initClockIRQ();
191 SetYtrigger(80);
192 irqSet(IRQ_VCOUNT, VcountHandler);
193 irqSet(IRQ_VBLANK, VblankHandler);
196 irqEnable( IRQ_VBLANK | IRQ_VCOUNT);
198 // Keep the ARM7 mostly idle
199 while (1) swiWaitForVBlank();
200 }