From 2854acc73b31447b1898d9f59c85bb3e66c5903e Mon Sep 17 00:00:00 2001 From: Kavanaugh Latiolais Date: Thu, 1 Feb 2024 20:08:38 -0600 Subject: [PATCH] II-17: Initializing wCurKeys and wNewKeys --- src/part2/input.md | 6 ++++++ unbricked/bricks/main.asm | 3 +++ unbricked/collision/main.asm | 3 +++ unbricked/functions/main.asm | 1 + unbricked/input/main.asm | 5 +++++ unbricked/objects/main.asm | 1 + 6 files changed, 19 insertions(+) diff --git a/src/part2/input.md b/src/part2/input.md index 67a99a32..c42d4712 100644 --- a/src/part2/input.md +++ b/src/part2/input.md @@ -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`. + +```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. diff --git a/unbricked/bricks/main.asm b/unbricked/bricks/main.asm index 3dcc7534..7522ee31 100644 --- a/unbricked/bricks/main.asm +++ b/unbricked/bricks/main.asm @@ -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 Main: ld a, [rLY] diff --git a/unbricked/collision/main.asm b/unbricked/collision/main.asm index feb49287..71f11e58 100644 --- a/unbricked/collision/main.asm +++ b/unbricked/collision/main.asm @@ -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: diff --git a/unbricked/functions/main.asm b/unbricked/functions/main.asm index f34628b3..7d10098b 100644 --- a/unbricked/functions/main.asm +++ b/unbricked/functions/main.asm @@ -68,6 +68,7 @@ ClearOam: ld a, %11100100 ld [rOBP0], a + ; Initialize variables ld a, 0 ld [wFrameCounter], a diff --git a/unbricked/input/main.asm b/unbricked/input/main.asm index e59f0c7a..f4349a9b 100644 --- a/unbricked/input/main.asm +++ b/unbricked/input/main.asm @@ -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: diff --git a/unbricked/objects/main.asm b/unbricked/objects/main.asm index ee74d209..74ca22ac 100644 --- a/unbricked/objects/main.asm +++ b/unbricked/objects/main.asm @@ -94,6 +94,7 @@ ClearOam: ; ANCHOR_END: enable-oam ; ANCHOR: main-loop + ; Initialize variables ld a, 0 ld [wFrameCounter], a