diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-19 23:12:39 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2024-12-19 23:21:33 +0100 |
| commit | 8b5feeed96b3110967f88420d058c6e916a67f60 (patch) | |
| tree | 01f85af2ec92e928be1f60d5e8d1a828a069024b /lib/xixanta/src/object.rs | |
| parent | ead34058aff63aa6b58c7378e7975d5285feca24 (diff) | |
| download | tools.nes-8b5feeed96b3110967f88420d058c6e916a67f60.tar.gz tools.nes-8b5feeed96b3110967f88420d058c6e916a67f60.zip | |
assembler: Implement and add tests for operators
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'lib/xixanta/src/object.rs')
| -rw-r--r-- | lib/xixanta/src/object.rs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/xixanta/src/object.rs b/lib/xixanta/src/object.rs index 8f177a1..2708647 100644 --- a/lib/xixanta/src/object.rs +++ b/lib/xixanta/src/object.rs @@ -32,6 +32,12 @@ pub struct Bundle { /// Whether the bytes on `bytes` contain the final value or not. This is /// used for internal purposes only. pub resolved: bool, + + /// Whether we have to consider the bundle to contain a negative number. + /// This comes from the fact that we just have a bunch of signednessless + /// bytes, but using the negative unary operator will give us a hint on how + /// to interpret it when needed. + pub negative: bool, } impl Bundle { @@ -52,6 +58,35 @@ impl Bundle { cycles: 0, affected_on_page: false, resolved: true, + negative: false, + } + } + + /// Returns the `bytes` field from the bundle as interpreted as bytes from a + /// regular integer. + pub fn value(&self) -> isize { + if self.negative { + isize::from_le_bytes([ + self.bytes[0], + self.bytes[1], + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + 0xFF, + ]) + } else { + isize::from_le_bytes([ + self.bytes[0], + self.bytes[1], + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + ]) } } } |
