Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/arm11/open_agb_firm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern "C"
#endif

Result oafParseConfigEarly(void);
bool shouldExit(u32 extraKeys);
void changeBacklight(s16 amount);
Result oafInitAndRun(void);
void oafUpdate(void);
Expand Down
3 changes: 2 additions & 1 deletion source/arm11/filebrowser.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "error_codes.h"
#include "fs.h"
#include "util.h"
#include "arm11/open_agb_firm.h"
#include "arm11/drivers/hid.h"
#include "arm11/fmt.h"
#include "drivers/gfx.h"
Expand Down Expand Up @@ -167,7 +168,7 @@ Result browseFiles(const char *const basePath, char selected[512])
GFX_waitForVBlank0();

hidScanInput();
if(hidGetExtraKeys(0) & (KEY_POWER_HELD | KEY_POWER)) goto end;
if(shouldExit(hidGetExtraKeys(0))) goto end;
kDown = hidKeysDown();
} while(kDown == 0);

Expand Down
2 changes: 1 addition & 1 deletion source/arm11/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main(void)
while(1)
{
hidScanInput();
if(hidGetExtraKeys(0) & (KEY_POWER_HELD | KEY_POWER)) break;
if(shouldExit(hidGetExtraKeys(0))) break;

oafUpdate();
}
Expand Down
7 changes: 7 additions & 0 deletions source/arm11/open_agb_firm.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ static Result loadGbaRom(const char *const path, u32 *const romSizeOut)
return res;
}

bool shouldExit(u32 extraKeys)
{
// Exit if power button is held or low battery alarm fires for 5% or lower
return (extraKeys & (KEY_POWER_HELD | KEY_POWER)) ||
((extraKeys & KEY_LOW_BATTERY) && (MCU_getBatteryLevel() <= 6));
}

void changeBacklight(s16 amount)
{
u8 min, max;
Expand Down
5 changes: 3 additions & 2 deletions source/arm11/patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "types.h"
#include "oaf_error_codes.h"
#include "util.h"
#include "arm11/open_agb_firm.h"
#include "arm11/drivers/hid.h"
#ifndef NDEBUG
#include "arm11/drivers/mcu.h"
Expand Down Expand Up @@ -323,7 +324,7 @@ Result patchRom(const char *const gamePath, u32 *romSize) {
while(1){
hidScanInput();
if(hidKeysHeld() == (KEY_Y | KEY_DUP) && hidKeysDown() != 0) break;
if(hidGetExtraKeys(0) & (KEY_POWER_HELD | KEY_POWER)) power_off();
if(shouldExit(hidGetExtraKeys(0))) power_off();
}
}

Expand All @@ -350,7 +351,7 @@ Result patchRom(const char *const gamePath, u32 *romSize) {
while(1){
hidScanInput();
if(hidKeysHeld() == (KEY_Y | KEY_DUP) && hidKeysDown() != 0) break;
if(hidGetExtraKeys(0) & (KEY_POWER_HELD | KEY_POWER)) power_off();
if(shouldExit(hidGetExtraKeys(0))) power_off();
}
}

Expand Down
3 changes: 2 additions & 1 deletion source/arm11/save_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <string.h>
#include "types.h"
#include "arm11/open_agb_firm.h"
#include "arm11/save_type.h"
#include "drivers/lgy_common.h"
#include "arm11/fmt.h"
Expand Down Expand Up @@ -255,7 +256,7 @@ u16 getSaveType(const OafConfig *const cfg, const u32 romSize, const char *const
GFX_waitForVBlank0();

hidScanInput();
if(hidGetExtraKeys(0) & (KEY_POWER_HELD | KEY_POWER)) goto end;
if(shouldExit(hidGetExtraKeys(0))) goto end;
kDown = hidKeysDown();
} while(kDown == 0);

Expand Down