Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to manually edit Wiimote/CC mappings #1240

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
43 changes: 39 additions & 4 deletions kernel/BT.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/* WiiU Pro Controller Documentation from TeHaxor69 */
/* lwBT ported from LibOGC */

#define IR_CFG_FILE 0x93005180
#define IR_CFG_SIZE 0x93005184

#include "global.h"
#include "string.h"
#include "BT.h"
Expand Down Expand Up @@ -738,10 +741,41 @@ void BTUpdateRegisters(void)
if(inited == 0)
return;

if(intr == 1)
{
intr = 0;
__readintrdataCB();
// Try to load Wiimote/Classic Controller bindings from ircc.ini
const char *filenames[2] = {
file_sd, file_usb,
"sd:/ircc.ini",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not in the app directory?
Cluttering up the root directory with all kinds of files is not nice.

"usb:/ircc.ini"
};

int i;
FIL f;
FRESULT res = FR_DISK_ERR;
for (i = 0; i < 2; i++) {
res = f_open_char(&f, filenames[i], FA_READ | FA_OPEN_EXISTING);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about stat()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (res == FR_OK)
break;
}

if (res == FR_OK) {
// File found, read the configuration
size_t fsize = f.obj.objsize;
UINT read;
f_read(&f, (void*)IR_CFG_FILE, fsize, &read);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to check return value?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, IR_CFG_FILE and IR_CFG_SIZE still need to be defined first with addresses. HID.c of course defines its equivalent terms, but I still need applicable addresses for Wiimotes/CC's: https://github.com/FIX94/Nintendont/blob/master/mem_map.txt

For now I've allocated 0x93005180 and 0x93005184 respectively.

DCFlushRange((void*)IR_CFG_FILE, fsize);
f_close(&f);
// Apply custom config (size is fsize)
*(vu32*)IR_CFG_SIZE = fsize;
} else {
// No config file found; fall back to defaults
*(vu32*)IR_CFG_SIZE = 0;
}

// Continue with the rest of the BTUpdateRegisters function
if(intr == 1)
{
intr = 0;
__readintrdataCB();
__issue_intrread();
}
if(bulk == 1)
Expand All @@ -751,6 +785,7 @@ void BTUpdateRegisters(void)
__issue_bulkread();
}

// Handle connected controllers
u32 i = 0, j = 0;
sync_before_read((void*)0x13003020,0x40);
for( ; i < BTChannelsUsed; ++i)
Expand Down