Use GetCommState16 to save state in OpenComm16.

Merge comm16 globals into one structure.
This commit is contained in:
Mike McCormack 2001-07-18 20:03:11 +00:00 committed by Alexandre Julliard
parent 4eb22c68b3
commit 1e72a3e96b
1 changed files with 19 additions and 25 deletions

View File

@ -108,15 +108,15 @@ struct DosDeviceStruct {
/* notifications */ /* notifications */
int wnd, n_read, n_write; int wnd, n_read, n_write;
HANDLE s_read, s_write; HANDLE s_read, s_write;
/* save terminal states */
DCB16 dcb;
/* pointer to unknown(==undocumented) comm structure */
LPCVOID *unknown;
}; };
static struct DosDeviceStruct COM[MAX_PORTS]; static struct DosDeviceStruct COM[MAX_PORTS];
static struct DosDeviceStruct LPT[MAX_PORTS]; static struct DosDeviceStruct LPT[MAX_PORTS];
/* pointers to unknown(==undocumented) comm structure */
static LPCVOID *unknown[MAX_PORTS];
/* save terminal states */
static struct termios m_stat[MAX_PORTS];
/* update window's semi documented modem status register */ /* update window's semi documented modem status register */
/* see knowledge base Q101417 */ /* see knowledge base Q101417 */
@ -289,11 +289,11 @@ static void CALLBACK comm_notification( ULONG_PTR private )
/* check for events */ /* check for events */
if ((ptr->eventmask & EV_RXFLAG) && if ((ptr->eventmask & EV_RXFLAG) &&
memchr(ptr->inbuf + ptr->ibuf_head, ptr->evtchar, len)) { memchr(ptr->inbuf + ptr->ibuf_head, ptr->evtchar, len)) {
*(WORD*)(unknown[cid]) |= EV_RXFLAG; *(WORD*)(COM[cid].unknown) |= EV_RXFLAG;
mask |= CN_EVENT; mask |= CN_EVENT;
} }
if (ptr->eventmask & EV_RXCHAR) { if (ptr->eventmask & EV_RXCHAR) {
*(WORD*)(unknown[cid]) |= EV_RXCHAR; *(WORD*)(COM[cid].unknown) |= EV_RXCHAR;
mask |= CN_EVENT; mask |= CN_EVENT;
} }
/* advance buffer position */ /* advance buffer position */
@ -337,7 +337,7 @@ static void CALLBACK comm_notification( ULONG_PTR private )
ptr->s_write = INVALID_HANDLE_VALUE; ptr->s_write = INVALID_HANDLE_VALUE;
} }
if (ptr->eventmask & EV_TXEMPTY) { if (ptr->eventmask & EV_TXEMPTY) {
*(WORD*)(unknown[cid]) |= EV_TXEMPTY; *(WORD*)(COM[cid].unknown) |= EV_TXEMPTY;
mask |= CN_EVENT; mask |= CN_EVENT;
} }
} }
@ -546,20 +546,18 @@ INT16 WINAPI OpenComm16(LPCSTR device,UINT16 cbInQueue,UINT16 cbOutQueue)
ERR("Couldn't open %s ! (%s)\n", COM[port].devicename, strerror(errno)); ERR("Couldn't open %s ! (%s)\n", COM[port].devicename, strerror(errno));
return IE_HARDWARE; return IE_HARDWARE;
} else { } else {
unknown[port] = SEGPTR_ALLOC(40); COM[port].unknown = SEGPTR_ALLOC(40);
memset(unknown[port], 0, 40); memset(COM[port].unknown, 0, 40);
COM[port].handle = handle; COM[port].handle = handle;
COM[port].commerror = 0; COM[port].commerror = 0;
COM[port].eventmask = 0; COM[port].eventmask = 0;
COM[port].evtchar = 0; /* FIXME: default? */ COM[port].evtchar = 0; /* FIXME: default? */
/* save terminal state */ /* save terminal state */
{int fd = FILE_GetUnixHandle(handle,GENERIC_READ); GetCommState16(port,&COM[port].dcb);
tcgetattr(fd,&m_stat[port]);
close(fd);}
/* set default parameters */ /* set default parameters */
if(COM[port].baudrate>-1){ if(COM[port].baudrate>-1){
DCB16 dcb; DCB16 dcb;
GetCommState16(port, &dcb); memcpy(&dcb,&COM[port].dcb,sizeof dcb);
dcb.BaudRate=COM[port].baudrate; dcb.BaudRate=COM[port].baudrate;
/* more defaults: /* more defaults:
* databits, parity, stopbits * databits, parity, stopbits
@ -583,9 +581,7 @@ INT16 WINAPI OpenComm16(LPCSTR device,UINT16 cbInQueue,UINT16 cbOutQueue)
} else COM[port].outbuf = NULL; } else COM[port].outbuf = NULL;
if (!COM[port].outbuf) { if (!COM[port].outbuf) {
/* not enough memory */ /* not enough memory */
{int fd = FILE_GetUnixHandle(handle,GENERIC_READ); SetCommState16(&COM[port].dcb);
tcsetattr(fd,TCSANOW,&m_stat[port]);
close(fd);}
CloseHandle(COM[port].handle); CloseHandle(COM[port].handle);
ERR("out of memory\n"); ERR("out of memory\n");
return IE_MEMORY; return IE_MEMORY;
@ -634,7 +630,7 @@ INT16 WINAPI CloseComm16(INT16 cid)
} }
if (!(cid&FLAG_LPT)) { if (!(cid&FLAG_LPT)) {
/* COM port */ /* COM port */
SEGPTR_FREE(unknown[cid]); /* [LW] */ SEGPTR_FREE(COM[cid].unknown); /* [LW] */
SERVICE_Delete( COM[cid].s_write ); SERVICE_Delete( COM[cid].s_write );
SERVICE_Delete( COM[cid].s_read ); SERVICE_Delete( COM[cid].s_read );
@ -643,9 +639,7 @@ INT16 WINAPI CloseComm16(INT16 cid)
free(ptr->inbuf); free(ptr->inbuf);
/* reset modem lines */ /* reset modem lines */
{int fd = FILE_GetUnixHandle(ptr->handle,GENERIC_READ); SetCommState16(&COM[cid].dcb);
tcsetattr(fd,TCSANOW,&m_stat[cid]);
close(fd);}
} }
if (!CloseHandle(ptr->handle)) { if (!CloseHandle(ptr->handle)) {
@ -814,7 +808,7 @@ INT16 WINAPI GetCommError16(INT16 cid,LPCOMSTAT16 lpStat)
WARN(" cid %d not comm port\n",cid); WARN(" cid %d not comm port\n",cid);
return CE_MODE; return CE_MODE;
} }
stol = (unsigned char *)unknown[cid] + COMM_MSR_OFFSET; stol = (unsigned char *)COM[cid].unknown + COMM_MSR_OFFSET;
COMM_MSRUpdate( ptr->handle, stol ); COMM_MSRUpdate( ptr->handle, stol );
if (lpStat) { if (lpStat) {
@ -858,11 +852,11 @@ SEGPTR WINAPI SetCommEventMask16(INT16 cid,UINT16 fuEvtMask)
return (SEGPTR)NULL; return (SEGPTR)NULL;
} }
/* it's a COM port ? -> modify flags */ /* it's a COM port ? -> modify flags */
stol = (unsigned char *)unknown[cid] + COMM_MSR_OFFSET; stol = (unsigned char *)COM[cid].unknown + COMM_MSR_OFFSET;
COMM_MSRUpdate( ptr->handle, stol ); COMM_MSRUpdate( ptr->handle, stol );
TRACE(" modem dcd construct %x\n",*stol); TRACE(" modem dcd construct %x\n",*stol);
return SEGPTR_GET(unknown[cid]); return SEGPTR_GET(COM[cid].unknown);
} }
/***************************************************************************** /*****************************************************************************
@ -884,8 +878,8 @@ UINT16 WINAPI GetCommEventMask16(INT16 cid,UINT16 fnEvtClear)
return 0; return 0;
} }
events = *(WORD*)(unknown[cid]) & fnEvtClear; events = *(WORD*)(COM[cid].unknown) & fnEvtClear;
*(WORD*)(unknown[cid]) &= ~fnEvtClear; *(WORD*)(COM[cid].unknown) &= ~fnEvtClear;
return events; return events;
} }