We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Brequest in DPMI

nmm
nmm asked
on
Medium Priority
299 Views
Last Modified: 2012-06-21
Using BP70 to create a DOS-Program.
How to use the btrcall-Interface from brequest
in DPMI-Mode? Or, in other words: how to call
real-Mode Interrupts which need pointers to realmode-memory
as parameters in DPMI-Mode.
Any Idea?
Comment
Watch Question

Commented:
Does a value must be passed to a segment register (DS/ES)???
nmm

Author

Commented:
Yes, there is a data-structure like

bparam=record
  buff: ^byte; {a realmode pointer to the databuffer!}
  len  : word; {the length of the databuffer}
  info: ^word;
 {etc...}
end;

a variable of this type:

var params:bparam;

and you have to put the segment of @params (the pointer to params) to DS , its offset to DX and call INT $7b

For windows there is a DLL: btrcall.dll, exporting a
function (no INT call necessary explicit).

If it is impossible to perform the interupt corrctly, may be one can use the DLL in the DPMI-DOS-Program in some manner??

Any ideas?

Mircea


 

Commented:
I have the same problem: you can set the segment value "normally" because this will make a GPF (Error 216)...

Maybe in the SWAGS (http://www.gdsoft.com/swag/swag.html)
nmm

Author

Commented:
Hey, this was a nice comment! Yes there is something about our
problem!

Commented:
Firstly, allocate a buffer in conventional memory to put the params, using the GlobalDOSAlloc function.var paramptr:pointer;  rmseg:word;  sel:word;  res:longint;...  res := GlobalDOSAlloc(sizeof(bparam)); {allocate memory}  if res=0 then  begin    writeln('Error allocating mem');    halt(0);  end;  sel := LoWord(res);  rmseg := hiword(res);  paramptr := ptr(sel,0); {assign pointer to memory}Having allocated the memory, the data must be copied across.  move(params,paramptr^,sizeof(bparam));(alternatively, store the data directly in the allocated mem)Then the real mode int can be called, using the DPMI function 0300h.type DPMIRegs = record  EDI,ESI,EBP:longint;  Res1:longint;  EBX,EDX,ECX,EAX:longint;  Flags:word;  ES,DS,FS,GS:word;  IP,CS:word;  SP,SS:word;end;var regs:Registers;  DRegs:DPMIRegs;...  Regs.ax := $300; {function number}  Regs.bx := $7b;  {interrupt to call}  Regs.cx := 0; {no params on stack}  Regs.es := seg(DRegs); {point to DPMI reg struc}  Regs.di := ofs(DRegs);  DRegs.ss := 0; {no stack}  DRegs.sp := 0;  DRegs.es := rmseg; {segment of pointer}  DRegs.edi := 0;    {offset=0}  {set up other parts of DRegs here}  Intr($31,Regs); {Do the interrupt}  Then copy the data back to the variable (optional)  move(paramptr^,params,sizeof(bparam));
And free the block  sel := GlobalDosFree(sel);  if sel<>0 then  begin    writeln('Error freeing block');    halt(0);  end;Hope this does the trick

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
nmm

Author

Commented:
Sorry I was absent for a while, but now I will check
your answer, aajw!
Cheers nmm
nmm

Author

Commented:
Hi aajw!
Sorry but it simply crashes, what is wrong?

Here is the code I used (with your extensions, DPMI is
defined)

UNIT BTRCALL;

Interface
uses dos{$ifdef dpmi},winapi{$endif};

const
      b_open    : word =    0;
      b_close   : word =    1;
      b_Insert  : word =    2;
      b_update  : word =    3;
      b_delete  : word =    4;
      b_geteq   : word =    5;
      b_getnx   : word =    6;
      b_getpr   : word =    7;
      b_getgr   : word =    8;
      b_getge   : word =    9;
      b_getlt   : word =   10;
      b_getle   : word =   11;
      b_getfi   : word =   12;
      b_getla   : word =   13;
      b_create  : word =   14;
      b_stat    : word =   15;
      b_extend  : word =   16;
      b_setdir  : word =   17;
      b_getdir  : word =   18;
      b_begtran : word =   19;
      b_endtran : word =   20;
      b_abotran : word =   21;
      b_getpos  : word =   22;
      b_setpos  : word =   23;
      b_snext   : word =   24;
      b_stop    : word =   25;
      b_version : word =   26;
      b_unlock  : word =   27;
      b_reset   : word =   28;
      b_setown  : word =   29;
      b_clrown  : word =   30;
      b_creinx  : word =   31;
      b_droinx  : word =   32;
      b_sfirst  : word =   33;
      b_slast   : word =   34;
      b_sprev   : word =   35;
      s_lockw   : word =  100;
      s_locknw  : word =  200;
      m_lockw   : word =  300;
      m_locknw  : word =  400;
      e_gnext   : word =   36;
      e_gprev   : word =   37;
      e_snext   : word =   38;
      e_sprev   : word =   39;
      e_insert  : word =   40;

      b_getkey_offset : word = 50;

{------- nur fr Btrieve 6.1. belangvoll -------}
      g_percent : word =   44;
      f_percent : word =   45;

type bparameter = record
     btr_data   : ^byte;  {eigentlich der Datenpuffer}
     btr_dlen   :  word;  {Datenpufferl„nge}
     btr_info   : ^word;  {eigentlich Infoblock}
     btr_fcb    : ^byte;  {eigentlich FCB}
     op_code    :  word;  {Operationscode}
     btr_key    : ^byte;
     {eigentlich Key}
     btr_klen   :  byte;
     btr_knr    :  shortint;
     status     : ^word;  {Rckgabewert}
     iface_id   :  word;  {const}
    end;
{$ifdef DPMI}
 type DPMIRegs = record
            EDI,ESI,EBP:longint;
            Res1:longint;
            EBX,EDX,ECX,EAX:longint;
            Flags:word; ES,DS,FS,GS:word;
            IP,CS:word;
            SP,SS:word;
         end;
{$endif}

 function BTRV(op,dlen : word;var pos_block,dat_block,key_block;
               klen,knr:integer) : word;


 var btr_status : word;

 function BTRVaktiv:Boolean;

Implementation

 var btrpar   : bparameter;
{$ifdef DPMI}
     paramptr : pointer;
     rmseg    : word;
     sel      : word;
     res      : longint;

{$endif}

 function BTRVaktiv:Boolean;
 type a=record
         l,h:word;
        end;
 var   bptr : pointer;
       b :a absolute bptr;
 begin
{  getIntVec($7b,bptr);
  BTRVaktiv:=word(bptr)=$33;}
 end;

{$ifndef DPMI}
  procedure aufruf;
  var   regs : registers;
  begin
   with btrpar do
   begin
    if  not BTRVaktiv then
    begin
     status^:=20;
     exit;
    end;
    with regs do
    begin
     bx:=0;
     es:=0;
     dx:= ofs(btrpar);
     ds:= seg(btrpar);
    end;
    intr($7b,regs);
   end;
  end;
{$else}
procedure aufruf;
var regs : Registers;
   DRegs : DPMIRegs;
begin
 move(btrpar,paramptr^,sizeof(btrpar));
 {alternatively, store the data directly in the allocated mem}
{ Then the real mode int can be called, using the DPMI function 0300h.}
 Regs.ax   := $300;       {function number}
 Regs.bx   := $7b;        {interrupt to call}
 Regs.cx   := 0;          {no params on stack}
 Regs.es   := seg(DRegs); {point to DPMI reg struc}
 Regs.di   := ofs(DRegs);
 DRegs.ss  := 0; {no stack}
 DRegs.sp  := 0;
 DRegs.es  := rmseg; {segment of pointer}
 DRegs.edi := 0; {offset=0} {set up other parts of DRegs here}
 Intr($31,Regs); {Do the interrupt}
  { Then copy the  data back to the variable (optional)}
 move(paramptr^,btrpar,sizeof(btrpar));
end;
{$endif}

  procedure Init_Parameter;
  begin
   with btrpar do
   begin
    btr_status:=0;
    iface_id   := $6176;
    status := @btr_status;
   end;
  end;

  function BTRV(op,dlen : word;var pos_block,dat_block,key_block;
                klen,knr:integer) : word;
  var s : word;
      b : array[1..125] of byte absolute pos_block;
  begin
   Init_Parameter;
   with btrpar do
   begin
    op_code :=op;
    btr_dlen:=dlen;
    btr_key :=@key_block;
    btr_data:=@dat_block;
    btr_info:=@pos_block;
    btr_fcb :=@b[91];
    btr_knr :=knr;
    btr_klen:=klen;
    aufruf;
    btrv:=status^;
   end;
  end;

{$ifdef DPMI}
var     ExitSave : Pointer;

procedure BtrCallExit;far;
begin
 ExitProc:=ExitSave;
 { And free the block}
 sel := GlobalDosFree(sel);
 if sel<>0 then
 begin
  writeln('Error freeing block'); halt(0);
 end;
end;

begin
 ExitSave:=ExitProc;
 ExitProc:=@BtrCallExit;
 res := GlobalDOSAlloc(sizeof(btrpar)); {allocate memory}
 if res=0 then
 begin
  writeln('Error allocating mem');
  halt(0);
 end;
 sel      := LoWord(res);

 rmseg    := hiword(res);
 paramptr := ptr(sel,0); {assign pointer to memory}
 {Hope this does the trick}
{$endif}
end.

Commented:
The memory allocation/deallocation routines work OK on my system.However, the set up of DRegs in your example is not how you described above. I'm sorry if I didn't make it clear, but DRegs should contain the registers as they are needed to call the interrupt. Unfortunately, the registers must be stored as the 32bit EAX,EBX etc, but assigning a word calue to them will just reference the low 16 bits, the normal regs AX,BX etc. and clear the (unused) high 16 bits.
nmm

Author

Commented:
Hi aajw!
Is does not work, sorry.
The problem semms to be, that in the strucure btrpar
are elements, which are pointers again to some
DOS-Memory.
If I allocate this mem also via globaldosalloc, I dont know how to get real-mode Pointer to it.
I tried to use wbtrcall.dll, the requestor for windows 3.11, but
it will not run (RTM.exe says: invalid entrypoint called)
Mircea

Commented:
You can allocate a RM pointer using the rmseg value returned in the call to GlobalDOSAlloc -var  rmptr:pointer;begin...{allocate mem here}  rmptr := ptr(rmseg,0);{Only use rmptr in real mode, or in structures which will be used in real mode}
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.