Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

II-17: Initializing wCurKeys and wNewKeys #76

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/part2/input.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ 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`.
kav marked this conversation as resolved.
Show resolved Hide resolved

```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
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ ClearOam:
ld a, %11100100
ld [rOBP0], a

; Initialize variables
kav marked this conversation as resolved.
Show resolved Hide resolved
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
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ ClearOam:
ld a, %11100100
ld [rOBP0], a

; Initialize 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
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ ClearOam:
ld a, %11100100
ld [rOBP0], a

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

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

; ANCHOR: initialize-vars
; Initialize 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
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ ClearOam:
; ANCHOR_END: enable-oam

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

Expand Down