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:

  1. Handle Redirection: Standard Out (stdout, Handle 1) or Standard Error (stderr, Handle 2) is redirected by COMMAND.COM to point to a newly opened handle corresponding to the LPT1 character device.
  2. DOS Kernel (MSDOS.SYS): The program writes to the handle using DOS API interrupt INT 21h, Function 40h (Write to File or Device).
  3. Character Device Driver (IO.SYS): The kernel references the Device Header Chain. It detects that LPT1 has 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 in IO.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:

  1. BIOS Translation: The driver invokes INT 17h, the standard ROM BIOS Printer Services interrupt.
  2. Subfunctions:
    • AH = 00h: Write Character to Printer.
    • AH = 01h: Initialize Printer Port.
    • AH = 02h: Read Printer Status.
  3. Register Assignment: For LPT1, the DX register is set to 0 (indicating the first parallel port). The character to be printed is placed in the AL register.

Physical I/O Port Interaction

The ROM BIOS executes the actual I/O instructions to transfer the byte to the physical Centronics/Parallel interface:

  1. Base Address Lookup: The BIOS reads the memory address for LPT1 stored in the BIOS Data Area (BDA) at memory location 0040:0008h. On most IBM-compatible systems, this resolves to base I/O port address 0x378 (or 0x3BC on older MDA systems).
  2. 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.
  3. Data Latching: Once ready, the character in AL is sent to the Data Register (Base + 0) using the OUT assembly instruction.
  4. Strobe Pulse: The BIOS asserts the /STROBE line 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.COM installs as a Terminate-and-Stay-Resident (TSR) program using INT 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 to LPT1 during idle CPU cycles, preventing the command prompt from freezing while awaiting printer hardware acknowledgment.