How MS-DOS 6.22 Pipes Printer Output to LPT1
This article provides an overview of how MS-DOS 6.22 routes data to a
local printer using the LPT1 port via command-line
redirection and piping. It covers the underlying architectural process,
starting from the COMMAND.COM command interpreter handling
of standard input/output redirection, progressing through the DOS kernel
character device layer, and concluding with BIOS interrupt calls and
physical parallel port hardware registers.
Reserved Device Names and Redirection Syntax
MS-DOS treats physical hardware ports as reserved system device
names. The first parallel port is mapped to LPT1 and
aliased as PRN.
When a user executes a command such as DIR > LPT1 or
pipes data using TYPE FILE.TXT | MORE > LPT1, MS-DOS
does not treat LPT1 as a file on a disk. Instead, the
command interpreter (COMMAND.COM) identifies the target as
a reserved character device.
In a standard pipe operation (such as
PROGRAM | PRINT_COMMAND), MS-DOS 6.22 does not support true
preemptive multitasking or inter-process pipes in memory. Instead, it
creates a hidden temporary file on the disk (often in the root directory
or the path specified by the TEMP environment variable) to
store the output of the first program. Once the first program
terminates, MS-DOS feeds that temporary file into the second program,
which is then redirected to the hardware device.
The MS-DOS File Handle and Device Driver Layer
When output is directed to LPT1, the operating system
handles the stream through standard input/output handles:
- Handle Redirection: Standard Out (stdout, Handle 1)
or Standard Error (stderr, Handle 2) is redirected by
COMMAND.COMto point to a newly opened handle corresponding to theLPT1character device. - DOS Kernel (
MSDOS.SYS): The program writes to the handle using DOS API interruptINT 21h, Function40h(Write to File or Device). - Character Device Driver (
IO.SYS): The kernel references the Device Header Chain. It detects thatLPT1has the character device attribute bit set (as opposed to a block device such as a floppy or hard drive). Control is handed over to the resident printer driver inIO.SYS.
Hardware Communication via BIOS Interrupt 17h
The resident DOS printer driver translates the byte stream from
INT 21h requests into hardware-level BIOS calls:
- BIOS Translation: The driver invokes
INT 17h, the standard ROM BIOS Printer Services interrupt. - Subfunctions:
AH = 00h: Write Character to Printer.AH = 01h: Initialize Printer Port.AH = 02h: Read Printer Status.
- Register Assignment: For
LPT1, theDXregister is set to0(indicating the first parallel port). The character to be printed is placed in theALregister.
Physical I/O Port Interaction
The ROM BIOS executes the actual I/O instructions to transfer the byte to the physical Centronics/Parallel interface:
- Base Address Lookup: The BIOS reads the memory
address for
LPT1stored in the BIOS Data Area (BDA) at memory location0040:0008h. On most IBM-compatible systems, this resolves to base I/O port address0x378(or0x3BCon older MDA systems). - Status Checking: The BIOS reads the Printer Status Register (Base + 1). It checks bit 7 (Busy) to ensure the printer's buffer is capable of accepting a new character. If busy, the system waits for a predetermined timeout period.
- Data Latching: Once ready, the character in
ALis sent to the Data Register (Base + 0) using theOUTassembly instruction. - Strobe Pulse: The BIOS asserts the
/STROBEline via the Printer Control Register (Base + 2) by briefly setting bit 0 high and then low. This pulse signals to the printer hardware that valid data is sitting on the parallel pins ready to be read into the printer's onboard buffer.
Background Spooling with PRINT.COM
If the background print utility PRINT.EXE is loaded,
MS-DOS 6.22 introduces a basic multiplexed spooling layer:
PRINT.COMinstalls as a Terminate-and-Stay-Resident (TSR) program usingINT 2Fh(the Multiplex Interrupt).- Instead of sending redirected output directly and synchronously through the standard blocking BIOS calls, print jobs can be queued.
- The utility hooks the system timer tick interrupt
(
INT 08h/INT 1Ch) and transfers characters toLPT1during idle CPU cycles, preventing the command prompt from freezing while awaiting printer hardware acknowledgment.