Hi there,

not much documentation here.



Part I: The executable


 LPTDETCT.COM
  
  Well, this is a simple LPT port detector program which is able to
  detect much more different electronic implementations of EPP ports
  than other utilities. Ok, there's no real need for such an util,
  it's only a demonstration application for the C-source LPT port
  detection routines. Userdefined port addresses can be specified as
  command line parameters, thus making LPTDETECT not only scan the
  standard LPT port addresses 0x3BC, 0x378 and 0x278, but also the
  addresses given as parameters. You can also use this utility to
  switch all bidirectional LPT ports (EPP, ECP and PS/2) into input
  mode or to program ECP ports with the Byte-(Sub-)mode.



 Using LPTDETCT with the /R switch:

  A very helpful function of this utility is the reinitialisation of
  the BIOS data area, if you use bidirectional PS/2 compatible LPT
  ports. Some BIOSes are not able to detect a PS/2 LPT port on a
  warm reboot if the port is programmed to input mode. This may
  confuse drivers or other software that checks the BIOS data area
  for registered LPT ports instead of checking port addresses
  directly.

  Another use may be the registration of LPT ports with nonstandard
  port addresses into the BIOS data area. You only have to put the
  base addresses of the additional ports as arguments and LPTDETCT
  checks for LPT ports at these addresses, too.

  By default the util does first read the BIOS data area for
  already registered LPT ports, then it checks all user defined port
  addresses, at last the standard port addresses are scanned.
  After scanning all port addresses for LPT ports and determining
  the LPT port type, the BIOS data area is filled up again with all
  the valid port addresses (up to 4 LPT port addresses).

  If you disable the check for already by the BIOS registered ports
  and disable the standard port address scan, that means you do only
  check for user defined LPT port addresses, the BIOS data area is
  filled up with port addresses in the same order you specify ports
  on the command line. Otherwise the data area is filled up with the
  standard port addresses first (0x3BC, 0x378, 0x278 in that order).

  So if you want to create sophisticated configurations, you should
  disable both the BIOS and the standard addresses check.
  Example: You have two LPT ports at 0x3BC and 0x278, but you don't
           want to have 0x3BC at LPT1:
                Solution: LPTDETCT /R /D /S 0x278 0x3BC


  Because the BIOS data area needs to be initialised only once, it
  is recommended to call this util only at boot time via the
  AUTOEXEC.BAT, if you use the /R switch.




Part II: The source (Version 0.11)

This is only a very short description of the basic port detection
routines (LPTDETCT.H, LPTDETCT.CPP), if you want more, check the
sources, there are some hints, comments and weblinks.


1. In general LPT ports can only be detected if the base port
   address is dividable by 4 without remainder and falls into the
   IO-area between 0x200 and 0x3FC.

   I decided to check for EPP and ECP ports at addresses dividable
   by 4 (instead of 8), because there are some motherboards which
   allow configuring ECP and EPP ports at the address 0x3BC. But
   keep in mind that according to some specifications valid EPP and
   ECP configurations use only the port address 0x378 or 0x278.
   This is a good advice, because EPP ports need 8 consecutive IO
   addresses (3 for other ports, except for EPP submode of ECP
   ports). Using an EPP port at 0x3BC may therefore interfere with
   your graphics card, because the monochrome compatible registers
   are located there.

2. In previous versions I did additional tests for mirrored ports
   and port address conflicts. These test have been removed,
   because of their little use and way too sophisticated code.

3. Before all the tests, a reset signal is sent for 16 microseconds
   first. This hopefully prevents producing trash on printers which
   are online.


--- The sequence of the different port type tests: ---

   1. testing for an ECP
   2. testing for an EPP
   3. testing for an EPP  advanced EPP test (enable via #define)
   4. testing for an PPP  this tests for a SPP and a PS/2 port type


--- How the different port type tests are working ---

ECP test:
   1. saving the ECR register and switching port
      to byte mode
   2. checking if the ECR register really exists
      and if the FIFO bits are read-only
   3. if there is an ECR, switch the ECP into
      FIFO-test-mode and check, if the FIFO-bits
      react on underflows
   4. restore the old value of the ECR, if there
      was an ECR
   5. if all tests were successful, it's an ECP,
      otherwise it's not


EPP test:
   The reliable detection of EPP ports is possibly an unsolvable
   problem. Until now no single algorithm could be found with which
   all EPP implementations on the market can be detected. Therefore
   two different detectors are used: if one of them returns a
   positive result, the port is passed as EPP type.

   
   1. switch port into input mode, additionally all handshake lines
      are manually (via control word) switched to low, preventing the
      EPP from doing automatic handshakes itself (works mostly).

 EPP address register test (first detetection routine)
   2. resetting timeout bit
   3. set address register (base+3) to 0xAA
   4. resetting timeout bit
   5. reread address register and compare
   6. resetting timeout bit
   7. set address register to 0x55
   8. resetting timeout bit
   9. reread address register and compare
  10. if both reread values were the same as the
      written ones, the port is passed as EPP,
      if not, go on with the timeout bit test

 EPP timeout bit test (alternative detection routine)
  11. resetting timeout bit
  12. write to and read from the address register
  13. check, if the timeout bit is set
  14. resetting timeout bit
  15. check, if the timeout bit is cleared
  16. if both checks were sucessful, the port is an
      EPP type, otherwise it's not

   In previous versions I had the following problem (found with
   a special handshake loopback plug). It should be solved now,
   because of the additions to point 1.

   (problems: If there's an EPP compatible device (ZIP drive ?)
              connected to the port, it may be possible that
              the timeout bit doesn't react and the EPP port
              cannot be detected. In this case the port will
              be detected as PS/2 type.)


PPP test:
   1. switching port to output mode (if it's a PS/2)
   2. writing to the data port (0xAA to base+0)
   3. reread data port and and compare
   4. writing to the data port (0x55 to base+0)
   5. reread data port and and compare
   6. if one of the reread values is not the same
      as the written one, the port is _no_ PPP
      (parallel printer port), otherwise do
      further tests
   7. switching port into input mode
   8. writing to the data port (0xAA to base+0)
   9. reread data port and and compare
  10. writing to the data port (0x55 to base+0)
  11. reread data port and and compare
  12. if one of the two previous comparisons fails,
      the port is an PS/2 one, if both reread values
      were the same as the written ones, the port is
      a SPP type



--- end of documentation ---

1998-11-15

Wolfgang Moser <womo@mindless.com>
               http://www.gm.fh-koeln.de/sourcen/sources.html

