include "hardware.inc" section "home/joypad.asm@hram", hram h_joypad: db h_joypad_down:: db h_joypad_pressed:: db h_joypad_released:: db section "home/joypad.asm", rom0 joypad_read:: ld a, r_joyp_select_dpad ldh [r_joyp], a rept 2 ldh a, [r_joyp] endr ; Save the dpad value to the high nybble cpl and r_joyp_data swap a ld b, a ld a, r_joyp_select_buttons ldh [r_joyp], a rept 6 ldh a, [r_joyp] endr ; Save the buttons to the low nybble cpl and r_joyp_data or b ldh [h_joypad], a ld a, r_joyp_select ldh [r_joyp], a ret joypad_update:: ldh a, [h_joypad] ld b, a ldh a, [h_joypad_down] ld c, a xor b ld d, a and c ldh [h_joypad_released], a ld a, d and b ldh [h_joypad_pressed], a ld a, b ldh [h_joypad_down], a ret