diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-13 16:12:08 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-13 16:15:06 +0100 |
| commit | 5f48de69f46d4da27b22c47178b2e6216f7a7801 (patch) | |
| tree | 8d4411c63b714565eeae62df0ff8691cce38d899 /lib/xixanta/src/mapping.rs | |
| parent | ab70669868a653534adb67700cacda2ffaeb46f0 (diff) | |
| download | tools.nes-5f48de69f46d4da27b22c47178b2e6216f7a7801.tar.gz tools.nes-5f48de69f46d4da27b22c47178b2e6216f7a7801.zip | |
Add support for cfg files
In order to make tools like `xa65` work seamlessly with existing
configurations, allow this format too instead of making developers
switch to a new file with TOML syntax.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/mapping.rs')
| -rw-r--r-- | lib/xixanta/src/mapping.rs | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/xixanta/src/mapping.rs b/lib/xixanta/src/mapping.rs index f86b513..49683ab 100644 --- a/lib/xixanta/src/mapping.rs +++ b/lib/xixanta/src/mapping.rs @@ -1,3 +1,4 @@ +use crate::cfg::parse_cfg_file; use crate::object::Bundle; use toml::{Table, Value}; @@ -28,8 +29,9 @@ pub struct Segment { /// Name of the segment. pub name: String, + /// Offset from the base address from where to push the next address for + /// this segment. pub offset: usize, - pub len: usize, /// Bundles that have been generated when assembling the nodes that have /// been parsed by a previous step. @@ -41,7 +43,6 @@ impl From<&str> for Segment { Segment { name: name.to_string(), offset: 0, - len: 0, bundles: vec![], } } @@ -102,7 +103,15 @@ pub struct Mapping { pub fn get_mapping_configuration(name: &str) -> Result<Vec<Mapping>, String> { let configuration = if std::fs::exists(name).unwrap_or(false) { match std::fs::read_to_string(name) { - Ok(contents) => load_configuration_for(contents.as_str())?, + Ok(contents) => { + // If this is a file, then it might not be a TOML one, but a + // .cfg as used by cc65. + if name.ends_with(".cfg") { + parse_cfg_file(contents.as_str())? + } else { + load_configuration_for(contents.as_str())? + } + } Err(_) => return Err(format!("could not read '{}'", name)), } } else { |
