aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-08-17 23:46:15 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-08-18 00:00:59 +0200
commitd284c0860f46164ebd1333af61b50d1785b2eae4 (patch)
tree5d9fae5ef04321cb2994f20f382725b8a2525d1d /lib
parentb1dea2297fb7c073143d8cd9cd9b762a511f7487 (diff)
downloadtools.nes-d284c0860f46164ebd1333af61b50d1785b2eae4.tar.gz
tools.nes-d284c0860f46164ebd1333af61b50d1785b2eae4.zip
xixanta: Allow for mapping size larger than 16 bit
In configuration files, the 'size' attribute can actually be larger than a 16-bit value, and that is fine inside of the ROM layout. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/xixanta/src/cfg.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/lib/xixanta/src/cfg.rs b/lib/xixanta/src/cfg.rs
index 9b0600a..66d2a28 100644
--- a/lib/xixanta/src/cfg.rs
+++ b/lib/xixanta/src/cfg.rs
@@ -62,13 +62,20 @@ fn get_hex_from(
if !string.starts_with('$') {
match symbols.get(string) {
Some(value) => return Ok(*value),
- None => return Err(format!("malformed hex value (line {line_num})")),
+ None => return Err(format!("malformed hex value '{string}' (line {line_num})")),
}
}
+ // NOTE: usually on this library we go with 16-bit hexadecimal values, but
+ // in configuration files, depending on how many banks exist and the size of
+ // each bank this can go over a 16-bit number. This is already noted on the
+ // `Mapping` struct (see `size` being `usize` and not `u16`). Hence, we
+ // allow for a lenght of maximum 5 digits on this hexadecimal
+ // value. Something over that and this has never been seen on NES/Famicom
+ // development as far as I know.
let val = &string[1..string.len()];
- if val.is_empty() || val.len() > 4 {
- return Err(format!("malformed hex value (line {line_num})"));
+ if val.is_empty() || val.len() > 5 {
+ return Err(format!("malformed hex value '{string}' (line {line_num})"));
}
Ok(usize::from_str_radix(val, 16).unwrap())