diff --git a/encoding.md b/encoding.md index 049e446..84e9f3f 100644 --- a/encoding.md +++ b/encoding.md @@ -22,13 +22,17 @@ If the instruction doesn't allow variable sizes or a size was not specified, set | 3- | | DEC[.8,16,32] | REM[.8,16,32] | NOT[.8,16,32] | | | | | | RTA | RETI | | | | | | # Condition table -| | | -| :---: | -------- | -| 0b000 | (always) | -| 0b001 | IFZ | -| 0b010 | IFNZ | -| 0b011 | IFC | -| 0b100 | IFNC | +| | | | +| :---: | ------ | --------------------------------------------- | +| 0b000 | --- | always | +| 0b001 | IFZ | zero | +| 0b010 | IFNZ | not zero | +| 0b011 | IFC | carry | +| 0b011 | IFLT | less than (equivalent to IFC) | +| 0b100 | IFNC | not carry | +| 0b100 | IFGTEQ | greater than or equal to (equivalent to IFNC) | +| 0b101 | IFGT | greater than | +| 0b110 | IFLTEQ | less than or equal to | # Destination table | | | diff --git a/src/cpu.rs b/src/cpu.rs index d6dfaa3..9a1f57c 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -73,6 +73,8 @@ impl Cpu { Condition::NotZero => !self.flag.zero, Condition::Carry => self.flag.carry, Condition::NotCarry => !self.flag.carry, + Condition::GreaterThan => !self.flag.carry && !self.flag.zero, + Condition::LessThanEqualTo => self.flag.carry || self.flag.zero, } } fn relative_to_absolute(&self, relative_address: u32) -> u32 { @@ -2689,6 +2691,10 @@ enum Condition { NotZero, Carry, NotCarry, + GreaterThan, + // GreaterThanEqualTo is equivalent to NotCarry + // LessThan is equivalent to Carry + LessThanEqualTo, } #[derive(Debug)] @@ -2783,6 +2789,8 @@ impl Instruction { 0x20 => Condition::NotZero, 0x30 => Condition::Carry, 0x40 => Condition::NotCarry, + 0x50 => Condition::GreaterThan, + 0x60 => Condition::LessThanEqualTo, _ => return None, }; match opcode {