dos下的硬件设备中断编号到了windows下还管用吗?

byteh 2003-07-16 12:20:54
dos下的硬件设备中断编号到了windows下还管用吗?比如原来dos下可以直接想外设发送或接受一些byte,到了windows下的delphi还管用吗?编写的程序会不会出现"can't run on windows"的错误!
比如qbasic中:inp(),和out(),在Opascal中有没有类似的函数!
或者是dos下:
debug
-o 70,10
-o 71,10
-q
这段代码的功能到delphi中能编程实现吗?该如何做?是不是非得编写vxd!
...全文
91 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
year2000bug 2003-07-17
  • 打赏
  • 举报
回复
必须进入ring0,
for example:

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, 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;
var
IDT : array [0..5] of byte; // 保存中断描述符表
lpOldGate : dword; // 存放旧向量
implementation

{$R *.dfm}
procedure aa; stdcall;
const ExceptionUsed = $03; // 中断号。
begin
asm
sidt IDT // 读入中断描述符表
mov ebx, dword ptr [IDT+2]
add ebx, 8*ExceptionUsed
cli
mov dx, word ptr [ebx+6]
shl edx, 16d
mov dx, word ptr [ebx]
mov [lpOldGate], edx
mov eax, offset @@Ring0Code // 修改向量,指向Ring0级代码段
mov word ptr [ebx], ax
shr eax, 16d
mov word ptr [ebx+6], ax
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 // 恢复被改了的向量
ret

@@Ring0Code: // Ring0级代码段
mov eax,cr0 // 此句在Ring3级会发生异常错误
mov dx, $61 // 以下语句是为了证明执行了此段代码,让PCSpeak发声
mov al, $ff
out dx, al
mov dx, $43
mov al, $b6
out dx, al
mov dx, $42
mov al, $f0
out dx, al
mov dx, $42
mov al, $0
out dx, al
iretd // 中断返回
end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
aa;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
asm
int 03h //
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
var bvalue : byte;
value : word;
begin // 停止PCSpeak发声
asm
mov dx, $61
in al, dx
mov bValue, al
end ;
value := bValue and $fc;
bValue := Trunc(Value and 255);
asm
mov dx, $61
mov al, bValue
out dx, al
end;
end;

end.
byteh 2003-07-17
  • 打赏
  • 举报
回复
好复杂!
阿发伯 2003-07-16
  • 打赏
  • 举报
回复
Windows不允许直接对硬件操作
span_space 2003-07-16
  • 打赏
  • 举报
回复
up
libra163 2003-07-16
  • 打赏
  • 举报
回复
Delphi中可以嵌套汇编

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧