joypad.asm 828 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. _Joypad::
  2. ; hJoyReleased: (hJoyLast ^ hJoyInput) & hJoyLast
  3. ; hJoyPressed: (hJoyLast ^ hJoyInput) & hJoyInput
  4. ld a, [hJoyInput]
  5. cp A_BUTTON + B_BUTTON + SELECT + START ; soft reset
  6. jp z, TrySoftReset
  7. ld b, a
  8. ld a, [hJoyLast]
  9. ld e, a
  10. xor b
  11. ld d, a
  12. and e
  13. ld [hJoyReleased], a
  14. ld a, d
  15. and b
  16. ld [hJoyPressed], a
  17. ld a, b
  18. ld [hJoyLast], a
  19. ld a, [wd730]
  20. bit 5, a
  21. jr nz, DiscardButtonPresses
  22. ld a, [hJoyLast]
  23. ld [hJoyHeld], a
  24. ld a, [wJoyIgnore]
  25. and a
  26. ret z
  27. cpl
  28. ld b, a
  29. ld a, [hJoyHeld]
  30. and b
  31. ld [hJoyHeld], a
  32. ld a, [hJoyPressed]
  33. and b
  34. ld [hJoyPressed], a
  35. ret
  36. DiscardButtonPresses:
  37. xor a
  38. ld [hJoyHeld], a
  39. ld [hJoyPressed], a
  40. ld [hJoyReleased], a
  41. ret
  42. TrySoftReset:
  43. call DelayFrame
  44. ; deselect (redundant)
  45. ld a, $30
  46. ld [rJOYP], a
  47. ld hl, hSoftReset
  48. dec [hl]
  49. jp z, SoftReset
  50. jp Joypad