home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PARADIS1 / PRINTER.PAS < prev    next >
Pascal/Delphi Source File  |  1992-02-24  |  5KB  |  159 lines

  1. (6899)  Thu 20 Feb 92  3:53
  2. By: Trevor Carlsen
  3. To: Joe Mezzanini
  4. Re: PRINTER PORTS
  5. St:
  6. ---------------------------------------------------------------------------
  7. @EID:3c57 18541ea3
  8. @TCID:5027a623 5a1b
  9.  JM> How does one code a program print to lpt2 instead of lpt1  ..
  10.  JM> harder yet, how would I offer a choice of lpt1 or lpt2 and
  11.  JM> even worse ... how do I check if the selected port really has a
  12.  JM> printer on it and it is on line.
  13.  
  14. Here is a handy little unit that you can use.  I have removed the printer unit
  15. that came with TP from the TURBO.TPL file and replaced it with this one.  The
  16. test for a printer being ready is not guaranteed to be infallible.  Once this
  17. printer has replaced the standard printer unit you will have to always specify
  18. what printer you wish to use thus -
  19.  
  20.   writeln(Lst[n],...);  where n is your printer number.
  21.  
  22. unit printer;
  23. {$D-,I-,S-}
  24. interface
  25.  
  26. uses dos;
  27.  
  28. const
  29.   PrinterNumb : byte = 0;
  30.  
  31. var
  32.   Lst        : array[1..2] of text;
  33.  
  34. function PrinterStatus(p: byte): byte;
  35. function PrinterReady(var b : byte; p: byte): boolean;
  36.  
  37. implementation
  38.  
  39. procedure RawMode(var L);       { make sure that device is in raw mode }
  40.   var
  41.     regs : registers;
  42.   begin
  43.     with regs do begin
  44.       bx   := TextRec(L).Handle;         { place the file handle in bx }
  45.       ax   := $4400;           { setup for function $44 sub-function 0 }
  46.       MSDos(regs);                              { execute dos function }
  47.       dl   := dl or $20;                            { bit 5 = raw mode }
  48.       dh   := 0;                                      { set dh to zero }
  49.       ax   := $4401;           { setup for function $44 sub-function 1 }
  50.       MSDos(regs)                               { execute dos function }
  51.     end; { with }
  52.   end; { RawMode }
  53.  
  54. function PrinterStatus(p: byte): byte;
  55.    { Returns the printer status. LPT1=p=1, LPT2=p=2 }
  56.    var regs   : registers; { from the dos unit                         }
  57.    begin
  58.      with regs do begin
  59.        dx := p - 1;        { The printer number                        }
  60.        ax := $0200;        { The function code for service wanted      }
  61.        intr($17,regs);     { $17= ROM bios int to return printer status}
  62.        PrinterStatus := ah;{ Bit 0 set = timed out                     }
  63.      end;                  {     1     = unused                        }
  64.    end;                    {     2     = unused                        }
  65.                            {     3     = I/O error                     }
  66.                            {     4     = printer selected              }
  67.                            {     5     = out of paper                  }
  68.                            {     6     = acknowledge                   }
  69.                            {     7     = printer not busy              }
  70.  
  71. function PrinterReady(var b : byte; p: byte): boolean;
  72.   begin
  73.     b := PrinterStatus(p);
  74.     PrinterReady := (b = $90)         { This may vary between printers }
  75.   end;
  76.  
  77. begin
  78.   assign(Lst[1],'LPT1');
  79.   rewrite(Lst[1]);
  80.   RawMode(Lst[1]);
  81.   assign(Lst[2],'LPT2');
  82.   rewrite(Lst[2]);
  83.   RawMode(Lst[2]);
  84. end.
  85.  
  86. TeeCee
  87.  
  88.  
  89. --- TC-ED   v2.01
  90.  * Origin: The Pilbara's Pascal Centre (+61 91 732569) (3:690/644)
  91.  
  92. @PATH: 690/644 640/821 209/209 396/1 170/400 512/0 1007 
  93.  
  94. ---------------------------------------------------------------------------
  95. (7117)  Fri 21 Feb 92 20:05
  96. By: Frank Derks
  97. To: Joe Mezzanini
  98. Re: PRINTER PORTS
  99. St:
  100. ---------------------------------------------------------------------------
  101. @MSGID: 2:280/509.2 29a5a5b1
  102. @REPLY: 1:260/512 1893573d
  103. Hello Joe,
  104.  
  105. On Maandag 17. Februari 1992, Joe Mezzanini wrote to All:
  106.  
  107.  JM> How does one code a program print to lpt2 instead of lpt1  ..
  108.  JM> harder yet, how would I offer a choice of lpt1 or lpt2 and
  109.  JM> even worse ... how do I check if the selected port really has a
  110.  JM> printer on it and it is on line.
  111.  
  112. If you use TP6.0 then it is possible to write assembly routines which will
  113. enable you to access the printer ports :
  114.  
  115. ASM
  116.  
  117. { Assembly code goes here }
  118.  
  119. END
  120.  
  121. The printer-ports are accessible through DOS-interrupt 17h.
  122. Service 0 will enable you to print a character :
  123.  
  124. { register dx contains the printer-port : 0 = LPT1, 1 = LPT2 }
  125. { register al contains the character to be printed           }
  126.  
  127.     mov     dx,0
  128.     mov     al,32h
  129.     int     17h
  130.  
  131. After the interrupt ah will contain the same values as described for
  132. service 2.
  133.  
  134. Using service 2 will give you the status of the printer port :
  135.  
  136. { register dx contains the printer-port : 0 = LPT1, 1 = LPT2 etc. }
  137.  
  138.     mov     dx,0
  139.     mov     ah,2
  140.     int     17h
  141.  
  142. After the interrupt, register ah contains the following :
  143.  
  144.   b0 = timeout
  145.   b1 = unused
  146.   b2 = unused
  147.   b3 = I/O-error
  148.   b4 = printer selected
  149.   b5 = out of paper
  150.   b6 = printer acknowledgement
  151.   b7 = busy
  152.  
  153. Luctor Nec Mergitur            -=<*>=-                          Phranck
  154.  
  155. --- GoldED 2.32/B1204+
  156.  * Origin: Frank's software-hell (2:280/509.2)
  157.  
  158. @PATH: 280/509 501 0 512/0 1007 
  159.