home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l043 / 3.ddi / AUXINOUT.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-11-02  |  2.9 KB  |  130 lines

  1.  
  2. {           Copyright (c) 1985, 87 by Borland International, Inc.            }
  3.  
  4. unit AuxInOut;
  5. { AUX example from P-373 of the Owner's Handbook. Use this
  6.   example instead of the one in the manual.
  7. }
  8.  
  9. interface
  10.  
  11. uses Dos;
  12.  
  13. procedure AssignAux(var F: Text; Port,Params: Word);
  14.  
  15. implementation
  16.  
  17. {$R-,S-}
  18.  
  19. type
  20.   AuxRec = record
  21.              Port,Params: Word;
  22.              Unused: array[1..12] of Byte;
  23.            end;
  24.  
  25. procedure AuxInit(Port,Params: Word);
  26. inline(
  27.   $58/          { POP   AX      ;Pop parameters         }
  28.   $5A/          { POP   DX      ;Pop port number        }
  29.   $B4/$00/      { MOV   AH,0    ;Code for initialize    }
  30.   $CD/$14);     { INT   14H     ;Call BIOS              }
  31.  
  32. function AuxInChar(Port: Word): Char;
  33. inline(
  34.   $5A/          { POP   DX      ;Pop port number        }
  35.   $B4/$02/      { MOV   AH,2    ;Code for input         }
  36.   $CD/$14);     { INT   14H     ;Call BIOS              }
  37.  
  38. procedure AuxOutChar(Port: Word; Ch: Char);
  39. inline(
  40.   $58/          { POP   AX      ;Pop character          }
  41.   $5A/          { POP   DX      ;Pop port number        }
  42.   $B4/$01/      { MOV   AH,1    ;Code for output        }
  43.   $CD/$14);     { INT   14H     ;Call BIOS              }
  44.  
  45. function AuxInReady(Port: Word): Boolean;
  46. inline(
  47.   $5A/          { POP   DX      ;Pop port number        }
  48.   $B4/$03/      { MOV   AH,3    ;Code for status        }
  49.   $CD/$14/      { INT   14H     ;Call BIOS              }
  50.   $88/$E0/      { MOV   AL,AH   ;Get line status in AH  }
  51.   $24/$01);     { AND   AL,1    ;Isolate Data Ready bit }
  52.  
  53. {$F+}
  54.  
  55. function AuxInput(var F: TextRec): Integer;
  56. var
  57.   P: Word;
  58. begin
  59.   with F,AuxRec(UserData) do
  60.   begin
  61.     P:=0;
  62.     while AuxInReady(Port) and (P<BufSize) do
  63.     begin
  64.       BufPtr^[P]:=AuxInChar(Port); Inc(P);
  65.     end;
  66.     BufPos:=0; BufEnd:=P;
  67.   end;
  68.   AuxInput:=0;
  69. end;
  70.  
  71. function AuxOutput(var F: TextRec): Integer;
  72. var
  73.   P: Word;
  74. begin
  75.   with F,AuxRec(UserData) do
  76.   begin
  77.     P:=0;
  78.     while P<BufPos do
  79.     begin
  80.       AuxOutChar(Port,BufPtr^[P]); Inc(P);
  81.     end;
  82.     BufPos:=0;
  83.   end;
  84.   AuxOutput:=0;
  85. end;
  86.  
  87. function AuxIgnore(var F: TextRec): Integer;
  88. begin
  89.   AuxIgnore:=0;
  90. end;
  91.  
  92. function AuxOpen(var F: TextRec): Integer;
  93. begin
  94.   with F,AuxRec(UserData) do
  95.   begin
  96.     AuxInit(Port,Params);
  97.     if Mode=fmInput then
  98.     begin
  99.       InOutFunc:=@AuxInput;
  100.       FlushFunc:=@AuxIgnore;
  101.     end else
  102.     begin
  103.       Mode:=fmOutput;
  104.       InOutFunc:=@AuxOutput;
  105.       FlushFunc:=@AuxOutput;
  106.     end;
  107.     CloseFunc:=@AuxIgnore;
  108.   end;
  109.   AuxOpen:=0;
  110. end;
  111.  
  112. {$F-}
  113.  
  114. procedure AssignAux;
  115. begin
  116.   with TextRec(F) do
  117.   begin
  118.     Handle:=$FFFF;
  119.     Mode:=fmClosed;
  120.     BufSize:=SizeOf(Buffer);
  121.     BufPtr:=@Buffer;
  122.     OpenFunc:=@AuxOpen;
  123.     AuxRec(UserData).Port:=Port;
  124.     AuxRec(UserData).Params:=Params;
  125.     Name[0]:=#0;
  126.   end;
  127. end;
  128.  
  129. end.
  130.