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 >
Wrap
Pascal/Delphi Source File
|
1992-02-24
|
5KB
|
159 lines
(6899) Thu 20 Feb 92 3:53
By: Trevor Carlsen
To: Joe Mezzanini
Re: PRINTER PORTS
St:
---------------------------------------------------------------------------
@EID:3c57 18541ea3
@TCID:5027a623 5a1b
JM> How does one code a program print to lpt2 instead of lpt1 ..
JM> harder yet, how would I offer a choice of lpt1 or lpt2 and
JM> even worse ... how do I check if the selected port really has a
JM> printer on it and it is on line.
Here is a handy little unit that you can use. I have removed the printer unit
that came with TP from the TURBO.TPL file and replaced it with this one. The
test for a printer being ready is not guaranteed to be infallible. Once this
printer has replaced the standard printer unit you will have to always specify
what printer you wish to use thus -
writeln(Lst[n],...); where n is your printer number.
unit printer;
{$D-,I-,S-}
interface
uses dos;
const
PrinterNumb : byte = 0;
var
Lst : array[1..2] of text;
function PrinterStatus(p: byte): byte;
function PrinterReady(var b : byte; p: byte): boolean;
implementation
procedure RawMode(var L); { make sure that device is in raw mode }
var
regs : registers;
begin
with regs do begin
bx := TextRec(L).Handle; { place the file handle in bx }
ax := $4400; { setup for function $44 sub-function 0 }
MSDos(regs); { execute dos function }
dl := dl or $20; { bit 5 = raw mode }
dh := 0; { set dh to zero }
ax := $4401; { setup for function $44 sub-function 1 }
MSDos(regs) { execute dos function }
end; { with }
end; { RawMode }
function PrinterStatus(p: byte): byte;
{ Returns the printer status. LPT1=p=1, LPT2=p=2 }
var regs : registers; { from the dos unit }
begin
with regs do begin
dx := p - 1; { The printer number }
ax := $0200; { The function code for service wanted }
intr($17,regs); { $17= ROM bios int to return printer status}
PrinterStatus := ah;{ Bit 0 set = timed out }
end; { 1 = unused }
end; { 2 = unused }
{ 3 = I/O error }
{ 4 = printer selected }
{ 5 = out of paper }
{ 6 = acknowledge }
{ 7 = printer not busy }
function PrinterReady(var b : byte; p: byte): boolean;
begin
b := PrinterStatus(p);
PrinterReady := (b = $90) { This may vary between printers }
end;
begin
assign(Lst[1],'LPT1');
rewrite(Lst[1]);
RawMode(Lst[1]);
assign(Lst[2],'LPT2');
rewrite(Lst[2]);
RawMode(Lst[2]);
end.
TeeCee
--- TC-ED v2.01
* Origin: The Pilbara's Pascal Centre (+61 91 732569) (3:690/644)
@PATH: 690/644 640/821 209/209 396/1 170/400 512/0 1007
---------------------------------------------------------------------------
(7117) Fri 21 Feb 92 20:05
By: Frank Derks
To: Joe Mezzanini
Re: PRINTER PORTS
St:
---------------------------------------------------------------------------
@MSGID: 2:280/509.2 29a5a5b1
@REPLY: 1:260/512 1893573d
Hello Joe,
On Maandag 17. Februari 1992, Joe Mezzanini wrote to All:
JM> How does one code a program print to lpt2 instead of lpt1 ..
JM> harder yet, how would I offer a choice of lpt1 or lpt2 and
JM> even worse ... how do I check if the selected port really has a
JM> printer on it and it is on line.
If you use TP6.0 then it is possible to write assembly routines which will
enable you to access the printer ports :
ASM
{ Assembly code goes here }
END
The printer-ports are accessible through DOS-interrupt 17h.
Service 0 will enable you to print a character :
{ register dx contains the printer-port : 0 = LPT1, 1 = LPT2 }
{ register al contains the character to be printed }
mov dx,0
mov al,32h
int 17h
After the interrupt ah will contain the same values as described for
service 2.
Using service 2 will give you the status of the printer port :
{ register dx contains the printer-port : 0 = LPT1, 1 = LPT2 etc. }
mov dx,0
mov ah,2
int 17h
After the interrupt, register ah contains the following :
b0 = timeout
b1 = unused
b2 = unused
b3 = I/O-error
b4 = printer selected
b5 = out of paper
b6 = printer acknowledgement
b7 = busy
Luctor Nec Mergitur -=<*>=- Phranck
--- GoldED 2.32/B1204+
* Origin: Frank's software-hell (2:280/509.2)
@PATH: 280/509 501 0 512/0 1007