diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-08-28 08:39:08 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-08-28 09:00:56 +0200 |
| commit | b93267c56565582b9a85e7a1255568e16abcafd2 (patch) | |
| tree | c987acc61a8f83694be425df440e472068f99582 /lib/xixanta | |
| parent | 165cbcf2f92ea0aa992e96d5feb8aacd9752ac47 (diff) | |
| download | tools.nes-b93267c56565582b9a85e7a1255568e16abcafd2.tar.gz tools.nes-b93267c56565582b9a85e7a1255568e16abcafd2.zip | |
nasm: Error out when using WRAM when not available
This commit introduces the ability to inspect the temptative header
before producing the actual output, and with that it checks whether the
Working RAM is being advertised or not. If it is not being advertised
but the assembler detected memory accesses to that region, then we are
in trouble and we should error out.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta')
| -rw-r--r-- | lib/xixanta/src/assembler.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index 23d4219..5ab0e3d 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -83,6 +83,10 @@ struct Assembler<'a> { // Sources that have been evaluated for the current session. This is // directly tied to `Parser::sources`. sources: Vec<SourceInfo>, + + // Whether the assembler has detected accesses to Working RAM or not + // (0x6000-0x7FFF). + accessing_working_ram: bool, } /// All the information that a caller needs after calling either @@ -104,6 +108,10 @@ pub struct AssemblerResult { /// The resulting mappings after assembling a source. You can count on /// fields like `offset` if `errors` is empty. pub mappings: Vec<Mapping>, + + /// Whether the resulting ROM needs Working RAM to be available in order to + /// work. Ignore this field if `errors` is not empty. + pub accessing_working_ram: bool, } /// Read the contents from the `reader` as a source file and produce a list of @@ -131,6 +139,7 @@ pub fn assemble( }], warnings: vec![], mappings: vec![], + accessing_working_ram: false, }; } }; @@ -161,6 +170,7 @@ pub fn assemble_with_mapping( errors, warnings: asm.warnings, mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }; } @@ -176,6 +186,7 @@ pub fn assemble_with_mapping( errors: e.into(), warnings: vec![], mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }; } } @@ -188,6 +199,7 @@ pub fn assemble_with_mapping( errors, warnings: asm.warnings, mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }; } @@ -201,6 +213,7 @@ pub fn assemble_with_mapping( errors, warnings: asm.warnings, mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }; } @@ -212,6 +225,7 @@ pub fn assemble_with_mapping( errors, warnings: asm.warnings, mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }; } @@ -222,12 +236,14 @@ pub fn assemble_with_mapping( errors: vec![], warnings: asm.warnings, mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }, Err(errors) => AssemblerResult { bundles: vec![], errors, warnings: asm.warnings, mappings: asm.mappings, + accessing_working_ram: asm.accessing_working_ram, }, } } @@ -249,6 +265,7 @@ impl<'a> Assembler<'a> { repeats_seen: 0, warnings: vec![], sources: vec![], + accessing_working_ram: false, } } @@ -2003,6 +2020,15 @@ impl<'a> Assembler<'a> { None => (AddressingMode::Implied, Bundle::new(true)), }; + // If the instruction is accessing memory and the bundle is resolved, we + // can start gathering info on the memory being used. + if bundle.resolved && !matches!(mode, AddressingMode::Implied | AddressingMode::Immediate) { + let value = bundle.value() as usize; + if (0x6000..0x8000).contains(&value) { + self.accessing_working_ram = true; + } + } + let mnemonic = node.value.value.to_lowercase(); match INSTRUCTIONS.get(&mnemonic) { Some(entries) => match entries.get(&mode) { |
