/* Copyright (C) Magna Carta Software, Inc. 1988-1990. All Rights Reserved. CCT13.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: ANSI.SYS terminal emulation. Receive interrupt handler written in C. NOTE: Deinstall ANSI.SYS before using this program. All other options must be changed in the source code and the source recompiled to change them. COMPATIBILITY: TURBOC v1.5+, POWERC v1.2+, MSC 5.0+/QUICK C, WATCOM C; */ #include #include #include #include #include #include /* MANIFEST CONSTANTS AND MACROS */ #define DO_MENU ALT_M /* key for command summary */ /* FUNCTION PROTOTYPES */ void cdecl far ccom_rx_int(void); void do_data_menu(COMM_PORT * p); short do_txfile_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); short transfer_progress(COMM_PORT *p, short status, unsigned long parm); /* GLOBAL VARIABLES */ COMM_PORT port1; char phone_number[] = "226-8088";/* MAGNA CARTA BBS (change if nec.) */ BYTE rxbuf[2048]; /* RECEIVE BUFFER */ int vers = 13; MODEM m1; #include /* NECESSARY FOR TERMINAL EMULATION */ #include /* NECESSARY FOR ANSI TERMINAL EMULATION */ #include TERMINAL t; #include "menus.c" /* ------------------------ PROGRAM BEGINS HERE --------------------------- */ int main(void) { init_port(&port1, COM1, 2400L, DATABITS8, PARITY_NONE, STOPBITS1); /* AS IN CCT11.C WE INSTALL OUR OWN INTERRUPT PROCESSING ROUTINE (IPR) */ install_ipr(&port1, RECEIVE, (void far *) ccom_rx_int, rxbuf, sizeof(rxbuf)); install_isr(&port1, 4, NULL); modem_assign(&port1, &m1); /* THIS BEGINS ANSI TERMINAL EMULATION */ init_term(&port1, &t, (void (*)()) ibmansi_init, bios_video); 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); 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, LOCAL_ECHO, TRUE); 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", "\tM. Modem Commands.", "\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 = bios_key(_KEYBRD_READ) & 0XFF; 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; case MODEM_MENU: do_modem_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 */ } /* DO_MODEM_MENU -- Send commands to the modem. */ short do_modem_menu(COMM_PORT *p) { short key; short DONE=FALSE, ret = 0; do { puts("\nSEND COMMANDS TO THE MODEM"); puts("\nD. Dial"); puts("H. Hangup"); puts("I. Initialize"); puts("O. Go Offline"); puts("R. Reset\n"); puts("\nAny other key exits"); key = bios_key(0) & 0XFF; switch (toupper(key)) { case 'D': ret = modem_dial(p, phone_number); DONE = TRUE; break; case 'H': ret = modem_hangup(p); break; case 'I': ret = modem_init(p, modem_type(p)); set_dtr(p, HIGH); break; case 'O': ret = modem_go_cmd(p, (short) atoi(&((MODEM *)p->modem)->escape[3])); break; case 'R': ret = modem_reset(p); break; default: DONE = TRUE; break; } } while (!DONE); return (ret); } /* CCOM_RX_INT -- interrupt processing routine for receive data. Called directly from the receive ISR. */ void cdecl far ccom_rx_int(void) { static BYTE c; static BYTE far *b_ptr; c = (BYTE) inp(port1.udata_reg_addr); b_ptr = (BYTE far *) port1.rxbufhead + 1; if (b_ptr > port1.rxbufend) b_ptr = port1.rxbuf; if (!(b_ptr == port1.rxbuftail)) { /* buffer is full */ *port1.rxbufhead = c; port1.rxbufhead = b_ptr; } }