diff --git a/source/common/hid.c b/source/common/hid.c index ae753a5..d5e9414 100644 --- a/source/common/hid.c +++ b/source/common/hid.c @@ -5,11 +5,15 @@ u32 InputWait() { static u64 delay = 0; u32 pad_state_old = HID_STATE; + u32 cart_state_old = CART_STATE; delay = (delay) ? 72 : 128; timer_start(); while (true) { u32 pad_state = HID_STATE; if (!(pad_state & BUTTON_ANY)) { // no buttons pressed + u32 cart_state = CART_STATE; + if (cart_state != cart_state_old) + return cart_state ? CART_INSERT : CART_EJECT; u32 special_key = i2cReadRegister(I2C_DEV_MCU, 0x10); if (special_key == 0x01) return pad_state | BUTTON_POWER; diff --git a/source/common/hid.h b/source/common/hid.h index 57a0ca5..2825ad7 100644 --- a/source/common/hid.h +++ b/source/common/hid.h @@ -3,6 +3,7 @@ #include "common.h" #define HID_STATE (~(*(volatile u32*)0x10146000) & BUTTON_ANY) +#define CART_STATE (~(*(volatile u8*)0x10000010) & 0x1) #define BUTTON_A (1 << 0) @@ -20,9 +21,11 @@ #define BUTTON_ANY 0x00000FFF #define BUTTON_ARROW (BUTTON_RIGHT|BUTTON_LEFT|BUTTON_UP|BUTTON_DOWN) -// special buttons +// special buttons / cart handling #define BUTTON_POWER (1 << 12) #define BUTTON_HOME (1 << 13) +#define CART_INSERT (1 << 14) +#define CART_EJECT (1 << 15) u32 InputWait(); bool CheckButton(u32 button); diff --git a/source/godmode.c b/source/godmode.c index 2098435..ff5649d 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -1146,9 +1146,9 @@ u32 GodMode() { InitEmuNandBase(); InitExtFS(); GetDirContents(current_dir, current_path); - if (cursor >= current_dir->n_entries) - cursor = current_dir->n_entries - 1; } + } else if ((pad_state & (CART_INSERT|CART_EJECT)) && (curr_drvtype & DRV_CART)) { + GetDirContents(current_dir, current_path); // refresh cart dir contents } }