GameBoy (Color) port of the GTA San Andreas arcade game Duality
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.

input.c 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * input.c
  3. * Duality
  4. *
  5. * Copyright (C) 2025 Thomas Buck <thomas@xythobuz.de>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * See <http://www.gnu.org/licenses/>.
  18. */
  19. #include <gbdk/platform.h>
  20. #include "banks.h"
  21. #include "input.h"
  22. static uint8_t joyp = 0;
  23. static uint8_t old_joyp = 0;
  24. static int8_t debug_cnt = 0;
  25. BANKREF(input)
  26. static const uint8_t key_debug_sequence[] = {
  27. J_UP, J_UP, J_DOWN, J_DOWN,
  28. J_LEFT, J_RIGHT, J_LEFT, J_RIGHT,
  29. J_B, J_A, /* J_START */
  30. };
  31. #define DEBUG_SEQUENCE_COUNT (sizeof(key_debug_sequence) / sizeof(key_debug_sequence[0]))
  32. void key_read(void) NONBANKED {
  33. old_joyp = joyp;
  34. joyp = joypad();
  35. if (debug_cnt < DEBUG_SEQUENCE_COUNT) {
  36. START_ROM_BANK(BANK(input));
  37. if (key_pressed(key_debug_sequence[debug_cnt])) {
  38. debug_cnt++;
  39. } else if (key_pressed(0xFF)) {
  40. debug_cnt = 0;
  41. }
  42. END_ROM_BANK();
  43. } else {
  44. if (key_pressed(0xFF ^ J_START)) {
  45. debug_cnt = 0;
  46. }
  47. }
  48. }
  49. uint8_t key_down(uint8_t key) NONBANKED {
  50. return joyp & key;
  51. }
  52. uint8_t key_pressed(uint8_t key) NONBANKED {
  53. return (joyp ^ old_joyp) & joyp & key;
  54. }
  55. int8_t key_debug(void) NONBANKED {
  56. return DEBUG_SEQUENCE_COUNT - debug_cnt;
  57. }