"Interfacing the IBM PC parallel printer port" - читать интересную книгу автора (Stewart Z.)


I have labeled the Data Out register bits as D0 to D7, with D0 being the
least significant bit and D7 the most signficant. The Control Out bits are
labeled C0 to C3 (for the ones which go to pins) and C4 (for IRQ enable),
and maybe C5 (for bidirection ports only, controls direction). The Status
In bits are labeled S3 to S7 (corresponding to data and CPU bit positions).
Often I will suffix C0 to C3 and S3 to S7 with a "+" or "-" as a reminder
of whether or not that register bit is inverted as compared to the output
or input pin it is associated with; "-" is for inverted, of course. All
the Data Out bits are direct (not inverted); likewise data in for
bidirectional printer ports, but I have not bothered to suffix a "+".

Hexadecimal numbers are prededed by "0x", the C convention.

A "tristated" or disabled electical output basically disconnects the output
from the line or pin (high impedance), neither driving it high nor low.

3. Addresses, naming, BIOS and DOS

IBM defined three standard port base addresses (in 80x86 IO address space).
The Printer Adaptor could use base address 0x378, or later 0x278, while
the Monochrome Display and Printer Adaptor used base address 0x3BC.

The IBM BIOS defines RAM space for 4 parallel printer port base addresses,
stored as 4 16 bit words starting at main memory address 0x408. During
bootup, the BIOS will check for parallel printer ports at base addresses
0x3BC, 0x378, and 0x278, in order, and store the base addresses of any
that are found in consecutive locations in this table. Unused entries
may be 0, or some BIOSes fill them with the first port address found.
Some software may ignore this table, but it is used by at least the BIOS
itself (eg: INT 17, Printer I/O), and by DOS, as described below.

The BIOS detects these ports by writing 0xAA to the Data Out register (at
I/O address Base+0), reading the Data Feedback register (same address), and
deciding there is a port installed if it reads 0xAA. This could be confused
if any lines are externally pulled up or down (or if the port defaulted to
tristate, or if there is another readback device register at that address).
The BIOS also counts the number of parallel ports it found and stores this
count in the upper two bits of the byte at 0x411 (yes, the table can hold
up to 4 entries, but the BIOS equipment flag printer count only goes to 3).

Warning: Just before this table there are 4 words at 0x400 which contain up
to 4 entries for base addresses for serial COM ports. At least some serial
port software is known to store more than 4 entries, thus overlapping the
parallel port table. Hopefully this is rare!

DOS (MSDOS and IBM DOS) maps these as LPTn devices. Unlike COMn devices and
comm ports, the name mapping varies depending on whether or not there is a
Monochrome Display and Printer Adaptor card or not. The first entry in
the BIOS table at 0x408 becomes LPT1, the second entry LPT2, and the third