@@ -152,6 +152,7 @@ where
152152 | Opcode :: LLess => {
153153 self . do_logical_op ( & mut context, op) ?;
154154 }
155+ Opcode :: Mid => self . do_mid ( & mut context, op) ?,
155156 Opcode :: FromBCD => self . do_from_bcd ( & mut context, op) ?,
156157 Opcode :: ToBCD => self . do_to_bcd ( & mut context, op) ?,
157158 Opcode :: Name => {
@@ -1146,6 +1147,43 @@ where
11461147 Ok ( ( ) )
11471148 }
11481149
1150+ fn do_mid ( & self , context : & mut MethodContext , op : OpInFlight ) -> Result < ( ) , AmlError > {
1151+ let [ Argument :: Object ( source) , Argument :: Object ( index) , Argument :: Object ( length) , target] =
1152+ & op. arguments [ ..]
1153+ else {
1154+ panic ! ( )
1155+ } ;
1156+ let index = index. as_integer ( ) ? as usize ;
1157+ let length = length. as_integer ( ) ? as usize ;
1158+
1159+ let result = Arc :: new ( match * * source {
1160+ Object :: String ( ref string) => {
1161+ if index >= string. len ( ) {
1162+ Object :: String ( String :: new ( ) )
1163+ } else {
1164+ let upper = usize:: min ( index + length, index + string. len ( ) ) ;
1165+ let chars = & string[ index..upper] ;
1166+ Object :: String ( String :: from ( chars) )
1167+ }
1168+ }
1169+ Object :: Buffer ( ref buffer) => {
1170+ if index >= buffer. len ( ) {
1171+ Object :: Buffer ( vec ! [ ] )
1172+ } else {
1173+ let upper = usize:: min ( index + length, index + buffer. len ( ) ) ;
1174+ let bytes = & buffer[ index..upper] ;
1175+ Object :: Buffer ( bytes. to_vec ( ) )
1176+ }
1177+ }
1178+ _ => Err ( AmlError :: InvalidOperationOnObject ) ?,
1179+ } ) ;
1180+
1181+ self . do_store ( context, target, result. clone ( ) ) ?;
1182+ context. contribute_arg ( Argument :: Object ( result) ) ;
1183+
1184+ Ok ( ( ) )
1185+ }
1186+
11491187 fn do_from_bcd ( & self , context : & mut MethodContext , op : OpInFlight ) -> Result < ( ) , AmlError > {
11501188 let [ Argument :: Object ( value) ] = & op. arguments [ ..] else { Err ( AmlError :: InvalidOperationOnObject ) ? } ;
11511189 let mut value = value. clone ( ) . unwrap_transparent_reference ( ) . as_integer ( ) ?;
0 commit comments