invert mappings

This commit is contained in:
Liz 2025-04-08 11:50:20 -04:00
parent 44fa2b265d
commit 858205c3dc

View file

@ -375,73 +375,66 @@ static void process_kbd_report (hid_keyboard_report_t const *report)
}
// this mapping is hard coded for a certain snes-style gamepad and picogb!
// Update this function in hid_app.c
static void process_gamepad_report(const uint8_t *report) {
uint16_t decoded_report = 0;
// Default input format from your HID explorer output:
// default input (no buttons pressed): 00 7F 7F 00 80 80 0F 00 00
// Y-axis (byte 2): 0x00=up, 0x7F=center, 0xFF=down
// Note: We're swapping UP/DOWN here to fix the menu navigation
if (report[2] < 0x40) {
decoded_report |= MASK_JOY2_DOWN; // Map UP to DOWN for the menu
} else if (report[2] > 0xB0) {
decoded_report |= MASK_JOY2_UP; // Map DOWN to UP for the menu
}
// Directional controls - X and Y axes
// Note: No need to swap or invert - the Game Boy code handles that
// X-axis (byte 1): 0x00=left, 0x7F=center, 0xFF=right
if (report[1] < 0x40) {
if (report[1] < 0x40) { // Left
decoded_report |= MASK_JOY2_LEFT;
} else if (report[1] > 0xB0) {
} else if (report[1] > 0xB0) { // Right
decoded_report |= MASK_JOY2_RIGHT;
}
// Y-axis (byte 2): 0x00=up, 0x7F=center, 0xFF=down
if (report[2] < 0x40) { // Up
decoded_report |= MASK_JOY2_UP;
} else if (report[2] > 0xB0) { // Down
decoded_report |= MASK_JOY2_DOWN;
}
// Face buttons (byte 6)
// Looking at emu.cpp, we need to map:
// - A button to MASK_KEY_USER3
// - B button to MASK_JOY2_BTN
// - Select to MASK_KEY_USER1
// - Start to MASK_KEY_USER2
// A: 00 7F 7F 00 80 80 2F 00 00 (bit 0x20)
// A button (maps to Game Boy A)
if (report[6] & 0x20) {
decoded_report |= MASK_KEY_USER3; // A button maps to gb.direct.joypad_bits.a
decoded_report |= MASK_KEY_USER3;
}
// B: 00 7F 7F 00 80 80 4F 00 00 (bit 0x40)
// B button (maps to Game Boy B)
if (report[6] & 0x40) {
decoded_report |= MASK_JOY2_BTN; // B button maps to gb.direct.joypad_bits.b
decoded_report |= MASK_JOY2_BTN;
}
// X: 00 7F 7F 00 80 80 1F 00 00 (bit 0x10) - Map to B as an alternative
// X button (alternate A button)
if (report[6] & 0x10) {
decoded_report |= MASK_JOY2_BTN; // X button maps to B
decoded_report |= MASK_KEY_USER3;
}
// Y: 00 7F 7F 00 80 80 8F 00 00 (bit 0x80) - Map to A as an alternative
// Y button (alternate B button)
if (report[6] & 0x80) {
decoded_report |= MASK_KEY_USER3; // Y button maps to A
decoded_report |= MASK_JOY2_BTN;
}
// Select: 00 7F 7F 00 80 80 0F 10 00 (byte 7, bit 0x10)
if (report[7] & 0x10) {
decoded_report |= MASK_KEY_USER1; // Select button
}
// Start: 00 7F 7F 00 80 80 0F 20 00 (byte 7, bit 0x20)
if (report[7] & 0x20) {
decoded_report |= MASK_KEY_USER2; // Start button
}
// R: 00 7F 7F 00 80 80 0F 02 00 (byte 7, bit 0x02) - Map to B as an alternative
if (report[7] & 0x02) {
decoded_report |= MASK_JOY2_BTN; // R button maps to B
}
// L: 00 7F 7F 00 80 80 0F 01 00 (byte 7, bit 0x01) - Map to A as an alternative
// Shoulder and menu buttons (byte 7)
// L button (alternate A button)
if (report[7] & 0x01) {
decoded_report |= MASK_KEY_USER3; // L button maps to A
decoded_report |= MASK_KEY_USER3;
}
// R button (alternate B button)
if (report[7] & 0x02) {
decoded_report |= MASK_JOY2_BTN;
}
// Select button
if (report[7] & 0x10) {
decoded_report |= MASK_KEY_USER1;
}
// Start button
if (report[7] & 0x20) {
decoded_report |= MASK_KEY_USER2;
}
// Send the decoded gamepad state