Skip to content

Commit 37ee652

Browse files
alnyanIsaacWoods
authored andcommitted
aml: implement DefSubtract opcode
1 parent edddb48 commit 37ee652

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

aml/src/expression.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ where
3737
"ExpressionOpcode",
3838
choice!(
3939
def_add(),
40+
def_subtract(),
4041
def_and(),
4142
def_or(),
4243
def_buffer(),
@@ -92,6 +93,32 @@ where
9293
.map(|((), result)| Ok(result))
9394
}
9495

96+
pub fn def_subtract<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
97+
where
98+
'c: 'a,
99+
{
100+
/*
101+
* DefSubtract := 0x74 Operand Operand Target
102+
* Operand := TermArg => Integer
103+
*/
104+
opcode(opcode::DEF_SUBTRACT_OP)
105+
.then(comment_scope(
106+
DebugVerbosity::AllScopes,
107+
"DefAdd",
108+
term_arg().then(term_arg()).then(target()).map_with_context(
109+
|((left_arg, right_arg), target), context| {
110+
let left = try_with_context!(context, left_arg.as_integer(context));
111+
let right = try_with_context!(context, right_arg.as_integer(context));
112+
let result = AmlValue::Integer(left.wrapping_sub(right));
113+
114+
try_with_context!(context, context.store(target, result.clone()));
115+
(Ok(result), context)
116+
},
117+
),
118+
))
119+
.map(|((), result)| Ok(result))
120+
}
121+
95122
pub fn def_and<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
96123
where
97124
'c: 'a,

aml/src/opcode.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub const EXT_DEF_SLEEP_OP: u8 = 0x22;
6464
pub const DEF_STORE_OP: u8 = 0x70;
6565
pub const DEF_ADD_OP: u8 = 0x72;
6666
pub const DEF_CONCAT_OP: u8 = 0x73;
67+
pub const DEF_SUBTRACT_OP: u8 = 0x74;
6768
pub const DEF_INCREMENT_OP: u8 = 0x75;
6869
pub const DEF_DECREMENT_OP: u8 = 0x76;
6970
pub const DEF_SHIFT_LEFT: u8 = 0x79;

0 commit comments

Comments
 (0)