瀏覽代碼

aml: implement DefSubtract opcode

Mark Poliakov 1 年之前
父節點
當前提交
37ee652164
共有 2 個文件被更改,包括 28 次插入0 次删除
  1. 27 0
      aml/src/expression.rs
  2. 1 0
      aml/src/opcode.rs

+ 27 - 0
aml/src/expression.rs

@@ -37,6 +37,7 @@ where
         "ExpressionOpcode",
         choice!(
             def_add(),
+            def_subtract(),
             def_and(),
             def_or(),
             def_buffer(),
@@ -92,6 +93,32 @@ where
         .map(|((), result)| Ok(result))
 }
 
+pub fn def_subtract<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
+where
+    'c: 'a,
+{
+    /*
+     * DefSubtract := 0x74 Operand Operand Target
+     * Operand := TermArg => Integer
+     */
+    opcode(opcode::DEF_SUBTRACT_OP)
+        .then(comment_scope(
+            DebugVerbosity::AllScopes,
+            "DefAdd",
+            term_arg().then(term_arg()).then(target()).map_with_context(
+                |((left_arg, right_arg), target), context| {
+                    let left = try_with_context!(context, left_arg.as_integer(context));
+                    let right = try_with_context!(context, right_arg.as_integer(context));
+                    let result = AmlValue::Integer(left.wrapping_sub(right));
+
+                    try_with_context!(context, context.store(target, result.clone()));
+                    (Ok(result), context)
+                },
+            ),
+        ))
+        .map(|((), result)| Ok(result))
+}
+
 pub fn def_and<'a, 'c>() -> impl Parser<'a, 'c, AmlValue>
 where
     'c: 'a,

+ 1 - 0
aml/src/opcode.rs

@@ -64,6 +64,7 @@ pub const EXT_DEF_SLEEP_OP: u8 = 0x22;
 pub const DEF_STORE_OP: u8 = 0x70;
 pub const DEF_ADD_OP: u8 = 0x72;
 pub const DEF_CONCAT_OP: u8 = 0x73;
+pub const DEF_SUBTRACT_OP: u8 = 0x74;
 pub const DEF_INCREMENT_OP: u8 = 0x75;
 pub const DEF_DECREMENT_OP: u8 = 0x76;
 pub const DEF_SHIFT_LEFT: u8 = 0x79;