Dec 122017
 
SET, not SWAP printer assignments. Great for use in batch files.
File LP.ZIP from The Programmer’s Corner in
Category Printer Utilities
SET, not SWAP printer assignments. Great for use in batch files.
File Name File Size Zip Size Zip Type
LP.COM 69 64 deflated
LP.DOC 4728 2022 deflated

Download File LP.ZIP Here

Contents of the LP.DOC file


Program to set printer assignments


There are a few printer swapping programs around. Run once
you swap LPT1 and LPT2. Run again you swap them back.

I don't like the idea of toggling printer assignments that
way, because you get screwed up if you lose track of which way you
have flopped. I prefer to explicitly force the assignment one way
or another so I'm always sure where I am. This makes it particu-
larly easy to create a reliable set of batch files to cause the
proper printer assignment whenever you want to run an application
that needs a special setup. You never have to worry about how
things were set before you started.

Program LP.COM lets you specify the way you want your
printers to be set up. Run LP with an argument of 1 and you set
things up the normal way: LPT1 (also known as PRN) is the printer
plugged into the primary port, and LPT2 is the one plugged into
the secondary port. Run it with an argument of 2 and you reverse
this assignment so that LPT1 becomes the printer in the secondary
port, and LPT2 becomes the printer in the primary port. Run as
many times as you want; the result is always the way you want it
to be.

The program provides a DOS exit code of zero if everything
went OK, and an exit code of 1 if it found an argument other than
the required value of 1 or 2. It's your job to test for the exit
code if you care about it.


Technical discussion:

There are 3 locations in the I/O port address space at which
printer cards can be configured: 278, 378, and 3BC. The 3BC
address is commonly used on combination monochrome display /
printer cards; the first two show up on other cards, often in a
jumper or switch selectable fashion. Often these are marked LPT1
and LPT2, which turns out not to be completely accurate in all
cases, as you will see.

At boot time, DOS scans downward through the 3 locations,
starting at 3BC, figuring out whether those addresses are actually
occupied in your system. It calls the first one it finds LPT1,
and so on. Each time it makes an assignment, it stores the I/O
port address in a table which starts at memory address 408,
occupying 2 bytes per LPT number and ordered by LPT number. When
DOS wants to write to a particular printer, it indexes into the
table, pulls out the right I/O port address, and then directs its
output to that port.

LP.COM simply compares the I/O port addresses which
correspond to LPT1 and LPT2, i.e. the values it finds in memory
locations 408 and 40A. If they are in descending order, the
printer assignments are the way DOS set them up, with LPT1 and
LPT2 in their normal configuration. If they are in ascending
order, the assignments have been switched. LP.COM either leaves
things the way it found them or swaps the contents of 408 and 40A,
depending on what you asked for in the argument. LPT3 is not
affected by LP.COM in any way.

I don't have a source file of LP.COM because I entered it
directly through DEBUG. Here's an annotated disassembly which
serves the same purpose:

0100 BB8000 MOV BX,0080 Addr in PSP
0103 8A07 MOV AL,[BX] # bytes of arg
0105 08C0 OR AL,AL Error if 0
0107 7437 JZ 0140
0109 43 Loop: INC BX Next byte of arg
010A 8A07 MOV AL,[BX]
010C 3C20 CMP AL,20 Skip if space
010E 74F9 JZ 0109
0110 31DB XOR BX,BX Set DS=0
0112 8EDB MOV DS,BX
0114 3C31 CMP AL,31 Arg = ASCII 1?
0116 740F JZ 0127 Yes. Set LPT1 primary
0118 3C32 CMP AL,32 No. Arg = ASCII 2?
011A 7524 JNZ 0140 No. Error
011C A10804 LPT2: MOV AX,[0408] Arg=2: Get LPT1 port
011F 3B060A04 CMP AX,[040A] Compare to LPT2 port
0123 7F0B JG 0130 Swap if primary is LPT1
0125 EB14 JMP 013B Primary already LPT2
0127 A10804 LPT1: MOV AX,[0408] Arg=1: Get LPT1 port
012A 3B060A04 CMP AX,[040A] Compare to LPT2 port
012E 7F0B JG 013B Primary already LPT1
0130 50 Swap: PUSH AX Swap port assignments
0131 A10A04 MOV AX,[040A]
0134 A30804 MOV [0408],AX
0137 58 POP AX
0138 A30A04 MOV [040A],AX
013B B8004C Exit: MOV AX,4C00 Normal exit; Code=0
013E CD21 INT 21
0140 B8014C Err: MOV AX,4C01 Error exit; Code=1
0143 CD21 INT 21

Bruce Bottomley
Columbia, MD
301 992-3908
CIS 72167,2477

February 1989


 December 12, 2017  Add comments

Leave a Reply