SHARE
TWEET

Repeating d-pad presses

ISSOtm Jun 13th, 2018 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     ; Try to perform RepeatPress
  2.     ld a, l ; Get ptr to RepeatPressCounter (will be used even if RepeatPress is disabled)
  3.     add a, Menu_RepeatPressCounter - Menu_EnableRepeatPress
  4.     ld e, a
  5.     adc a, h
  6.     sub e
  7.     ld d, a
  8.     ld b, 0 ; Start by supposing no button will be RepeatPress'd
  9.     ; If any (non-ignored) button is pressed, stop RepeatPress
  10.     ldh a, [hPressedButtons]
  11.     and c ; It's fine to do this, since a pressed button is held anyways
  12.     jr z, .dontResetRepeatPress
  13.     xor a
  14.     ld [de], a
  15. .dontResetRepeatPress
  16.     ld a, [hli] ; Read EnableRepeatPress
  17.     and a
  18.     jr z, .skipRepeatPress
  19.  
  20.     ld a, c ; Get held buttons
  21.     and PADF_DOWN | PADF_UP | PADF_LEFT | PADF_RIGHT ; Get d-pad only
  22.     ; Check if exactly 1 direction is being held
  23.     jr z, .skipRepeatPress ; If 0, don't do anything
  24. .getFirstDirection
  25.     add a, a
  26.     jr nc, .getFirstDirection ; Keep going until the first bit is shifted out
  27.     jr nz, .skipRepeatPress ; If more bits remain, more than 1 button is being held, so skip
  28.     ; So, only 1 direction is being held, and if it has just been pressed, the state is currently zero
  29.     ; Increment the counter
  30.     ld a, [de]
  31.     inc a
  32.     ld [de], a
  33.     cp 32
  34.     jr c, .skipRepeatPress ; Unless the counter reaches 32, don't do anything
  35.     ld a, 30
  36.     ld [de], a ; Reset counter (to apply delay)
  37.     ld a, c
  38.     and PADF_DOWN | PADF_UP | PADF_LEFT | PADF_RIGHT
  39.     ld b, a ; Mark this button as RepeatPress'd
  40.  
  41. .skipRepeatPress
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