ENVI^ ForceLocal=1
SET$ NL=0d 0a

_SUB TestEFIBoot  //ret
  SET &vMsg=
  ENVI ?&Buf=FVAR,BootOrder
  ENVI-addr ;&bootOrderLength=&Buf
  GETF -bin  &Buf,0#%bootOrderLength%,&&bootOrderInx  //HEX
  SET< vMsg=%NL%[BootOrder] [%bootOrderInx%]

  SET &BUFFER_SIZE=4096
  ^SET$ &Buf2=*%BUFFER_SIZE% 0
  SET-mkdummy  &Buf2x=&Buf2@6  //UINT32 USHORT
       //First 4 bytes make a uint32_t comprised of flags. 0x1 means the boot option is active (not disabled)
  SET &I=0
  LOOP #%I%<%bootOrderLength%, //Boot####变量名称
  {  SET?short Buf=&&Inx:%I%
     CALC I=%I%+2
     @TEAM~ CALC -base=16  #Inx=%inx% | 0x100000~ MSTR Inx=5,4,%Inx%  //16进制4位 ####
     SET &BootName=Boot%Inx%
     ENVI ?&Buf2=FVAR,Boot%Inx%
     SET?long Buf2=&&flags:0
     SET-mkdummy  &Buf2x=&Buf2@6  //跳过 UINT32 USHORT
     SET< vMsg=%NL%[%BootName%]%flags% [%Buf2x%]
  }
  MSTR * vMsg=3,0,vMsg
  ENVI-ret-copy %~1=vMsg
_END

_SUB ChOrderEFIBoot   // inx1  inx2
  SET &vMsg=
  ENVI ?&Buf=FVAR,BootOrder
  ENVI-addr ;&bootOrderLength=&Buf
  GETF -bin  &Buf,0#%bootOrderLength%,&&bootOrderInx  //HEX
 
  CALC #num=%bootOrderLength% / 2  * 2
  ^CALC #Inx1=(%1 - 1) *2
  ^CALC #Inx2=(%2 - 1) *2
  IFEX #[  %Inx1%<0 |  %Inx2%<0 | %Inx1%>=%num% | %Inx2%>=%num%  ], EXIT 

  SET?short &Buf=&v1:%Inx1%
  SET?short &Buf=&v2:%Inx2%

  SET-short &Buf=%v2%:%Inx1%
  SET-short &Buf=%v1%:%Inx2%

  ENVI ?-v  =FVAR+,BootOrder,&Buf  //SET New data 
_END


TestEFIBoot &&ret1

MESS. 交换顺序测试 #YN *30000 $N
FIND $%&YesNo%<>Yes, EXIT

ChOrderEFIBoot 2 3 //2 3 交换顺序

TestEFIBoot &&ret2
MESS. %&ret1% %NL%------>%NL%%&ret2%

