📄 putc.c
字号:
/* A module of ASYNCx.LIB version 1.02 */
#include <dos.h>
#include "asyncdef.h"
/**************************************************************
Send the character in c to the port associated with p. If
there are no characters in the output buffer, wait for the
UART to be ready to transmit another character, and send the
character to the UART. Otherwise, wait (if necessary) for the
output buffer to be able to accept another character, and put
the character into the output buffer.
This function returns the value of the character in c if it
is is able to either be sent to the port or put into the
output buffer to be sent later. Latter, when XON/XOFF logic
is added to this routine, a -1 will be returned if an XOFF
has been received and the output buffer is full.
**************************************************************/
int a_putc(int c,register ASYNC *p)
{byte *bp;
/*
** If the output buffer of this port is not empty, attempt to put the
** character into the output buffer so that it can be sent later.
** Otherwise, just send the character directly to the UART so that it
** can be transmitted.
*/
if (p->ocount)
{/*
** Point bp to the position in the output buffer immediately after
** the current head of the buffer. This will allow us to see if the
** buffer can accept any more characters or not.
*/
bp=p->obufhead+1;
if (bp==p->obufend)
bp=p->obuf;
/*
** Wait until the output buffer can accept another character. Then
** put the character into the output buffer. If the buffer is full
** and an XOFF character has been received, return a value of -1.
*/
while(bp==p->obuftail)
if (p->recvxoff)
return -1;
/*
** Put the character into the output buffer and return the value of
** the character.
*/
*(p->obufhead)=c;
p->obufhead=bp;
p->ocount++;
return c;
}
else
{/*
** Wait for the UART to be ready to accept another character to be
** transmitted. After it is ready, give the new character to the UART
** so that it can be transmitted, and return the value of the
** characeter.
*/
while((inportb(p->base+LSR) & 0x20) == 0);
outportb(p->base+DATA,(unsigned char)c);
return c;
}
} /* end of a_putc(c,p) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -