/* Copyright (C) Magna Carta Software, Inc. 1990, 1991. All Rights Reserved CCT01.C -- A slightly more advanced telecommunications program. CAPABILITY: Same as CCT00.C plus: interrupt driven reception */ #include #include #include #include /* MANIFEST CONSTANTS AND MACROS */ #define MENU ALT_M /* key for menu */ /* FUNCTION PROTOTYPES */ short menu(void); void term(COMM_PORT *p); /* GLOBAL VARIABLES */ COMM_PORT port1; BYTE rxbuf[2048]; /* RECEIVE BUFFER */ short vers = 1; /* ------------------------ PROGRAM BEGINS HERE --------------------------- */ int main(void) { /* FIRST, INITIALIZE THE PORT */ u8250_init(&port1, COM1, 2400L, DATABITS8, PARITY_NONE, STOPBITS1); /* NEXT, CALL install_ipr() TO INSTALL AN "INTERRUPT PROCESSING ROUTINE" FOR RECEIVE DATA. SINCE WE ARE GOING TO USE THE CCT DEFAULT IPR, THE POINTER TO THE FUNCTION IS "NULL". */ install_ipr(&port1, RECEIVE, NULL, rxbuf, sizeof(rxbuf)); /* FINALLY, INSTALL THE INTERRUPT SERVICE ROUTINE THAT IS CALLED WHEN AN INTERRUPT OCCURS ON THE PORT AND IN TURN CALLS THE "IPR" INSTALLED ABOVE NOTE: THE SECOND PARAMETER IS THE IRQ. FOR COM2, USE "3". THE THIRD PARAMETER IS A POINTER TO THE ISR. SINCE WE USE THE CCT DEFAULT ISR, SPECIFY IT AS 'NULL'. */ install_isr(&port1, 4, NULL); /* USE IRQ4 */ 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); set_dtr(&port1, LOW); /* Optional: set Data Terminal Ready 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 signed to detect a -1 return */ for (;;) { /* CHECK SERIAL PORT FOR BYTE */ if ((c = c_inchar(p)) != EOF) { putchar(c); fflush(stdout); } /* CHECK KEYBOARD FOR A KEY PRESS */ if ((c = inkey()) != 0) { if (c == MENU) { if (menu()) break; } else c_putc(p, c); } } } #define EXIT 'Q' /* key to exit from main */ short menu(void) { int c, retval = 0; static char *menus[] = { "\tQ. EXIT from TERM.", NULL /* null string terminates list */ }; char **p_menu; c = !EXIT; while (c != EXIT && c != LF) { 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; break; default: break; } } puts("\nExiting menu"); return (retval); /* will be zero except if EXIT */ }