Skip to content

Commit

Permalink
add test for high bits of tilemap entries
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Mar 3, 2020
1 parent 64b0ce1 commit 18480e9
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/cmd/asm/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ where
)?;
(asm_meta.to_string(None)?, "meta")
} else {
let asm_data =
code.assemble_data(asm_args.format.clone(), asm_args.conflate_tilemaps)?;
let asm_data = code.assemble_data(asm_args.format.clone(), conflate)?;
let data_lc = asm_data.line_count();
let output = asm_meta.to_string(Some(*line_start))?;
let res = format!(
Expand Down
5 changes: 5 additions & 0 deletions vera/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ impl AssembledPrimitive {
for _ in 0..(c_data.tilemap_length - ret_data.len()) {
ret_data.push(0);
}
if ret_data.len() != c_data.tilemap_length {
return Err(
ErrorKind::InvalidAsmFormat("Conflated tilemap length is wrong".into()).into(),
);
}
Ok(ret_data)
}

Expand Down
2 changes: 1 addition & 1 deletion vera/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ pub use imageset::{VeraImage, VeraImageSet, VeraImageSetLoadConfig, VeraPixelDep
pub use palette::{VeraPalette, VeraPaletteEntry, VeraPaletteLoadConfig};
pub use png_util::png_to_frames;
pub use sprite::VeraSprite;
pub use tilemap::{VeraTileMap, VeraTileMapDim, VeraTileMapMode};
pub use tilemap::{VeraTileMap, VeraTileMapDim, VeraTileMapEntry, VeraTileMapMode};
5 changes: 5 additions & 0 deletions vera/src/tilemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,11 @@ impl VeraTileMap {
let skip = self.map_width.val_as_u32() * 2 - pane_width * 2;
(start_index, stride, skip)
}

/// Tiles
pub fn get_tiles(&self) -> &Vec<VeraTileMapEntry> {
&self.tiles
}
}

impl Assemblable for VeraTileMap {
Expand Down
Binary file added vera/tests/data/tilemap/imageset-large-4bpp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vera/tests/data/tilemap/palette-large.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vera/tests/data/tilemap/tilemap-large-4bpp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 67 additions & 1 deletion vera/tests/tilemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use aloevera_vera::Error;
use aloevera_vera::{AsmFormat, Assemblable};
use aloevera_vera::{
VeraImageSet, VeraImageSetLoadConfig, VeraPalette, VeraPaletteLoadConfig, VeraPixelDepth,
VeraTileMap, VeraTileMapDim, VeraTileMapMode,
VeraTileMap, VeraTileMapDim, VeraTileMapEntry, VeraTileMapMode,
};

#[test]
Expand Down Expand Up @@ -192,3 +192,69 @@ fn tilemap_128_x_32_x_16_4bpp() -> Result<(), Error> {

Ok(())
}

#[test]
fn tilemap_64_x_32_x_8_4bpp() -> Result<(), Error> {
init_test_logger();
let paldata = include_bytes!("data/tilemap/palette-large.png");
// Load Palette straigt from tilemap
let pal_config = VeraPaletteLoadConfig {
direct_load: true,
include_defaults: false,
sort: false,
..VeraPaletteLoadConfig::default()
};
let palette = VeraPalette::derive_from_png("palette_error", paldata.to_vec(), &pal_config)?;
println!("{}", palette);

// create imageset from tilemap
let setdata = include_bytes!("data/tilemap/imageset-large-4bpp.png");
let mut set = VeraImageSet::new("tileset_error", 8, 8);
let config = VeraImageSetLoadConfig::default();
set.load_from_png(setdata.to_vec(), &config)?;
set.format_indices(&palette, VeraPixelDepth::BPP4)?;
println!("{}", set);

let frame = set.frame_at(256)?;
println!("{}", frame);

// Init tilemap
let mut tilemap = VeraTileMap::init_from_imageset(
"tilemap_error",
VeraTileMapMode::Tile4BPP,
VeraTileMapDim::Dim64,
VeraTileMapDim::Dim32,
&set,
)?;

// And a correct one
let mapdata = include_bytes!("data/tilemap/tilemap-large-4bpp.png");
tilemap.load_from_png(mapdata.to_vec(), None, 0, 0, 0)?;

// Check high bit set correctly
let mut high_bit_index = 0;

for (i, f) in tilemap.get_tiles().iter().enumerate() {
if let VeraTileMapEntry::Tile234(281, _, _, _) = f {
high_bit_index = i;
break;
}
}

let code = tilemap.assemble()?;
println!("{}", tilemap);

let low = code.data_raw()[high_bit_index * 2];
let high = code.data_raw()[high_bit_index * 2 + 1];
let mut test_u16: u16 = (high as u16 & 3) << 8;
test_u16 |= low as u16;
assert_eq!(281, test_u16);

let asm = code.assemble_meta(crate::AsmFormat::Ca65, false)?;
println!("{}", asm.to_string(None)?);

let asm = code.assemble_data(crate::AsmFormat::Ca65, false)?;
println!("{}", asm.to_string(None)?);

Ok(())
}

0 comments on commit 18480e9

Please sign in to comment.