summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOxore <oxore@protonmail.com>2019-11-11 00:26:40 +0300
committerOxore <oxore@protonmail.com>2019-11-11 00:26:40 +0300
commitfdd1c7d66bc5fa0712422af9a069e2a84de8c1a4 (patch)
tree73fd946b3b9fe425a9c5ea5ef367ac384fc682d5 /src
parentb04ff5229e6561851ad3a75cd0054f5d90d6d401 (diff)
Add operand size detection for fetching operands
Diffstat (limited to 'src')
-rw-r--r--src/core.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/core.rs b/src/core.rs
index 7779dab..a05d75e 100644
--- a/src/core.rs
+++ b/src/core.rs
@@ -80,6 +80,19 @@ impl fmt::Display for Op {
}
}
+impl Operand {
+ fn size(&self) -> usize {
+ match self {
+ Operand::Acc => 0,
+ Operand::Direct(_) => 1,
+ Operand::Indirect(_) => 0,
+ Operand::Data(_) => 1,
+ Operand::Register(_) => 0,
+ Operand::Reladdr(_) => 1,
+ }
+ }
+}
+
pub struct Core {
pc: u16,
ram: Ram,
@@ -116,9 +129,12 @@ impl Core {
} else {
None
};
+ let operand2_offset = match &operand1 {
+ Some(o) => o.size(),
+ _ => 0,
+ };
let operand2 = if let Some(operand) = op.operand2 {
- // TODO: offset must be based on operand1's size
- Some(self.map_operand(operand, 2))
+ Some(self.map_operand(operand, operand2_offset))
} else {
None
};