Skip to content

Commit c4dfa4a

Browse files
authored
Add missing variables in input chapter (#36)
1 parent 3644586 commit c4dfa4a

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/part2/input.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ Because of this, we only need to call `UpdateKeys` once per frame.
2020

2121
This is important, because not only is it faster to reload the inputs that we've already processed, but it also means that we will always act on the same inputs, even if the player presses or releases a button mid-frame.
2222

23+
First, let's set aside some room for the two variables that `UpdateKeys` will use; paste this at the end of the `main.asm`:
24+
25+
```rgbasm,linenos,start={{#line_no_of "" ../../unbricked/input/main.asm:vars}}
26+
{{#include ../../unbricked/input/main.asm:vars}}
27+
```
28+
29+
Each variable must reside in RAM, and not ROM, because ROM is "Read-Only" (so you can't modify it).
30+
Additionally, each variable only needs to be one byte large, so we use `db` ("Define Byte") to reserve one byte of RAM for each.
31+
2332
We're going to use the `and` opcode, which we can use to set the zero flag (`z`) to the value of the bit.
2433
We can use this along with the `PADF` constants in hardware.inc to read a particular key.
2534

unbricked/input/main.asm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ PaddleEnd:
416416
SECTION "Counter", WRAM0
417417
wFrameCounter: db
418418

419+
; ANCHOR: vars
419420
SECTION "Input Variables", WRAM0
420421
wCurKeys: db
421422
wNewKeys: db
423+
; ANCHOR_END: vars

0 commit comments

Comments
 (0)