Skip to main content

Module joypad

Module joypad 

Source
Expand description

The eight buttons.

read returns a Buttons, a bit per button and set where held. The hardware is the other way round, clearing the bit of a button that is down. See https://gbdev.io/pandocs/Joypad_Input.html.

Pad is the usual way in. It keeps the previous reading, which turns “what is held” into “what changed”.

let vblank = unsafe { ppu::Vblank::listen() };
let mut pad = Pad::new();
loop {
    vblank.wait();
    pad.poll();

    if pad.just_pressed.a() {
        jump();
    }
    x = x.wrapping_add_signed(pad.pressed.x() as i8);
}

§Reading from a handler

read selects a row, reads it, then selects the other and reads that. A handler reading the joypad in between finishes with both rows off, and the half of the interrupted read that has not happened yet comes back as nothing pressed. Nothing reports that, so poll in one place.

Structs§

Buttons
The eight buttons, set where held.
Pad
The buttons, and what changed at the last poll.

Enums§

DPadX
Where the d-pad points left or right, as a number to add to a coordinate.
DPadY
Where the d-pad points up or down, as a number to add to a coordinate.

Functions§

read
Read the buttons.