INCLUDE "hardware.inc" Section "Input Data", WRAM0 lastKeys:: db keys:: db Section "Input Code", ROM0 ; Initialize input ; NOTE: Inline if needed Keys_Init:: ld hl, lastKeys xor a ld [hl+], a ld [hl], a ; Update the input state Keys_Update:: ld a, P1F_GET_BTN ld [rP1], a ; wait a few cycles ld a, [rP1] ld a, [rP1] ; extract btn bits into top of B cpl and $f swap a ld b, a ld a, P1F_GET_DPAD ld [rP1], a ; wait more cycles ld a, [rP1] ld a, [rP1] ld a, [rP1] ld a, [rP1] ld a, [rP1] ld a, [rP1] ; extract dpad bits into bottom of B cpl and $f or b ld b, a ; swap to use flag macros from hardware.inc ; TODO: optimize this code to avoid swap (very small win) swap b ; lastKeys <- keys ; keys <- B ld hl, keys ld a, [hl] ld [hl], b dec hl ld [hl], a ret