Skip to content

Commit 86b47eb

Browse files
committed
aml: implement DefToBCD and DefFromBCD
1 parent 62330d0 commit 86b47eb

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

aml/src/lib.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![no_std]
22
#![feature(let_chains, inherent_str_constructors)]
33

4-
54
extern crate alloc;
65

76
pub mod namespace;
@@ -148,6 +147,8 @@ where
148147
| Opcode::LLess => {
149148
self.do_logical_op(&mut context, op)?;
150149
}
150+
Opcode::FromBCD => self.do_from_bcd(&mut context, op)?,
151+
Opcode::ToBCD => self.do_to_bcd(&mut context, op)?,
151152
Opcode::Name => {
152153
let [Argument::Namestring(name), Argument::Object(object)] = &op.arguments[..] else {
153154
panic!()
@@ -593,8 +594,7 @@ where
593594
Opcode::Wait => todo!(),
594595
Opcode::Reset => todo!(),
595596
Opcode::Release => todo!(),
596-
Opcode::FromBCD => todo!(),
597-
Opcode::ToBCD => todo!(),
597+
Opcode::FromBCD | Opcode::ToBCD => context.start_in_flight_op(OpInFlight::new(opcode, 2)),
598598
Opcode::Revision => {
599599
context.contribute_arg(Argument::Object(Arc::new(Object::Integer(INTERPRETER_REVISION))));
600600
}
@@ -989,6 +989,38 @@ where
989989
Ok(())
990990
}
991991

992+
fn do_from_bcd(&self, context: &mut MethodContext, op: OpInFlight) -> Result<(), AmlError> {
993+
let [Argument::Object(value)] = &op.arguments[..] else { Err(AmlError::InvalidOperationOnObject)? };
994+
let Object::Integer(mut value) = **value else { Err(AmlError::InvalidOperationOnObject)? };
995+
996+
let mut result = 0;
997+
let mut i = 1;
998+
while value > 0 {
999+
result += (value & 0x0f) * i;
1000+
i *= 10;
1001+
value >>= 4;
1002+
}
1003+
1004+
context.contribute_arg(Argument::Object(Arc::new(Object::Integer(result))));
1005+
Ok(())
1006+
}
1007+
1008+
fn do_to_bcd(&self, context: &mut MethodContext, op: OpInFlight) -> Result<(), AmlError> {
1009+
let [Argument::Object(value)] = &op.arguments[..] else { Err(AmlError::InvalidOperationOnObject)? };
1010+
let Object::Integer(mut value) = **value else { Err(AmlError::InvalidOperationOnObject)? };
1011+
1012+
let mut result = 0;
1013+
let mut i = 0;
1014+
while value > 0 {
1015+
result |= (value % 10) << (4 * i);
1016+
value /= 10;
1017+
i += 1;
1018+
}
1019+
1020+
context.contribute_arg(Argument::Object(Arc::new(Object::Integer(result))));
1021+
Ok(())
1022+
}
1023+
9921024
fn do_size_of(&self, context: &mut MethodContext, op: OpInFlight) -> Result<(), AmlError> {
9931025
let [Argument::Object(object)] = &op.arguments[..] else { Err(AmlError::InvalidOperationOnObject)? };
9941026
let object = object.clone().unwrap_reference();

0 commit comments

Comments
 (0)