home *** CD-ROM | disk | FTP | other *** search
/ PC Media 23 / PC MEDIA CD23.iso / share / prog / pcl4w12 / line.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-06  |  3.1 KB  |  130 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. #define RTS_CTS_CONTROL 1
  17.  
  18. /* private */
  19. static WORD RxSelector = 0;
  20. static WORD TxSelector = 0;
  21. static WORD LockCount = 0;
  22. static void FreeDOSmemory(void);
  23.  
  24. void GoOnLine(void)
  25. {DWORD dwValue;
  26.  int RetCode;
  27.  int Port;
  28.  HMENU hMenu;
  29.  if(OnLineFlag) return;
  30.  Port = GetPort();
  31.  /* allocate windows/DOS memory for receive buffer */
  32.  dwValue = GlobalDosAlloc(2<<(3+RXBUFFERCODE));
  33.  if(dwValue)
  34.    {/* get selector */
  35.     RxSelector = LOWORD(dwValue);
  36.     LockCount = GlobalPageLock(RxSelector);
  37.     if(LockCount==0) FatalFlag = TRUE;
  38.    }
  39.  else FatalFlag = TRUE;
  40.  /* memory allocation error ? */
  41.  if(FatalFlag)
  42.    {RxSelector = 0;
  43.     ErrorMessage("Cannot allocate memory");
  44.     return;
  45.    }
  46.  /* pass selector to PCL4W */
  47.  RetCode = SioRxBuf(Port,RxSelector,RXBUFFERCODE);
  48.  if(RetCode<0)
  49.    {SioError(RetCode,"SioRxBuf");
  50.     FreeDOSmemory();
  51.     return;
  52.    }
  53.  if(SioInfo('I'))
  54.    {/* allocate windows/DOS memory for transmit buffer */
  55.     dwValue = GlobalDosAlloc(2<<(3+TXBUFFERCODE));
  56.     if(dwValue)
  57.       {/* get selector */
  58.        TxSelector = LOWORD(dwValue);
  59.        LockCount = GlobalPageLock(TxSelector);
  60.       if(LockCount==0) FatalFlag = TRUE;
  61.       }
  62.     else FatalFlag = TRUE;
  63.     /* memory allocation error ? */
  64.     if(FatalFlag)
  65.       {TxSelector = 0;
  66.        ErrorMessage("Cannot allocate memory");
  67.        return;
  68.       }
  69.     /* pass selector to PCL4W */
  70.     RetCode = SioTxBuf(Port,TxSelector,TXBUFFERCODE);
  71.     if(RetCode<0)
  72.       {SioError(RetCode,"SioTxBuf");
  73.        FreeDOSmemory();
  74.        return;
  75.       }
  76.     DisplayLine("TX interrupts enabled");
  77.    }
  78.  /* reset Port */
  79.  RetCode = SioReset(Port,GetBaud());
  80.  if(RetCode<0)
  81.    {SioError(RetCode,"SioReset");
  82.     FreeDOSmemory();
  83.     return;
  84.    }
  85.  /* set DTR & RTS */
  86.  SioDTR(Port,'S');
  87.  SioRTS(Port,'S');
  88. #if RTS_CTS_CONTROL
  89.  /* set flow control */
  90.  SioFlow(Port,TRUE);
  91.  DisplayLine("Flow control enabled");
  92. #endif
  93.  /* Set FIFO level for 16550 */
  94.  if( SioFIFO(Port,LEVEL_14) ) DisplayLine("16550 UART detected");
  95.  /* clear PCL4C receive buffer */
  96.  SioRxFlush(Port);
  97.  OnLineFlag = TRUE;
  98.  SetTitle();
  99.  hMenu = GetMenu(hMainWnd);
  100.  CheckMenuItem(hMenu,MSG_OFFLINE,MF_BYCOMMAND | MF_UNCHECKED);
  101.  CheckMenuItem(hMenu,MSG_ONLINE,MF_BYCOMMAND | MF_CHECKED);
  102. } /* end GoOnLine */
  103.  
  104. void GoOffLine()
  105. {HMENU hMenu;
  106.  FreeDOSmemory();
  107.  if(OnLineFlag)
  108.    {SioDone((int)GetPort());
  109.     hMenu = GetMenu(hMainWnd);
  110.     CheckMenuItem(hMenu,MSG_ONLINE,MF_BYCOMMAND | MF_UNCHECKED);
  111.     CheckMenuItem(hMenu,MSG_OFFLINE,MF_BYCOMMAND | MF_CHECKED);
  112.     OnLineFlag = FALSE;
  113.     SetTitle();
  114.    }
  115. } /* end GoOffLine */
  116.  
  117. void FreeDOSmemory(void)
  118. {
  119.  if(RxSelector)
  120.    {GlobalPageUnlock(RxSelector);
  121.     GlobalDosFree(RxSelector);
  122.     RxSelector = 0;
  123.    }
  124.  if(TxSelector)
  125.    {GlobalPageUnlock(TxSelector);
  126.     GlobalDosFree(TxSelector);
  127.     RxSelector = 0;
  128.    }
  129. }
  130.