joypad.asm 621 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. ReadJoypad::
  2. ; Poll joypad input.
  3. ; Unlike the hardware register, button
  4. ; presses are indicated by a set bit.
  5. ld a, 1 << 5 ; select direction keys
  6. ld c, 0
  7. ld [rJOYP], a
  8. rept 6
  9. ld a, [rJOYP]
  10. endr
  11. cpl
  12. and %1111
  13. swap a
  14. ld b, a
  15. ld a, 1 << 4 ; select button keys
  16. ld [rJOYP], a
  17. rept 10
  18. ld a, [rJOYP]
  19. endr
  20. cpl
  21. and %1111
  22. or b
  23. ld [hJoyInput], a
  24. ld a, 1 << 4 + 1 << 5 ; deselect keys
  25. ld [rJOYP], a
  26. ret
  27. Joypad::
  28. ; Update the joypad state variables:
  29. ; [hJoyReleased] keys released since last time
  30. ; [hJoyPressed] keys pressed since last time
  31. ; [hJoyHeld] currently pressed keys
  32. homecall _Joypad
  33. ret