/* Copyright (C) Magna Carta Software, Inc. 1990, 1991. All Rights Reserved. CCT00.C -- First example telecommunications program. CAPABILITY: Dumb terminal program that polls COM1 for data. All options must be set in the code and the source recompiled to change them. Good for 1200 bps on an AT class machine, 300 bps on a slower machine. */ #include #include #include #include /* our communications routines */ /* MANIFEST CONSTANTS */ #define MENU ALT_M /* key for command summary */ /* FUNCTION PROTOTYPES */ void term(COMM_PORT *p); /* the main program loop */ short menu(void); /* the function that handles the menu */ /* GLOBAL VARIABLES */ COMM_PORT port1; /* the structure describing the port */ short vers = 0; /* the version number of "CCT-COMM" */ /* ------------------------ PROGRAM BEGINS HERE --------------------------- */ int main(void) { /* THIS FUNCTION INITIALIZES A PC SERIAL PORT THAT USES A UART THAT IS A MEMBER OF THE '8250' FAMILY. THE CONSTANT 'COM1' IS DEFINED AS 0X3F8. IF YOU USE A DIFFERENT PORT, MODIFY THIS PARAMETER. */ u8250_init(&port1, COM1, 1200L, DATABITS8, PARITY_NONE, STOPBITS1); printf("CCT-COMM Version %d: Press Alt-M for a list of commands\n", vers); term(&port1); 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(COMM_PORT *p_port) { short c; /* must be int to detect a -1 return */ for (;;) { /* CHECK SERIAL PORT FOR BYTE */ if ((c = c_inchar(p_port)) != EOF) putch(c); /* CHECK KEYBOARD FOR A KEY PRESS */ if ((c = inkey()) != 0) { if (c == MENU) { if (menu()) break; } else c_putc(p_port, c); } } } #define EXIT 'Q' /* key to exit from menu */ short menu(void) { int c, retval = 0; static char *menus[] = { "\tQ. EXIT from TERM.", NULL /* null string terminates list */ }; char **menup; c = !EXIT; while (c != EXIT && c != LF) { puts("\n\n"); for (menup = menus; *menup != NULL; menup++) printf("%s\n", *menup); printf("\n\t\t Enter selection (CR to quit menu) : "); c = getchar(); c = toupper(c); switch (c) { case EXIT: retval = 1; break; default: break; } } puts("\nExiting menu"); return (retval); /* will be zero except if EXIT */ }