home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware 1 2 the Maxx
/
sw_1.zip
/
sw_1
/
PROGRAM
/
PCL4C30.ZIP
/
INTERCOM.C
< prev
next >
Wrap
Text File
|
1992-01-20
|
4KB
|
170 lines
/*
** --- intercom.c ---
**
** EXAMPLE CODE: This example is meant to be a simple 2 user intercom
** system. Run on two systems connected via modem or null modem cable.
**
** This example program (not the PCL4C library) is donated to
** the Public Domain by MarshallSoft Computing, Inc. It is
** provided as an example of the use of the PCL4C.
**
*/
#include <stdio.h>
#include "pcl4c.h"
#define FALSE 0
#define TRUE !FALSE
#define ESC 0x1b
#define EOL 0x0d
#define HOR 205
#define VER 186
#define URC 187
#define LRC 188
#define ULC 201
#define LLC 200
#define CLC 204
#define CRC 185
#define NORMAL 0x07
/*** Global Variables ***/
int Port = 0; /* COM port # 0 ( COM1 ) */
int BaudCode = Baud2400; /* Code for 2400 baud */
char RxBuf[64]; /* PCL4C receive buffer */
int SrcRow = 1; /* cursor row for outgoing */
int SrcCol = 1; /* cursor column for outgoing */
int DstRow = 13; /* cursor row for incoming */
int DstCol = 1; /* cursor column for incoming */
/*** Main ***/
main(argc,argv)
int argc;
char *argv[];
{int row;
char c;
int i, rc;
/* get port number */
if(argc!=2)
{printf("Usage: 'INTERCOM port ' -- example 'INTERCOM 1'\n");
exit(1);
}
/* get port number from command line */
Port = atoi(argv[1]) - 1;
if((Port<0) || (Port>3))
{printf("ERROR: Port must be 1 to 4\n");
exit(1);
}
/* setup receive buffer */
ErrorCheck( SioRxBuf(Port,RxBuf,Size64) );
/* set port parmameters */
ErrorCheck( SioParms(Port,NoParity,OneStopBit,WordLength8) );
/* reset the port */
ErrorCheck( SioReset(Port,BaudCode) );
/* clear screen */
Scroll(0,0,24,79,0,7);
/* draw top horizontal bar */
Position(0,0);
putchar(ULC);
Duplicate(HOR,22);
printf(" INTERCOM 1.0: Type <ESC> to exit ");
Duplicate(HOR,22);
putchar(URC);
/* draw vertical bars to reach middle horizontal bar */
for(row=1;row<=11;row++)
{Position(row,0); AttrWrite(VER,NORMAL);
Position(row,79); AttrWrite(VER,NORMAL);
}
/* draw middle horizontal bar */
Position(12,0);
putchar(CLC);
Duplicate(HOR,78);
putchar(CRC);
/* draw vertical bars to reach bottom horizontal bar */
for(row=13;row<=23;row++)
{Position(row,0); putchar(VER);
Position(row,79); putchar(VER);
}
/* draw bottom horizontal bar */
Position(24,0);
putchar(LLC);
Duplicate(HOR,78);
/* position cursor */
Position(SrcRow,SrcCol);
/* enter intercom loop */
while(TRUE)
{/* was key pressed ? */
if(SioKeyPress())
{i = SioKeyRead();
if((char)i==ESC)
{/* restore COM port status & exit */
SioDone(Port);
exit(1);
}
else
{/* send over serial line */
SioPutc(Port,i);
/* echo in our area */
DisplayChar(i,&SrcRow,&SrcCol,1);
}
} /* end if */
/* any incoming over serial port ? */
i = SioGetc(Port,0);
if(i>-1) DisplayChar(i,&DstRow,&DstCol,13);
} /* end while */
} /* end main */
int DisplayChar(Ch,RowPtr,ColPtr,FirstRow)
char Ch;
int *RowPtr;
int *ColPtr;
int FirstRow;
{/* position cursor */
Position(*RowPtr,*ColPtr);
/* write character */
if(Ch==(char)EOL)
{/* next line */
*ColPtr = 78;
}
else AttrWrite(Ch,NORMAL);
/* advance cursor */
Advance(RowPtr,ColPtr,FirstRow);
} /* end DisplayChar */
int Advance(RowPtr,ColPtr,FirstRow)
int *RowPtr;
int *ColPtr;
int FirstRow;
{(*ColPtr)++;
if(*ColPtr==79)
{(*RowPtr)++;
if(*RowPtr==FirstRow+11)
{Scroll(FirstRow,1,FirstRow+10,78,1,7);
*RowPtr = FirstRow+10;
*ColPtr = 1;
}
else *ColPtr = 1;
}
/* position cursor */
Position(*RowPtr,*ColPtr);
} /* end Advance */
int ErrorCheck(Code)
int Code;
{/* trap PCL error codes */
if(Code<0)
{SioError(Code);
exit(1);
}
} /* end ErrorCheck */
int Duplicate(Ch, Count)
char Ch;
int Count;
{int i;
for(i=1;i<=Count;i++) putchar(Ch);
} /* end Duplicate */