是不是 FMP_Command 在C 和 PASCAL 定义不同呢?
The commands are called with an assembler 'int' instruction with the parameters in registers.
The interrupt number will have been found before with the method described in 'Installation'.
Note: As mentioned under ‘Installation’, if your C-Compiler has difficulty using the int86 function, you should call a vector instead. In this case, use the inline assembly version of FMP_Command below.
The parameters are always of the form :
BH : Command id
BL : Stream handle
CX : flags (eventually combined with a value)
DX,AX : a 32 bits value (high word in DX) or a pointer with the segment in DX and the offset in AX.
In return, BX will indicate if the command was successful. It is zero in this case otherwise in will contain the error code. The error code is in BH. If the error code indicates ado
S error, BL will contain thedo
S error code.
If the command returns a value, it will always be in DX,AX (high word in DX).
Only the registers AX,BX,CX,DX will be modified by the driver call.
The simplest way to call the driver is this:
#include <dos.h>
#include “wtypes.h”
unsigned long FMP_Command(BYTE Command,BYTE hStream,
WORD Flags, DWORD Value)
{
union REGS InRegs,OutRegs;
unsigned Error;
InRegs.h.bh=Command;
InRegs.h.bl=hStream;
InRegs.x.dx=Value>>16;
InRegs.x.ax=(unsigned)Value;
InRegs.x.cx=Flags;
int86(FMPIntNb,&InRegs,&OutRegs);
/* FMPIntNb is the interrupt */
/* number of the driver */
FMPStatus=OutRegs.x.bx;
return ((unsigned long)(OutRegs.x.dx)<<16)+OutRegs.x.ax;
}
If, however, this int86() call causes problems, and you are using C language that supports inline assembly language, you can use a function defined like this for calling the driver:
#include <dos.h>
#include “wtypes.h”
unsigned long FMP_Command(BYTE Command,BYTE hStream,
WORD Flags,DWORD Value)
{
if (!Vector)
{
FMPStatus=FMPE_ERROR;
return 0L;
}
// Set up for the command
_asm mov bh, Command
_asm mov bl, hStream
_asm mov dx, word ptr Value+2
_asm mov dx, word ptr Value
_asm mov cx, Flags
_asm pushf
_asm call dword ptr [Vector]
// Get the error
FMPStatus=_BX;
// the return value is already in ax,dx -- Ignore the warning
}
and in Turbo Pascal :
usesdo
s;
function FMP_Command(Command, Stream : byte;
Value : longint;
Flgs : word) : longint ;
var
Regs:registers;
Error:word;
begin
with Regsdo
begin
bh:=Command;
bl:=Stream;
dx:=Value shr 16;
ax:=word(Value);
cx:=Flgs;
Intr(FMPIntNb,Regs);
(* FMPIntNb is the interrupt *)
(* number of the driver *)
Error:=bx;
(* check for errors here *)
FMP_Command:=longint(dx) shl 16 + ax;
end;
end;
For each command, you can specify the flag FMPF_TEST. This flag is used to know if the driver or hardware can support the command, and no action will take place.