diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core.rs | 86 |
1 files changed, 33 insertions, 53 deletions
diff --git a/src/core.rs b/src/core.rs index 74f79b0..4c3202b 100644 --- a/src/core.rs +++ b/src/core.rs @@ -390,46 +390,10 @@ impl Core { Opname::Illegal => (), Opname::Push => self.push(op.operand1.expect("PUSH has no operand given")), Opname::Pop => self.pop(op.operand1.expect("POP has no operand given")), - Opname::Sjmp => { - if let Some(operand) = op.operand1 { - match operand { - Operand::Reladdr(reladdr) => self.sjmp(reladdr), - _ => panic!("SJMP got incompatible operand"), - } - } else { - panic!("SJMP has no operand given") - } - } - Opname::Ajmp => { - if let Some(operand) = op.operand1 { - match operand { - Operand::Addr11(addr) => self.ajmp(addr), - _ => panic!("AJMP got incompatible operand"), - } - } else { - panic!("AJMP has no operand given") - } - } - Opname::Ljmp => { - if let Some(operand) = op.operand1 { - match operand { - Operand::Addr16(addr) => self.ljmp(addr), - _ => panic!("LJMP got incompatible operand"), - } - } else { - panic!("LJMP has no operand given") - } - } - Opname::Jnz => { - if let Some(operand) = op.operand1 { - match operand { - Operand::Reladdr(addr) => self.jnz(addr), - _ => panic!("JNZ got incompatible operand"), - } - } else { - panic!("JNZ has no operand given") - } - } + Opname::Sjmp => self.sjmp(op.operand1.expect("SJMP has no operand given")), + Opname::Ajmp => self.ajmp(op.operand1.expect("AJMP has no operand given")), + Opname::Ljmp => self.ljmp(op.operand1.expect("LJMP has no operand given")), + Opname::Jnz => self.jnz(op.operand1.expect("JNZ has no operand given")), } } @@ -462,7 +426,7 @@ impl Core { Operand::Direct(dir) => dir, Operand::Indirect(r) => self.ram[r.to_ram_offset() as usize], Operand::Register(r) => r.to_ram_offset(), - other => panic!("Mov: got incompatible first operand \"{:?}\"", other), + other => panic!("MOV got incompatible first operand \"{:?}\"", other), }; let value = match o2 { Operand::Acc => RAM_OFFSET_ACC, @@ -470,7 +434,7 @@ impl Core { Operand::Indirect(r) => self.ram[r.to_ram_offset() as usize], Operand::Data(r) => r, Operand::Register(r) => r.to_ram_offset(), - other => panic!("Mov: got incompatible second operand \"{:?}\"", other), + other => panic!("MOV got incompatible second operand \"{:?}\"", other), }; self.ram[dest as usize] = value; } @@ -495,23 +459,39 @@ impl Core { } } - fn sjmp(&mut self, reladdr: i8) { - self.pc = (self.pc as i16 + i16::from(reladdr)) as u16; + fn sjmp(&mut self, o: Operand) { + match o { + Operand::Reladdr(reladdr) => self.pc = (self.pc as i16 + i16::from(reladdr)) as u16, + _ => panic!("SJMP got incompatible operand"), + } } - fn ajmp(&mut self, addr11: u16) { - assert!(addr11 <= 0x4FFu16); - // Clear 11 low bits of PC and add address, that is within these 11 bits - self.pc = (self.pc & !0x4FFu16) & addr11; + fn ajmp(&mut self, o: Operand) { + match o { + Operand::Addr11(addr11) => { + assert!(addr11 <= 0x4FFu16); + // Clear 11 low bits of PC and add address, that is within these 11 bits + self.pc = (self.pc & !0x4FFu16) & addr11; + } + _ => panic!("AJMP got incompatible operand"), + } } - fn ljmp(&mut self, addr: u16) { - self.pc = addr; + fn ljmp(&mut self, o: Operand) { + match o { + Operand::Addr16(addr) => self.pc = addr, + _ => panic!("LJMP got incompatible operand"), + } } - fn jnz(&mut self, reladdr: i8) { - if self.ram[usize::from(RAM_OFFSET_ACC)] != 0 { - self.pc = (self.pc as i16 + i16::from(reladdr)) as u16; + fn jnz(&mut self, o: Operand) { + match o { + Operand::Reladdr(reladdr) => { + if self.ram[usize::from(RAM_OFFSET_ACC)] != 0 { + self.pc = (self.pc as i16 + i16::from(reladdr)) as u16; + } + } + _ => panic!("JNZ got incompatible operand"), } } } |