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.

60 lines
918 B

2 years ago
  1. INCLUDE "hardware.inc"
  2. Section "Input Data", WRAM0
  3. lastKeys:: db
  4. keys:: db
  5. Section "Input Code", ROM0
  6. ; Initialize input
  7. ; NOTE: Inline if needed
  8. Keys_Init::
  9. ld hl, lastKeys
  10. xor a
  11. ld [hl+], a
  12. ld [hl], a
  13. ; Update the input state
  14. Keys_Update::
  15. ld a, P1F_GET_BTN
  16. ld [rP1], a
  17. ; wait a few cycles
  18. ld a, [rP1]
  19. ld a, [rP1]
  20. ; extract btn bits into top of B
  21. cpl
  22. and $f
  23. swap a
  24. ld b, a
  25. ld a, P1F_GET_DPAD
  26. ld [rP1], a
  27. ; wait more cycles
  28. ld a, [rP1]
  29. ld a, [rP1]
  30. ld a, [rP1]
  31. ld a, [rP1]
  32. ld a, [rP1]
  33. ld a, [rP1]
  34. ; extract dpad bits into bottom of B
  35. cpl
  36. and $f
  37. or b
  38. ld b, a
  39. ; swap to use flag macros from hardware.inc
  40. ; TODO: optimize this code to avoid swap (very small win)
  41. swap b
  42. ; lastKeys <- keys ; keys <- B
  43. ld hl, keys
  44. ld a, [hl]
  45. ld [hl], b
  46. dec hl
  47. ld [hl], a
  48. ret