/********************************************/
/* Text.h */
/********************************************/
#include <conio.h>
#include <stdio.h>
class text
{
int x1,y1,x2,y2;
public:
text()
{
window(1,1,80,25);
textbackground(0);
textcolor(15);
clrscr();
gotoxy(1,1);
printf("%s","COM-COM COMMUNiCATOR"

;
gotoxy(1,25);
printf("%s","(`) is for exit"

;
window(1,2,80,13);
x1=y1=1;
textbackground(1);
clrscr();
window(1,14,80,24);
x2=y2=1;
textbackground(2);
clrscr();
}
void me(int xx)
{
window(1,14,80,24);
textbackground(2);
textcolor(4);
gotoxy(x2,y2);
if (xx==13) cprintf("\n\r"

; else cprintf("%c",xx);
x2=wherex();
y2=wherey();
}
void he(int xx)
{
window(1,2,80,13);
textbackground(1);
textcolor(3);
gotoxy(x1,y1);
if (xx==13) cprintf("\n\r"

; else cprintf("%c",xx);
x1=wherex();
y1=wherey();
}
};
//--------------------------------------------------------
/********************************************/
/* Terminal.cpp */
/********************************************/
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include "text.h"
int com[4]={0x3f8,0x2f8,0x3e8,0x2e8};
union REGS regs;
text *t;
int c;
void init(int xx);
void interface()
{
textbackground(0);
clrscr();
window(30,15,50,20);
textbackground(5);
clrscr();
cprintf("CHOOSE COM:\n\n"

;
cprintf("\roCOM1\n"

;
cprintf("\roCOM2\n"

;
cprintf("\roCOM3\n"

;
cprintf("\roCOM4"

;
gotoxy(1,3);cprintf("v\r"

;
char m=1;
int y;
do
{
m=getch();
m-=49;
y=3+m;
if (m<4&&m>=0) {cprintf("o"

;gotoxy(1,y);cprintf("v\r"

;}
}
while (m!=13-49);
init(wherey()-3);
c=wherey()-3;
t=new text;
}
void init(int xx)
{
outport(com[xx]+3,0x80);
outport(com[xx],12);
outport(com[xx]+1,0);
outport(com[xx]+3,0);
outport(com[xx]+3,3);
}
void out(int xx)
{
int x;
if (x=inport(com[xx]+5)&1,x!=0)
t->he(inport(com[xx]));
}
void in(int xy)
{
int x;
regs.h.ah=6;
regs.h.dl=0xff;
int86(0x21,®s,®s);
x=inport(com[xy]+5)&0x20;
if (regs.h.al!=0&&x==0x20)
{
t->me(regs.h.al);
outport(com[xy],regs.h.al);
}
}
void main()
{
interface();
do
{
in(c);
out(c);
}
while (regs.h.al!=96);
}