/* Copyright (C) Magna Carta Software, Inc. 1988-1990. All Rights Reserved. CCT14.C CAPABILITY: 1) Uses interrupt driven reception; 2) Data transfer rate can be set at run time; 3) Data format can be adjusted at run time; 4) Formatted serial input is used; 5) Formatted serial output is used; 6) Direct control over the modem; NEW: VT100 terminal emulation. NOTE: We recommend that you deinstall ANSI.SYS before using this program. All other options must be changed in the source code and the source recompiled to change them. */ #include #include #include #include #include /* MANIFEST CONSTANTS AND MACROS */ #define DO_MENU ALT_M /* key for command summary */ /* FUNCTION PROTOTYPES */ void do_data_menu(COMM_PORT * p); short do_modem_menu(COMM_PORT *p); long do_speed_menu(COMM_PORT * p); void term(COMM_PORT *p); short menu(COMM_PORT *p); /* GLOBAL VARIABLES */ COMM_PORT port1; BYTE rxbuf[2048]; /* RECEIVE BUFFER */ int vers = 14; int xchar[256]; #include /* NECESSARY FOR TERMINAL EMULATION */ #include /* NECESSARY FOR VT100 TERMINAL EMULATION */ TERMINAL t; #include "menus.c" /* ------------------------ PROGRAM BEGINS HERE --------------------------- */ int main(void) { init_port(&port1, COM1, 2400L, DATABITS8, PARITY_NONE, STOPBITS1); install_ipr(&port1, RECEIVE, NULL, rxbuf, sizeof(rxbuf)); install_isr(&port1, 4, NULL); /* THIS BEGINS VT100 TERMINAL EMULATION */ init_term(&port1, &t, (void (*)()) vt100_init, bios_video); bios_ed(&t, 7, 0); bios_cur_pos(&t, 0, 0); printf("\nCCT-COMM Version %d: Press Alt-M for a list of commands\n", vers); term(&port1); printf("\nEnd of CCT-COMM%d\n", vers); set_dtr(&port1, LOW); return (0); } /* TERM -- The terminal emulation routine. Simply polls the COM port and the keyboard alternately for characters. */ void term(COMM_PORT *p) { short c; /* must be int to detect a -1 return */ set_rx_xlat(p, EOL, FALSE); set_rx_xlat(p, LOCAL_ECHO, TRUE); set_tx_xlat(p, LOCAL_ECHO, FALSE); set_tx_xlat(p, CASE, FALSE); for (;;) { /* CHECK SERIAL PORT FOR BYTE */ c_getc(p); /* CHECK KEYBOARD FOR A KEY PRESS */ if ((c = inkey()) != 0) { if (c == DO_MENU) { if (menu(p) == 1) break; } else c_putc(p, c); } } } #define DATA_FORMAT 'D' /* key to set speed */ #define DATA_SPEED 'S' /* key to set speed */ #define MODEM_MENU 'M' /* key to send modem commands */ #define EXIT 'Q' /* key to exit from main */ short menu(COMM_PORT *p) { short c, retval = 0, DONE = FALSE; static char *menus[] = { "\tD. Data Format", "\tS. Data Transfer Rate.", "\tQ. EXIT from COMM.", NULL /* null string terminates list */ }; char **p_menu; c = !EXIT; 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; case DATA_FORMAT: do_data_menu(p); break; case DATA_SPEED: do_speed_menu(p); break; default: DONE = TRUE; break; } } puts("\nExiting menu"); set_tx_xlat(p, LOCAL_ECHO, FALSE); return (retval); /* will be zero except if EXIT */ }