gameboy-rust/src/affine_raster_demo.rs

40 lines
1.2 KiB
Rust

//! CPU-driven affine raster distortion. HBlank DMA changes BG2PB for the next
//! line transition; internal origins accumulate the resulting horizontal shifts.
use crate::{
graphics_demo::{GraphicsDemo, GraphicsError},
input::Buttons,
machine::Machine,
memory::MemoryError,
video::Framebuffer,
};
/// Completed updates and signed pan X/Y, as three debug words.
pub const AFFINE_RASTER_STATE: u32 = crate::affine_demo::AFFINE_STATE;
/// 160 halfwords generated by ARM code during each VBlank.
pub const AFFINE_RASTER_TABLE: u32 = 0x0200_1000;
pub struct AffineRasterDemo {
runner: GraphicsDemo,
}
impl AffineRasterDemo {
pub fn new() -> Result<Self, MemoryError> {
Ok(Self {
runner: GraphicsDemo::with_program(crate::affine_demo::raster_program())?,
})
}
pub fn machine(&self) -> &Machine {
self.runner.machine()
}
/// Arrows pan; Q rotates; W zooms; Z bypasses raster distortion; Enter resets pan.
pub fn frame(
&mut self,
buttons: Buttons,
output: &mut Framebuffer,
) -> Result<usize, GraphicsError> {
self.runner.frame_with_control(buttons, output, 0x402)
}
}