mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 17:41:33 +11:00
Test logo now displays
This commit is contained in:
parent
b2c16f754b
commit
93d82f309e
|
@ -3,7 +3,10 @@ use hashbrown::HashMap;
|
|||
|
||||
use crate::memory_mapped::{MemoryMapped, MemoryMapped1DArray};
|
||||
|
||||
use super::{set_graphics_mode, set_graphics_settings, DisplayMode, GraphicsSettings};
|
||||
use super::{
|
||||
palette16, set_graphics_mode, set_graphics_settings, DisplayMode, GraphicsSettings, Priority,
|
||||
DISPLAY_CONTROL,
|
||||
};
|
||||
|
||||
const TILE_BACKGROUND: MemoryMapped1DArray<u32, { 2048 * 8 }> =
|
||||
unsafe { MemoryMapped1DArray::new(0x06000000) };
|
||||
|
@ -26,10 +29,16 @@ impl TileFormat {
|
|||
}
|
||||
|
||||
pub struct TileSet<'a> {
|
||||
tiles: &'a [u8],
|
||||
tiles: &'a [u32],
|
||||
format: TileFormat,
|
||||
}
|
||||
|
||||
impl<'a> TileSet<'a> {
|
||||
pub fn new(tiles: &'a [u32], format: TileFormat) -> Self {
|
||||
Self { tiles, format }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub struct TileSetReference {
|
||||
id: u16,
|
||||
|
@ -145,20 +154,16 @@ impl<'a> VRamManager<'a> {
|
|||
"Stale tile data requested"
|
||||
);
|
||||
|
||||
let tile_offset = (tile as usize) * data.format.tile_size();
|
||||
&data.tiles[tile_offset..(tile_offset + data.format.tile_size())]
|
||||
let tile_offset = (tile as usize) * data.format.tile_size() / 4;
|
||||
&data.tiles[tile_offset..(tile_offset + data.format.tile_size() / 4)]
|
||||
} else {
|
||||
panic!("Cannot find tile data at given reference");
|
||||
};
|
||||
|
||||
let tile_size_in_words = TileFormat::FourBpp.tile_size() / 4;
|
||||
|
||||
unsafe {
|
||||
let (_, tile_data, _) = tile_slice.align_to::<u32>();
|
||||
|
||||
for (i, &word) in tile_data.iter().enumerate() {
|
||||
TILE_BACKGROUND.set(index_to_copy_into * tile_size_in_words + i, word);
|
||||
}
|
||||
for (i, &word) in tile_slice.iter().enumerate() {
|
||||
TILE_BACKGROUND.set(index_to_copy_into * tile_size_in_words + i, word);
|
||||
}
|
||||
|
||||
TileIndex(index_to_copy_into as u16)
|
||||
|
@ -187,6 +192,19 @@ impl<'a> VRamManager<'a> {
|
|||
PALETTE_BACKGROUND.set(index, colour);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_background_palette(&mut self, pal_index: u8, palette: &palette16::Palette16) {
|
||||
for (colour_index, &colour) in palette.colours.iter().enumerate() {
|
||||
PALETTE_BACKGROUND.set(pal_index as usize * 16 + colour_index, colour);
|
||||
}
|
||||
}
|
||||
|
||||
/// Copies palettes to the background palettes without any checks.
|
||||
pub fn set_background_palettes(&mut self, palettes: &[palette16::Palette16]) {
|
||||
for (palette_index, entry) in palettes.iter().enumerate() {
|
||||
self.set_background_palette(palette_index as u8, entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
@ -205,7 +223,7 @@ pub struct RegularMap {
|
|||
screenblock: u8,
|
||||
x_scroll: u16,
|
||||
y_scroll: u16,
|
||||
priority: u8,
|
||||
priority: Priority,
|
||||
|
||||
tiles: [Tile; 32 * 32],
|
||||
tiles_dirty: bool,
|
||||
|
@ -219,7 +237,7 @@ impl RegularMap {
|
|||
screenblock,
|
||||
x_scroll: 0,
|
||||
y_scroll: 0,
|
||||
priority: 0,
|
||||
priority: Priority::P0,
|
||||
|
||||
tiles: [Tile(0); 32 * 32],
|
||||
tiles_dirty: true,
|
||||
|
@ -231,6 +249,12 @@ impl RegularMap {
|
|||
self.tiles_dirty = true;
|
||||
}
|
||||
|
||||
pub fn show(&mut self) {
|
||||
let mode = DISPLAY_CONTROL.get();
|
||||
let new_mode = mode | (1 << (self.background_id + 0x08));
|
||||
DISPLAY_CONTROL.set(new_mode);
|
||||
}
|
||||
|
||||
pub fn commit(&mut self) {
|
||||
let new_bg_control_value = (self.priority as u16) | ((self.screenblock as u16) << 8);
|
||||
|
||||
|
@ -246,6 +270,8 @@ impl RegularMap {
|
|||
for (i, tile) in self.tiles.iter().enumerate() {
|
||||
screenblock_memory.set(i, tile.0);
|
||||
}
|
||||
|
||||
self.tiles_dirty = false;
|
||||
}
|
||||
|
||||
const fn bg_control_register(&self) -> MemoryMapped<u16> {
|
||||
|
@ -261,7 +287,7 @@ impl RegularMap {
|
|||
}
|
||||
|
||||
const fn screenblock_memory(&self) -> MemoryMapped1DArray<u16, { 32 * 32 }> {
|
||||
unsafe { MemoryMapped1DArray::new(0x0600_0000 + 0x1000 * self.screenblock as usize) }
|
||||
unsafe { MemoryMapped1DArray::new(0x0600_0000 + 0x1000 * self.screenblock as usize / 2) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,23 +1,31 @@
|
|||
/*use crate::display::background::BackgroundDistributor;
|
||||
use crate::display::background::Tiled0;
|
||||
|
||||
use super::background::{Tile, TileFormat, TileSet};
|
||||
|
||||
crate::include_gfx!("gfx/agb_logo.toml");
|
||||
|
||||
pub fn display_logo(gfx: &mut BackgroundDistributor) {
|
||||
use super::background::Map;
|
||||
gfx.set_background_palettes(agb_logo::test_logo.palettes);
|
||||
gfx.set_background_tilemap(0, agb_logo::test_logo.tiles);
|
||||
pub fn display_logo(gfx: &mut Tiled0) {
|
||||
gfx.vram
|
||||
.set_background_palettes(agb_logo::test_logo.palettes);
|
||||
|
||||
let mut back = gfx.get_regular().unwrap();
|
||||
let background_tilemap = TileSet::new(agb_logo::test_logo.tiles, TileFormat::FourBpp);
|
||||
let background_tilemap_reference = gfx.vram.add_tileset(background_tilemap);
|
||||
|
||||
let mut entries: [u16; 30 * 20] = [0; 30 * 20];
|
||||
for tile_id in 0..(30 * 20) {
|
||||
let palette_entry = agb_logo::test_logo.palette_assignments[tile_id as usize] as u16;
|
||||
entries[tile_id as usize] = tile_id | (palette_entry << 12);
|
||||
let mut back = gfx.background();
|
||||
|
||||
for y in 0..20 {
|
||||
for x in 0..30 {
|
||||
let tile_id = y * 30 + x;
|
||||
|
||||
let palette_entry = agb_logo::test_logo.palette_assignments[tile_id as usize] as u16;
|
||||
let tile = gfx.vram.add_tile(background_tilemap_reference, tile_id);
|
||||
|
||||
back.set_tile(x, y, Tile::new(tile, false, false, palette_entry))
|
||||
}
|
||||
}
|
||||
|
||||
back.set_map(Map::new(&entries, (30_u32, 20_u32).into(), 0));
|
||||
back.show();
|
||||
back.commit();
|
||||
back.show();
|
||||
}
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
@ -31,4 +39,4 @@ mod tests {
|
|||
|
||||
crate::test_runner::assert_image_output("gfx/test_logo.png");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -109,6 +109,7 @@ pub fn busy_wait_for_vblank() {
|
|||
while VCOUNT.get() < 160 {}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Priority {
|
||||
P0 = 0,
|
||||
P1 = 1,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use super::{bitmap3::Bitmap3, bitmap4::Bitmap4};
|
||||
use super::{background::Tiled0, bitmap3::Bitmap3, bitmap4::Bitmap4};
|
||||
|
||||
#[non_exhaustive]
|
||||
pub struct Video {}
|
||||
|
@ -14,7 +14,7 @@ impl Video {
|
|||
unsafe { Bitmap4::new() }
|
||||
}
|
||||
|
||||
// pub fn tiled0(&mut self) -> BackgroundDistributor {
|
||||
// unsafe { BackgroundDistributor::new() }
|
||||
// }
|
||||
pub fn tiled0(&mut self) -> Tiled0 {
|
||||
unsafe { Tiled0::new() }
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue