www.pudn.com > commutil.zip > POLYCOMM.CPP
// ******************************************************************** // // // // POLYCOMM.CPP // // Copyright (c) 1993, Michael Holmes and Bob Flanders // // C++ Communication Utilities // // // // Chapter 7: Receiving a FAX // // Last changed in chapter 7 // // // // This file contains the main function for the PolyComm // // program. This code is Borland C++ version 3.x specific. // // Code for Microsoft C/C++ version 7 is on diskette. // // // // Compile with: BCC -O2-i -mc polycomm.cpp // // // // ******************************************************************** // #include// standard i/o library #include // variable argument list #include // string handling routines #include // std conversion routines #include // dos functions #include // character routines #include // console functions #include // bios functions #include // i/o functions #include // directory routines #include // ..attribute bits #include // ..and file control #include "keys.h" // keyboard definitions #define CURSOR() _setcursortype(_NORMALCURSOR) // normal text cursor #define BIGCURSOR() _setcursortype(_SOLIDCURSOR) // insert mode cursor #define NOCURSOR() _setcursortype(_NOCURSOR) // turn off cursor #define COUNT(x) (sizeof(x) / sizeof(x[0])) // item count #define NOT ! // shorthand logical #define BYTE char // single byte #define UINT unsigned int // unsigned integer #define UCHAR unsigned char // ..and unsigned character #define ULONG unsigned long // ..and unsigned long #define MAX_PATH 79 // maximum path length #define MIX(x,y) ((x << 4) + (y)) // mix colors for fg and bg #define FG(x) (unsigned char) x >> 4 // extract foreground color #define BG(x) x & 0x07 // ..and background color #define IN(x) inportb(base + x) // read a UART register #define OUT(x,y) outportb(base + x, y) // ..and write a register #define NULLPTR(x) &x ? x : "" // make null ptr point to null #define LAST(s) s[strlen(s) - 1] // last character in string #define SECS(x) (long) (x * 182L) / 10L // seconds to ticks conversion #define TRUE 1 // true value #define FALSE 0 // false value #define SOH 1 // start of header #define STX 2 // start of text #define ETX 3 // end of text #define EOT 4 // end of transmission #define ACK 6 // positive acknowledgment #define XOFF 19 // flow control X-OFF #define DLE 16 // data link escape #define NAK 21 // negative acknowledgment #define CAN 24 // cancel process /* ******************************************************************** * * * UART Register Definitions * * ******************************************************************** */ // UART regs (base address +) #define RBR 0 // receive buffer register #define THR 0 // transmit holding register #define DLL 0 // divisor latch LSB #define DLM 1 // divisor latch MSB #define IER 1 // interrupt enable register #define IIR 2 // interrupt id register #define FCR 2 // FIFO control register #define AFR 2 // alternate function register #define LCR 3 // line control register #define MCR 4 // modem control register #define LSR 5 // line status register #define MSR 6 // modem status register #define SCR 7 // scratch register // interrupt enable register #define IER_RBF 0x01 // receive buffer full #define IER_TBE 0x02 // transmit buffer empty #define IER_LSI 0x04 // line status interrupt #define IER_MSI 0x08 // modem status interrupt #define IER_ALL 0x0f // enable all interrupts // interrupt id register #define IIR_PEND 0x01 // interrupt pending = 0 #define IIR_II 0x06 // interrupt id bits // 000 = modem status change // 001 = trans holding empty // 010 = receive buffer full // 110 = receive fifo full // 011 = line status change #define IIR_MSI 0x00 // modem status interrupt #define IIR_TBE 0x02 // transmit buffer empty #define IIR_RBF 0x04 // receive buffer full #define IIR_LSI 0x06 // line status interrupt #define IIR_RFF 0x0c // receive fifo threshold // fifo control register #define FCR_FIFO 0x01 // fifo enable #define FCR_RCVR 0x02 // receiver fifo reset #define FCR_XMIT 0x04 // transmit fifo reset #define FCR_DMA 0x08 // DMA mode select #define FCR_TRIGGER 0xc0 // receiver trigger select // 00 = 1 byte // 01 = 4 bytes // 10 = 8 bytes // 11 = 14 bytes #define FCR_16550 0xc7 // 16550 fifo enable/reset // line control register #define LCR_WLEN 0x03 // word length // 10 = 7 bits // 11 = 8 bits #define LCR_STOP 0x04 // stop bits // 0 = 1 stop bit // 1 = 2 stop bits #define LCR_PARITY 0x08 // parity enable // 0 = no parity // 1 = send/check parity #define LCR_EVEN 0x10 // even/odd parity // 0 = odd parity // 1 = even parity #define LCR_BREAK 0x40 // break, set to xmit break #define LCR_DLAB 0x80 // divisor latch access bit // modem control register #define MCR_DTR 0x01 // DTR control #define MCR_RTS 0x02 // RTS control #define MCR_OUT2 0x08 // OUT2 control #define MCR_DO 0x0b // dtr, rts & out2 enabled // line status register #define LSR_DR 0x01 // data ready #define LSR_ORUN 0x02 // overrun error #define LSR_PRTY 0x04 // parity error #define LSR_FRM 0x08 // framing error #define LSR_BRK 0x10 // break interrupt #define LSR_THRE 0x20 // transmit holding reg empty #define LSR_TSRE 0x40 // transmit shift reg empty #define LSR_ERROR 0x1e // error conditions // modem status register #define MSR_DCTS 0x01 // delta clear to send #define MSR_DDSR 0x02 // delta data set ready #define MSR_TERI 0x04 // trailing edge ring indicator #define MSR_DCD 0x08 // delta carrier detect #define MSR_CTS 0x10 // clear to send #define MSR_DSR 0x20 // data set ready (modem ready) #define MSR_RI 0x40 // ring indicated #define MSR_CD 0x80 // carrier detected /* ******************************************************************** * * * 8259 Programmable Interrupt Controller Definitions * * ******************************************************************** */ #define I8259 0x20 // control register address #define EOI 0x20 // end of interrupt command #define I8259M 0x21 // mask register /* ******************************************************************** * * * Routine definitions * * ******************************************************************** */ void initialization(int, char **), // initialization status_line(void), // update status line wait_ms(long), // wait in milliseconds wait(long); // ..and wait in seconds int about(int, int), // about box routine pc_exit(int, int), // menu exit routine ports(int, int), // port selection menu routine comm_parms(int, int), // comm parms menu routine hangup(int, int), // hangup menu routine phone_list(int, int), // phonebook menu routine dl_xmodem(int, int), // xmodem download menu rtn ul_xmodem(int, int), // ..and upload menu routine dl_ymodem(int, int), // ymodem download menu rtn ul_ymodem(int, int), // ..and upload menu routine rcv_fax(int, int), // receive a fax send_fax(int, int), // .. and send a fax get_key(int); // get any type of key /* ******************************************************************** * * * Set the stack size to 8k * * ******************************************************************** */ extern unsigned _stklen = 8192; /* ******************************************************************** * * * PolyComm includes * * ******************************************************************** */ #include "window.cpp" // window class #include "menu.cpp" // menu class #include "list.cpp" // list class #include "comm.cpp" // basic comm support #include "global.cpp" // strings and global data #include "utility.cpp" // utility functions #include "protocol.cpp" // protocol class #include "xmodem.cpp" // XMODEM and XMODEM/CRC class #include "ymodem.cpp" // YMODEM class #include "command.cpp" // command menu routine #include "dial.cpp" // dial menu routines #include "config.cpp" // configuration menu rtns #include "fax.cpp" // facsimile support #include "transfer.cpp" // transfer file menu rtns /* ******************************************************************** * * * main() -- PolyComm mainline * * ******************************************************************** */ void main(int argc, // command line token count char *argv[]) // ..and command line tokens { printf(copyright); // display copyright msg initialization(argc, argv); // init and parse cmd line while(NOT quit_flag) // loop 'til user requests out { terminal_handler(); // try to get a keyboard char if (NOT comm->IEmpty()) // q. any incoming com chars? terminal_display(); // a. yes .. show input stream } rc = 0; // clear DOS errorlevel quit_with(done); // ..and give completion msg } /* ******************************************************************** * * * initialization() -- perform framework initializations * * ******************************************************************** */ void initialization(int ac, // command line token count char *av[]) // ..and command line tokens { struct text_info screen; // screen info structure old_break = _dos_getvect(0x1b); // get old ^break handler addr if (ac > 2 || // q. need help.. NOT strcmp(av[1], "/?")) // ..or want help? quit_with(help); // a. yes .. give help/quit _dos_setvect(0x1b, control_break); // set up control break _dos_setvect(0x24, critical_routine); // ..and DOS critical handler gettextinfo(&screen); // get current screen info max_lines = screen.screenheight; // save max lines on screen if (screen.screenwidth < 80) // q. less than 80 columns? quit_with(bad_width); // a. yes .. give error/quit if (screen.currmode == BW80 || // q. black and white mode.. screen.currmode == MONO) // ..or monochrome mode? { main_menu.SetColors(mono_1, mono_2); // a. yes .. set up for term_cn = mono_2; // ..monochrome display term_cr = mono_1; // ..for all windows stat_cn = mono_1; } load_config(av[1]); // load modem config file load_pb(); // ..and phonebook file check_ports(); // check for available ports build_comm(); // set up Comm object wait_ms(500L); // wait a little bit full_screen = 1; // show init complete status_line(); // ..and display status line _wscroll = 1; // set scrolling mode term = new Window(1, 1, 80, 24, // define terminal window term_cn, term_cr); // ..and its colors term->Open(none); // ..then open w/o borders comm->IClear(); // ..clear input buffer }