Skip to content

Commit

Permalink
add initial ability to conflate tilemaps for bin output
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Feb 22, 2020
1 parent 98b3a42 commit b351a81
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
1 change: 1 addition & 0 deletions samples/tile_wall/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ project.av: $(RESOURCES)
$(ALOEVERA) -p project.av tilemap load -x 0 -y 10 wall_tilemap tile_wall-map.png
$(ALOEVERA) -p project.av asm ./output/ all
$(ALOEVERA) -p project.av asm -f basic ./output/ all
$(ALOEVERA) -p project.av asm -f bin ./output/ all

generate_resources: project.av

Expand Down
48 changes: 38 additions & 10 deletions vera/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ impl AssembledString {
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ConflateInfo {
/// start offset from start of vera tilemap
start_offset: u32,
start_offset: usize,
/// number of tiles to draw per row
stride: u32,
stride: usize,
/// number of tiles to skip per row
skip: u32,
skip: usize,
/// Total vera tilemap length, in bytes
tilemap_length: usize,
}

/// Holds raw assembled data, pre-formatting
Expand Down Expand Up @@ -158,11 +160,18 @@ impl AssembledPrimitive {
}

/// set Tilemap values
pub fn set_tilemap_conflate_info(&mut self, start_offset: u32, stride: u32, skip: u32) {
pub fn set_tilemap_conflate_info(
&mut self,
start_offset: u32,
stride: u32,
skip: u32,
tilemap_length: u32,
) {
self.conflate_info = Some(ConflateInfo {
start_offset,
stride,
skip,
start_offset: start_offset as usize,
stride: stride as usize,
skip: skip as usize,
tilemap_length: tilemap_length as usize,
});
}

Expand Down Expand Up @@ -208,9 +217,28 @@ impl AssembledPrimitive {
&self.data
}

/// Conflate raw data in-place
pub fn conflate_data(&self) -> Result<Vec<u8>, Error> {
Ok(self.data.clone())
/// Conflate raw data
fn conflate_data(&self) -> Result<Vec<u8>, Error> {
let c_data = match self.conflate_info.clone() {
Some(c) => c,
None => {
return Err(ErrorKind::InvalidAsmFormat("Missing Conflate Data".into()).into());
}
};
// Add zeroes up to start index
let mut ret_data = vec![0u8; c_data.start_offset];
for i in (0..self.data.len()).step_by(c_data.stride) {
let mut slice_vec = vec![0; c_data.stride];
slice_vec.copy_from_slice(&self.data[i..i + c_data.stride]);
ret_data.append(&mut slice_vec);
for _ in 0..c_data.skip {
ret_data.push(0);
}
}
for _ in 0..(c_data.tilemap_length - ret_data.len()) {
ret_data.push(0);
}
Ok(ret_data)
}

/// Output Meta, formatted for assembly target
Expand Down
3 changes: 2 additions & 1 deletion vera/src/tilemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ impl Assemblable for VeraTileMap {
let mut retval = AssembledPrimitive::new(self.id());
// load instructions
let (start_index, stride, skip) = self.calc_start_index_stride_and_skip();
retval.set_tilemap_conflate_info(start_index, stride, skip);
let length = self.map_width.val_as_u32() * self.map_height.val_as_u32() * 2;
retval.set_tilemap_conflate_info(start_index, stride, skip, length);
retval.add_meta(format!("{} size is {}", self.id, self.size()));
retval.add_meta(format!(
"Start write into map_data addr + ${:02X}",
Expand Down
4 changes: 4 additions & 0 deletions vera/tests/tilemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ fn tilemap_text_8_x_8() -> Result<(), Error> {
let asm = code.assemble_data(crate::AsmFormat::Ca65, false)?;
println!("{}", asm.to_string(None)?);

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

Ok(())
}

Expand Down

0 comments on commit b351a81

Please sign in to comment.