Conversation
|
Updated the approach. The button injection (sleepButtons config) is gone. After digging into gbatek, KEYCNT (4000132h) is strictly an exit/wake mechanism for Stop mode. No unpatched GBA game enters sleep through a button combo - games that support sleep do it through their own menu code. The only ROMs that respond to a button combo are patched with gba-sleephack, which injects assembly to poll for the combo in the VBlank handler. Injecting buttons on lid close also caused input bleed into gameplay (the shoulder buttons would register as real presses before the game had a chance to enter sleep). So the new version just does 3DS-side sleep on lid close: mute audio, stop frame capture, turn off backlights, breathing LED. On lid open it restores everything and force-wakes the GBA in case it was in Stop mode. The colorOverride and defaultSave u16->u8 changes are still in there since they were part of the original commit. |
Implements sleep-on-lid-close from profi200#282: mutes audio, stops LGYCAP capture, turns off backlight and sets breathing LED while lid is closed, then restores everything (including a force-wake of the GBA hardware) when the lid reopens. Also adds colorOverride config option from the same PR. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
So this mimics the AGB_FIRM behavior except for triggering the sleep button combo, right? Cool! |
|
I cherry picked both commits into my feature/stretch branch and compiled it again. |
Ah i spoke too soon it seems. As we all know this game has one lengthy intro. If you close the lid right after it started and open it again some couple of minutes later you'll notice the device wasn't actually asleep. The sound is muted and the screen is off, but the game keeps running. Isn't it supposed to trigger SWI 03h (GBA) - Stop? @tasken |
Inject a configurable GBA button combo on lid close to trigger sleep in games that support it. Mute audio, stop frame capture, and dim the power LED while the lid is closed. Add colorOverride and sleepButtons config options. Change defaultSave from u16 to u8.
GBA KEYCNT is exit-only — no unpatched game enters sleep via button combo, so injecting buttons on lid close is unnecessary and causes input bleed into gameplay. Remove sleepButtons config option and simplify handleLidSleep to only manage 3DS-side sleep state.
handleLidSleep() was unconditionally poking REG_HID_PADCNT and the LGY sleep-ack bit on every lid reopen, duplicating what lgySleepIsr() already does correctly and only when a real GBA Stop-mode wake fires. Doing it here too could clobber the wake condition the ISR just armed, or force-wake a game that's still legitimately asleep.
c9c97d2 to
791941f
Compare
The GBA keeps running the whole time the lid is closed - there's no way to pause it from the 3DS side, so this was never real sleep, just display/audio muted. Back up the save at the moment the lid closes so a power loss while it's closed doesn't lose progress, the same way the normal shutdown path already does.
Couldn't trigger Tried to actually fix this. Real 3DS-side sleep ( Leaving this cosmetic (display/audio off, GBA keeps running), added a save backup on lid-close so nothing's lost. Open to someone else solving the real fix. |
|
As far as I am aware, the SP has no hinge sensor. At least, from what I remember playing mine, games are entirely unaware of the state of it and will happily continue playing even if it's closed |
^This. |
|
So given that GBA |
|
So here's my testing so far: Quick overview
This is pretty much in line with findings previously described on problemkaputt.de and 3dbrew.org. |
|
Okay, so i've spent a lot of time with this. My first approach was to automatically apply asdolo's sleep-hack on any loaded rom in memory directly in open_agb_firm. That worked, but just like his original gba-sleep-patcher-tool it didn't work with all roms (Mario Kart Super Circuit, Aladdin, Metal Slug Advance - to name but a few). I'm happy to report there's a better way. In fact there IS a way to trigger
I'll add a tech reference later. Please check this out, build the firmware yourself as usual, test it and tell me what you think: |
|
oh boy as a rural simpleton i have been looking forward to this feature! where can i download it? |
|
wait how do i build it im a rural simpleton i would love to test it but im horrid with code and compiling stuff sorry
|
I got you boo: |
Holyshoot! |
|
wait i was playing dkc1 and it didnt sleep,.. |
|
That'd be weird, but i'll check as well lol |
i just replaced the firmware with your version so maby i need to like regenerate the backup firmwares? i dont know i hope i did it right |
|
Works for me with the debug build. I didn't actually test the release build (as they should be the same). I'll check that as well. WDYM backup firmware? You just need to hold the START button as you press the 3DS power button and then select whichever open_agb_firm.firm you put in /luma/payloads/. |
im using fastboot so when i press the l button when booting i start in gba mode. i also have firmware backups that shouldent matter but they are for if one of my firmware's breaks the backup should still work. |
|
i replaced the openagbfirm.firm with your version then renamed your version to openagbfirm.firm |
|
So both builds work for me. Could you test this without fastboot? |
|
Perfect! Your log shows that PDN sleep was in fact triggered correctly. If you did a longer sleep test with this you'd see a lot less battery drain. Furthermore your log shows that the New 3DS XL uses the same register values as my New 3DS. So your test confirmed this to be fully working on the New 3DS XL. Thanks mate! |
|
Okay, so i've been working on this a lot and this is my final build for now. Features Added Compared with
|
|
Here is my test results, they look great! I changed my EDIT: Just for good measure, I also kept my 3DS in sleep for 10 mins this test |
|
hihihi! i just got back from camping! so sorry for the delay! it was wonderfull tho. ill test as soon as i can. but in 2 days im going camping again.. so i will be unavailable for a week! i do want to know tho, what is the difference from the sleep mode where the screen and audio shuts off, compared to the 3ds / gba sleep mode? |
Great! It works just like it should. Also your latest power state dump shows that i got rid of all the ARM9 logging. There isn't anything to optimize there power wise anyway.
My fork of open_gba_firm features real SWI 03h GBA (ARM7) sleep. That was tricky to do. The firmware loads the rom into memory and then dynamically injects an IRQ sleep handler into the game (well the memory image, not the actual rom) that just sits there and waits for a signal (closing the lid, or L+SELECT) to initiate the GBA low power SWI 03h sleep mode. This works with all games. You don't need to sleephack patch your roms anymore. So we got GBA sleeping now, great. But it's still a (New)3DS console and that's ARM11. It's got its own low power sleep mode. That's called PDN sleep. My fork also does that. So effectively this is happening: So as result we got ARM7 (GBA) and ARM11 (3DS) sleeping and that saves a lot of juice. If you are looking for more info about how it all works you can find that here with all the code and firmware releases. |
|
so, compared to your v1 sleep code, and to no sleep code, whats the battery like? |
|
I'm not really here for testing, just passing through and helping out with what I know. 3DS is out of commission currently |
|
ok just updated to the new firmware, and i can tell it works because it takes it a few halfs of a second to kick back on the gpu. if the 3ds on sleep mode lasts like 3(?) days, and the gba processor in sleep mode probably has a very minimal power drain, so this should add up to like 2~3 days in sleep mode! wowie! |
|
good news! so i was playing warioland 4 gba, fun game! but then i got real tired. so i closed the lid and went to bed. but this time, blue! it was still on BLUE!! WOW! thats epic! YAY! |
While GPL3 does allow monetization in general, i'm a huge advocate for free software. Working on this has been good fun (so far) for the most part and i learned a whole lot. Arm assembly isn't exactly my strong suit 😅
Awesome, mate! Enjoy 😄 PS: there's a release build on my github page that doesn't show all the debug stuff and keeps the second screen shut off. |
Hey, i could issue a PR no problem. It would qualify to be automatically merged. |
|
should i then close this one in favor of a new one you make @dleicht? |
|
@tasken we could do that. I will reference #282 from my PR, because i used some of your code 👍 But there's still a lot to do before i will issue a PR. Right now O2DS is broken, because i thought it's a good idea to switch the bottom screen backlight off as soon as the game starts. Unfortunately that affects both screens on the O2DS. |
It affects both screens because both screens is one screen. The o2DS only has one physical screen, it's just separated in software and hidden behind the shell |
Oh yeah, i know, but thanks anyway. It's already fixed in my local dev branch. I'm fixin a couple of other issues and then commit the next release. |
|
Yeah forget about that. I messed it up. |
|
ooh i'm excited for this |
|
why does the wierless light stay on? |
OAF shouldn't touch wifi. If you boot OAF as a luma payload then WIFI should stay off. I used the power led for debugging in the debug build to figure out different stages of errors during arm11 core1 sleep development. But i never messed with wifi. I had a couple of MCU debug probes write into already occupied registers and that may have caused weird side effects, but most probably nothing wifi related. On what hardware are you running OAF and how do you boot it? |
|
im using quickboot i think it's called, and im launching it from the forwarder app dohicky! |
|
|
|
Safeguards aside the dynamic sleep handler patching is whacky at best. |
|
woa wacky ram time? |
|
Nope. save original 252 bytes of rom image space we wouldn't need to find a safe place to store the handler as we'd restore the og data afterwards. |
|
OMG! 0x0C stmdb sp!, {r2, r12}
0x10 swi 0x03
0x14 ldmia sp!, {r2, r12}I was struggling with finding a proper place to store the 252 bytes sleep handler. Storing it in the rom image does work, but we can't be sure it doesn't affect the game. Storing it in game memory yields the same basic problem. We don't need a sleep handler on the GBA side of things. All we need is proper SWI 03h. So, why is this better:
open_agb_firm treats the O2DS sleep switch exactly the same as the 3DS lid, so in theory this should work on the O2DS. Please test this release build again on your hardware and let me know. If this works on all platforms i'll have a PR ready in no time: |
|
wowwowwow! |
|
closing in favor of #295 |
What changed
Closing the 3DS lid now enters a proper sleep state: audio is muted, frame capture stops, backlights turn off, and the power LED switches to the breathing pattern. Opening the lid restores everything. If the GBA happened to enter Stop mode while the lid was closed, it gets force-woken on lid open.
No config options needed. Works with all games.
Also added
colorOverrideconfig option (same pattern assaveOverride) and changeddefaultSavefrom u16 to u8 since it only needs values 0-15.