home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST0605.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-07-31  |  3.4 KB  |  108 lines

  1. Unit EchoDev;
  2. { This routine implements a Text File Device Driver that will }
  3. { echo a single write or writeln statement to the screen and  }
  4. { to the printer.  It does this by outputting each character  }
  5. { in the buffer to the screen with a BIOS interrupt, and to   }
  6. { the printer.  It can easily be expaned to include a boolean }
  7. { variable that will determine whether the echoing is to take }
  8. { place or not.                                               }
  9. Interface
  10.  
  11. Uses
  12.   Dos;                   { This unit is necessary for a TFDD  }
  13.  
  14. Var
  15.   Echo : Text;           { This is the Echo device            }
  16.   LptPort : Byte;        { LPT Port number for output         }
  17.  
  18. Implementation
  19.  
  20. {$F+}
  21.  
  22. Function NulRoutine( Var F : TextRec ) : Integer;
  23. { This routine will be called for any routine that is not     }
  24. { necessary for usage by the Text File Device Driver.         }
  25. Begin
  26.   NulRoutine := 0;         { Return an I/O result of 0        }
  27. End;
  28.  
  29. Procedure WriteChar( Ch : Char );
  30. { This routine will output the character passed with a BIOS   }
  31. { routine.  This handles the screen part of the echoing TFDD  }
  32. Var
  33.   DisplayPage : Byte Absolute $40:$62;
  34.                               { BIOS Data Area of Active Page }
  35.   Regs : Registers;           { Used in the INTR call         }
  36.  
  37. Begin
  38.   Regs.AH := $0E;
  39.   Regs.AL := Ord( Ch );
  40.   Regs.BH := DisplayPage;
  41.   Regs.BL := 0;
  42.   Intr( $10, Regs );
  43. End;
  44.  
  45. Function EchoOutput( Var F: TextRec ): integer;
  46. { This is the Output driving routine.  It is called for each  }
  47. { write or writeln statement.  When this routine is invoked,  }
  48. { each character in the buffer will be written to the printer }
  49. { and written to the screen.                                  }
  50. Var
  51.   Regs: Registers;      { Used in the INTR Call               }
  52.   P : word;             { Position within the Text Buffer     }
  53.  
  54. Begin
  55.   With F do
  56.   Begin
  57.     P := 0;
  58.     Regs.AH := 16;
  59.     While (P < BufPos) and ((regs.ah and 16) = 16) do
  60.     Begin
  61.       WriteChar( BufPtr^[P] );
  62.       Regs.AL := Ord(BufPtr^[P]);
  63.       Regs.AH := 0;
  64.       Regs.DX := UserData[1];
  65.       Intr($17,Regs);
  66.       Inc(P);
  67.     end;
  68.     BufPos := 0;
  69.   End;
  70.   if (Regs.AH and 16) = 16 then
  71.     EchoOutput := 0              { No error           }
  72.    else
  73.      if (Regs.AH and 32 ) = 32 then
  74.        EchoOutput := 159         { Out of Paper       }
  75.    else
  76.       EchoOutput := 160;        { Device write Fault }
  77. End;
  78.  
  79. {$F-}
  80.  
  81. Procedure AssignEcho( Var F : Text );
  82. { This is the procedure that will set up the Text Record to   }
  83. { allow output to both the printer and the screen.  It sets   }
  84. { up all of the fields in the TextRec, so as to support the   }
  85. { Input and Output routines in Turbo Pascal.                  }
  86. Begin
  87.   With TextRec( F ) Do
  88.     begin
  89.       Handle      := $FFFF;
  90.       Mode        := fmOutput;
  91.       BufSize     := SizeOf(Buffer);
  92.       BufPtr      := @Buffer;
  93.       BufPos      := 0;
  94.       OpenFunc    := @NulRoutine;
  95.       InOutFunc   := @EchoOutput;
  96.       FlushFunc   := @EchoOutput;
  97.       CloseFunc   := @EchoOutput;
  98.       UserData[1] := LptPort - 1;  { We subtract one because }
  99.   end;                          { Dos Counts from zero.   }
  100. end;
  101.  
  102. Begin  { Initilization }
  103.   LptPort := 1;          { Default LPT port.  Change this to  }
  104.                          { output to a different LPT port.    }
  105.   AssignEcho( Echo );    { Setup the Echo device              }
  106. End.
  107.  
  108.