mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 08:11:33 +11:00
Update the background example to search for the colour
This commit is contained in:
parent
b219e00454
commit
bf4a6887a5
|
@ -31,18 +31,19 @@ fn main(mut gba: agb::Gba) -> ! {
|
|||
|
||||
let colours: Box<[_]> = (0..160).map(|i| ((i * 0xffff) / 160) as u16).collect();
|
||||
|
||||
let mut frame = 0;
|
||||
let background_colour = 0x732b; // generated using `https://agbrs.dev/colour`
|
||||
let background_colour_index = vram
|
||||
.find_colour_index_16(0, background_colour)
|
||||
.expect("Should contain colour 0x732b");
|
||||
|
||||
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) };
|
||||
let _background_color_transfer = unsafe {
|
||||
dma.hblank_transfer(
|
||||
&vram.background_palette_colour_dma(0, background_colour_index),
|
||||
&colours,
|
||||
)
|
||||
};
|
||||
|
||||
vblank.wait_for_vblank();
|
||||
frame += 1;
|
||||
if frame > 160 {
|
||||
frame = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -461,4 +461,11 @@ impl VRamManager {
|
|||
self.set_background_palette(palette_index as u8, entry);
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the index of the colour for a given background palette, or None if it doesn't exist
|
||||
pub fn find_colour_index_16(&mut self, palette_index: usize, colour: u16) -> Option<usize> {
|
||||
assert!(palette_index < 16);
|
||||
|
||||
(0..16).find(|i| PALETTE_BACKGROUND.get(palette_index * 16 + i) == colour)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue