Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(WIP) Improved Sleep Mode #42

Open
wants to merge 1 commit into
base: kernel_experiments
Choose a base branch
from

Conversation

shinyquagsire23
Copy link

Not expecting this to be merged per-se but I figured it would be better to have the PR for discussion/experiments.

Additions:

  • Basic sleep support
    • LCD backlight is turned off when lid is closed, and turned back on when it is opened.
    • Codec is muted when lid is closed and unmuted when lid is opened.
    • Backlight and codec are also adjusted when a GBA game suspends and a sleep IRQ is sent.
  • Extended sleep support/Sleep-anywhere
    • When the lid is closed, arm11 will signal to arm9 to try and force the ARM7 into a suspended state.
    • Using the 0x20 byte bootrom overlay, ARM7 execution can be hijacked by trapping all vectors to infinite loop and waiting for a SWI call or IRQ. The ARM9 can then manipulate program flow within the overlay to set HALTCNT and suspend the ARM7 properly.
    • End result: GBA games are fully paused and suspended to low-power mode when the lid is closed.

Current Regressions:

  • BIOS/logo boot is forced for now, due to the overlay being actively used for sleep-anywhere.
  • Something is asserting on shutdown after the LCD backlight is turned off? Not sure if this affects saving or not.

Other notes:

  • ARM7 hijacking might allow for savestates similar to how the EZ Flash Omega does them (dump all memory+registers to 0x0E000000, restore later). The only caveat iirc is that some IO is write-only.
  • If the lid is closed during an IRQ, it will not suspend to low-power mode currently.
  • The LCD and GPU are still active while sleeping.

If anyone wants to test the changes I have a build here.

@profi200
Copy link
Owner

Looks interesting.

Yeah, the mute and just turning off the backlight is not ideal. Real sleep mode is more involved since basically every GPU block needs to be deinitialized and VRAM must also be powered off. Then PDN trickery needs to be implemented (a hardware sleep mode). I have not bothered with real sleep mode yet because gsp is a bitch to understand. You can use CODEC_deinit() which is basically sleep and power off in one. CODEC_wakeup() brings it right back up.

And yeah, i have played with the BIOS vector overlay before and thought about ways to use it. I'm worrying a bit about accuracy with this approach. A good while ago i tested a different way. We can transfer data via ARM7 KEYCNT and the other way around with button override. From ARM7 to ARM11 i archived over 950 KiB/s with hand crafted asm. I expect less than half in the other direction because ARM7 needs to notify ARM11 for every received byte. The other way around ARM7 is so much slower that we can pump data out without needing to care about ARM11. This would effectively make save states and the like possible. Maybe also wireless adapter and gyro "emulation" by patching games to use this communication channel. I call this "lgylink".

Also yeah, there are certain freezes here and there if the timing is off. Might be related to LgyFb (FIFO overrun?). This can also happen when taking screenshots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants