Skip to main content

Vblank

Struct Vblank 

Source
pub struct Vblank(/* private fields */);
Expand description

The frame clock: proof that the VBlank interrupt is reaching the counter.

Everything that waits for a frame hangs without it.

Implementations§

Source§

impl Vblank

Source

pub unsafe fn listen() -> Self

Listen for the VBlank interrupt.

§Safety

Turns interrupts on. That is preemption, which the surrounding code may have been written to rule out.

Source

pub fn frame_count(&self) -> u8

Frames counted since boot, wrapping at 256.

wrapping_sub of two readings is the frames between them; a plain subtraction is what overflows across the wrap.

Source

pub fn wait(&self)

Block until the next frame.

The CPU sleeps while waiting. Does not return with the LCD off, since no VBlank arrives then, nor where a replacement handler skips frame_tick.

Source

pub fn with<R>(&self, f: impl FnOnce(Access<'_>) -> R) -> R

Wait for the next frame, then run f inside its VBlank.

Nothing enforces the window. f keeps running once the PPU has moved on, and writes past that point are dropped in silence.

vblank.with(|d| {
    bg::set_scroll(d, camera_x, camera_y);
    obj::set(d, 0, player);
});

// Overruns: the tail of the tileset lands after the window and is lost.
// `with_lcd_off` has no deadline.
vblank.with(|d| load_tileset(&TILES, d));

Waiting goes through wait, so this does not return under the same conditions.

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.