#167228 - Echo49 - Fri Mar 06, 2009 6:31 am
libnds has a built in routine when it detects a lid close, but how can I write my own?
Last edited by Echo49 on Fri Mar 06, 2009 10:13 pm; edited 1 time in total
#167229 - Dwedit - Fri Mar 06, 2009 9:05 am
The normal process is that the ARM7 checks if the screen has been closed for 20 frames, then sends the ARM9 a request for sleep mode.
Then the ARM9 sends a sleep confirmation to the ARM7, which makes the ARM7 put the system to sleep.
You will need to replace Libnds's default ARM9 FIFO_PM handler with your own.
The default handler checks if the message is PM_REQ_SLEEP, then tells the ARM9 to call systemSleep(), which tells the ARM7 to put the system in sleep mode.
Your replacement handler should look like this:
Code: |
void MY_powerValueHandler(u32 value, void* data){
switch(value)
{
case PM_REQ_SLEEP:
{
//Your Code Here
}
break;
default:
{
powerValueHandler(value,data); //call the default power value handler for other cases
}
}
}
|
Note: the only case handled by libnds's ARM9 powerValueHandler is sleep mode request, so this example code to handle the default case does absolutely nothing, but if the LibNDS team ever adds anything more here, it will be future-ready.
When you want the DS to sleep, call systemSleep(). If you don't call systemSleep within 20 frames of receiving a sleep request, the ARM7 will repeatedly send you a sleep request every 20 frames.
My reccomendation for the "Your Code Here" is to just set a flag, and let the normal code handle the request. For example, you could pause game logic, play a sound effect, wait for the sound effect to finish, then enter sleep mode. You can also check if the screen has been opened since you started playing the sound effect, and make it not sleep.
To install the replacement for powerValueHandler, run this:
Code: |
fifoSetValue32Handler(FIFO_PM, MY_powerValueHandler, 0);
|
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#167245 - Echo49 - Fri Mar 06, 2009 10:13 pm
Thank you, I will be trying that.
On the note of custom handlers, how would I go about modifying the defaultExceptionHandler to dumping the register and stack information not to the screen, but to a file? Is this possible?
#167294 - Echo49 - Sun Mar 08, 2009 10:26 am
OK, I've poked around and found the setExceptionHandler() and the defaultHandler() functions, the latter from which (I think) I can copy most of the dumping code.
I guess the question now is, can I use file operations inside the handler? For example, calling fopen()/fclose() and replacing the iprintf() with fprintf()?
#168571 - FluBBa - Wed May 06, 2009 1:57 pm
Sorry for hijacking this old thread but it was the only one I found that had anything to do with systemSleep.
What should I do if I want to put the NDS to sleep without it being closed?
I tried to call systemSleep from the ARM9 but it didn't work at all, on HW the screen flashes once and on No$GBA the sound just stops working.
So is there any message I should send to the ARM7 or how can this be done?
(I want to have a autosleep timeout, waking up by either closing/opening the lid or a key combo).
_________________
I probably suck, my not is a programmer.
#168572 - elhobbs - Wed May 06, 2009 3:25 pm
FluBBa wrote: |
Sorry for hijacking this old thread but it was the only one I found that had anything to do with systemSleep.
What should I do if I want to put the NDS to sleep without it being closed?
I tried to call systemSleep from the ARM9 but it didn't work at all, on HW the screen flashes once and on No$GBA the sound just stops working.
So is there any message I should send to the ARM7 or how can this be done?
(I want to have a autosleep timeout, waking up by either closing/opening the lid or a key combo). |
the systemSleep functionality is hardcoded to wake on IRQ_LID. I am not sure if this will prevent it from sleeping since the lid is never closed. you could try a custom handler on the arm7 that wakes on IRQ_KEYS instead.
you may already know this (and it does not appear to be related to your current issue) but sleeping on lid close is not on by default. it needs to be enabled by sending PM_REQ_SLEEP_ENABLE to the arm7.
#168573 - FluBBa - Wed May 06, 2009 4:33 pm
Hmmm, I can see a potential problem about the lid open/close checking, maybe I have to skip that function.
About sleeping when closing the lid, I haven't touched anything about the ARM7 yet but it works as is and I was hoping I wouldn't need to code anything specific for the ARM7 now that libnds is starting to support most common tasks.
_________________
I probably suck, my not is a programmer.
#168574 - elhobbs - Wed May 06, 2009 5:09 pm
if you are trying to save battery - maybe just turn off the backlights instead.
#168576 - FluBBa - Wed May 06, 2009 9:40 pm
I guess I just do something like that instead.
_________________
I probably suck, my not is a programmer.
#168577 - Dwedit - Wed May 06, 2009 11:06 pm
deleteme
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#168584 - a128 - Thu May 07, 2009 5:39 pm
Powermanagment was all done very well here
http://meraman.dip.jp/index.php?NDS_POWER_ENG
_________________
"Hey! It compiles! Ship it!"
#169117 - Echo49 - Sat Jun 20, 2009 12:52 pm
Reviving this...
At the moment, if defaultExceptionHandler is used to dump register information on a crash, No$gba doesn't display the text. There's a problem with my code that somehow only seems to crash No$gba, but not hardware.
Since Martin's disappeared, I can't grab a debug copy of No$gba. Is there anything I can do to find out the state of the emulator when it crashes? Does nocashMessage() only work with the debugger version of No$gba?
Also, I think the crash only started happening after I updated to r26. I compiled using r26 an older version of my game which I know worked fine on No$gba when compiled with r25, which crashed in the same manner.