📄 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 specific for the Microsoft C/C++ //
// version 7 compiler. //
// //
// Compile with: CL /AC polycomm.cpp /link graphics //
// //
// ******************************************************************** //
#include <stdio.h> // standard i/o library
#include <stdarg.h> // variable argument list
#include <string.h> // string handling routines
#include <stdlib.h> // std conversion routines
#include <dos.h> // dos functions
#include <ctype.h> // character routines
#include <conio.h> // console functions
#include <bios.h> // bios functions
#include <io.h> // i/o functions
#include <direct.h> // directory routines
#include <sys\types.h> // system types definition
#include <sys\stat.h> // ..attribute bits
#include <fcntl.h> // ..and file control
#include <graph.h> // text mode routines
#include "keys.h" // keyboard definitions
#define CURSOR() _settextcursor(0x0707) // normal text cursor
#define BIGCURSOR() _settextcursor(0x0000) // insert mode cursor
#define NOCURSOR() _settextcursor(0x2000) // 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) _inp(base + x) // read a UART register
#define OUT(x,y) _outp(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
#define MK_FP(s,o) (((long) s << 16) | (long) o) // make a long pointer
#define INT_PARMS UINT es, UINT ds, /* interrupt calling conv */\
UINT di, UINT si, \
UINT bp, UINT sp, \
UINT bx, UINT dx, \
UINT cx, UINT ax, \
UINT ip, UINT cs, \
UINT flags
/* ******************************************************************** *
*
* 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 emtpy
#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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -