Skip to content

Commit

Permalink
conflation of tilemaps confirmed working
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Feb 22, 2020
1 parent b351a81 commit 0ca9b5f
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 31 deletions.
5 changes: 4 additions & 1 deletion samples/tile_wall/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ 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
# Output tilemap again, but conflated
$(ALOEVERA) -p project.av asm ./output/tilemaps -c select wall_tilemap wall_tilemap.ca65.conflated.inc
$(ALOEVERA) -p project.av asm -f bin ./output/tilemaps -c select wall_tilemap wall_tilemap.ca65.conflated.bin
$(ALOEVERA) -p project.av asm -f cc65 ./output/tilemaps -c select wall_tilemap wall_tilemap.cc65.conflated.bin

generate_resources: project.av

Expand Down
18 changes: 18 additions & 0 deletions samples/tile_wall/tile_wall.s
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,28 @@ jmp start
rts
.endproc

.proc load_tilemap_conflated
v_address_set $10000, 1
set_const_16 $00, tilemap_conflated

TARGET = 4096 ;loop until size reached

loop:
lda ($00),y
sta VERA_DATA0
add_constant_16 $00, 1
loop_till_eq_16 $00, (tilemap_conflated + TARGET), loop
rts
.endproc

start:
jsr set_mode
jsr load_palette
jsr load_imageset
jsr clear_map
jsr load_tilemap
;Alternatively, comment in below for the conflated straight-load version
;jsr load_tilemap_conflated
;turn off layer 2 to see our handiwork
v_address_set $F3000, 0
lda #$0 ;default, off
Expand All @@ -123,3 +139,5 @@ imageset:
.include "output/imagesets/wall_tiles.ca65.inc"
tilemap:
.include "output/tilemaps/wall_tilemap.ca65.inc"
tilemap_conflated:
.include "output/tilemaps/wall_tilemap.ca65.conflated.inc"
27 changes: 16 additions & 11 deletions src/cmd/asm/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ where
{
for v in values {
let code = v.assemble()?;
let asm_meta = code.assemble_meta(asm_args.format.clone())?;
let conflate = asm_args.format == AsmFormat::Bin || asm_args.conflate_tilemaps;
let asm_meta = code.assemble_meta(asm_args.format.clone(), conflate)?;
let meta_lc = asm_meta.line_count();
let (output, ext) = if asm_args.format == AsmFormat::Bin {
let (file_name, bin_address) = match sel_args.clone() {
Expand Down Expand Up @@ -67,16 +68,20 @@ where
}
(res, ext)
};
let file_name = match sel_args.clone() {
Some(s) => format!("{}.meta", s.out_file),
None => format!(
"{}/{}.{}.{}",
asm_args.out_dir,
v.id(),
asm_args.format,
ext
),
};
let mut file_name = format!(
"{}/{}.{}.{}",
asm_args.out_dir,
v.id(),
asm_args.format,
ext
);
if let Some(s) = sel_args.clone() {
if asm_args.format == AsmFormat::Bin {
file_name = format!("{}.meta", s.out_file);
} else {
file_name = s.out_file.clone();
}
}
common::output_to_file(&file_name, output.as_bytes(), &asm_args.sd_image)?;
}
Ok(())
Expand Down
22 changes: 18 additions & 4 deletions vera/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ pub struct ConflateInfo {
skip: usize,
/// Total vera tilemap length, in bytes
tilemap_length: usize,
/// Differing Meta
conflated_meta: Vec<String>,
}

/// Holds raw assembled data, pre-formatting
Expand Down Expand Up @@ -166,12 +168,14 @@ impl AssembledPrimitive {
stride: u32,
skip: u32,
tilemap_length: u32,
conflated_meta: Vec<String>,
) {
self.conflate_info = Some(ConflateInfo {
start_offset: start_offset as usize,
stride: stride as usize,
skip: skip as usize,
tilemap_length: tilemap_length as usize,
conflated_meta,
});
}

Expand Down Expand Up @@ -242,12 +246,22 @@ impl AssembledPrimitive {
}

/// Output Meta, formatted for assembly target
pub fn assemble_meta(&self, out_format: AsmFormat) -> Result<AssembledString, Error> {
pub fn assemble_meta(
&self,
out_format: AsmFormat,
conflate: bool,
) -> Result<AssembledString, Error> {
let mut retval = AssembledString::new(&out_format);
let mut meta = &self.meta;
let conf_meta;
if self.conflate_info.is_some() && conflate {
conf_meta = self.conflate_info.as_ref().unwrap().conflated_meta.clone();
meta = &conf_meta;
}
if out_format == AsmFormat::Cc65 {
retval.add(format!("/**"));
}
for m in self.meta.iter() {
for m in meta.iter() {
retval.add(match out_format {
AsmFormat::Ca65 => format!(";{}", m),
AsmFormat::Basic => format!("REM {}", m.to_uppercase()),
Expand Down Expand Up @@ -334,7 +348,7 @@ fn test_assemble() -> Result<(), Error> {
prim.add_data(&[16u8; 34]);

let mut line_count = 1;
let meta_strs = prim.assemble_meta(AsmFormat::Basic)?;
let meta_strs = prim.assemble_meta(AsmFormat::Basic, false)?;
let num_lines = meta_strs.line_count();
let meta_str = meta_strs.to_string(Some(line_count))?;
line_count += num_lines;
Expand All @@ -349,7 +363,7 @@ fn test_assemble() -> Result<(), Error> {
println!("{}", data_str);
assert!(data_str.ends_with("8 DATA 16,16\n"));

let meta_strs = prim.assemble_meta(AsmFormat::Ca65)?;
let meta_strs = prim.assemble_meta(AsmFormat::Ca65, false)?;
let meta_str = meta_strs.to_string(None)?;

let data_strs = prim.assemble_data(AsmFormat::Ca65, false)?;
Expand Down
2 changes: 1 addition & 1 deletion vera/src/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ mod test {
let palette = VeraPalette::default();
let code = palette.assemble()?;
println!("palette: {}", palette);
let asm = code.assemble_meta(crate::AsmFormat::Ca65)?;
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)?);
Expand Down
9 changes: 8 additions & 1 deletion vera/src/tilemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,14 @@ impl Assemblable for VeraTileMap {
// load instructions
let (start_index, stride, skip) = self.calc_start_index_stride_and_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);
let mut conflated_meta = vec![];
conflated_meta.push(format!("{} - size is {}", self.id, length));
conflated_meta.push(format!(
"{}x{} 2 byte Tilemap entries",
self.map_width.val_as_u32(),
self.map_height.val_as_u32()
));
retval.set_tilemap_conflate_info(start_index, stride, skip, length, conflated_meta);
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: 2 additions & 2 deletions vera/tests/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ fn bitmap_load_8bpp() -> Result<(), Error> {
let sprite = VeraBitmap::init_from_imageset("bitmap", &set)?;

let code = sprite.assemble()?;
let asm = code.assemble_meta(crate::AsmFormat::Ca65)?;
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)?);

// assemble BASIC
let line_start = 1000;
let asm = code.assemble_meta(crate::AsmFormat::Basic)?;
let asm = code.assemble_meta(crate::AsmFormat::Basic, false)?;
let len_to_add = asm.line_count();
println!("{}", asm.to_string(Some(line_start))?);
let asm = code.assemble_data(crate::AsmFormat::Ca65, false)?;
Expand Down
10 changes: 5 additions & 5 deletions vera/tests/imageset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ fn imageset_indexed_8_2_x_8_2bpp() -> Result<(), Error> {
set.format_indices(&palette, VeraPixelDepth::BPP8)?;
println!("{}", set);
let code = set.assemble()?;
let asm = code.assemble_meta(crate::AsmFormat::Ca65)?;
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)?);
Expand All @@ -251,7 +251,7 @@ fn imageset_indexed_8_2_x_8_2bpp() -> Result<(), Error> {
set.format_indices(&palette, VeraPixelDepth::BPP4)?;
println!("{}", set);
let code = set.assemble()?;
let asm = code.assemble_meta(crate::AsmFormat::Ca65)?;
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)?);
Expand All @@ -260,7 +260,7 @@ fn imageset_indexed_8_2_x_8_2bpp() -> Result<(), Error> {
set.format_indices(&palette, VeraPixelDepth::BPP2)?;
println!("{}", set);
let code = set.assemble()?;
let asm = code.assemble_meta(crate::AsmFormat::Ca65)?;
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)?);
Expand Down Expand Up @@ -297,14 +297,14 @@ fn imageset_text_8_x_8_1bpp() -> Result<(), Error> {

println!("depth: {:?}", set.depth);
let code = set.assemble()?;
let asm = code.assemble_meta(crate::AsmFormat::Ca65)?;
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)?);

// assemble BASIC
let line_start = 1000;
let asm = code.assemble_meta(crate::AsmFormat::Basic)?;
let asm = code.assemble_meta(crate::AsmFormat::Basic, false)?;
let len_to_add = asm.line_count();
println!("{}", asm.to_string(Some(line_start))?);
let asm = code.assemble_data(crate::AsmFormat::Basic, false)?;
Expand Down
4 changes: 2 additions & 2 deletions vera/tests/sprite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ fn sprite_load_4bpp() -> Result<(), Error> {
let sprite = VeraSprite::init_from_imageset("sprite", &set)?;

let code = sprite.assemble()?;
let asm = code.assemble_meta(crate::AsmFormat::Ca65)?;
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)?);

// assemble BASIC
let line_start = 1000;
let asm = code.assemble_meta(crate::AsmFormat::Basic)?;
let asm = code.assemble_meta(crate::AsmFormat::Basic, false)?;
let len_to_add = asm.line_count();
println!("{}", asm.to_string(Some(line_start))?);
let asm = code.assemble_data(crate::AsmFormat::Basic, false)?;
Expand Down
8 changes: 4 additions & 4 deletions vera/tests/tilemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn tilemap_32_x_32_x_16_8bpp() -> Result<(), Error> {
println!("{}", tilemap);
let code = tilemap.assemble()?;
println!("palette: {}", palette);
let asm = code.assemble_meta(crate::AsmFormat::Ca65)?;
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)?);
Expand Down Expand Up @@ -114,7 +114,7 @@ fn tilemap_text_8_x_8() -> Result<(), Error> {
println!("{}", tilemap);

let code = tilemap.assemble()?;
let asm = code.assemble_meta(crate::AsmFormat::Ca65)?;
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)?);
Expand All @@ -134,7 +134,7 @@ fn tilemap_text_8_x_8() -> Result<(), Error> {

// and output in format 1
let code = tilemap.assemble()?;
let asm = code.assemble_meta(crate::AsmFormat::Ca65)?;
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)?);
Expand Down Expand Up @@ -185,7 +185,7 @@ fn tilemap_128_x_32_x_16_4bpp() -> Result<(), Error> {

println!("{}", tilemap);
let code = tilemap.assemble()?;
let asm = code.assemble_meta(crate::AsmFormat::Ca65)?;
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)?);
Expand Down

0 comments on commit 0ca9b5f

Please sign in to comment.