hid: Updated structs.

This commit is contained in:
yellows8 2020-11-20 16:37:20 -05:00 committed by fincs
parent 967a5054a3
commit 902af6cce0
No known key found for this signature in database
GPG Key ID: 62C7609ADA219C60
2 changed files with 171 additions and 156 deletions

View File

@ -451,19 +451,13 @@ typedef struct SixAxisSensorValues {
// End enums and output structs // End enums and output structs
/// HidCommonStateHeader /// HidCommonLifoHeader
typedef struct HidCommonStateHeader { typedef struct HidCommonLifoHeader {
u64 timestamp_ticks; u64 sampling_number;
u64 total_entries; u64 buffer_count;
u64 latest_entry; u64 tail;
u64 max_entry; u64 count;
} HidCommonStateHeader; } HidCommonLifoHeader;
/// HidCommonStateEntry
typedef struct HidCommonStateEntry {
u64 timestamp;
u8 state[];
} HidCommonStateEntry;
// Begin HidTouchScreen // Begin HidTouchScreen
@ -482,7 +476,7 @@ typedef struct HidTouchState {
/// HidTouchScreenState /// HidTouchScreenState
typedef struct HidTouchScreenState { typedef struct HidTouchScreenState {
u64 timestamp; u64 sampling_number;
s32 count; s32 count;
u32 reserved; u32 reserved;
HidTouchState touches[16]; HidTouchState touches[16];
@ -490,24 +484,29 @@ typedef struct HidTouchScreenState {
/// HidTouchScreenStateAtomicStorage /// HidTouchScreenStateAtomicStorage
typedef struct HidTouchScreenStateAtomicStorage { typedef struct HidTouchScreenStateAtomicStorage {
u64 timestamp; u64 sampling_number;
HidTouchScreenState state; HidTouchScreenState state;
} HidTouchScreenStateAtomicStorage; } HidTouchScreenStateAtomicStorage;
/// HidTouchScreenLifo /// HidTouchScreenLifo
typedef struct HidTouchScreenLifo { typedef struct HidTouchScreenLifo {
HidCommonStateHeader header; HidCommonLifoHeader header;
HidTouchScreenStateAtomicStorage entries[17]; HidTouchScreenStateAtomicStorage storage[17];
u8 padding[0x3c8];
} HidTouchScreenLifo; } HidTouchScreenLifo;
/// HidTouchScreenSharedMemoryFormat
typedef struct HidTouchScreenSharedMemoryFormat {
HidTouchScreenLifo lifo;
u8 padding[0x3c8];
} HidTouchScreenSharedMemoryFormat;
// End HidTouchScreen // End HidTouchScreen
// Begin HidMouse // Begin HidMouse
/// HidMouseState /// HidMouseState
typedef struct HidMouseState { typedef struct HidMouseState {
u64 timestamp; u64 sampling_number;
MousePosition position; MousePosition position;
u32 buttons; u32 buttons;
u32 attributes; u32 attributes;
@ -515,49 +514,58 @@ typedef struct HidMouseState {
/// HidMouseStateAtomicStorage /// HidMouseStateAtomicStorage
typedef struct HidMouseStateAtomicStorage { typedef struct HidMouseStateAtomicStorage {
u64 timestamp; u64 sampling_number;
HidMouseState state; HidMouseState state;
} HidMouseStateAtomicStorage; } HidMouseStateAtomicStorage;
/// HidMouseLifo /// HidMouseLifo
typedef struct HidMouseLifo { typedef struct HidMouseLifo {
HidCommonStateHeader header; HidCommonLifoHeader header;
HidMouseStateAtomicStorage entries[17]; HidMouseStateAtomicStorage storage[17];
u8 padding[0xB0];
} HidMouseLifo; } HidMouseLifo;
/// HidMouseSharedMemoryFormat
typedef struct HidMouseSharedMemoryFormat {
HidMouseLifo lifo;
u8 padding[0xB0];
} HidMouseSharedMemoryFormat;
// End HidMouse // End HidMouse
// Begin HidKeyboard // Begin HidKeyboard
/// HidKeyboardState /// HidKeyboardState
typedef struct HidKeyboardState { typedef struct HidKeyboardState {
u64 timestamp; u64 sampling_number;
u64 modifier; u64 modifier;
u32 keys[8]; u32 keys[8];
} HidKeyboardState; } HidKeyboardState;
/// HidKeyboardStateAtomicStorage /// HidKeyboardStateAtomicStorage
typedef struct HidKeyboardStateAtomicStorage { typedef struct HidKeyboardStateAtomicStorage {
u64 timestamp; u64 sampling_number;
HidKeyboardState state; HidKeyboardState state;
} HidKeyboardStateAtomicStorage; } HidKeyboardStateAtomicStorage;
/// HidKeyboardLifo /// HidKeyboardLifo
typedef struct HidKeyboardLifo { typedef struct HidKeyboardLifo {
HidCommonStateHeader header; HidCommonLifoHeader header;
HidKeyboardStateAtomicStorage entries[17]; HidKeyboardStateAtomicStorage storage[17];
u8 padding[0x28];
} HidKeyboardLifo; } HidKeyboardLifo;
/// HidKeyboardSharedMemoryFormat
typedef struct HidKeyboardSharedMemoryFormat {
HidKeyboardLifo lifo;
u8 padding[0x28];
} HidKeyboardSharedMemoryFormat;
// End HidKeyboard // End HidKeyboard
// Begin HidNpad // Begin HidNpad
/// Npad colors. /// Npad colors.
/// Color fields are zero when not set. /// Color fields are zero when not set.
typedef struct HidNpadControllerColor typedef struct HidNpadControllerColor {
{
u32 color_body; ///< RGBA Body Color u32 color_body; ///< RGBA Body Color
u32 color_buttons; ///< RGBA Buttons Color u32 color_buttons; ///< RGBA Buttons Color
} HidNpadControllerColor; } HidNpadControllerColor;
@ -573,110 +581,117 @@ typedef struct HidNpadStateHeader {
HidNpadControllerColor right_colors; HidNpadControllerColor right_colors;
} HidNpadStateHeader; } HidNpadStateHeader;
/// HidNpadStateEntry /// HidNpadCommonState
typedef struct HidNpadStateEntry { typedef struct HidNpadCommonState {
u64 timestamp; u64 sampling_number;
u64 buttons; u64 buttons;
JoystickPosition joysticks[JOYSTICK_NUM_STICKS]; JoystickPosition joysticks[JOYSTICK_NUM_STICKS];
u32 connectionState; u32 attributes;
u32 pad; u32 reserved;
} HidNpadStateEntry; } HidNpadCommonState;
typedef HidNpadStateEntry HidNpadFullKeyState; typedef HidNpadCommonState HidNpadFullKeyState;
typedef HidNpadStateEntry HidNpadHandheldState; typedef HidNpadCommonState HidNpadHandheldState;
typedef HidNpadStateEntry HidNpadJoyDualState; typedef HidNpadCommonState HidNpadJoyDualState;
typedef HidNpadStateEntry HidNpadJoyLeftState; typedef HidNpadCommonState HidNpadJoyLeftState;
typedef HidNpadStateEntry HidNpadJoyRightState; typedef HidNpadCommonState HidNpadJoyRightState;
/// HidNpadGcState /// HidNpadGcState
typedef struct HidNpadGcState { typedef struct HidNpadGcState {
u64 timestamp; u64 sampling_number;
u64 buttons; u64 buttons;
JoystickPosition joysticks[JOYSTICK_NUM_STICKS]; JoystickPosition joysticks[JOYSTICK_NUM_STICKS];
u32 connectionState; u32 attributes;
u32 l_trigger; ///< L analog trigger. Valid range: 0x0-0x7FFF. u32 l_trigger; ///< L analog trigger. Valid range: 0x0-0x7FFF.
u32 r_trigger; ///< R analog trigger. Valid range: 0x0-0x7FFF. u32 r_trigger; ///< R analog trigger. Valid range: 0x0-0x7FFF.
u32 pad; u32 pad;
} HidNpadGcState; } HidNpadGcState;
typedef HidNpadStateEntry HidNpadPalmaState; typedef HidNpadCommonState HidNpadPalmaState;
/// HidNpadLarkState /// HidNpadLarkState
typedef struct HidNpadLarkState { typedef struct HidNpadLarkState {
u64 timestamp; u64 sampling_number;
u64 buttons; u64 buttons;
JoystickPosition joysticks[JOYSTICK_NUM_STICKS]; ///< Joysticks state are always zero. JoystickPosition joysticks[JOYSTICK_NUM_STICKS]; ///< Joysticks state are always zero.
u32 connectionState; u32 attributes;
u32 unk; u32 lark_type_l_and_main; ///< LarkTypeLAndMain
} HidNpadLarkState; } HidNpadLarkState;
/// HidNpadHandheldLarkState /// HidNpadHandheldLarkState
typedef struct HidNpadHandheldLarkState { typedef struct HidNpadHandheldLarkState {
u64 timestamp; u64 sampling_number;
u64 buttons; u64 buttons;
JoystickPosition joysticks[JOYSTICK_NUM_STICKS]; JoystickPosition joysticks[JOYSTICK_NUM_STICKS];
u32 connectionState; u32 attributes;
u32 unk0; u32 lark_type_l_and_main; ///< LarkTypeLAndMain
u32 unk1; u32 lark_type_r; ///< LarkTypeR
u32 pad; u32 pad;
} HidNpadHandheldLarkState; } HidNpadHandheldLarkState;
/// HidNpadLuciaState /// HidNpadLuciaState
typedef struct HidNpadLuciaState { typedef struct HidNpadLuciaState {
u64 timestamp; u64 sampling_number;
u64 buttons; u64 buttons;
JoystickPosition joysticks[JOYSTICK_NUM_STICKS]; ///< Joysticks state are always zero. JoystickPosition joysticks[JOYSTICK_NUM_STICKS]; ///< Joysticks state are always zero.
u32 connectionState; u32 attributes;
u32 unk; u32 lucia_type; ///< LuciaType
} HidNpadLuciaState; } HidNpadLuciaState;
typedef HidNpadStateEntry HidNpadSystemExtState; typedef HidNpadCommonState HidNpadSystemExtState;
typedef HidNpadStateEntry HidNpadSystemState; ///< Joysticks state are always zero. Only the following button bits are available: KEY_A, KEY_B, KEY_X, KEY_Y, KEY_DLEFT, KEY_DUP, KEY_DRIGHT, KEY_DDOWN, KEY_L, KEY_R. typedef HidNpadCommonState HidNpadSystemState; ///< Joysticks state are always zero. Only the following button bits are available: KEY_A, KEY_B, KEY_X, KEY_Y, KEY_DLEFT, KEY_DUP, KEY_DRIGHT, KEY_DDOWN, KEY_L, KEY_R.
/// HidControllerInputEntry /// HidNpadCommonStateAtomicStorage
typedef struct HidControllerInputEntry { typedef struct HidNpadCommonStateAtomicStorage {
u64 timestamp; u64 sampling_number;
HidNpadStateEntry state; HidNpadCommonState state;
} HidControllerInputEntry; } HidNpadCommonStateAtomicStorage;
/// HidControllerLayout /// HidNpadCommonLifo
typedef struct HidControllerLayout { typedef struct HidNpadCommonLifo {
HidCommonStateHeader header; HidCommonLifoHeader header;
HidControllerInputEntry entries[17]; HidNpadCommonStateAtomicStorage storage[17];
} HidControllerLayout; } HidNpadCommonLifo;
/// HidNpadGcTriggerState /// HidNpadGcTriggerState
typedef struct HidNpadGcTriggerState { typedef struct HidNpadGcTriggerState {
u64 timestamp; u64 sampling_number;
u32 l_trigger; u32 l_trigger;
u32 r_trigger; u32 r_trigger;
} HidNpadGcTriggerState; } HidNpadGcTriggerState;
/// HidNpadGcTriggerStateEntry /// HidNpadGcTriggerStateAtomicStorage
typedef struct HidNpadGcTriggerStateEntry { typedef struct HidNpadGcTriggerStateAtomicStorage {
u64 timestamp; u64 sampling_number;
HidNpadGcTriggerState state; HidNpadGcTriggerState state;
} HidNpadGcTriggerStateEntry; } HidNpadGcTriggerStateAtomicStorage;
/// HidNpadGcTriggerLifo
typedef struct HidNpadGcTriggerLifo {
HidCommonLifoHeader header;
HidNpadGcTriggerStateAtomicStorage storage[17];
} HidNpadGcTriggerLifo;
/// HidSixAxisSensorState /// HidSixAxisSensorState
typedef struct HidSixAxisSensorState { typedef struct HidSixAxisSensorState {
u64 unk_1; u64 delta_time;
u64 timestamp; u64 sampling_number;
SixAxisSensorValues values; SixAxisSensorValues values;
u64 unk_3; u32 attributes;
u32 reserved;
} HidSixAxisSensorState; } HidSixAxisSensorState;
/// HidNpadSixAxisSensorState /// HidSixAxisSensorStateAtomicStorage
typedef struct HidNpadSixAxisSensorState { typedef struct HidSixAxisSensorStateAtomicStorage {
u64 timestamp; u64 sampling_number;
HidSixAxisSensorState state; HidSixAxisSensorState state;
} HidNpadSixAxisSensorState; } HidSixAxisSensorStateAtomicStorage;
/// HidControllerSixAxisLayout /// HidNpadSixAxisSensorLifo
typedef struct HidControllerSixAxisLayout { typedef struct HidNpadSixAxisSensorLifo {
HidCommonStateHeader header; HidCommonLifoHeader header;
HidNpadSixAxisSensorState entries[17]; HidSixAxisSensorStateAtomicStorage storage[17];
} HidControllerSixAxisLayout; } HidNpadSixAxisSensorLifo;
/// NpadSystemProperties /// NpadSystemProperties
typedef struct { typedef struct {
@ -712,28 +727,28 @@ typedef struct {
/// HidNfcXcdDeviceHandleState /// HidNfcXcdDeviceHandleState
typedef struct HidNfcXcdDeviceHandleState { typedef struct HidNfcXcdDeviceHandleState {
u64 handle; u64 handle;
u8 flag0; u8 is_available;
u8 flag1; u8 is_activated;
u8 pad[6]; u8 reserved[6];
u64 timestamp; u64 sampling_number;
} HidNfcXcdDeviceHandleState; } HidNfcXcdDeviceHandleState;
/// HidNfcXcdDeviceHandleStateEntry /// HidNfcXcdDeviceHandleStateEntry
typedef struct HidNfcXcdDeviceHandleStateEntry { typedef struct HidNfcXcdDeviceHandleStateEntry {
u64 timestamp; u64 sampling_number;
HidNfcXcdDeviceHandleState state; HidNfcXcdDeviceHandleState state;
} HidNfcXcdDeviceHandleStateEntry; } HidNfcXcdDeviceHandleStateEntry;
/// HidNpad /// HidNpad
typedef struct HidNpad { typedef struct HidNpad {
HidNpadStateHeader header; HidNpadStateHeader header;
HidControllerLayout layouts[7]; HidNpadCommonLifo layouts[7];
HidControllerSixAxisLayout sixaxis[6]; HidNpadSixAxisSensorLifo sixaxis[6];
u32 deviceType; u32 device_type;
u32 pad; u32 reserved;
HidNpadSystemProperties system_properties; HidNpadSystemProperties system_properties;
HidNpadSystemButtonProperties system_button_properties; HidNpadSystemButtonProperties system_button_properties;
u32 batteryCharge[3]; u32 battery_level[3];
union { union {
struct { // [1.0.0-3.0.2] struct { // [1.0.0-3.0.2]
u8 nfc_xcd_device_handle_header[0x20]; u8 nfc_xcd_device_handle_header[0x20];
@ -749,19 +764,19 @@ typedef struct HidNpad {
}; };
u8 mutex[0x8]; u8 mutex[0x8];
u8 unk_x4210[0x18]; u8 unk_x4210[0x18];
HidCommonStateHeader npad_gc_trigger_header; HidNpadGcTriggerLifo gc_trigger_lifo;
HidNpadGcTriggerStateEntry npad_gc_trigger_state[17]; u32 lark_type_l_and_main; ///< LarkTypeLAndMain
u32 unk_x43E0; u32 lark_type_r; ///< LarkTypeR
u32 unk_x43E4; u32 lucia_type; ///< LuciaType
u32 unk_x43E8; u32 unk_x43EC;
u8 unk_x43EC[0xC14]; u8 unk_x43F0[0xC10];
} HidNpad; } HidNpad;
// End HidNpad // End HidNpad
/// HidConsoleSixAxisSensor /// HidConsoleSixAxisSensor
typedef struct { typedef struct {
u64 timestamp; ///< Timestamp in samples u64 sampling_number; ///< Timestamp in samples
u8 is_at_rest; ///< IsSevenSixAxisSensorAtRest u8 is_at_rest; ///< IsSevenSixAxisSensorAtRest
u8 pad[0x3]; u8 pad[0x3];
float verticalization_error; ///< VerticalizationError float verticalization_error; ///< VerticalizationError
@ -772,9 +787,9 @@ typedef struct {
/// HidSharedMemory /// HidSharedMemory
typedef struct HidSharedMemory { typedef struct HidSharedMemory {
u8 debug_pad[0x400]; u8 debug_pad[0x400];
HidTouchScreenLifo touchscreen; HidTouchScreenSharedMemoryFormat touchscreen;
HidMouseLifo mouse; HidMouseSharedMemoryFormat mouse;
HidKeyboardLifo keyboard; HidKeyboardSharedMemoryFormat keyboard;
u8 digitizer[0x1000]; ///< [10.0.0+] Digitizer [1.0.0-9.2.0] BasicXpad u8 digitizer[0x1000]; ///< [10.0.0+] Digitizer [1.0.0-9.2.0] BasicXpad
u8 home_button[0x200]; u8 home_button[0x200];
u8 sleep_button[0x200]; u8 sleep_button[0x200];
@ -790,7 +805,7 @@ typedef struct HidSharedMemory {
/// HidSevenSixAxisSensorState /// HidSevenSixAxisSensorState
typedef struct { typedef struct {
u64 timestamp0; u64 timestamp0;
u64 timestamp1; u64 sampling_number;
u64 unk_x10; u64 unk_x10;
float unk_x18[10]; float unk_x18[10];
@ -798,15 +813,15 @@ typedef struct {
/// HidSevenSixAxisSensorStateEntry /// HidSevenSixAxisSensorStateEntry
typedef struct { typedef struct {
u64 timestamp; u64 sampling_number;
u64 unused; u64 unused;
HidSevenSixAxisSensorState state; HidSevenSixAxisSensorState state;
} HidSevenSixAxisSensorStateEntry; } HidSevenSixAxisSensorStateEntry;
/// HidSevenSixAxisSensorStates /// HidSevenSixAxisSensorStates
typedef struct { typedef struct {
HidCommonStateHeader header; HidCommonLifoHeader header;
HidSevenSixAxisSensorStateEntry entries[0x21]; HidSevenSixAxisSensorStateEntry storage[0x21];
} HidSevenSixAxisSensorStates; } HidSevenSixAxisSensorStates;
/// HidSixAxisSensorHandle /// HidSixAxisSensorHandle

View File

@ -28,7 +28,7 @@ static RwLock g_hidLock;
static HidTouchScreenState g_touchScreenState; static HidTouchScreenState g_touchScreenState;
static HidMouseState g_mouseState; static HidMouseState g_mouseState;
static HidKeyboardState g_keyboardState; static HidKeyboardState g_keyboardState;
static HidNpadStateEntry g_controllerEntries[10]; static HidNpadCommonState g_controllerEntries[10];
static u64 g_mouseOld, g_mouseHeld, g_mouseDown, g_mouseUp; static u64 g_mouseOld, g_mouseHeld, g_mouseDown, g_mouseUp;
static u64 g_keyboardModOld, g_keyboardModHeld, g_keyboardModDown, g_keyboardModUp; static u64 g_keyboardModOld, g_keyboardModHeld, g_keyboardModDown, g_keyboardModUp;
@ -258,7 +258,7 @@ void hidScanInput(void) {
} }
g_controllerP1AutoID = CONTROLLER_HANDHELD; g_controllerP1AutoID = CONTROLLER_HANDHELD;
if (g_controllerEntries[CONTROLLER_PLAYER_1].connectionState & CONTROLLER_STATE_CONNECTED) if (g_controllerEntries[CONTROLLER_PLAYER_1].attributes & CONTROLLER_STATE_CONNECTED)
g_controllerP1AutoID = CONTROLLER_PLAYER_1; g_controllerP1AutoID = CONTROLLER_PLAYER_1;
rwlockWriteUnlock(&g_hidLock); rwlockWriteUnlock(&g_hidLock);
@ -326,7 +326,7 @@ Result hidGetNpadControllerColorSplit(HidNpadIdType id, HidNpadControllerColor *
} }
u32 hidGetNpadDeviceType(HidNpadIdType id) { u32 hidGetNpadDeviceType(HidNpadIdType id) {
return atomic_load_explicit(&_hidGetNpadInternalState(id)->deviceType, memory_order_acquire); return atomic_load_explicit(&_hidGetNpadInternalState(id)->device_type, memory_order_acquire);
} }
void hidGetNpadSystemProperties(HidNpadIdType id, HidNpadSystemProperties *out) { void hidGetNpadSystemProperties(HidNpadIdType id, HidNpadSystemProperties *out) {
@ -338,7 +338,7 @@ void hidGetNpadSystemButtonProperties(HidNpadIdType id, HidNpadSystemButtonPrope
} }
static void _hidGetNpadPowerInfo(HidNpad *npad, HidPowerInfo *info, u32 powerInfo, u32 i) { static void _hidGetNpadPowerInfo(HidNpad *npad, HidPowerInfo *info, u32 powerInfo, u32 i) {
info->batteryCharge = atomic_load_explicit(&npad->batteryCharge[i], memory_order_acquire); info->batteryCharge = atomic_load_explicit(&npad->battery_level[i], memory_order_acquire);
if (info->batteryCharge > 4) info->batteryCharge = 4; // sdknso would Abort when this occurs. if (info->batteryCharge > 4) info->batteryCharge = 4; // sdknso would Abort when this occurs.
info->isCharging = (powerInfo & BIT(i)) != 0; info->isCharging = (powerInfo & BIT(i)) != 0;
@ -372,29 +372,29 @@ u8 hidGetAppletFooterUiTypes(HidNpadIdType id) {
return atomic_load_explicit(&_hidGetNpadInternalState(id)->applet_footer_ui_type, memory_order_acquire); return atomic_load_explicit(&_hidGetNpadInternalState(id)->applet_footer_ui_type, memory_order_acquire);
} }
static size_t _hidGetStates(HidCommonStateHeader *header, void* in_states, size_t max_states, size_t state_offset, size_t sampling_number_offset, void* states, size_t entrysize, size_t count) { static size_t _hidGetStates(HidCommonLifoHeader *header, void* in_states, size_t max_states, size_t state_offset, size_t sampling_number_offset, void* states, size_t entrysize, size_t count) {
s32 total_entries = (s32)atomic_load_explicit(&header->max_entry, memory_order_acquire); s32 total_entries = (s32)atomic_load_explicit(&header->count, memory_order_acquire);
if (total_entries < 0) total_entries = 0; if (total_entries < 0) total_entries = 0;
if (total_entries > count) total_entries = count; if (total_entries > count) total_entries = count;
s32 latest_entry = (s32)atomic_load_explicit(&header->latest_entry, memory_order_acquire); s32 tail = (s32)atomic_load_explicit(&header->tail, memory_order_acquire);
for (s32 i=0; i<total_entries; i++) { for (s32 i=0; i<total_entries; i++) {
s32 entrypos = (((latest_entry + (max_states+1)) - total_entries) + i) % max_states; s32 entrypos = (((tail + (max_states+1)) - total_entries) + i) % max_states;
HidCommonStateEntry *state_entry = (HidCommonStateEntry*)((uintptr_t)in_states + entrypos*(state_offset+entrysize)); void* state_entry = (void*)((uintptr_t)in_states + entrypos*(state_offset+entrysize));
void* out_state = (void*)((uintptr_t)states + (total_entries-i-1)*entrysize); void* out_state = (void*)((uintptr_t)states + (total_entries-i-1)*entrysize);
void* out_state_prev = (void*)((uintptr_t)states + (total_entries-i)*entrysize); void* out_state_prev = (void*)((uintptr_t)states + (total_entries-i)*entrysize);
u64 timestamp0=0, timestamp1=0; u64 sampling_number0=0, sampling_number1=0;
timestamp0 = atomic_load_explicit(&state_entry->timestamp, memory_order_acquire); sampling_number0 = atomic_load_explicit((u64*)state_entry, memory_order_acquire);
memcpy(out_state, (void*)((uintptr_t)state_entry + state_offset), entrysize); memcpy(out_state, (void*)((uintptr_t)state_entry + state_offset), entrysize);
timestamp1 = atomic_load_explicit(&state_entry->timestamp, memory_order_acquire); sampling_number1 = atomic_load_explicit((u64*)state_entry, memory_order_acquire);
if (timestamp0 != timestamp1 || (i>0 && *((u64*)((uintptr_t)out_state+sampling_number_offset)) - *((u64*)((uintptr_t)out_state_prev+sampling_number_offset)) != 1)) { if (sampling_number0 != sampling_number1 || (i>0 && *((u64*)((uintptr_t)out_state+sampling_number_offset)) - *((u64*)((uintptr_t)out_state_prev+sampling_number_offset)) != 1)) {
s32 tmpcount = (s32)atomic_load_explicit(&header->max_entry, memory_order_acquire); s32 tmpcount = (s32)atomic_load_explicit(&header->count, memory_order_acquire);
tmpcount = total_entries < tmpcount ? tmpcount : total_entries; tmpcount = total_entries < tmpcount ? tmpcount : total_entries;
total_entries = tmpcount < count ? tmpcount : count; total_entries = tmpcount < count ? tmpcount : count;
latest_entry = (s32)atomic_load_explicit(&header->latest_entry, memory_order_acquire); tail = (s32)atomic_load_explicit(&header->tail, memory_order_acquire);
i=-1; i=-1;
} }
@ -413,7 +413,7 @@ size_t hidGetTouchScreenStates(HidTouchScreenState *states, size_t count) {
if (sharedmem == NULL) if (sharedmem == NULL)
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized)); diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized));
size_t total = _hidGetStates(&sharedmem->touchscreen.header, sharedmem->touchscreen.entries, 17, offsetof(HidTouchScreenStateAtomicStorage,state), offsetof(HidTouchScreenState,timestamp), states, sizeof(HidTouchScreenState), count); size_t total = _hidGetStates(&sharedmem->touchscreen.lifo.header, sharedmem->touchscreen.lifo.storage, 17, offsetof(HidTouchScreenStateAtomicStorage,state), offsetof(HidTouchScreenState,sampling_number), states, sizeof(HidTouchScreenState), count);
size_t max_touches = sizeof(states[0].touches)/sizeof(states[0].touches[0]); size_t max_touches = sizeof(states[0].touches)/sizeof(states[0].touches[0]);
for (size_t i=0; i<total; i++) { for (size_t i=0; i<total; i++) {
if (states[i].count > max_touches) states[i].count = max_touches; if (states[i].count > max_touches) states[i].count = max_touches;
@ -431,7 +431,7 @@ size_t hidGetMouseStates(HidMouseState *states, size_t count) {
if (sharedmem == NULL) if (sharedmem == NULL)
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized)); diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized));
size_t total = _hidGetStates(&sharedmem->mouse.header, sharedmem->mouse.entries, 17, offsetof(HidMouseStateAtomicStorage,state), offsetof(HidMouseState,timestamp), states, sizeof(HidMouseState), count); size_t total = _hidGetStates(&sharedmem->mouse.lifo.header, sharedmem->mouse.lifo.storage, 17, offsetof(HidMouseStateAtomicStorage,state), offsetof(HidMouseState,sampling_number), states, sizeof(HidMouseState), count);
return total; return total;
} }
@ -445,7 +445,7 @@ size_t hidGetKeyboardStates(HidKeyboardState *states, size_t count) {
if (sharedmem == NULL) if (sharedmem == NULL)
diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized)); diagAbortWithResult(MAKERESULT(Module_Libnx, LibnxError_NotInitialized));
size_t total = _hidGetStates(&sharedmem->keyboard.header, sharedmem->keyboard.entries, 17, offsetof(HidKeyboardStateAtomicStorage,state), offsetof(HidKeyboardState,timestamp), states, sizeof(HidKeyboardState), count); size_t total = _hidGetStates(&sharedmem->keyboard.lifo.header, sharedmem->keyboard.lifo.storage, 17, offsetof(HidKeyboardStateAtomicStorage,state), offsetof(HidKeyboardState,sampling_number), states, sizeof(HidKeyboardState), count);
return total; return total;
} }
@ -454,10 +454,10 @@ void hidInitializeNpad(void) {
if (R_FAILED(rc)) diagAbortWithResult(rc); if (R_FAILED(rc)) diagAbortWithResult(rc);
} }
static size_t _hidGetNpadStates(HidNpad *npad, u32 layout, HidNpadStateEntry *states, size_t count) { static size_t _hidGetNpadStates(HidNpad *npad, u32 layout, HidNpadCommonState *states, size_t count) {
HidControllerLayout *states_buf = &npad->layouts[layout]; HidNpadCommonLifo *states_buf = &npad->layouts[layout];
if (count > 17) count = 17; if (count > 17) count = 17;
return _hidGetStates(&states_buf->header, states_buf->entries, 17, offsetof(HidControllerInputEntry,state), offsetof(HidNpadStateEntry,timestamp), states, sizeof(HidNpadStateEntry), count); return _hidGetStates(&states_buf->header, states_buf->storage, 17, offsetof(HidNpadCommonStateAtomicStorage,state), offsetof(HidNpadCommonState,sampling_number), states, sizeof(HidNpadCommonState), count);
} }
size_t hidGetNpadStatesFullKey(HidNpadIdType id, HidNpadFullKeyState *states, size_t count) { size_t hidGetNpadStatesFullKey(HidNpadIdType id, HidNpadFullKeyState *states, size_t count) {
@ -506,25 +506,25 @@ size_t hidGetNpadStatesJoyRight(HidNpadIdType id, HidNpadJoyRightState *states,
} }
size_t hidGetNpadStatesGc(HidNpadIdType id, HidNpadGcState *states, size_t count) { size_t hidGetNpadStatesGc(HidNpadIdType id, HidNpadGcState *states, size_t count) {
HidNpadStateEntry tmp_entries[17]; HidNpadCommonState tmp_entries[17];
HidNpadGcTriggerState tmp_entries_trigger[17]; HidNpadGcTriggerState tmp_entries_trigger[17];
HidNpad *npad = _hidGetNpadInternalState(id); HidNpad *npad = _hidGetNpadInternalState(id);
size_t total = _hidGetNpadStates(npad, 0, tmp_entries, count); size_t total = _hidGetNpadStates(npad, 0, tmp_entries, count);
size_t total2 = _hidGetStates(&npad->npad_gc_trigger_header, npad->npad_gc_trigger_state, 17, offsetof(HidNpadGcTriggerStateEntry,state), offsetof(HidNpadGcTriggerState,timestamp), tmp_entries_trigger, sizeof(HidNpadGcTriggerState), total); size_t total2 = _hidGetStates(&npad->gc_trigger_lifo.header, npad->gc_trigger_lifo.storage, 17, offsetof(HidNpadGcTriggerStateAtomicStorage,state), offsetof(HidNpadGcTriggerState,sampling_number), tmp_entries_trigger, sizeof(HidNpadGcTriggerState), total);
if (total2 < total) total = total2; if (total2 < total) total = total2;
memset(states, 0, sizeof(HidNpadGcState) * total); memset(states, 0, sizeof(HidNpadGcState) * total);
for (size_t i=0; i<total; i++) { for (size_t i=0; i<total; i++) {
states[i].timestamp = tmp_entries[i].timestamp; states[i].sampling_number = tmp_entries[i].sampling_number;
// sdknso would handle button-bitmasking with ControlPadRestriction here. // sdknso would handle button-bitmasking with ControlPadRestriction here.
states[i].buttons = tmp_entries[i].buttons; states[i].buttons = tmp_entries[i].buttons;
memcpy(states[i].joysticks, tmp_entries[i].joysticks, sizeof(tmp_entries[i].joysticks)); // sdknso uses index 0 for the src here. memcpy(states[i].joysticks, tmp_entries[i].joysticks, sizeof(tmp_entries[i].joysticks)); // sdknso uses index 0 for the src here.
states[i].connectionState = tmp_entries[i].connectionState; states[i].attributes = tmp_entries[i].attributes;
states[i].l_trigger = tmp_entries_trigger[i].l_trigger; states[i].l_trigger = tmp_entries_trigger[i].l_trigger;
states[i].r_trigger = tmp_entries_trigger[i].r_trigger; states[i].r_trigger = tmp_entries_trigger[i].r_trigger;
@ -543,18 +543,18 @@ size_t hidGetNpadStatesPalma(HidNpadIdType id, HidNpadPalmaState *states, size_t
} }
size_t hidGetNpadStatesLark(HidNpadIdType id, HidNpadLarkState *states, size_t count) { size_t hidGetNpadStatesLark(HidNpadIdType id, HidNpadLarkState *states, size_t count) {
HidNpadStateEntry tmp_entries[17]; HidNpadCommonState tmp_entries[17];
HidNpad *npad = _hidGetNpadInternalState(id); HidNpad *npad = _hidGetNpadInternalState(id);
size_t total = _hidGetNpadStates(npad, 0, tmp_entries, count); size_t total = _hidGetNpadStates(npad, 0, tmp_entries, count);
memset(states, 0, sizeof(HidNpadLarkState) * total); memset(states, 0, sizeof(HidNpadLarkState) * total);
u32 unk = atomic_load_explicit(&npad->unk_x43E0, memory_order_acquire); u32 lark_type_l_and_main = atomic_load_explicit(&npad->lark_type_l_and_main, memory_order_acquire);
if (!(unk>=1 && unk<=4)) unk = 0; if (!(lark_type_l_and_main>=1 && lark_type_l_and_main<=4)) lark_type_l_and_main = 0;
for (size_t i=0; i<total; i++) { for (size_t i=0; i<total; i++) {
states[i].timestamp = tmp_entries[i].timestamp; states[i].sampling_number = tmp_entries[i].sampling_number;
// sdknso would handle button-bitmasking with ControlPadRestriction here. // sdknso would handle button-bitmasking with ControlPadRestriction here.
@ -562,56 +562,56 @@ size_t hidGetNpadStatesLark(HidNpadIdType id, HidNpadLarkState *states, size_t c
// Leave joysticks state at zeros. // Leave joysticks state at zeros.
states[i].connectionState = tmp_entries[i].connectionState; states[i].attributes = tmp_entries[i].attributes;
states[i].unk = unk; states[i].lark_type_l_and_main = lark_type_l_and_main;
} }
return total; return total;
} }
size_t hidGetNpadStatesHandheldLark(HidNpadIdType id, HidNpadHandheldLarkState *states, size_t count) { size_t hidGetNpadStatesHandheldLark(HidNpadIdType id, HidNpadHandheldLarkState *states, size_t count) {
HidNpadStateEntry tmp_entries[17]; HidNpadCommonState tmp_entries[17];
HidNpad *npad = _hidGetNpadInternalState(id); HidNpad *npad = _hidGetNpadInternalState(id);
size_t total = _hidGetNpadStates(npad, 1, tmp_entries, count); size_t total = _hidGetNpadStates(npad, 1, tmp_entries, count);
memset(states, 0, sizeof(HidNpadHandheldLarkState) * total); memset(states, 0, sizeof(HidNpadHandheldLarkState) * total);
u32 unk0 = atomic_load_explicit(&npad->unk_x43E0, memory_order_acquire); u32 lark_type_l_and_main = atomic_load_explicit(&npad->lark_type_l_and_main, memory_order_acquire);
if (!(unk0>=1 && unk0<=4)) unk0 = 0; if (!(lark_type_l_and_main>=1 && lark_type_l_and_main<=4)) lark_type_l_and_main = 0;
u32 unk1 = atomic_load_explicit(&npad->unk_x43E4, memory_order_acquire); u32 lark_type_r = atomic_load_explicit(&npad->lark_type_r, memory_order_acquire);
if (!(unk1>=1 && unk1<=4)) unk1 = 0; if (!(lark_type_r>=1 && lark_type_r<=4)) lark_type_r = 0;
for (size_t i=0; i<total; i++) { for (size_t i=0; i<total; i++) {
states[i].timestamp = tmp_entries[i].timestamp; states[i].sampling_number = tmp_entries[i].sampling_number;
// sdknso would handle button-bitmasking with ControlPadRestriction here. // sdknso would handle button-bitmasking with ControlPadRestriction here.
states[i].buttons = tmp_entries[i].buttons; states[i].buttons = tmp_entries[i].buttons;
memcpy(states[i].joysticks, tmp_entries[i].joysticks, sizeof(tmp_entries[i].joysticks)); // sdknso uses index 0 for the src here. memcpy(states[i].joysticks, tmp_entries[i].joysticks, sizeof(tmp_entries[i].joysticks)); // sdknso uses index 0 for the src here.
states[i].connectionState = tmp_entries[i].connectionState; states[i].attributes = tmp_entries[i].attributes;
states[i].unk0 = unk0; states[i].lark_type_l_and_main = lark_type_l_and_main;
states[i].unk1 = unk1; states[i].lark_type_r = lark_type_r;
} }
return total; return total;
} }
size_t hidGetNpadStatesLucia(HidNpadIdType id, HidNpadLuciaState *states, size_t count) { size_t hidGetNpadStatesLucia(HidNpadIdType id, HidNpadLuciaState *states, size_t count) {
HidNpadStateEntry tmp_entries[17]; HidNpadCommonState tmp_entries[17];
HidNpad *npad = _hidGetNpadInternalState(id); HidNpad *npad = _hidGetNpadInternalState(id);
size_t total = _hidGetNpadStates(npad, 0, tmp_entries, count); size_t total = _hidGetNpadStates(npad, 0, tmp_entries, count);
memset(states, 0, sizeof(HidNpadLuciaState) * total); memset(states, 0, sizeof(HidNpadLuciaState) * total);
u32 unk = atomic_load_explicit(&npad->unk_x43E8, memory_order_acquire); u32 lucia_type = atomic_load_explicit(&npad->lucia_type, memory_order_acquire);
if (!(unk>=1 && unk<=3)) unk = 0; if (!(lucia_type>=1 && lucia_type<=3)) lucia_type = 0;
for (size_t i=0; i<total; i++) { for (size_t i=0; i<total; i++) {
states[i].timestamp = tmp_entries[i].timestamp; states[i].sampling_number = tmp_entries[i].sampling_number;
// sdknso would handle button-bitmasking with ControlPadRestriction here. // sdknso would handle button-bitmasking with ControlPadRestriction here.
@ -619,8 +619,8 @@ size_t hidGetNpadStatesLucia(HidNpadIdType id, HidNpadLuciaState *states, size_t
// Leave joysticks state at zeros. // Leave joysticks state at zeros.
states[i].connectionState = tmp_entries[i].connectionState; states[i].attributes = tmp_entries[i].attributes;
states[i].unk = unk; states[i].lucia_type = lucia_type;
} }
return total; return total;
@ -696,7 +696,7 @@ size_t hidGetSixAxisSensorStates(HidSixAxisSensorHandle handle, HidSixAxisSensor
} }
HidNpad *npad = _hidGetNpadInternalState(handle.npad_id_type); HidNpad *npad = _hidGetNpadInternalState(handle.npad_id_type);
size_t total = _hidGetStates(&npad->sixaxis[index].header, npad->sixaxis[index].entries, 17, offsetof(HidNpadSixAxisSensorState,state), offsetof(HidSixAxisSensorState,timestamp), states, sizeof(HidSixAxisSensorState), count); size_t total = _hidGetStates(&npad->sixaxis[index].header, npad->sixaxis[index].storage, 17, offsetof(HidSixAxisSensorStateAtomicStorage,state), offsetof(HidSixAxisSensorState,sampling_number), states, sizeof(HidSixAxisSensorState), count);
return total; return total;
} }
@ -706,7 +706,7 @@ bool hidIsControllerConnected(HidControllerID id) {
if (id < 0 || id > 9) return 0; if (id < 0 || id > 9) return 0;
rwlockReadLock(&g_hidLock); rwlockReadLock(&g_hidLock);
bool flag = (g_controllerEntries[id].connectionState & CONTROLLER_STATE_CONNECTED) != 0; bool flag = (g_controllerEntries[id].attributes & CONTROLLER_STATE_CONNECTED) != 0;
rwlockReadUnlock(&g_hidLock); rwlockReadUnlock(&g_hidLock);
return flag; return flag;
} }
@ -1602,7 +1602,7 @@ Result hidGetSevenSixAxisSensorStates(HidSevenSixAxisSensorState *states, size_t
HidSevenSixAxisSensorStates *states_buf = (HidSevenSixAxisSensorStates*)g_sevenSixAxisSensorBuffer; HidSevenSixAxisSensorStates *states_buf = (HidSevenSixAxisSensorStates*)g_sevenSixAxisSensorBuffer;
size_t total = _hidGetStates(&states_buf->header, states_buf->entries, 0x21, offsetof(HidSevenSixAxisSensorStateEntry,state), offsetof(HidSevenSixAxisSensorState,timestamp1), states, sizeof(HidSevenSixAxisSensorState), count); size_t total = _hidGetStates(&states_buf->header, states_buf->storage, 0x21, offsetof(HidSevenSixAxisSensorStateEntry,state), offsetof(HidSevenSixAxisSensorState,sampling_number), states, sizeof(HidSevenSixAxisSensorState), count);
if (total_out) *total_out = total; if (total_out) *total_out = total;
return 0; return 0;