Skip to content

Commit fc705b9

Browse files
authored
Merge pull request #1 from wilkersonrdevon/feature/title-screen
Adds title screen section to tutorial
2 parents e6bdd77 + ed44d69 commit fc705b9

File tree

2 files changed

+398
-0
lines changed

2 files changed

+398
-0
lines changed

unbricked/title-screen/input.asm

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
; This is a simplified version of pads.z80 by PinoBatch for use in gb-asm-tutorial
2+
; All labels are intentionally not exported to avoid confusing the reader with unfamiliar syntax.
3+
; Once linking is introduced in part 3, a new, exported version of this file will be provided.
4+
5+
INCLUDE "../hardware.inc"
6+
7+
SECTION "Input Variables", WRAM0
8+
wCurKeys:: db
9+
wNewKeys:: db
10+
11+
SECTION "UpdateKeys", ROM0
12+
13+
UpdateKeys::
14+
; Poll half the controller
15+
ld a, P1F_GET_BTN
16+
call .onenibble
17+
ld b, a ; B7-4 = 1; B3-0 = unpressed buttons
18+
19+
; Poll the other half
20+
ld a, P1F_GET_DPAD
21+
call .onenibble
22+
swap a ; A3-0 = unpressed directions; A7-4 = 1
23+
xor a, b ; A = pressed buttons + directions
24+
ld b, a ; B = pressed buttons + directions
25+
26+
; And release the controller
27+
ld a, P1F_GET_NONE
28+
ldh [rP1], a
29+
30+
; Combine with previous wCurKeys to make wNewKeys
31+
ld a, [wCurKeys]
32+
xor a, b ; A = keys that changed state
33+
and a, b ; A = keys that changed to pressed
34+
ld [wNewKeys], a
35+
ld a, b
36+
ld [wCurKeys], a
37+
ret
38+
39+
.onenibble
40+
ldh [rP1], a ; switch the key matrix
41+
call .knownret ; burn 10 cycles calling a known ret
42+
ldh a, [rP1] ; ignore value while waiting for the key matrix to settle
43+
ldh a, [rP1]
44+
ldh a, [rP1] ; this read counts
45+
or a, $F0 ; A7-4 = 1; A3-0 = unpressed keys
46+
.knownret
47+
ret

0 commit comments

Comments
 (0)