Autodetect cart inserts / ejects

This commit is contained in:
d0k3 2017-01-16 01:56:04 +01:00
parent b00fb89164
commit eae783d6c3
3 changed files with 10 additions and 3 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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
}
}