~nytpu/ankano unlisted

4a8f53c38d5277a78d7155ffb7c9e5e502606859 — nytpu 4 months ago a19791a
add keys handler
2 files changed, 82 insertions(+), 9 deletions(-)

A src/keys.asm
M src/loop.asm
A src/keys.asm => src/keys.asm +78 -0
@@ 0,0 1,78 @@
; Copyright (C) 2020 nytpu
; This file is licensed under the terms of the MIT License.
; For more license details, see LICENSE or <https://mit-license.org/>.

INCLUDE "defines.asm"

SECTION "Keys Handler", ROM0
; handle keypad input
; @destroy hl, b
KeyHandler::
	; use b so a is available for key handlers
	ld a, [hHeldKeys]
	and a ; cp 0
	jr z, .keypadDone ; no input this frame
	ld [wSaveA], a
	and $0F ; only d-pad is pressed
	jr z, .dPadOnly

	ld a, [wSaveA]
	and PADF_A
	jr z, .aDone
	; do stuff that should be done for a
	; jump to .aDone if
	ld a, %00011011
	ld [hBGP], a
	ld a, [wSaveA]
.aDone

	ld a, [wSaveA]
	and PADF_B
	jr z, .bDone
	; stuff for b
	ld a, %11100100
	ld [hBGP], a
.bDone

	ld a, [wSaveA]
	and PADF_SELECT
	jr z, .selDone
	; stuff for select
.selDone

	ld a, [wSaveA]
	and PADF_START
	jr z, .startDone
	; stuff for start
.startDone

.dPadOnly
	ld a, [wSaveA]
	and PADF_RIGHT
	jr z, .rightDone
	; stuff for right
.rightDone

	ld a, [wSaveA]
	and PADF_LEFT
	jr z, .leftDone
	; stuff for left
.leftDone

	ld a, [wSaveA]
	and PADF_UP
	jr z, .upDone
	; stuff for up
.upDone

	ld a, [wSaveA]
	and PADF_DOWN
	jr z, .downDone
	; stuff for down
.downDone
	; cleanup, if needed
.keypadDone
	ret

SECTION "Keys Scratch", WRAM0
wSaveA: db

M src/loop.asm => src/loop.asm +4 -9
@@ 41,6 41,9 @@ INCLUDE "res/spritemap.2bpp.pb16.size"
	PURGE NB_PB16_BLOCKS
	call pb16_unpack_block

	ld a, %11100100
	ld [hBGP], a

	ld a, LCDCF_ON | LCDCF_BGON | LCDCF_BG9800 | LCDCF_BG8800
	ldh [rLCDC], a



@@ 49,15 52,7 @@ INCLUDE "res/spritemap.2bpp.pb16.size"
	ld a, 1
	ldh [hCanSoftReset], a
MainLoop:
	ld hl, hHeldKeys
	bit 0, [hl]
	jr z, .notA
	ld a, %00011011
	ld [rBGP], a
.notA
	ld a, %11100100
	ld [hBGP], a
.keypadDone
	call KeyHandler
	; if there's any more time before vblank
	rst WaitVBlank
	jr MainLoop