Skip to content

Commit d52e461

Browse files
kavISSOtm
andauthored
II-17: Initialize wCurKeys and wNewKeys (#76)
Co-authored-by: Eldred Habert <[email protected]>
1 parent c435afb commit d52e461

File tree

6 files changed

+20
-0
lines changed

6 files changed

+20
-0
lines changed

src/part2/input.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ First, let's set aside some room for the two variables that `UpdateKeys` will us
2929
Each variable must reside in RAM, and not ROM, because ROM is "Read-Only" (so you can't modify it).
3030
Additionally, each variable only needs to be one byte large, so we use `db` ("Define Byte") to reserve one byte of RAM for each.
3131

32+
Before we read these variables we will also want to initialize them.
33+
We can do that below our initialization of `wFrameCounter`.
34+
35+
```rgbasm,linenos,start={{#line_no_of "" ../../unbricked/input/main.asm:initialize-vars}}
36+
{{#include ../../unbricked/input/main.asm:initialize-vars}}
37+
```
38+
3239
We're going to use the `and` opcode, which we can use to set the zero flag (`z`) to the value of the bit.
3340
We can use this along with the `PADF` constants in hardware.inc to read a particular key.
3441

unbricked/bricks/main.asm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ ClearOam:
9090
ld a, %11100100
9191
ld [rOBP0], a
9292

93+
; Initialize global variables
9394
ld a, 0
9495
ld [wFrameCounter], a
96+
ld [wCurKeys], a
97+
ld [wNewKeys], a
9598

9699
Main:
97100
ld a, [rLY]

unbricked/collision/main.asm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ ClearOam:
9090
ld a, %11100100
9191
ld [rOBP0], a
9292

93+
; Initialize global variables
9394
ld a, 0
9495
ld [wFrameCounter], a
96+
ld [wCurKeys], a
97+
ld [wNewKeys], a
9598

9699
; ANCHOR: momentum
97100
Main:

unbricked/functions/main.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ ClearOam:
6868
ld a, %11100100
6969
ld [rOBP0], a
7070

71+
; Initialize global variables
7172
ld a, 0
7273
ld [wFrameCounter], a
7374

unbricked/input/main.asm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ ClearOam:
6868
ld a, %11100100
6969
ld [rOBP0], a
7070

71+
; ANCHOR: initialize-vars
72+
; Initialize global variables
7173
ld a, 0
7274
ld [wFrameCounter], a
75+
ld [wCurKeys], a
76+
ld [wNewKeys], a
77+
; ANCHOR_END: initialize-vars
7378

7479
; ANCHOR: main
7580
Main:

unbricked/objects/main.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ ClearOam:
9494
; ANCHOR_END: enable-oam
9595

9696
; ANCHOR: main-loop
97+
; Initialize global variables
9798
ld a, 0
9899
ld [wFrameCounter], a
99100

0 commit comments

Comments
 (0)