hid: Add return type to GetNpadStates - #73
Conversation
german77
left a comment
There was a problem hiding this comment.
Normally sdk functions return the nn::Result of the operation. In this overload the error triggers an abort and instead it returns the number of valid entries. When you just start the game the input ring buffer is empty and won't be able to provide the 16 requested entries. This period is very brief so most games asume the ring buffer is always full.
@german77 reviewed 1 file and all commit messages, and made 2 comments.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on MonsterDruide1).
include/nn/hid.h line 521 at r1 (raw file):
void GetNpadState(NpadJoyRightState*, const u32& port); s32 GetNpadStates(NpadFullKeyState*, s32, const u32& port);
Your assumption is correct for the parameters. Although the port is actually the NpadId. Same for the others.
Libnx has this function documented although the parameters are in different order https://github.com/switchbrew/libnx/blob/master/nx/include/switch/services/hid.h#L1709
Suggestion:
s32 GetNpadStates(NpadFullKeyState* states, s32 count, const u32& id);
When checking the SDK binary, it gets obvious that
GetNpadStatesshould return an integer. According to my understanding,GetNpadStatescan fetch multiple states at once (mSamplingNumbertells them apart), so the first parameter is a buffer of potentially multiple states, the second parameter is the buffer size and the third is the port. The return type might be the number of entries that were added to the buffer, but I'm not fully sure about that. Odyssey works with hardcoded buffer size of 16, but ignores the return value of this function.This change is