A dungeon delver roguelike using Pathfinder 2nd edition rules
at gb 39 lines 1.0 kB view raw
1INCLUDE "hardware.inc/hardware.inc" 2 3SECTION "Input", ROM0 4 5Input:: 6 ; Poll half the controller 7 ld a, P1F_GET_BTN 8 call .onenibble 9 ld b, a ; B7-4 = 1; B3-0 = unpressed buttons 10 11 ; Poll the other half 12 ld a, P1F_GET_DPAD 13 call .onenibble 14 swap a ; A3-0 = unpressed directions; A7-4 = 1 15 xor a, b ; A = pressed buttons + directions 16 ld b, a ; B = pressed buttons + directions 17 18 ; And release the controller 19 ld a, P1F_GET_NONE 20 ldh [rP1], a 21 22 ; Combine with previous wCurKeys to make wNewKeys 23 ld a, [wCurKeys] 24 xor a, b ; A = keys that changed state 25 and a, b ; A = keys that changed to presed 26 ld [wNewKeys], a 27 ld a, b 28 ld [wCurKeys], a 29 ret 30 31.onenibble 32 ldh [rP1], a ; switch the key matrix 33 call .knownret ; burn 10 cycles calling a known ret 34 ldh a, [rP1] ; ignore value while waiting for the key matrix to settle 35 ldh a, [rP1] 36 ldh a, [rP1] ; this read counts 37 or a, $f0 ; A7-4 = 1; A3-0 = unpressed keys 38.knownret 39 ret