From 18480e9c96748a96578e4f77f1e06b3306f2aa63 Mon Sep 17 00:00:00 2001 From: Yeastplume Date: Tue, 3 Mar 2020 11:02:50 +0000 Subject: [PATCH] add test for high bits of tilemap entries --- src/cmd/asm/command.rs | 3 +- vera/src/asm.rs | 5 ++ vera/src/lib.rs | 2 +- vera/src/tilemap.rs | 5 ++ .../data/tilemap/imageset-large-4bpp.png | Bin 0 -> 8900 bytes vera/tests/data/tilemap/palette-large.png | Bin 0 -> 575 bytes .../tests/data/tilemap/tilemap-large-4bpp.png | Bin 0 -> 2214 bytes vera/tests/tilemap.rs | 68 +++++++++++++++++- 8 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 vera/tests/data/tilemap/imageset-large-4bpp.png create mode 100644 vera/tests/data/tilemap/palette-large.png create mode 100644 vera/tests/data/tilemap/tilemap-large-4bpp.png diff --git a/src/cmd/asm/command.rs b/src/cmd/asm/command.rs index fc19d1d..2ebb636 100644 --- a/src/cmd/asm/command.rs +++ b/src/cmd/asm/command.rs @@ -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!( diff --git a/vera/src/asm.rs b/vera/src/asm.rs index 212e515..5e976e6 100644 --- a/vera/src/asm.rs +++ b/vera/src/asm.rs @@ -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) } diff --git a/vera/src/lib.rs b/vera/src/lib.rs index 55af76b..1c65961 100644 --- a/vera/src/lib.rs +++ b/vera/src/lib.rs @@ -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}; diff --git a/vera/src/tilemap.rs b/vera/src/tilemap.rs index 426b49c..b5a9e5b 100644 --- a/vera/src/tilemap.rs +++ b/vera/src/tilemap.rs @@ -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 { + &self.tiles + } } impl Assemblable for VeraTileMap { diff --git a/vera/tests/data/tilemap/imageset-large-4bpp.png b/vera/tests/data/tilemap/imageset-large-4bpp.png new file mode 100644 index 0000000000000000000000000000000000000000..70f40bdec2ec963fab8dbbdf703eb79e5ff44bc7 GIT binary patch literal 8900 zcma)hWl$VIx8>mOF2NE!5S#&mySq<9aLd5p5C(!1AUFhqOBe!#L6Zz_K_@_h2X}WE zV9@1zuXbx+?Vs%*T`jk|>fEk#@9ooZ272lwgp7m$0DweOL&XRHzyLmui}0}?`j(g7#N~eqFfo~?jU8&<*OHrleXmROxb+zZ<-Wu1>grkVjMt#?hWz7~XGVg+HWs~cL$ALC*6HyFgn0Ic7D zH}xW-m`bueVH$EQ9_Ko#R977MVUhvA_yLlMt&!Wl#}Ar0nO$@r#<1gNB8CSY;t&SE zD*i{mu$EJ&UMwHD6v^ z4P@Q?bzsWr$JCVCW}lM{&2ERsy>47^i$+a^{3US-Dx~f%)8?Hl;G?A>*dJQgdxTSD zFA6xl?3fWF!(`*#wZ7>zzbua1;?!gts1+3+92t?=^tR|*jkqs<*g2LwpS=9oyK~P& zwveCRNev_1UTv-$GaiqIzH`D&?=5D!3;OWjwQN(^BNUb1x#AO8@&WQU!z(DR#Q$st zgdv%)zIA$UO!Z(pQ`iWc<}hTG!*Kg1oWf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--git a/vera/tests/tilemap.rs b/vera/tests/tilemap.rs index c1f85b9..94768ab 100644 --- a/vera/tests/tilemap.rs +++ b/vera/tests/tilemap.rs @@ -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] @@ -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(()) +}