@@ 72,7 72,47 @@ impl <'a> Processor<'a> {
else {self.reg[operands.2] = self.reg[operands.0].wrapping_add(self.reg[operands.1])};
}
0x0001 => { //Subtraction
-
+ if toggles.1 {
+ (self.reg[operands.2], self.flags[toggles.2 as usize]) = {
+ if toggles.0 {
+ let (uncast_return, flag) = (self.reg[operands.0] as i16).overflowing_add(-(self.reg[operands.1] as i16));
+ (uncast_return as u16, flag)
+ }
+ else {
+ (self.reg[operands.0].wrapping_sub(self.reg[operands.1]), self.reg[operands.0] < self.reg[operands.1])
+ }
+ }
+ }
+ else {
+ self.reg[operands.2] = self.reg[operands.0].wrapping_sub(self.reg[operands.1]);
+ }
+ }
+ 0x0002 => { //Multiplication
+ if toggles.1 {
+ (self.reg[operands.2], self.flags[toggles.2 as usize]) = {
+ if toggles.0 {
+ let (uncast_return, flag) = (self.reg[operands.1] as i16).overflowing_mul(self.reg[operands.1] as i16);
+ (uncast_return as u16, flag)
+ }
+ else {
+ self.reg[operands.0].overflowing_mul(self.reg[operands.1])
+ }
+ }
+ }
+ else {
+ self.reg[operands.2] = self.reg[operands.0].wrapping_mul(self.reg[operands.1]);
+ }
+ }
+ 0x0003 => {
+ if self.reg[operands.2] == 0 && toggles.1 {self.flags[toggles.2 as usize] = true}
+ else if self.reg[operands.2] != 0 {
+ if toggles.0 {
+ self.reg[operands.2] = ((self.reg[operands.0] as i16)/(self.reg[operands.1] as i16)) as u16;
+ }
+ else {
+ self.reg[operands.2] = self.reg[operands.0]/self.reg[operands.1];
+ }
+ }
}
_ => return true
}