paulo@0: /*--------------------------------------------------------------------------------- paulo@0: paulo@0: LOCKJAW Tetromino Game: ARM7 core paulo@0: paulo@0: Copyright (C) 2005-2007 paulo@0: Damian Yerrick (tepples) paulo@0: paulo@0: based on paulo@0: default ARM7 core paulo@0: paulo@0: Copyright (C) 2005-2007 paulo@0: Michael Noland (joat) paulo@0: Jason Rogers (dovoto) paulo@0: Dave Murphy (WinterMute) paulo@0: paulo@0: This software is provided 'as-is', without any express or implied paulo@0: warranty. In no event will the authors be held liable for any paulo@0: damages arising from the use of this software. paulo@0: paulo@0: Permission is granted to anyone to use this software for any paulo@0: purpose, including commercial applications, and to alter it and paulo@0: redistribute it freely, subject to the following restrictions: paulo@0: paulo@0: 1. The origin of this software must not be misrepresented; you paulo@0: must not claim that you wrote the original software. If you use paulo@0: this software in a product, an acknowledgment in the product paulo@0: documentation would be appreciated but is not required. paulo@0: 2. Altered source versions must be plainly marked as such, and paulo@0: must not be misrepresented as being the original software. paulo@0: 3. This notice may not be removed or altered from any source paulo@0: distribution. paulo@0: paulo@0: ---------------------------------------------------------------------------------*/ paulo@0: #include paulo@0: #include paulo@0: #include "talkback.h" // custom talkback paulo@0: paulo@0: void ljSoundEffects(unsigned long int sounds, paulo@0: int countdown); paulo@0: void ljMusic(void); paulo@0: extern int order; paulo@0: extern char ticksLeft; paulo@0: extern char row; paulo@0: extern char musicPaused; paulo@0: paulo@0: paulo@0: paulo@0: paulo@0: void powerOffDS(void) paulo@0: { paulo@0: writePowerManagement(PM_CONTROL_REG, 1 << 6);//6 DS power (0: on, 1: shut down!) paulo@0: } paulo@0: paulo@0: void doSleep(void) { paulo@0: paulo@0: // Check if the lid has been closed. paulo@0: if(IPC->buttons & BIT(7)) { paulo@0: // Save the current interrupt sate. paulo@0: u32 ie_save = REG_IE; paulo@0: // Turn the speaker down. paulo@0: swiChangeSoundBias(0,0x400); paulo@0: // Save current power state. paulo@0: int power = readPowerManagement(PM_CONTROL_REG); paulo@0: // Set sleep LED. paulo@0: writePowerManagement(PM_CONTROL_REG, PM_LED_CONTROL(1)); paulo@0: // Register for the lid interrupt. paulo@0: REG_IE = IRQ_LID; paulo@0: paulo@0: // Power down till we get our interrupt. paulo@0: swiSleep(); //waits for PM (lid open) interrupt paulo@0: paulo@0: REG_IF = ~0; paulo@0: // Restore the interrupt state. paulo@0: REG_IE = ie_save; paulo@0: // Restore power state. paulo@0: writePowerManagement(PM_CONTROL_REG, power); paulo@0: paulo@0: // Turn the speaker up. paulo@0: swiChangeSoundBias(1,0x400); paulo@0: IPC->buttons &= ~BIT(7); paulo@0: } paulo@0: } paulo@0: paulo@0: void VblankHandler(void) { paulo@0: paulo@0: doSleep(); paulo@0: paulo@0: volatile P8A7Talkback *tb = (P8A7Talkback *)IPC->soundData; paulo@0: if (tb) { paulo@0: int cmd = tb->cmd; paulo@0: tb->cmd = 0; paulo@0: paulo@0: switch (cmd) { paulo@0: case TALKBACK_POWER_OFF: paulo@0: powerOFF(POWER_SOUND); paulo@0: powerOffDS(); paulo@0: swiWaitForVBlank(); paulo@0: break; paulo@0: case TALKBACK_PLAY_MUSIC: paulo@0: musicPaused = 0; paulo@0: break; paulo@0: case TALKBACK_STOP_MUSIC: paulo@0: musicPaused = 1; paulo@0: order = 0; paulo@0: row = 0; paulo@0: ticksLeft = 1; paulo@0: break; paulo@0: case TALKBACK_PAUSE_MUSIC: paulo@0: musicPaused = 1; paulo@0: } paulo@0: unsigned long int fx = tb->sounds; paulo@0: tb->sounds = 0; paulo@0: paulo@0: ljSoundEffects(fx, tb->countdown); paulo@0: } paulo@0: paulo@0: ljMusic(); paulo@0: paulo@0: } paulo@0: paulo@0: paulo@0: paulo@0: // All below this is wintermute's and may need to be replaced paulo@0: // with new versions of libnds paulo@0: paulo@0: paulo@0: touchPosition first,tempPos; paulo@0: paulo@0: //--------------------------------------------------------------------------------- paulo@0: void VcountHandler() { paulo@0: //--------------------------------------------------------------------------------- paulo@0: static int lastbut = -1; paulo@0: paulo@0: uint16 but=0, x=0, y=0, xpx=0, ypx=0, z1=0, z2=0; paulo@0: paulo@0: but = REG_KEYXY; paulo@0: paulo@0: if (!( (but ^ lastbut) & (1<<6))) { paulo@0: paulo@0: tempPos = touchReadXY(); paulo@0: paulo@0: if ( tempPos.x == 0 || tempPos.y == 0 ) { paulo@0: but |= (1 <<6); paulo@0: lastbut = but; paulo@0: } else { paulo@0: x = tempPos.x; paulo@0: y = tempPos.y; paulo@0: xpx = tempPos.px; paulo@0: ypx = tempPos.py; paulo@0: z1 = tempPos.z1; paulo@0: z2 = tempPos.z2; paulo@0: } paulo@0: paulo@0: } else { paulo@0: lastbut = but; paulo@0: but |= (1 <<6); paulo@0: } paulo@0: paulo@0: IPC->touchX = x; paulo@0: IPC->touchY = y; paulo@0: IPC->touchXpx = xpx; paulo@0: IPC->touchYpx = ypx; paulo@0: IPC->touchZ1 = z1; paulo@0: IPC->touchZ2 = z2; paulo@0: IPC->buttons = but; paulo@0: paulo@0: } paulo@0: paulo@0: paulo@0: paulo@0: //--------------------------------------------------------------------------------- paulo@0: int main(int argc, char ** argv) { paulo@0: //--------------------------------------------------------------------------------- paulo@0: paulo@0: // set up custom ipc struct paulo@0: IPC->soundData = 0; paulo@0: paulo@0: // read User Settings from firmware paulo@0: readUserSettings(); paulo@0: paulo@0: //enable sound paulo@0: powerON(POWER_SOUND); paulo@0: writePowerManagement(PM_CONTROL_REG, ( readPowerManagement(PM_CONTROL_REG) & ~PM_SOUND_MUTE & ~(1 << 6) ) | PM_SOUND_AMP ); paulo@0: SOUND_CR = SOUND_ENABLE | SOUND_VOL(0x7F); paulo@0: paulo@0: irqInit(); paulo@0: paulo@0: // Start the RTC tracking IRQ paulo@0: initClockIRQ(); paulo@0: paulo@0: SetYtrigger(80); paulo@0: irqSet(IRQ_VCOUNT, VcountHandler); paulo@0: irqSet(IRQ_VBLANK, VblankHandler); paulo@0: paulo@0: paulo@0: irqEnable( IRQ_VBLANK | IRQ_VCOUNT); paulo@0: paulo@0: // Keep the ARM7 mostly idle paulo@0: while (1) swiWaitForVBlank(); paulo@0: }