📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure Speed(count:word); stdcall;
const ExceptionUsed = $03; { 中断号也可以用其它的中断号}
var
IDT : array [0..5] of byte; { 保存中断描述符表}
lpOldGate : dword; {存放旧向量}
begin
asm
push ebx
sidt IDT {读入中断描述符表}
mov ebx, dword ptr [IDT+2]{IDT表基地址}
add ebx, 8*ExceptionUsed {计算中断在中断描述符表中的位置}
cli {关中断}
mov dx, word ptr [ebx+6] {取6,7字节 另外4字节用于门属性和选择子 }
shl edx, 16d {左移16位}
mov dx, word ptr [ebx] {取1,2字节 }
mov [lpOldGate], edx {保存旧的中断门}
mov eax, offset @@Ring0Code {修改向量,指向Ring0级代码段}
mov word ptr [ebx], ax {低16位,保存到1,2字}
shr eax, 16d
mov word ptr [ebx+6], ax {高16位,保存到6,7位}
int ExceptionUsed {发生中断}
mov ebx, dword ptr [IDT+2] {重新定位到中断描述符表中}
add ebx, 8*ExceptionUsed
mov edx, [lpOldGate]
mov word ptr [ebx], dx
shr edx, 16d
mov word ptr [ebx+6], dx {恢复被改了的向量}
pop ebx
jmp @@exit1
@@Ring0Code: {Ring0级代码段}
{0011 0100}
mov al,$34 {写入8253控制寄存器,设置写0号定时器}
out $43,al
mov ax,Count
out $40,al {写定时值低位}
mov al,ah
out $40,al {写定时值高位}
iretd {中断返回}
@@exit1:
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Speed($6000); //慢
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Speed($1742);
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Speed($500); //快
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -