home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / windows / c / pclw11 / line.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-25  |  3.1 KB  |  129 lines

  1. /*** line ***/
  2.  
  3. #include "windows.h"
  4. #include "line.h"
  5. #include "pcl4w.h"
  6. #include "config.h"
  7. #include "simple.h"
  8. #include "expect.h"
  9. #include "sioerror.h"
  10. #include "simpl_io.h"
  11.  
  12. extern HWND hMainWnd;
  13. extern int FatalFlag;
  14. extern int OnLineFlag;
  15.  
  16. /* private */
  17. static WORD RxSelector = 0;
  18. static WORD TxSelector = 0;
  19. static WORD LockCount = 0;
  20. static void FreeDOSmemory(void);
  21.  
  22. void GoOnLine(void)
  23. {DWORD dwValue;
  24.  int RetCode;
  25.  int Port;
  26.  HMENU hMenu;
  27.  if(OnLineFlag) return;
  28.  /* allocate windows/DOS memory for receive buffer */
  29.  dwValue = GlobalDosAlloc(2<<(3+RXBUFFERCODE));
  30.  if(dwValue)
  31.    {/* get selector */
  32.     RxSelector = LOWORD(dwValue);
  33.     LockCount = GlobalPageLock(RxSelector);
  34.     if(LockCount==0) FatalFlag = TRUE;
  35.    }
  36.  else FatalFlag = TRUE;
  37.  /* memory allocation error ? */
  38.  if(FatalFlag)
  39.    {RxSelector = 0;
  40.     ErrorMessage("Cannot allocate memory");
  41.     return;
  42.    }
  43.  /* pass selector to PCL4C */
  44.  Port = GetPort();
  45.  RetCode = SioRxBuf(Port,RxSelector,RXBUFFERCODE);
  46.  if(RetCode<0)
  47.    {SioError(RetCode,"SioRxBuf");
  48.     FreeDOSmemory();
  49.     return;
  50.    }
  51.  if(SioInfo('I'))
  52.    {/* allocate windows/DOS memory for transmit buffer */
  53.     dwValue = GlobalDosAlloc(2<<(3+TXBUFFERCODE));
  54.     if(dwValue)
  55.       {/* get selector */
  56.        TxSelector = LOWORD(dwValue);
  57.        LockCount = GlobalPageLock(TxSelector);
  58.       if(LockCount==0) FatalFlag = TRUE;
  59.       }
  60.     else FatalFlag = TRUE;
  61.     /* memory allocation error ? */
  62.     if(FatalFlag)
  63.       {TxSelector = 0;
  64.        ErrorMessage("Cannot allocate memory");
  65.        return;
  66.       }
  67.     /* pass selector to PCL4C */
  68.     Port = GetPort();
  69.     RetCode = SioTxBuf(Port,TxSelector,TXBUFFERCODE);
  70.     if(RetCode<0)
  71.       {SioError(RetCode,"SioTxBuf");
  72.        FreeDOSmemory();
  73.        return;
  74.       }
  75.     DisplayLine("TX interrupts enabled");
  76.    }
  77.  /* reset Port */
  78.  RetCode = SioReset(Port,GetBaud());
  79.  if(RetCode<0)
  80.    {SioError(RetCode,"SioReset");
  81.     FreeDOSmemory();
  82.     return;
  83.    }
  84.  /* set DTR & RTS */
  85.  SioDTR(Port,'S');
  86.  SioRTS(Port,'S');
  87. #if RTS_CTS_CONTROL
  88.  /* set flow control */
  89.  SioFlow(Port,TRUE);
  90.  DisplayLine("Flow control enabled");
  91. #endif
  92.  /* Set FIFO level for 16550 */
  93.  if( SioFIFO(Port,LEVEL_14) ) DisplayLine("16550 UART detected");
  94.  /* clear PCL4C receive buffer */
  95.  SioRxFlush(Port);
  96.  OnLineFlag = TRUE;
  97.  SetTitle();
  98.  hMenu = GetMenu(hMainWnd);
  99.  CheckMenuItem(hMenu,MSG_OFFLINE,MF_BYCOMMAND | MF_UNCHECKED);
  100.  CheckMenuItem(hMenu,MSG_ONLINE,MF_BYCOMMAND | MF_CHECKED);
  101. } /* end GoOnLine */
  102.  
  103. void GoOffLine()
  104. {HMENU hMenu;
  105.  FreeDOSmemory();
  106.  if(OnLineFlag)
  107.    {SioDone((int)GetPort());
  108.     hMenu = GetMenu(hMainWnd);
  109.     CheckMenuItem(hMenu,MSG_ONLINE,MF_BYCOMMAND | MF_UNCHECKED);
  110.     CheckMenuItem(hMenu,MSG_OFFLINE,MF_BYCOMMAND | MF_CHECKED);
  111.     OnLineFlag = FALSE;
  112.     SetTitle();
  113.    }
  114. } /* end GoOffLine */
  115.  
  116. void FreeDOSmemory(void)
  117. {
  118.  if(RxSelector)
  119.    {GlobalPageUnlock(RxSelector);
  120.     GlobalDosFree(RxSelector);
  121.     RxSelector = 0;
  122.    }
  123.  if(TxSelector)
  124.    {GlobalPageUnlock(TxSelector);
  125.     GlobalDosFree(TxSelector);
  126.     RxSelector = 0;
  127.    }
  128. }
  129.