/* Copyright (C) Magna Carta Software, Inc. 1990,1991. All Rights Reserved CCT10.C: CCT09.C plus... 1) File transmission with error correction using any of: XMODEM checksum, XMODEM-CRC, XMODEM-1K, YMODEM, YMODEM-g, ZMODEM; */ #include #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_port); short do_modem_menu(COMM_PORT *p_port); short do_receive_file_menu(COMM_PORT *p_port); long do_speed_menu(COMM_PORT * p_port); void term(COMM_PORT *p); short menu(COMM_PORT *p); short xfer_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[4048]; /* RECEIVE BUFFER */ int vers = 10; MODEM m1; XFER x; /* MUST be initialized to 0 */ #include "menus.c" #include "xfermsg.c" /* ------------------------ PROGRAM BEGINS HERE --------------------------- */ int main(void) { u8250_init(&port1, COM1, 19200L, DATABITS8, PARITY_NONE, STOPBITS1); install_ipr(&port1, RECEIVE, NULL, rxbuf, sizeof(rxbuf)); install_isr(&port1, 4, NULL); 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_port) { short c; /* must be int to detect a -1 return */ set_rx_xlat(p_port, LOCAL_ECHO, ON); for (;;) { /* CHECK SERIAL PORT FOR BYTE */ c = c_getc(p_port); /* CHECK KEYBOARD FOR A KEY PRESS */ if ((c = inkey()) != 0) { if (c == DO_MENU) { if (menu(p_port) == 1) break; } else c_putc(p_port, 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 FILE_RX_MENU 'R' /* key to transfer files */ #define EXIT 'Q' /* key to exit from main */ short menu(COMM_PORT *p_port) { short c, retval = 0, DONE = FALSE; static char *menus[] = { "\tD. Data Format", "\tM. Modem Commands.", "\tR. File Receive 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 = getchar(); c = toupper(c); switch (c) { case EXIT: retval = 1; DONE = TRUE; break; case DATA_FORMAT: do_data_menu(p_port); break; case DATA_SPEED: do_speed_menu(p_port); break; case MODEM_MENU: DONE = do_modem_menu(p_port); break; case FILE_RX_MENU: DONE = do_receive_file_menu(p_port); break; default: DONE = TRUE; break; } } puts("\nExiting menu"); set_tx_xlat(p_port, 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_port) { 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"); puts("\nAny other key exits"); key = bios_key(0) & 0XFF; switch (toupper(key)) { case 'D': modem_dial(p_port, "226-8088"); ret = 1; DONE = TRUE; break; case 'H': modem_hangup(p_port); break; case 'I': modem_init(p_port, modem_type(p_port)); set_dtr(p_port, HIGH); break; case 'O': modem_go_cmd(p_port, (short) atoi(&((MODEM *)p_port->modem)->escape[3])); break; case 'R': modem_reset(p_port); break; default: DONE = TRUE; break; } } while (!DONE); return (ret); } /* DO_RECEIVE_FILE_MENU -- Receive a file from a remote system using XMODEM checksum. */ short do_receive_file_menu(COMM_PORT *p) { short ret = 0; short ch, protocol; printf("\nEnter 'Y'(YMODEM), 'G' (YMODEM-g), 'X'(XMODEM), 'C' (XMODEM-CRC), '1'(XMODEM-1K)\n"); ch = getche(); ch = toupper(ch); if (ch == 'Y') protocol = YMODEM; else if (ch == 'C') protocol = XMODEM_CRC; else if (ch == '1') protocol = XMODEM_1K; else if (ch == 'G') protocol = YMODEM_G; else if (ch == 'Z') protocol = ZMODEM; else protocol = XMODEM; puts("\nRECEIVING FILE FROM REMOTE SYSTEM USING THE X/YMODEM PROTOCOL"); /* NOTE: IF YMODEM-g IS USED AND NO FLOW CONTROL IS SPECIFIED BY US, CCT USES XONXOFF. UNCOMMENT THE LINE BELOW TO USE RTS/CTS WITH YMODEM-g. NOTE: SOME COMM. PACKAGES REPORT "CONNECTION LOST" IF CTS GOES LOW DURING A TRANSFER. */ set_rx_xlat(p, LOCAL_ECHO, OFF); ret = freceive(p, &x, protocol, 8*1024, xfer_progress); set_rx_xlat(p, LOCAL_ECHO, ON); return (ret); }