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

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