fox32+fox32asm: Add proper support for greater than and less than

This adds IFGT, IFGTEQ, IFLT, and IFLTEQ, which makes it easier to
check for these conditions.
This commit is contained in:
Ry 2022-03-12 12:15:27 -08:00
parent 492e8d51a1
commit 9fb445f688
2 changed files with 22 additions and 4 deletions

View File

@ -55,10 +55,14 @@ size = @{
} }
condition = @{ condition = @{
"ifz" | "ifz" |
"ifnz" | "ifnz" |
"ifc" | "ifc" |
"ifnc" "ifnc" |
"ifgteq" |
"ifgt" |
"iflteq" |
"iflt"
} }
instruction = { instruction = {

View File

@ -205,6 +205,10 @@ enum Condition {
NotZero, NotZero,
Carry, Carry,
NotCarry, NotCarry,
GreaterThan,
// GreaterThanEqualTo is equivalent to NotCarry
// LessThan is equivalent to Carry
LessThanEqualTo,
} }
#[derive(PartialEq, Debug, Clone)] #[derive(PartialEq, Debug, Clone)]
@ -561,6 +565,10 @@ fn parse_condition(pair: &pest::iterators::Pair<Rule>) -> Condition {
"ifnz" => Condition::NotZero, "ifnz" => Condition::NotZero,
"ifc" => Condition::Carry, "ifc" => Condition::Carry,
"ifnc" => Condition::NotCarry, "ifnc" => Condition::NotCarry,
"ifgt" => Condition::GreaterThan,
"ifgteq" => Condition::NotCarry,
"iflt" => Condition::Carry,
"iflteq" => Condition::LessThanEqualTo,
_ => panic!("Unsupported condition: {}", pair.as_str()), _ => panic!("Unsupported condition: {}", pair.as_str()),
} }
} }
@ -976,6 +984,8 @@ fn condition_source_destination_to_byte(node: &AstNode) -> u8 {
Condition::NotZero => 0x20, Condition::NotZero => 0x20,
Condition::Carry => 0x30, Condition::Carry => 0x30,
Condition::NotCarry => 0x40, Condition::NotCarry => 0x40,
Condition::GreaterThan => 0x50,
Condition::LessThanEqualTo => 0x60,
} }
} }
AstNode::OperationOne {condition, ..} => { AstNode::OperationOne {condition, ..} => {
@ -985,6 +995,8 @@ fn condition_source_destination_to_byte(node: &AstNode) -> u8 {
Condition::NotZero => 0x20, Condition::NotZero => 0x20,
Condition::Carry => 0x30, Condition::Carry => 0x30,
Condition::NotCarry => 0x40, Condition::NotCarry => 0x40,
Condition::GreaterThan => 0x50,
Condition::LessThanEqualTo => 0x60,
} }
} }
AstNode::OperationTwo {condition, ..} => { AstNode::OperationTwo {condition, ..} => {
@ -994,6 +1006,8 @@ fn condition_source_destination_to_byte(node: &AstNode) -> u8 {
Condition::NotZero => 0x20, Condition::NotZero => 0x20,
Condition::Carry => 0x30, Condition::Carry => 0x30,
Condition::NotCarry => 0x40, Condition::NotCarry => 0x40,
Condition::GreaterThan => 0x50,
Condition::LessThanEqualTo => 0x60,
} }
} }
_ => panic!("Attempting to parse a non-instruction AST node as an instruction: {:#?}", node), _ => panic!("Attempting to parse a non-instruction AST node as an instruction: {:#?}", node),