SHARE
TWEET

Joyoad Routine That Isn't The Standard

ISSOtm Aug 3rd, 2018 300 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     ; Poll joypad and update regs
  2.  
  3.     ld c, LOW(rP1)
  4.     ld a, $20 ; Select D-pad
  5.     ld [$ff00+c], a
  6. REPT 6
  7.     ld a, [$ff00+c]
  8. ENDR
  9.     or $F0 ; Set 4 upper bits (give them consistency)
  10.     ld b, a
  11.  
  12.     ; Filter impossible D-pad combinations
  13.     and $0C ; Filter only Down and Up
  14.     ld a, b
  15.     jr nz, .notUpAndDown
  16.     or $0C ; If both are pressed, "unpress" them
  17.     ld b, a
  18. .notUpAndDown
  19.     and $03 ; Filter only Left and Right
  20.     jr nz, .notLeftAndRight
  21.     ld a, b
  22.     or $03 ; If both are pressed, "unpress" them
  23.     ld b, a
  24. .notLeftAndRight
  25.     swap b ; Put D-pad buttons in upper nibble
  26.  
  27.     ld a, $10 ; Select buttons
  28.     ld [$ff00+c], a
  29. REPT 6
  30.     ld a, [$ff00+c]
  31. ENDR
  32.     ; On SsAB held, soft-reset
  33.     and $0F
  34.     jp z, Reset
  35.  
  36.     or $F0 ; Set 4 upper bits
  37.     xor b ; Mix with D-pad bits, and invert all bits (such that pressed=1) thanks to "or $F0"
  38.     ld b, a
  39.  
  40.     ldh a, [hHeldButtons]
  41.     cpl
  42.     and b
  43.     ldh [hPressedButtons], a
  44.  
  45.     ld a, b
  46.     ldh [hHeldButtons], a
  47.  
  48.     ; Release joypad
  49.     ld a, $30
  50.     ld [$ff00+c], a
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top