/*****************************************************************************
 *                                 ibmcomt.c                                 *
 *****************************************************************************
 * DESCRIPTION: This is a simple test program for IBMCOM.  It acts like a    *
 *              dump terminal at a fixed speed with no commands except Alt-X *
 *              to exit the program.  Obviously it doesn't test all of       *
 *              all of IBMCOM, but it tests the most important parts --      *
 *              receiving and sending characters.                            *
 *                                                                           *
 * REVISIONS:   18 OCT 89 - RAC - Translated from the Pascal.                *
 *****************************************************************************/

#include        <stdio.h>
#include        "ibmcom.h"
#include	"patch.h"

STARTPATCH
int PORT=1;
ENDPATCH

#define SPEED   9600

get_key()  {
    int c;
    if ((c = getch())!=0) return c;
    else  return getch() + 256;
}

main(argc,argv) 
int argc;
char *argv[];
{

    int herb;

    SETUP;

    if ((herb = com_install(PORT))!=0) {
        printf("com_install() error: %d\n", herb);
        return;
        }
    com_raise_dtr();
    com_set_speed(SPEED);
    com_set_parity(COM_NONE, 1);
    clrscr();
    printf("IBMCOM Test\n");
    while (1) {
        if (kbhit()) {
            herb = get_key();
            if (herb == 301 /* Alt-X */) {
                com_deinstall();
                exit();
                }
            com_tx(herb);
            }
        if ((herb = com_rx()) != -1)
            putchar(herb);
        }
    }
    
void setup()
{
	printf("Setup\n\n");
	printf("Port    Address    IRQ\n");
	printf("COM1      3f8       4\n");
	printf("COM2      2f8       3\n");
	printf("COM3      3e8       4\n");
	printf("COM4      2e8       3\n\n");
	printf("Attention if you want to use COM3 or COM4:\n\n");
	printf("COM1 and COM3 cannot be used simultaneously\n");
	printf("COM2 and COM4 cannot be used simultaneously\n");
	printf("If your mouse is connected to COM1 you should not use COM3\n");
	printf("If your mouse is connected to COM2 you should not use COM4\n\n");
	printf("If your modem is connected to COM1 you can use COM3 if this program\n");
	printf("and the communication program are not running at the same time\n\n");
	printf("If your modem is connected to COM2 you can use COM4 if this program\n");
	printf("and the communication program are not running at the same time\n\n");
	printf("Give comport number: ");
	fflush(stdout);
	scanf("%d",&PORT);
	printf("\n\nSetup finished\n\n");
}
