🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: alt.msdos.programmer
1 messages
1 total messages Started by Lucio Menzel Fri, 07 Aug 1992 03:36
Terminal emulation using _bios_serialcom()
#64
Author: Lucio Menzel
Date: Fri, 07 Aug 1992 03:36
91 lines
2920 bytes
Dear colleagues:
 
I am trying to write a simple terminal emulation program in C using
Microsoft C 5.1 for MSDOS, tried to use _bios_serialcom() but have
problems with the interpretation of the status returned.
 
At the end of this message is some C code I wrote (it doesn't work).
 
Any help with this will be much appreciated. Please reply by e-mail.
Thanks...
 
             Lucio Menzel -- lumenzel@eastern.uucp
 
-----------------------8<----------------cut----here----------
#include <stdio.h>
#include <conio.h>
 
#define ESC (char)27
 
char bCommGetChar(char cPort, char *pc)
{
// check port to see if there is a byte to read,
// if so read it, asign to *pc and return 1.
// If there's no byte to read return 0
 
        unsigned uStatus;
        uStatus = _bios_serialcom(_COM_STATUS, cPort - 1, 0);
        if (uStatus & ...)
        {
                uStatus = _bios_serialcom(_COM_RECEIVE, cPort - 1, 0);
                if (uStatus & ...)
                {
                        *pc = (char)(uStatus & 0x00ff);
                        return (char)1;
                }
        }
 
        return 0;
}
 
char bCommPutChar(char cPort, char c)
{
// wait until the port is ready and then send the byte
 
        unsigned uStatus;
 
        while (1)
        {
                uStatus = _bios_serialcom(_COM_STATUS, cPort - 1, 0);
                if (uStatus & ...)
                        break;
        }
        uStatus = _bios_serialcom(_COM_SEND, cPort - 1, c);
        return uStatus & ...;
}
                
int main(void)
{
        char c, cPort = (char)1;        // COM1
        unsigned uStatus = 
                _bios_serialcom(
                        _COM_INIT, 
                        cPort - 1, 
                        _COM_EVENPARITY|_COM_CHR7|_COM_STOP1|_COM_1200
                        );
 
        if (uStatus & ...)
        {
                fprintf(stderr, "\7Cant set serial port\n");
                return 1;
        }
 
        puts("ESC to end");
        while (1)
        {
                if (bCommGetChar(cPort, &c))
                        putchar(c);
                if (kbhit())
                {
                        c = (char)getchar();
                        if (c == ESC)
                                break;
                        if (!bCommPutChar(cPort, c))
                                printf("error sending %c\n", c);
                }
        }
 
        return 0;
}
 
/*EOF*/
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads