diff --git a/book/src/04-non-video/01-buttons.md b/book/src/04-non-video/01-buttons.md index 2aa065c..9111bfd 100644 --- a/book/src/04-non-video/01-buttons.md +++ b/book/src/04-non-video/01-buttons.md @@ -63,6 +63,23 @@ the whole frame. If you've worked with polling input before that should sound totally normal, but if not just always remember to gather the input once per frame and then use that value across the whole frame. +### Detecting New Presses + +The keypad only tells you what's _currently_ pressed, but if you want to check +what's _newly_ pressed it's not too much harder. + +All that you do is store the last frame's keys and compare them to the current +keys with an `XOR`. In the `gba` crate it's called `KeyInput::difference`. Once +you've got the difference between last frame and this frame, you know what +changes happened. + +* If something is in the difference and _not pressed_ in the last frame, that + means it was newly pressed. +* If something is in the difference and _pressed_ in the last frame that means + it was newly released. +* If something is not in the difference then there's no change between last + frame and this frame. + ## Key Interrupt Control * KEYCNT, `0x400_0132`, `u16`, read/write diff --git a/src/io/display.rs b/src/io/display.rs index e3ada94..ce7cda6 100644 --- a/src/io/display.rs +++ b/src/io/display.rs @@ -85,7 +85,7 @@ pub fn display_control() -> DisplayControlSetting { /// If the `VCOUNT` register reads equal to or above this then you're in vblank. pub const VBLANK_SCANLINE: u16 = 160; -/// Vertical Counter (LY). +/// Vertical Counter (LY). Read only. /// /// Gives the current scanline that the display controller is working on. If /// this is at or above the `VBLANK_SCANLINE` value then the display controller