mirror of
https://github.com/italicsjenga/agb.git
synced 2025-01-11 09:31:34 +11:00
Start work for new proc macro by generating a TileData
This commit is contained in:
parent
4a9f98e09c
commit
383c5454ea
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<u16> = unsafe { MemoryMapped::new(0x0400_0000) };
|
||||
const DISPLAY_STATUS: MemoryMapped<u16> = unsafe { MemoryMapped::new(0x0400_0004) };
|
||||
|
|
17
agb/src/display/tile_data.rs
Normal file
17
agb/src/display/tile_data.rs
Normal file
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue