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!

解决方案 »

  1.   

    必须进入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.