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
impl Vblank
Sourcepub unsafe fn listen() -> Self
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.
Sourcepub fn frame_count(&self) -> u8
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.
Sourcepub fn wait(&self)
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.
Sourcepub fn with<R>(&self, f: impl FnOnce(Access<'_>) -> R) -> R
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.