annotate src/dssleep.c @ 0:c84446dfb3f5

initial add
author paulo@localhost
date Fri, 13 Mar 2009 00:39:12 -0700
parents
children
rev   line source
paulo@0 1 #include <nds.h>
paulo@0 2
paulo@0 3 /*
paulo@0 4 by Mighty Max and melw,
paulo@0 5 after http://forum.gbadev.org/viewtopic.php?t=12011
paulo@0 6 */
paulo@0 7
paulo@0 8 int needLidSleep(void) {
paulo@0 9 // when reading keys
paulo@0 10 if (IPC->buttons & 0x0080) {
paulo@0 11 /* hinge is closed */
paulo@0 12
paulo@0 13 /* Step 1: Turn off all interrupts but vblank for waking up */
paulo@0 14 unsigned long oldIE = REG_IE;
paulo@0 15 REG_IE = IRQ_VBLANK;
paulo@0 16
paulo@0 17 /* Step 2: Power off most of the system */
paulo@0 18 powerOFF(POWER_LCD);
paulo@0 19
paulo@0 20 /* Step 3: Wait one vblank at a time until the ARM7 tells us
paulo@0 21 that the lid is no longer closed */
paulo@0 22 while (IPC->buttons & 0x0080) {
paulo@0 23 swiWaitForVBlank();
paulo@0 24 }
paulo@0 25
paulo@0 26 /* Step 4: Wait a bit more (necessary?) */
paulo@0 27 swiWaitForVBlank();
paulo@0 28
paulo@0 29 /* Step 5: Restore old machine state */
paulo@0 30 powerON(POWER_LCD);
paulo@0 31 REG_IE = oldIE;
paulo@0 32 return 1;
paulo@0 33 }
paulo@0 34 return 0;
paulo@0 35 }