aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/nasm/src/main.rs24
-rw-r--r--lib/xixanta/src/mapping.rs42
2 files changed, 64 insertions, 2 deletions
diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs
index fbe2bef..9d97507 100644
--- a/crates/nasm/src/main.rs
+++ b/crates/nasm/src/main.rs
@@ -3,7 +3,7 @@ use clap::Parser as ClapParser;
use std::fs::File;
use std::io::{self, Read, Write};
use xixanta::assembler::Assembler;
-use xixanta::mapping::NROM;
+use xixanta::mapping::{Segment, EMPTY, NROM, NROM65};
/// Assembler for the 6502 microprocessor that targets the NES.
#[derive(ClapParser, Debug)]
@@ -13,6 +13,10 @@ struct Args {
/// when this argument is not given.
file: Option<String>,
+ /// Linker configuration to be used. Defaults to 'nrom'.
+ #[arg(short = 'c', long)]
+ config: Option<String>,
+
/// Disassemble instead of assembling. Disabled by default.
#[arg(short, long, default_value_t = false)]
disassemble: bool,
@@ -31,7 +35,6 @@ struct Args {
fn main() -> Result<()> {
let args = Args::parse();
- let mut assembler = Assembler::new(NROM.to_vec());
// Select the input stream.
let input: Box<dyn Read> = match args.file {
@@ -53,6 +56,23 @@ fn main() -> Result<()> {
}
};
+ // Select the linker configuration.
+ let segments: Vec<Segment> = match args.config {
+ Some(c) => match c.to_lowercase().as_str() {
+ "empty" => EMPTY.to_vec(),
+ "nrom" => NROM.to_vec(),
+ "nrom65" => NROM65.to_vec(),
+ _ => {
+ println!("Unnown linker configuration '{}'", c);
+ std::process::exit(1);
+ }
+ },
+ None => NROM.to_vec(),
+ };
+
+ // Initialize the assembler with the given linker configuration.
+ let mut assembler = Assembler::new(segments);
+
// After the parse operation, just print the results.
if args.disassemble {
// let instructions = assembler.disassemble(input)?;
diff --git a/lib/xixanta/src/mapping.rs b/lib/xixanta/src/mapping.rs
index bd2fc2c..657a94b 100644
--- a/lib/xixanta/src/mapping.rs
+++ b/lib/xixanta/src/mapping.rs
@@ -43,6 +43,48 @@ lazy_static! {
bundles: vec![],
}
];
+ pub static ref NROM65: Vec<Segment> = vec![
+ Segment {
+ name: String::from("HEADER"),
+ start: 0x0000,
+ size: 0x0010,
+ offset: 0,
+ fill: Some(0x00),
+ bundles: vec![],
+ },
+ Segment {
+ name: String::from("VECTORS"),
+ start: 0xFFFA,
+ size: 0x0006,
+ offset: 0,
+ fill: Some(0x00),
+ bundles: vec![],
+ },
+ Segment {
+ name: String::from("STARTUP"),
+ start: 0x8000,
+ size: 0x7FFA,
+ offset: 0,
+ fill: Some(0x00),
+ bundles: vec![],
+ },
+ Segment {
+ name: String::from("CODE"),
+ start: 0x8000,
+ size: 0x7FFA,
+ offset: 0,
+ fill: Some(0x00),
+ bundles: vec![],
+ },
+ Segment {
+ name: String::from("CHARS"),
+ start: 0x0000,
+ size: 0x2000,
+ offset: 0,
+ fill: Some(0x00),
+ bundles: vec![],
+ }
+ ];
}
#[derive(Debug, Clone, Eq, Ord, PartialEq, PartialOrd)]