home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 5.ddi / MWHC.005 / V3 < prev    next >
Encoding:
Text File  |  1992-12-09  |  3.3 KB  |  99 lines

  1. -- An exact copy of this module appears in both the Pascal and C libraries.
  2. {*********************************************************************
  3. (C) Copyright 1983-1992 MetaWare Incorporated;  Santa Cruz, CA 95060.
  4. *********************************************************************}
  5.  
  6. Export(System,MSDOS,Fileh_type);
  7. pragma include('STATUS.pf');
  8. pragma include('SYSTEM.pf');
  9. pragma include('MSDOS.pf');
  10. pragma fragmented_implementation(System);
  11. pragma fragmented_implementation(MSDOS);
  12. with Status;
  13.  
  14. program Implement_DOS_interface;
  15. pragma Alias(Implement_DOS_interface,Implement.RTE || 'dos_interface1');
  16.  
  17.  
  18. with Registers;
  19. with Loopholes:[Address,Adr,Retype,&];
  20. { Interface with the dos calls.
  21.   For each MS DOS call, certain registers must be set, and certain
  22.   registers retrieved.    Here we "set" these registers by storing into
  23.   a data area common with an assembly language routine that picks up
  24.   the data and places it into the registers.  After the call to the DOS,
  25.   the assembly language routine places the value of the registers back
  26.   into the data area.  Thus the precise contents of the registers,
  27.   as required by the DOS calls, is implemented in this module;
  28.   the chore of calling DOS is placed upon a single assembly routine.
  29. }
  30.  
  31. procedure DOS(I:Byte);
  32.    begin
  33.    Ax.h := I;            { Load the function byte. }
  34.    CALLDOS;
  35.    { Carry set (error occurred)?    }
  36.    if Odd(Flags) then begin
  37.       Errno := Ax.R %Retype Error_type;
  38.       AX.R := 0; CX.R := 0; DX.R := 0;
  39.      { Guard against user forgetting to inspect errno. }
  40.       end
  41. -- When compiling with the proper "implemen.pf", PPLIB is true.
  42. #if PPLIB
  43.    else Errno := No_error_occurred;
  44. #endif
  45.    end;
  46.  
  47. procedure Load_ptr(var Rs,Rd: register; A:Address);
  48.    var R: record case boolean of true:(Rd,Rs:register);
  49.       false:(A:Address); end;
  50.    { Pointers are: <displacement> <segment> }
  51.    with Loopholes:[Address,Longptr,Adr];
  52.    var L:Longptr(Integer);
  53.    type Seg_offset = record Off:Implement.Byte_count; Seg: Cardinal; end;
  54.    begin
  55.    -- We can't use retypes here because we'd have to include
  56.    -- both small and large data cases, and the compiler would
  57.    -- complain about one or the other being of the wrong size.
  58.    R.A := A;
  59.    if Loopholes.Sizeof(A) < Loopholes.Sizeof(L) then begin
  60.       -- Small data model.  DS is always the segment.
  61.       -- Address something in the static area to get DS put into L.
  62.       L := Adr(AX) %Retype Typeof(L);
  63.       Rs.R := (L %Retype Seg_offset).Seg;
  64. --    Rs.R := GETDS();    -- old code.  We can get DS from longptr now.
  65.       end
  66.    else Rs := R.Rs;
  67.    Rd := R.Rd;
  68.    end;
  69.  
  70. procedure Load_DS_DX(A:Address);
  71.    begin Load_ptr(DS,DX,A);
  72.    end;
  73.  
  74. procedure Close(F: File_handle);
  75.    begin
  76.    BX.R := F; DOS(62);
  77.    end;
  78.  
  79. (*    -- Never used; removed.
  80. function CurrentDir(WhichDrive:integer):CurrentDirString;
  81.    var S:^integer; I,Len:integer;
  82.    begin
  83.    DX.L := WhichDrive;
  84.    Load_ptr(DS,SI,Adr(CurrentDir[1]));
  85.    DOS(71);
  86.    S := Retype(Adr(CurrentDir),Typeof(S));
  87.     { Get rid of [1] and -2 when compiler is fixed. }
  88.    Len := 64;
  89.    if Errno <> 0 then
  90.       for I := 1 to 64 do if CurrentDir[I] = chr(0) then begin
  91.      Len := I-1; exit;
  92.      end;
  93.    S^ := Len;
  94.    end;
  95. *)
  96.  
  97. -- (C) Copyright 1983,84,85 MetaWare Incorporated;  Santa Cruz, CA 95060.
  98.  
  99.