阅读内容 

Delphi三十六之硬件篇

[日期:2001-01-15] 来源:yesky  作者:陈立平 [字体: ]
  1 .端口读写

function ReadPortB( wPort : word ) : Byte;

 begin
  asm
  mov dx, wPort
  in al, dx
  mov result, al
 end;

end;

procedure WritePortB( wPort : word; bValue : Byte );

 begin
  asm
 
   mov dx, wPort
   mov al, bValue
   out dx, al
 end;

end;

  2.获知当前机器CPU的速率(MHz)

function CPUSpeed: Double;

 const
  DelayTime = 500;

 var
  TimerHi, TimerLo: Dword;
  PriorityClass, Priority: Integer;

 begin
 PriorityClass := GetPriorityClass(GetCurrentProcess);
 Priority := GetThreadPriority(GetCurrentThread);
 SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS);
 SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL);
 Sleep(10);

 asm
  dw 310Fh
  mov TimerLo, eax
  mov TimerHi, edx
 end;

 Sleep(DelayTime);
 asm
  dw 310Fh
  sub eax, TimerLo
  sbb edx, TimerHi
  mov TimerLo, eax
  mov TimerHi, edx
 end;

 SetThreadPriority(GetCurrentThread, Priority);
 SetPriorityClass(GetCurrentProcess, PriorityClass);
 Result := TimerLo / (1000.0 * DelayTime);

 end;

  3.获取当前机器的所有物理内存

function GetMemoryTotalPhys : Dword;

 var
  memStatus: TMemoryStatus;

 begin
  memStatus.dwLength := sizeOf ( memStatus );
  GlobalMemoryStatus ( memStatus );
  Result := memStatus.dwTotalPhys;
end;

阅读:
录入:

推荐 】 【 打印
相关新闻      
本文评论       全部评论
发表评论
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款


点评: 字数
姓名:
Advertisement
内容查询


Advertisement