Ignore:
Timestamp:
Dec 4, 2001, 1:58:02 PM (24 years ago)
Author:
phaller
Message:

Improvements on parallel port support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/hmparport.cpp

    r7538 r7542  
    1 /* $Id: hmparport.cpp,v 1.14 2001-12-04 00:07:25 phaller Exp $ */
     1/* $Id: hmparport.cpp,v 1.15 2001-12-04 12:56:52 phaller Exp $ */
    22
    33/*
     
    9191
    9292// Hardwired parallel port configuration information.
    93 // Yet unsure if it's beneficial to query Resource Manager
    94 // for these values as direct port i/o is not allowed anyway.
     93// @@@PH better query the Resource Manager
    9594typedef struct tagParallelPortConfiguration
    9695{
     
    9897  ULONG ulPortBase;
    9998  ULONG ulPortSpan;
     99  ULONG ulEcpPortBase;
     100  ULONG ulEcpPortSpan;
    100101} PARALLELPORTCONFIGURATION, *PPARALLELPORTCONFIGURATION;
    101102
    102 #define NUM_PARALLELPORTS 3
    103 static PARALLELPORTCONFIGURATION arrParallelPorts[NUM_PARALLELPORTS] = {
    104   {1, 0x378, 8},
    105   {2, 0x278, 8},
    106   {3, 0x3bc, 8}
     103#define MAX_PARALLEL_PORTS_CONFIGURATION 3
     104static PARALLELPORTCONFIGURATION arrParallelPorts[MAX_PARALLEL_PORTS_CONFIGURATION] =
     105{
     106  {1, 0x378, 8, 0x778, 3},
     107  {2, 0x278, 8, 0x678, 3},
     108  {3, 0x3bc, 8, 0x000, 0}
    107109};
    108110
     
    135137
    136138
    137 HMDeviceParPortClass::HMDeviceParPortClass(LPCSTR lpDeviceName) : HMDeviceHandler(lpDeviceName)
     139HMDeviceParPortClass::HMDeviceParPortClass(LPCSTR lpDeviceName) :
     140  HMDeviceHandler(lpDeviceName)
    138141{
    139142  dprintf(("HMDeviceParPortClass::HMDevParPortClass(%s)\n",
     
    145148 
    146149  // first, we determine the number of parallel port devices available
    147   BYTE  bParallelPorts = NUM_PARALLELPORTS;
    148  
    149 #if 0
    150   // Note:
    151   // OSLibDosDevConfig does *NOT* report any OS/2 related information
    152   // about the parallel ports such as LPT redirections or even an
    153   // installed LPT device driver, it appears to just report what the
    154   // BIOS told.
    155  
    156   DWORD rc = OSLibDosDevConfig(&bParallelPorts,
     150 
     151  // PH 2001-12-04 Note:
     152  // This call will not return any information about redirected LPT ports.
     153  // We have a specific application requiring exactly this behaviour as it
     154  // cannot talk to redirected LPTs anyway.
     155  // For any change in this behaviour, we'd require a configuration switch.
     156  bNumberOfParallelPorts = 0;
     157  DWORD rc = OSLibDosDevConfig(&bNumberOfParallelPorts,
    157158                               DEVINFO_PRINTER);
    158159  dprintf(("HMDeviceParPortClass: Parallel ports reported: %d\n",
    159           bParallelPorts));
    160   if (0 == bParallelPorts)
     160          bNumberOfParallelPorts));
     161  if (0 == bNumberOfParallelPorts)
    161162    return;
    162  
    163   // @@@PH
    164   // query configuration data from Resource Manager
    165   // (base i/o ports, etc. for the IOCTL_INTERNAL_GET_xxx)
    166 #endif
    167163 
    168164  VOID *pData;
     
    174170 
    175171  // add symbolic links to the "real name" of the device
     172  if (bNumberOfParallelPorts > 0)
    176173  {
    177174    // Note: \\.\LPTx: is invalid (NT4SP6)
    178175    PSZ pszLPT  = strdup("\\\\.\\LPTx");
    179176    PSZ pszLPT2 = strdup("\\Device\\ParallelPort0");
    180     for (char ch = '1'; ch <= '1' + (bParallelPorts - 1); ch++)
     177    for (char ch = '1'; ch <= '1' + (bNumberOfParallelPorts - 1); ch++)
    181178    {
    182179      pszLPT[7] = ch;
     
    210207BOOL HMDeviceParPortClass::FindDevice(LPCSTR lpClassDevName, LPCSTR lpDeviceName, int namelength)
    211208{
     209  // Don't accept any name if no parallel ports have been detected
     210  if (bNumberOfParallelPorts == 0)
     211    return FALSE;
     212 
    212213  // can be both, "LPT1" and "LPT1:"
    213     if(namelength > 5)
    214         return FALSE;  //can't be lpt name
    215 
    216     //first 3 letters 'LPT'?
    217     if(lstrncmpiA(lpDeviceName, lpClassDevName, 3) != 0) {
    218         return FALSE;
    219     }
    220 
    221     if(namelength == 5 && lpDeviceName[4] != ':') {
    222         return FALSE;
    223     }
    224  
    225     // can support up tp LPT9
    226     if ( (lpDeviceName[3] >= '1') &&
    227          (lpDeviceName[3] <= '1' + NUM_PARALLELPORTS) )
    228     {
    229       return TRUE;
    230     }
    231  
    232     return FALSE;
     214  if(namelength > 5)
     215    return FALSE;  //can't be lpt name
     216
     217  //first 3 letters 'LPT'?
     218  if(lstrncmpiA(lpDeviceName, lpClassDevName, 3) != 0)
     219    return FALSE;
     220
     221  if(namelength == 5 && lpDeviceName[4] != ':')
     222    return FALSE;
     223 
     224  // can support up tp LPT9
     225  if ( (lpDeviceName[3] >= '1') &&
     226       (lpDeviceName[3] <= '1' + bNumberOfParallelPorts) )
     227  {
     228    return TRUE;
     229  }
     230
     231  return FALSE;
    233232}
    234233
     
    245244           pHMHandleDataTemplate));
    246245 
    247  char lptname[6];
     246  char lptname[6];
    248247
    249248  dprintf(("HMDeviceParPortClass: Parallel port %s open request\n", lpFileName));
    250 
     249 
     250  // Don't accept any name if no parallel ports have been detected
     251  if (bNumberOfParallelPorts == 0)
     252  {
     253    return ERROR_DEV_NOT_EXIST;
     254  }
     255 
    251256  strcpy(lptname, lpFileName);
    252257  lptname[4] = 0;   //get rid of : (if present) (eg LPT1:)
     
    280285   
    281286    // safety check (device no 0..8 -> LPT1..9)
    282     if (ulPortNo > 8)
     287    if (ulPortNo > MAX_PARALLEL_PORTS_CONFIGURATION)
    283288    {
    284       delete pHMHandleData->lpHandlerData;
     289      HMDeviceParPortClass::CloseHandle(pHMHandleData);
    285290      return ERROR_DEV_NOT_EXIST;
    286291    }
     
    719724        // function driver for parallel ports uses to control the ECP
    720725        // operation of the parallel port.
    721         pPPI->OriginalEcpController.LowPart  = pPPD->pHardwareConfiguration->ulPortBase;
     726        pPPI->OriginalEcpController.LowPart  = pPPD->pHardwareConfiguration->ulEcpPortBase;
    722727        pPPI->OriginalEcpController.HighPart = 0;
    723728       
     
    727732       
    728733        // Specifies the size, in bytes, of the I/O port resource.
    729         pPPI->SpanOfEcpController = pPPD->pHardwareConfiguration->ulPortSpan;
     734        pPPI->SpanOfEcpController = pPPD->pHardwareConfiguration->ulEcpPortSpan;
    730735       
    731736        // Not used.
Note: See TracChangeset for help on using the changeset viewer.