diff --git a/include/arm11/open_agb_firm.h b/include/arm11/open_agb_firm.h index 653a3e7..919e770 100644 --- a/include/arm11/open_agb_firm.h +++ b/include/arm11/open_agb_firm.h @@ -32,6 +32,8 @@ void changeBacklight(s16 amount); Result oafInitAndRun(void); void oafUpdate(void); void oafFinish(void); +void oafSleep(void); +void oafWakeup(void); #ifdef __cplusplus } // extern "C" diff --git a/libraries/libn3ds b/libraries/libn3ds index 083c8ff..15f7b8c 160000 --- a/libraries/libn3ds +++ b/libraries/libn3ds @@ -1 +1 @@ -Subproject commit 083c8ffa3f56a49802fa74b6afe45a96820f0439 +Subproject commit 15f7b8c5f33695f8f1610b007f10630293081592 diff --git a/source/arm11/main.c b/source/arm11/main.c index 8f1243d..9a3cc50 100644 --- a/source/arm11/main.c +++ b/source/arm11/main.c @@ -42,6 +42,8 @@ int main(void) { hidScanInput(); if(hidGetExtraKeys(0) & (KEY_POWER_HELD | KEY_POWER)) break; + if(hidGetExtraKeys(0) & KEY_SHELL) oafSleep(); + if(!(hidGetExtraKeys(0) & KEY_SHELL)) oafWakeup(); oafUpdate(); } diff --git a/source/arm11/open_agb_firm.c b/source/arm11/open_agb_firm.c index 6144da7..066925a 100644 --- a/source/arm11/open_agb_firm.c +++ b/source/arm11/open_agb_firm.c @@ -43,6 +43,7 @@ #include "arm11/patch.h" #include "arm11/bitmap.h" +#include "arm11/drivers/interrupt.h" #define OAF_WORK_DIR "sdmc:/3ds/open_agb_firm" #define OAF_SAVE_DIR "saves" // Relative to work dir. @@ -94,6 +95,7 @@ static OafConfig g_oafConfig = 14 // defaultSave }; static KHandle g_frameReadyEvent = 0; +static bool g_isSleeping = false; @@ -616,6 +618,7 @@ Result oafInitAndRun(void) void oafUpdate(void) { + if (g_isSleeping) return; const u32 *const maps = g_oafConfig.buttonMaps; const u32 kHeld = hidKeysHeld(); u16 pressed = 0; @@ -638,4 +641,31 @@ void oafFinish(void) LGYCAP_deinit(LGYCAP_DEV_TOP); g_frameReadyEvent = 0; LGY11_deinit(); +} + +void oafSleep(void) +{ + if(g_isSleeping) return; + LGYCAP_stop(LGYCAP_DEV_TOP); + IRQ_disable(IRQ_CDMA_EVENT0); + clearEvent(g_frameReadyEvent); + + CODEC_setVolumeOverride(-128); + GFX_sleep(); + g_isSleeping = true; +} + +void oafWakeup(void) +{ + if (!g_isSleeping) return; + GFX_sleepAwake(); + // VRAM is cleared upon waking up + // need to readjust screen after waking up + adjustGammaTableForGba(); + + LGYCAP_start(LGYCAP_DEV_TOP); + IRQ_enable(IRQ_CDMA_EVENT0); + CODEC_setVolumeOverride(127); + g_isSleeping = false; + } \ No newline at end of file