You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
2.7 KiB

  1. /* gc_n64_usb : Gamecube or N64 controller to USB firmware
  2. Copyright (C) 2007-2015 Raphael Assenat <raph@raphnet.net>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <avr/pgmspace.h>
  15. #include "mappings.h"
  16. #include "gamepads.h"
  17. #include "usbpad.h"
  18. /* Default N64 and Gamecube mappings meant to work together
  19. * i.e. Controllers should be mostly interchangeable
  20. *
  21. * - Main buttons first
  22. * - Common buttons at the same place
  23. * - Similar layout for GC Y/X and N64 C-Left and C-Down
  24. */
  25. const static struct mapping map_gc_default[] PROGMEM = {
  26. { GC_BTN_A, USB_BTN(0) },
  27. { GC_BTN_B, USB_BTN(1) },
  28. { GC_BTN_Z, USB_BTN(2) },
  29. { GC_BTN_START, USB_BTN(3) },
  30. { GC_BTN_L, USB_BTN(4) },
  31. { GC_BTN_R, USB_BTN(5) },
  32. { GC_BTN_Y, USB_BTN(8) }, // N64 C-Left
  33. { GC_BTN_X, USB_BTN(7) }, // N64 C-Down
  34. { GC_BTN_DPAD_UP, USB_BTN(10) },
  35. { GC_BTN_DPAD_DOWN, USB_BTN(11) },
  36. { GC_BTN_DPAD_LEFT, USB_BTN(12) },
  37. { GC_BTN_DPAD_RIGHT, USB_BTN(13) },
  38. { } /* terminator */
  39. };
  40. const static struct mapping map_n64_default[] PROGMEM = {
  41. { N64_BTN_A, USB_BTN(0) },
  42. { N64_BTN_B, USB_BTN(1) },
  43. { N64_BTN_Z, USB_BTN(2) },
  44. { N64_BTN_START, USB_BTN(3) },
  45. { N64_BTN_L, USB_BTN(4) },
  46. { N64_BTN_R, USB_BTN(5) },
  47. { N64_BTN_C_UP, USB_BTN(6) },
  48. { N64_BTN_C_DOWN, USB_BTN(7) }, // GC X
  49. { N64_BTN_C_LEFT, USB_BTN(8) }, // GC_Y
  50. { N64_BTN_C_RIGHT, USB_BTN(9) },
  51. { N64_BTN_DPAD_UP, USB_BTN(10) },
  52. { N64_BTN_DPAD_DOWN, USB_BTN(11) },
  53. { N64_BTN_DPAD_LEFT, USB_BTN(12) },
  54. { N64_BTN_DPAD_RIGHT, USB_BTN(13) },
  55. { } /* terminator */
  56. };
  57. static uint16_t domap(const struct mapping *map, uint16_t input)
  58. {
  59. const struct mapping *cur = map;
  60. uint16_t out = 0;
  61. uint16_t ctl_btn, usb_btn;
  62. while (1) {
  63. ctl_btn = pgm_read_word(&cur->ctl_btn);
  64. usb_btn = pgm_read_word(&cur->usb_btn);
  65. if (!ctl_btn || !usb_btn)
  66. break;
  67. if (input & ctl_btn) {
  68. out |= usb_btn;
  69. }
  70. cur++;
  71. }
  72. return out;
  73. }
  74. uint16_t mappings_do(uint8_t mapping_id, uint16_t input)
  75. {
  76. switch(mapping_id) {
  77. case MAPPING_GAMECUBE_DEFAULT:
  78. return domap(map_gc_default, input);
  79. case MAPPING_N64_DEFAULT:
  80. return domap(map_n64_default, input);
  81. }
  82. return 0;
  83. }