diff --git a/agb-image-converter/src/rust_generator.rs b/agb-image-converter/src/rust_generator.rs index 27c4902..ae28863 100644 --- a/agb-image-converter/src/rust_generator.rs +++ b/agb-image-converter/src/rust_generator.rs @@ -12,9 +12,12 @@ pub(crate) fn generate_code( tile_size: TileSize, crate_prefix: String, ) -> io::Result<()> { + writeln!(output, "#[allow(non_upper_case_globals)]")?; + writeln!(output, "pub const {}: {}::display::tile_data::TileData = {{", "test", crate_prefix)?; + writeln!( output, - "pub const PALETTE_DATA: &[{}::display::palette16::Palette16] = &[", + "const PALETTE_DATA: &[{}::display::palette16::Palette16] = &[", crate_prefix, )?; @@ -39,7 +42,7 @@ pub(crate) fn generate_code( writeln!(output, "];")?; writeln!(output)?; - writeln!(output, "pub const TILE_DATA: &[u32] = &[",)?; + writeln!(output, "const TILE_DATA: &[u32] = &[",)?; let tile_size = tile_size.to_size(); @@ -82,7 +85,7 @@ pub(crate) fn generate_code( writeln!(output, "];")?; writeln!(output)?; - write!(output, "pub const PALETTE_ASSIGNMENT: &[u8] = &[")?; + write!(output, "const PALETTE_ASSIGNMENT: &[u8] = &[")?; for (i, assignment) in results.assignments.iter().enumerate() { if i % 16 == 0 { @@ -93,5 +96,7 @@ pub(crate) fn generate_code( writeln!(output, "\n];")?; + writeln!(output, "{}::display::tile_data::TileData::new(PALETTE_DATA, TILE_DATA, PALETTE_ASSIGNMENT)\n}};", crate_prefix)?; + Ok(()) } diff --git a/agb/examples/test_logo.rs b/agb/examples/test_logo.rs index 888e04d..29f4988 100644 --- a/agb/examples/test_logo.rs +++ b/agb/examples/test_logo.rs @@ -10,14 +10,14 @@ pub fn main() -> ! { let mut gba = agb::Gba::new(); let mut gfx = gba.display.video.tiled0(); - gfx.set_background_palettes(example_logo::PALETTE_DATA); - gfx.set_background_tilemap(0, example_logo::TILE_DATA); + gfx.set_background_palettes(example_logo::test.palettes); + gfx.set_background_tilemap(0, example_logo::test.tiles); let mut back = gfx.get_background().unwrap(); let mut entries: [u16; 30 * 20] = [0; 30 * 20]; for tile_id in 0..(30 * 20) { - let palette_entry = example_logo::PALETTE_ASSIGNMENT[tile_id as usize] as u16; + let palette_entry = example_logo::test.palette_assignments[tile_id as usize] as u16; entries[tile_id as usize] = tile_id | (palette_entry << 12); } diff --git a/agb/src/display/example_logo.rs b/agb/src/display/example_logo.rs index 9adc2b3..2d5379f 100644 --- a/agb/src/display/example_logo.rs +++ b/agb/src/display/example_logo.rs @@ -4,14 +4,14 @@ include!(concat!(env!("OUT_DIR"), "/test_logo.rs")); fn logo_display(gba: &mut crate::Gba) { let mut gfx = gba.display.video.tiled0(); - gfx.set_background_palettes(PALETTE_DATA); - gfx.set_background_tilemap(0, TILE_DATA); + gfx.set_background_palettes(test.palettes); + gfx.set_background_tilemap(0, test.tiles); let mut back = gfx.get_background().unwrap(); let mut entries: [u16; 30 * 20] = [0; 30 * 20]; for tile_id in 0..(30 * 20) { - let palette_entry = PALETTE_ASSIGNMENT[tile_id as usize] as u16; + let palette_entry = test.palette_assignments[tile_id as usize] as u16; entries[tile_id as usize] = tile_id | (palette_entry << 12); } diff --git a/agb/src/display/mod.rs b/agb/src/display/mod.rs index afd8157..9b00c4e 100644 --- a/agb/src/display/mod.rs +++ b/agb/src/display/mod.rs @@ -22,6 +22,8 @@ pub mod tiled0; pub mod vblank; /// Giving out graphics mode. pub mod video; +/// Data produced by agb-image-converter +pub mod tile_data; const DISPLAY_CONTROL: MemoryMapped = unsafe { MemoryMapped::new(0x0400_0000) }; const DISPLAY_STATUS: MemoryMapped = unsafe { MemoryMapped::new(0x0400_0004) }; diff --git a/agb/src/display/tile_data.rs b/agb/src/display/tile_data.rs new file mode 100644 index 0000000..aa6630e --- /dev/null +++ b/agb/src/display/tile_data.rs @@ -0,0 +1,17 @@ +use crate::display::palette16::Palette16; + +pub struct TileData { + pub palettes: &'static [Palette16], + pub tiles: &'static [u32], + pub palette_assignments: &'static [u8], +} + +impl TileData { + pub const fn new(palettes: &'static [Palette16], tiles: &'static [u32], palette_assignments: &'static [u8]) -> Self { + TileData { + palettes, + tiles, + palette_assignments, + } + } +} \ No newline at end of file