aboutsummaryrefslogtreecommitdiff
path: root/crates/xa65/src
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-08-17 23:45:09 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-08-18 00:00:59 +0200
commitb1dea2297fb7c073143d8cd9cd9b762a511f7487 (patch)
tree68789baca1a8f1987fb7827e186f3221724d0128 /crates/xa65/src
parent26d0fed1bc2201955ff0138f0ba9f7c5b23e15eb (diff)
downloadtools.nes-b1dea2297fb7c073143d8cd9cd9b762a511f7487.tar.gz
tools.nes-b1dea2297fb7c073143d8cd9cd9b762a511f7487.zip
xa65: Introduce the -b/--bin option
This allows to configure an alternative binary for the 'nasm' program, which is convenient for testing development binaries. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'crates/xa65/src')
-rw-r--r--crates/xa65/src/main.rs31
1 files changed, 24 insertions, 7 deletions
diff --git a/crates/xa65/src/main.rs b/crates/xa65/src/main.rs
index d10ee19..726f673 100644
--- a/crates/xa65/src/main.rs
+++ b/crates/xa65/src/main.rs
@@ -10,6 +10,7 @@ const VERSION: &str = "0.1.0";
#[derive(Default)]
struct Args {
file: String,
+ bin: Option<String>,
config: Option<String>,
target: Option<String>,
out: String,
@@ -20,6 +21,7 @@ fn print_help() {
println!("Bridge between 'nasm' and 'ca65'.\n");
println!("usage: xa65 [OPTIONS] <FILE>\n");
println!("Options:");
+ println!(" -b, --bin <PROGRAM>\tAlternative to the binary for 'nasm'.");
println!(" -C, --config <FILE>\tLinker configuration to be used, whether an identifier or a file path.");
println!(" -o, --out <FILE>\tFile path where the output should be located after execution.");
println!(" --target nes\t\tUsed for compatibility with 'ca65'.");
@@ -37,6 +39,13 @@ fn parse_arguments() -> Args {
while let Some(arg) = args.next() {
match arg.as_str() {
+ "-b" | "--bin" => match res.bin {
+ Some(_) => die("only specify the '-b/--bin' flag once".to_string()),
+ None => match args.next() {
+ Some(v) => res.bin = Some(v),
+ None => die("you need to provide a value for the '-b/--bin' flag".to_string()),
+ },
+ },
"-C" | "--config" => match res.config {
Some(_) => die("only specify the '-C/--config' flag once".to_string()),
None => match args.next() {
@@ -122,10 +131,18 @@ fn find_binary(name: &str) -> Option<PathBuf> {
}
// Returns the path for the binaries for 'nasm' and 'cl65'.
-fn get_binaries() -> Result<(PathBuf, PathBuf), String> {
- let nasm = match find_binary("nasm") {
+fn get_binaries(nasm_name: String) -> Result<(PathBuf, PathBuf), String> {
+ let nasm = match find_binary(&nasm_name) {
Some(nasm) => nasm,
- None => return Err("could not find 'nasm'".to_string()),
+ None => {
+ let path = Path::new(&nasm_name);
+
+ if path.exists() {
+ path.to_path_buf()
+ } else {
+ return Err("could not find 'nasm'".to_string());
+ }
+ }
};
let cl65 = match find_binary("cl65") {
Some(cl65) => cl65,
@@ -189,8 +206,11 @@ fn attempt_hexdump(dir: &Path) {
}
fn main() {
+ // Parse arguments.
+ let args = parse_arguments();
+
// Make sure that the binaries are there.
- let (nasm, cl65) = match get_binaries() {
+ let (nasm, cl65) = match get_binaries(args.bin.unwrap_or("nasm".to_string())) {
Ok((nasm, cl65)) => (nasm, cl65),
Err(e) => {
die(e);
@@ -198,9 +218,6 @@ fn main() {
}
};
- // Parse arguments.
- let args = parse_arguments();
-
// Generate a temporary directory in which both binary files will be placed
// as an intermediate step.
let dir = temporary_dir();