Metropoli BBS
VIEWER: cct16.c MODE: TEXT (ASCII)
/*
Copyright (C) Magna Carta Software, Inc. 1990, 1991.  All Rights Reserved

CCT16.C -- Receive on two ports simultaneously.  Derived from CCT01.C.
CAPABILITY:  Dumb terminal program that uses interrupt driven reception.
This version uses EasyMode for easy initialization of the COMM_PORT
structures.

USAGE:  Characters typed at the keyboard are sent out of "port1" and
received characters echoed to the screen.  Install (for example) a modem
on this line.  "port2" is receive only.  Install a direct connection on this
line and send an ASCII (text) file from the remote system.

NOTE: You may need to change the IRQs and I/O addresses below to suit
your system.
*/

#include <comm.h>
#include <conio.h>
#include <ctype.h>
#include <dos.h>

/* MANIFEST CONSTANTS AND MACROS */
#define MENU            ALT_M           /* key for menu */

/* FUNCTION PROTOTYPES */
short   menu(void);
void    term(void);


/* GLOBAL VARIABLES */
COMM_PORT   port1, port2;
BYTE        rxbuf1[2048];           /* RECEIVE BUFFER FOR PORT 1 */
BYTE        rxbuf2[2048];           /* RECEIVE BUFFER FOR PORT 2 */
short       vers = 1;



/* ------------------------ PROGRAM BEGINS HERE --------------------------- */
int main(void)
{
    init_port(&port1, 0X3E8, 2400L, DATABITS8, PARITY_NONE, STOPBITS1);
    init_port(&port2, COM1, 38400L, DATABITS8, PARITY_NONE, STOPBITS1);
    printf("CCT-COMM Version %d: Press Alt-M for a list of commands\n", vers);
    term();
    printf("\nEnd of CCT-COMM%d\n", vers);

    return (0);
}



/*
TERM -- The terminal emulation routine. Simply polls the COM port and the
keyboard alternately for characters.
*/
void term(void)
{
    short c;              /* must be signed to detect a -1 return */

    set_rx_xlat(&port1, LOCAL_ECHO, ON);
    set_rx_xlat(&port2, LOCAL_ECHO, ON);
    for (;;) {
        /* CHECK SERIAL PORT1 FOR BYTE */
        c_getc(&port1);

        /* CHECK SERIAL PORT2 FOR BYTE */
        c_getc(&port2);

        /* CHECK KEYBOARD FOR A KEY PRESS */
        if ((c = inkey()) != 0) {
            if (c == MENU) {
                if (menu() == 1) break;
            }
            else c_putc(&port1, c);
        }
    }
}



#define EXIT 'Q'                /* key to exit from main */


short menu(void)
{
    short c, retval = 0, DONE = FALSE;
    static char *menus[] = {
        "\tQ.  EXIT from TERM.",
        NULL
    };
    char **p_menu;

    while (!DONE) {
        puts("\n\n");
        for (p_menu = menus; *p_menu != NULL; p_menu++) printf("%s\n", *p_menu);
        printf("\n\t\t Enter selection (CR to quit menu) :  ");
        c = getchar();
        c = toupper(c);
        switch (c) {
            case EXIT:
                retval = 1;
                DONE = TRUE;
                break;
            default:
                DONE = TRUE;
                break;
        }
    }
    puts("\nExiting menu");

    return (retval);                /* will be zero except if EXIT */
}

[ RETURN TO DIRECTORY ]