Skip to content

Commit

Permalink
add ability to specify .bin load address at assembly time
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Feb 21, 2020
1 parent 24c8bc6 commit a19b554
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion samples/bitmap/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ project.av: $(RESOURCES)
$(ALOEVERA) -p project.av asm ./output/ all
$(ALOEVERA) -p project.av asm -f basic ./output/ all
#$(ALOEVERA) create sd_image kq5.img
#$(ALOEVERA) -p project.av asm -f bin . -s kq5.img select kq5_bmp kq5_bmp.bin
#$(ALOEVERA) -p project.av asm -f bin ./output/ select -a 0x2200 kq5_bmp kq5_bmp.bin

generate_resources: project.av

Expand Down
6 changes: 6 additions & 0 deletions src/bin/aloevera.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ subcommands:
- out_file:
help: Output asset location
index: 2
- bin_address:
help: When outputting .bin files, the 16-bit load address to use as the header (e.g 0xbaba, baba)
long: bin_address
short: a
takes_value: true
default_value: "0x0000"
- palette:
about: Import and manipulate palette files
subcommands:
Expand Down
14 changes: 13 additions & 1 deletion src/cmd/asm/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn perform_assemble<T>(
file_name: Option<&str>,
line_start: &mut usize,
sd_image: &Option<String>,
bin_address: Option<[u8; 2]>,
) -> Result<(), Error>
where
T: Assemblable,
Expand All @@ -45,7 +46,7 @@ where
Some(f) => f.into(),
None => format!("{}/{}.bin", out_dir, v.id()),
};
common::output_to_file(&file_name, &code.data_as_bin(None), sd_image)?;
common::output_to_file(&file_name, &code.data_as_bin(bin_address), sd_image)?;
(asm_meta.to_string(None)?, "meta")
} else {
let asm_data = code.assemble_data(output_format.clone())?;
Expand Down Expand Up @@ -89,6 +90,7 @@ pub fn asm_all(g_args: &GlobalArgs, args: &AsmArgs) -> Result<(), Error> {
None,
&mut line_start,
&args.sd_image,
None,
)?;
}
if !proj.imagesets.is_empty() {
Expand All @@ -101,6 +103,7 @@ pub fn asm_all(g_args: &GlobalArgs, args: &AsmArgs) -> Result<(), Error> {
None,
&mut line_start,
&args.sd_image,
None,
)?;
}
if !proj.tilemaps.is_empty() {
Expand All @@ -113,6 +116,7 @@ pub fn asm_all(g_args: &GlobalArgs, args: &AsmArgs) -> Result<(), Error> {
None,
&mut line_start,
&args.sd_image,
None,
)?;
}
let mut sprites = vec![];
Expand Down Expand Up @@ -141,6 +145,7 @@ pub fn asm_all(g_args: &GlobalArgs, args: &AsmArgs) -> Result<(), Error> {
None,
&mut line_start,
&args.sd_image,
None,
)?;
}
let mut bitmaps = vec![];
Expand Down Expand Up @@ -169,6 +174,7 @@ pub fn asm_all(g_args: &GlobalArgs, args: &AsmArgs) -> Result<(), Error> {
None,
&mut line_start,
&args.sd_image,
None,
)?;
}

Expand All @@ -179,6 +185,7 @@ pub fn asm_all(g_args: &GlobalArgs, args: &AsmArgs) -> Result<(), Error> {
pub struct AsmSelectArgs {
pub asset_id: String,
pub out_file: String,
pub bin_address: [u8; 2],
}

pub fn asm_select(
Expand All @@ -197,6 +204,7 @@ pub fn asm_select(
Some(&args.out_file),
&mut line_start,
&asm_args.sd_image,
Some(args.bin_address),
)?;
return Ok(());
}
Expand All @@ -208,6 +216,7 @@ pub fn asm_select(
Some(&args.out_file),
&mut line_start,
&asm_args.sd_image,
Some(args.bin_address),
)?;
return Ok(());
}
Expand All @@ -219,6 +228,7 @@ pub fn asm_select(
Some(&args.out_file),
&mut line_start,
&asm_args.sd_image,
Some(args.bin_address),
)?;
return Ok(());
}
Expand All @@ -242,6 +252,7 @@ pub fn asm_select(
Some(&args.out_file),
&mut line_start,
&asm_args.sd_image,
Some(args.bin_address),
)?;
return Ok(());
}
Expand All @@ -265,6 +276,7 @@ pub fn asm_select(
Some(&args.out_file),
&mut line_start,
&asm_args.sd_image,
Some(args.bin_address),
)?;
return Ok(());
}
Expand Down
19 changes: 19 additions & 0 deletions src/cmd/asm/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use clap::ArgMatches;

use super::command::{self, AsmArgs, AsmSelectArgs};
use crate::cmd::common::{self, GlobalArgs};
use crate::util;
use crate::{Error, ErrorKind};

use vera::AsmFormat;
Expand Down Expand Up @@ -45,6 +46,23 @@ pub fn parse_asm_select_args(
) -> Result<AsmSelectArgs, Error> {
let asset_id = common::parse_required(args, "asset_id")?;
let out_file = common::parse_required(args, "out_file")?;

let mut bin_address = common::parse_required(args, "bin_address")?
.to_owned()
.to_uppercase();
if bin_address.starts_with("0X") {
bin_address = bin_address.split_off(2);
};
let bin_address_vec = util::hex::from_hex(bin_address)?;
if bin_address_vec.len() != 2 {
let msg = format!(".bin start address must be 16 bytes (4 hex digits)");
return Err(ErrorKind::ArgumentError(msg).into());
}
let mut bin_address = [0, 0];
for i in 0..2 {
bin_address[i] = bin_address_vec[i];
}

Ok(AsmSelectArgs {
asset_id: asset_id.into(),
out_file: format!(
Expand All @@ -53,6 +71,7 @@ pub fn parse_asm_select_args(
std::path::MAIN_SEPARATOR,
out_file
),
bin_address,
})
}

Expand Down
2 changes: 2 additions & 0 deletions util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ pub mod fat;
// Logging related
pub mod logger;
pub use crate::logger::{init_logger, init_test_logger};

pub mod hex;

0 comments on commit a19b554

Please sign in to comment.