/* Basic RS-232 communications routine in Borland C
  uses FOSSIL driver */

#include <dos.h>
#include <bios.h>
#include <conio.h>
#include <stdio.h>

#define COM2       1
#define DATA_READY 0x100
#define TRUE       1
#define FALSE      0


#define SETTINGS ( 0xC0 | 0x00 | 0x04 | 0x03)


int main(void)
{
int in, out, status, DONE = FALSE;

    textbackground(BLUE);
    textcolor(YELLOW);
    clrscr();

    if(fos_init(COM2) == 0x1954)
    {
         bioscom(0, SETTINGS, COM2);
         while (!DONE)
         {
              status = bioscom(3, 0, COM2);
              if (status & DATA_READY)
              {
                   putch(out = bioscom(2, 0, COM2) & 0xFF);
                   if(out == '\x0A')
                       if(wherey() == 25) clreol();
              }
              if (bioskey(1))
              {
                   if ((in = bioskey(0) & 0xFF) == '\x1B')
                        DONE = TRUE;
                   bioscom(1, in, COM2);
              }
        }
        textbackground(BLACK);
        textcolor(LIGHTGRAY);
        clrscr();
        fos_deinit(COM2);
        return 0;
    }
    else
         printf("Error: FOSSIL driver not installed\n");
}

fos_init(int p)
{
    _AH = 0x04;                       /* Initialize FOSSIL driver COM2 */
    _DX = p;                          /* (and check if installed)      */
    geninterrupt(0x14);
    return _AX;
}

fos_deinit(int p)
{
    _AH = 0x05;
    _DX = p;
    geninterrupt(0x14);
    return 0;
}