Skip to content

Commit

Permalink
II-17: Initialize wCurKeys and wNewKeys (#76)
Browse files Browse the repository at this point in the history
Co-authored-by: Eldred Habert <eldredhabert0@gmail.com>
  • Loading branch information
kav and ISSOtm committed Feb 16, 2024
1 parent c435afb commit d52e461
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/part2/input.md
Expand Up @@ -29,6 +29,13 @@ First, let's set aside some room for the two variables that `UpdateKeys` will us
Each variable must reside in RAM, and not ROM, because ROM is "Read-Only" (so you can't modify it).
Additionally, each variable only needs to be one byte large, so we use `db` ("Define Byte") to reserve one byte of RAM for each.

Before we read these variables we will also want to initialize them.
We can do that below our initialization of `wFrameCounter`.

```rgbasm,linenos,start={{#line_no_of "" ../../unbricked/input/main.asm:initialize-vars}}
{{#include ../../unbricked/input/main.asm:initialize-vars}}
```

We're going to use the `and` opcode, which we can use to set the zero flag (`z`) to the value of the bit.
We can use this along with the `PADF` constants in hardware.inc to read a particular key.

Expand Down
3 changes: 3 additions & 0 deletions unbricked/bricks/main.asm
Expand Up @@ -90,8 +90,11 @@ ClearOam:
ld a, %11100100
ld [rOBP0], a

; Initialize global variables
ld a, 0
ld [wFrameCounter], a
ld [wCurKeys], a
ld [wNewKeys], a

Main:
ld a, [rLY]
Expand Down
3 changes: 3 additions & 0 deletions unbricked/collision/main.asm
Expand Up @@ -90,8 +90,11 @@ ClearOam:
ld a, %11100100
ld [rOBP0], a

; Initialize global variables
ld a, 0
ld [wFrameCounter], a
ld [wCurKeys], a
ld [wNewKeys], a

; ANCHOR: momentum
Main:
Expand Down
1 change: 1 addition & 0 deletions unbricked/functions/main.asm
Expand Up @@ -68,6 +68,7 @@ ClearOam:
ld a, %11100100
ld [rOBP0], a

; Initialize global variables
ld a, 0
ld [wFrameCounter], a

Expand Down
5 changes: 5 additions & 0 deletions unbricked/input/main.asm
Expand Up @@ -68,8 +68,13 @@ ClearOam:
ld a, %11100100
ld [rOBP0], a

; ANCHOR: initialize-vars
; Initialize global variables
ld a, 0
ld [wFrameCounter], a
ld [wCurKeys], a
ld [wNewKeys], a
; ANCHOR_END: initialize-vars

; ANCHOR: main
Main:
Expand Down
1 change: 1 addition & 0 deletions unbricked/objects/main.asm
Expand Up @@ -94,6 +94,7 @@ ClearOam:
; ANCHOR_END: enable-oam

; ANCHOR: main-loop
; Initialize global variables
ld a, 0
ld [wFrameCounter], a

Expand Down

0 comments on commit d52e461

Please sign in to comment.