diff --git a/agb/examples/dma_effect.rs b/agb/examples/dma_effect.rs deleted file mode 100644 index 5d08c693..00000000 --- a/agb/examples/dma_effect.rs +++ /dev/null @@ -1,71 +0,0 @@ -#![no_std] -#![no_main] - -extern crate alloc; - -use alloc::boxed::Box; - -use agb::{ - display::{ - example_logo, - tiled::{RegularBackgroundSize, TileFormat, TiledMap}, - }, - interrupt::VBlank, -}; - -#[agb::entry] -fn main(mut gba: agb::Gba) -> ! { - let (gfx, mut vram) = gba.display.video.tiled0(); - - let mut input = agb::input::ButtonController::new(); - - let mut map = gfx.background( - agb::display::Priority::P0, - RegularBackgroundSize::Background32x32, - TileFormat::FourBpp, - ); - - let dma = gba.dma.dma().dma0; - - example_logo::display_logo(&mut map, &mut vram); - - let vblank = VBlank::get(); - - let offsets: Box<[_]> = (0..160 * 2).collect(); - let colours: Box<[_]> = (0..160).map(|i| ((i * 0xffff) / 160) as u16).collect(); - - let mut frame = 0; - - let mut effect = false; - - loop { - input.update(); - - if input.is_just_pressed(agb::input::Button::A) { - effect = !effect; - } - - let _x_scroll_transfer = if effect { - Some(unsafe { dma.hblank_transfer(&map.x_scroll_dma(), &offsets[frame..]) }) - } else { - map.set_scroll_pos((0i16, 0i16)); - None - }; - - let _background_color_transfer = if !effect { - Some(unsafe { - dma.hblank_transfer(&vram.background_palette_colour_dma(0, 2), &colours) - }) - } else { - vram.set_background_palette_colour(0, 0, 0xffff); - None - }; - - map.commit(&mut vram); - vblank.wait_for_vblank(); - frame += 1; - if frame > 160 { - frame = 0; - } - } -} diff --git a/agb/examples/dma_effect_background_colour.rs b/agb/examples/dma_effect_background_colour.rs new file mode 100644 index 00000000..6efc4ed9 --- /dev/null +++ b/agb/examples/dma_effect_background_colour.rs @@ -0,0 +1,48 @@ +#![no_std] +#![no_main] + +extern crate alloc; + +use alloc::boxed::Box; + +use agb::{ + display::{ + example_logo, + tiled::{RegularBackgroundSize, TileFormat}, + }, + interrupt::VBlank, +}; + +#[agb::entry] +fn main(mut gba: agb::Gba) -> ! { + let (gfx, mut vram) = gba.display.video.tiled0(); + + let mut map = gfx.background( + agb::display::Priority::P0, + RegularBackgroundSize::Background32x32, + TileFormat::FourBpp, + ); + + let dma = gba.dma.dma().dma0; + + example_logo::display_logo(&mut map, &mut vram); + + let vblank = VBlank::get(); + + let colours: Box<[_]> = (0..160).map(|i| ((i * 0xffff) / 160) as u16).collect(); + + let mut frame = 0; + + loop { + // hardcoding palette index 2 here which you wouldn't want to do in a real example (instead, look for + // the colour you want to replace) + let _background_color_transfer = + unsafe { dma.hblank_transfer(&vram.background_palette_colour_dma(0, 2), &colours) }; + + vblank.wait_for_vblank(); + frame += 1; + if frame > 160 { + frame = 0; + } + } +} diff --git a/agb/examples/dma_effect_background_scroll.rs b/agb/examples/dma_effect_background_scroll.rs new file mode 100644 index 00000000..eb5cdfaa --- /dev/null +++ b/agb/examples/dma_effect_background_scroll.rs @@ -0,0 +1,46 @@ +#![no_std] +#![no_main] + +extern crate alloc; + +use alloc::boxed::Box; + +use agb::{ + display::{ + example_logo, + tiled::{RegularBackgroundSize, TileFormat}, + }, + interrupt::VBlank, +}; + +#[agb::entry] +fn main(mut gba: agb::Gba) -> ! { + let (gfx, mut vram) = gba.display.video.tiled0(); + + let mut map = gfx.background( + agb::display::Priority::P0, + RegularBackgroundSize::Background32x32, + TileFormat::FourBpp, + ); + + let dma = gba.dma.dma().dma0; + + example_logo::display_logo(&mut map, &mut vram); + + let vblank = VBlank::get(); + + let offsets: Box<[_]> = (0..160 * 2).collect(); + + let mut frame = 0; + + loop { + let _x_scroll_transfer = + unsafe { dma.hblank_transfer(&map.x_scroll_dma(), &offsets[frame..]) }; + + vblank.wait_for_vblank(); + frame += 1; + if frame > 160 { + frame = 0; + } + } +}