home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / grafik / gp / printer2.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-04-15  |  3.8 KB  |  117 lines

  1. Unit Printer2;  { file PRINTER2.PAS }
  2.  
  3. {    This Unit is a replacement for  the Printer Unit that    }
  4. { came with Turbo Pascal Version 4.0.  It's purpose is two    }
  5. { fold.  It will allow a user to change the printer port that }
  6. { the LST file is writing to on the fly.  This takes the      }
  7. { place of LstOutPtr and the routine on page 369 of the Turbo }
  8. { Pascal Version 3.0 manual.  The second purpose of this Unit }
  9. { is that it will also circumvent DOS's stripping of a ^Z     }
  10. { ($1A, the End Of File character) when writinf to the        }
  11. { printer as an ASCII device.  ^Z was usually sent as         }
  12. { part of a graphics string to a printer.  In Version 3.0 of  }
  13. { Turbo Pascal an ASCII device was opened in binary mode, and }
  14. { in Version 4.0 an ASCII device is opened in ASCII mode and  }
  15. { DOS thus strips a ^Z.                                       }
  16. {                                                             }
  17. {    This also provides a good example of a Text file         }
  18. { device driver.                                              }
  19.  
  20. Interface
  21.  
  22. Uses DOS;         { for using Intr()  }
  23.  
  24. Var
  25.   LST : Text;     { Publis LST file variable }
  26.  
  27. Procedure SetPrinter( Port: Byte );
  28. {     SetPrinter sets the printer number to Port where Port   }
  29. { is 'n' in 'LPTn'.  To write to Lpt2, SetPrinter(2) etc..    }
  30. { This lets you change line printers on the fly.              }
  31.  
  32. Implementation
  33.  {    The following routines MUST be FAR calls because they   }
  34.  { are called bt the Read and Write routines.  They are not   }
  35.  { Public (in the Implementation section) because they should }
  36.  { only be accessed by the Read and Write routines.           }
  37.  
  38. {$F+}
  39.  
  40. {    LSTNoFunction performs a NUL operation for a Reset or    }
  41. { Rewrite on LST ( Just in case).                             }
  42.  
  43. Function LSTNoFunction( Var F: TextRec ): Integer;
  44. Begin
  45.   LSTNoFunction:= 0;      { no error }
  46. End;
  47.  
  48. {     LSTOutputToPrinter sends the output to the Printer       }
  49. { port number stored in the first byte of the UserData area    }
  50. { of the Text Record.                                          }
  51.  
  52. Function LSTOutputToPrinter( Var F: TextRec): Integer;
  53. var
  54.   Regs: Registers;
  55.   P : word;
  56. Begin
  57.   With F Do
  58.   Begin
  59.     P:= 0;
  60.     Regs.AH := 16;
  61.     While (P < BufPos) and ((Regs.AH and 16) = 16) Do
  62.     Begin
  63.       Regs.AL:= Ord(BufPtr^[P]);
  64.       Regs.AH:= 0;
  65.       Regs.DX:= UserData[1];
  66.       Intr($17,Regs);
  67.       Inc(P);
  68.     End;
  69.     BufPos:= 0;
  70.   End;
  71.   If (Regs.AH and 16) = 16 Then
  72.     LSTOutputToPrinter := 0         { no error }
  73.    Else
  74.      If ( Regs.AH and 32) = 32 then
  75.        LSTOutputToPrinter := 159    { out of paper }
  76.    Else
  77.      LSTOutputToPrinter := 160;     { device write fault }
  78.   End;
  79.  
  80. {$F-}
  81.  
  82. {     AsignLST both sets up the LST text file record as       }
  83. { would ASSIGN, and initializes it as would a RESET.  It also }
  84. { stores the Port number in the first byte of the UserData    }
  85. { area.                                                       }
  86.  
  87. Procedure AssignLST( Port : Byte);
  88. Begin
  89.   With TextRec(LST) Do
  90.     Begin
  91.       Handle         := $FFF0;
  92.       Mode           := fmOutPut;
  93.       BufSize        := SizeOf(Buffer);
  94.       BufPtr         := @Buffer;
  95.       BufPos         := 0;
  96.       OpenFunc       := @LSTNoFunction;
  97.       InOutFunc      := @LSTOutputToPrinter;
  98.       FlushFunc      := @LSTOutputToPrinter;
  99.       CloseFunc      := @LSTOutputToPrinter;
  100.       UserData[1]    := Port - 1;  { DOS counts from zero }
  101.     End;
  102. End;
  103.  
  104. Procedure SetPrinter(Port : Byte);  { documented above }
  105. Begin
  106.   With TextRec(LST) Do
  107.     UserData[1] := Port - 1  { DOS counts from zero }
  108. End;
  109.  
  110. Begin    { Initialization }
  111.   AssignLST( 1 );               { Call AssignLST so its works }
  112. End.                            { like Turbo's Printer Unit   }
  113.  
  114.  
  115.  
  116.  
  117.