⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 txzm.c

📁 这个程序是用于通讯的
💻 C
字号:

/*/////////////////////////////////////////////////////////////////////
//                                                                   //
//  TXZM.C -- zmodem protocol driver (formerly ZMP)                  //
//                                                                   //
//    (c) 1991,92, Mike Dumdei, 6 Holly Lane, Texarkana TX, 75503    //
//                                                                   //
//////////////////////////////////////////////////////////////////// */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <process.h>
#include <ctype.h>
#include <io.h>
#include <dos.h>
#include <bios.h>
#include "comm.h"
#include "ansidrv.h"
#include "extra.h"
#include "colors.h"
#include "zmdos.h"

#if defined (__TURBOC__)
  #include <dir.h>
  #define ChDrive(d) setdisk((d)-1)
#elif defined (__ZTC__)
  #include <direct.h>
  #define ChDrive(d) _chdrive(d)
#elif defined (__MSC__)
  int ndrives;
  #define ChDrive(d) _dos_setdrive((d), &ndrives)
#endif

#define ALT_C       0x2e00
#define ALT_D       0x2000
#define ALT_E       0x1200
#define ALT_H       0x2300
#define ALT_L       0x2600
#define ALT_P       0x1900
#define ALT_R       0x1300
#define ALT_S       0x1f00
#define ALT_X       0x2d00
#define FK1         0x3b00
#define PGUP        0x4900
#define PGDN        0x5100
#define ALT_EQU     0x8300
#define X_ESC       0x011b

void AddToList(char *subdir);
char *CaptureBaudRate(void);
char *ConvertSecs(long secs);
long ConvertTicks(long ticks);
int Dial(void);
void DrawBox(int row, int col, int nrows, int ncols, int color, int style);
void DspZmodemScrn(void);
char *ExpandSubDirs(char *fnames);
int FileTransfer(void);
void HelpFunc(void);
void InitDefaults(void);
void MiniTermMode(void);
void ProcCmdLine(int argc, char * *argv);
int prompt(char *buf, int maxlen);
int RecurseSubDirs(char *sd);
int RepeatDial(void);
void SetFIFOLevels(int rxFIFOlevel, int txFIFOlevel);
int SetParams(char *newparams);
void usage(void);
void vDisplay(int row, int col, char *format, ...);
int waitfor(int ticks, ...);
void ZMsg(int type, ...);

extern int  _C_ TestDesqView(void);
extern int  _C_ DV_VideoSeg(int);
extern void _C_ DV_TimeSlice(void);

/*/////////////////////////////////////////////////////////
//  Configuration structure.  Structure is used to allow //
//  the defaults to be changed modifying the EXE.        //
//  "TXZMCFG:" is the tag to search for to find the start//
//  of the structure in the EXE.                         //
//////////////////////////////////////////////////////// */
struct PROTCONFIG
{
    char    tag[8], DLPath[80], ULPath[80];
    long    LocBaud, MinFifoBaud;
    int     ComBase, IRQ, Vctr;
    int     h_VBufSize, h_BufSize, b_VBufSize, b_BufSize;
    int     TxWindow, ZExistOpts, XYExistOpts;
    int     FifoTxLvl, FifoRxLvl;
    char    IgnCarrier, MsrFlow, KeepTime, EscCtl, OvlyIO;
    char    Color[10], Mono[10];
} cfg =
{
    "TXZMCFG:", "", "",
    0L, 1L,
    0x3f8, IRQ4, VCTR4,
    2048, 0, 20508, 20480,
    0, 1, 2,
    8, 8,
    0, 0, 1, 0, 1,
    {  WHT|BLU_B,  H_GRN|BLU_B,  H_RED|BLU_B,    YLW|BLU_B,
       GRY|BLU_B,    YLW|BLU_B,  H_RED|BLU_B,  H_MAG|BLU_B,
       CYN,              CYN_B  },
    { WHT, WHT, RVRS, H_WHT, WHT, H_WHT, H_WHT, H_WHT, WHT, WHT_B }
};

/*/////////////////////////////////////////////////////////
//  Screen data structure                                //
//////////////////////////////////////////////////////// */
typedef struct
{
    int row, col, color, count;
    char *text;
} SCREENDATA;

/*/////////////////////////////////////////////////////////
//  Global variables                                     //
//////////////////////////////////////////////////////// */
ASYNC port;                 /* ASYNC port structure */
int combase, irq, vctr;     /* port address, IRQ number, & vector */
int openmask = 0;           /* mask for forcing no FIFOs, no MSR intrpts */
long LocBaud = 0L;          /* CPU to modem/device baud rate */
char params[12] = "";       /* port parameters */
char lockedbaud[12] = "";   /* locked baud parameter */
char fnames[256] = "";      /* list of files to send if sending */
char minsecs[10];           /* ticks to min:secs buffer */
char *color;                /* pointer to list of colors */
int txtcolor;               /* color of most screen message output */
char buf[256];              /* general purpose buffer */
int goodargs = 0;           /* got an 'r' or an 's' on command line */
char *node = NULL;          /* for bbs use: LASTUSER.BBS format file name */
int miniterm = 0;           /* mini-terminal mode selected */
char OvlyIO;                /* overlay disk and serial I/O flag */
char *flist;                /* used when expanding subdirectories */
char mask[14];              /* used when expanding subdirectories */
int plen;                   /* used when expanding subdirectories */
int tryDV = 0;              /* cmdline switch to test for DesqView */
int checkcarrier = 0;       /* check for carrier during 'waitfor' flag */
int stripmask = 0xff;       /* strip high bit mask for miniterm mode */
char phone[40] = "";        /* phone number to dial */

long tfBytes, tCPS;         /* total bytes transferred, average CPS */
int tFiles;                 /* number of files transferred */

/*/////////////////////////////////////////////////////////
//                                                       //
//      Main                                             //
//                                                       //
//:mai////////////////////////////////////////////////// */
void cdecl main(int argc, char *argv[])
{
    int i;

    color = ((initvid() & 0xff) == CO80) ? cfg.Color : cfg.Mono;
    txtcolor = (int)color[1] & 0xff;
    InitDefaults();
    ProcCmdLine(argc, argv);
    if (!goodargs)
        usage();

    if (tryDV && TestDesqView() != 0)
    {
        i = DV_VideoSeg(v_seg);
        if (v_seg != i)
            v_seg = i, v_snow = 0;
    }
    if (*params)
        ConnectBaud = atol(params);
    if (*lockedbaud)
        LocBaud = atol(lockedbaud);
    if (LocBaud == 0L)
        LocBaud = ConnectBaud;
    if (LocBaud != 0L)
    {
        sprintf(params, "%ldN81", LocBaud);
        if (LocBaud < cfg.MinFifoBaud)
            openmask |= 0x4000;
    }

    if (OvlyIO)
        VBufSize = cfg.h_VBufSize, BufSize = cfg.h_BufSize;
    else
        VBufSize = cfg.b_VBufSize, BufSize = cfg.b_BufSize;
    if (BufSize)
        ZFR0 &= ~CANOVIO;

    AllocRingBuffer(&port, 2048, 4096, 0);
    while (1)
    {
        i = async_open(&port, combase, irq, vctr|openmask, params);
        if (i != 0)
        {
            printf("\nSerial port open error, Error code = %d\n\a", i);
            exit(i - 20); /* -20 so exit code don't clash with zm result */
        }
        if (ConnectBaud == 0L)
        {
            ConnectBaud = atol(port.BPDSstr);
            strcpy(params, port.BPDSstr);
            if (ConnectBaud < cfg.MinFifoBaud && async_16550(&port)
             && !(openmask & 0x4000))
            {
                async_close(&port);
                openmask |= 0x4000;
                continue;
            }
        }
        break;
    }
    async_msrflow(&port, cfg.MsrFlow);
    tickhookset(1);

    if (miniterm)
    {
        pushscrn(0, 0, 25, 80);
        SetFIFOLevels(1, 1);
        MiniTermMode(), i = 0;
        popscrn();
    }
    else
    {
        i = FileTransfer();
        sprintf(buf, "TXZM exit code = %d", i);
        v_color = WHT;
        d_strat(23, 0, buf);
    }
    async_close(&port);
    tickhookset(0);
    exit(i);
}

/*/////////////////////////////////////////////////////////
//  AddToList                                            //
//:add////////////////////////////////////////////////// */
void AddToList(char *subdir)
{
    static char bkslsh[2] = " ";
    int i, j;

    if (*(strchr(subdir, '\0') - 1) == '\\' || subdir == GetNameExt(subdir))
        j = 1, *bkslsh = '\0';
    else
        j = 2, *bkslsh = '\\';
    i = plen - 1;
    plen += (strlen(subdir) + strlen(mask) + j);
    flist = realloc(flist, plen);
    sprintf(&flist[i], "\n%s%s%s", subdir, bkslsh, mask);
}

/*/////////////////////////////////////////////////////////
//  CaptureBaudRate                                      //
//:cap////////////////////////////////////////////////// */
char *CaptureBaudRate(void)
{
    int i;
    static char *b[] = { "300", "300", "1200", "2400", "4800", "7200",
        "9600", "14400", "19200" };

    checkcarrier = 0;
    i = waitfor(18, "\r", b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8], NULL);
    return ((i >= 0 && i <= 8) ? b[i] : NULL);
}

/*///////////////////////////////////////////////
//  ConvertSecs                                //
//:con//////////////////////////////////////// */
char *ConvertSecs(long secs)
{
    sprintf(minsecs, "%01ld:%02ld   " , uldiv(secs, 60L), ulmod(secs, 60L));
    return(minsecs);
}

/*///////////////////////////////////////////////
//  ConvertTicks                               //
//:con//////////////////////////////////////// */
long ConvertTicks(long ticks)
{
    long secs = uldiv(ulmul(ticks, 10L), 182L) + 1L;
    ConvertSecs(secs);
    return(secs);
}

/*/////////////////////////////////////////////////////////
//  Dial                                                 //
//:dia////////////////////////////////////////////////// */
int Dial(void)
{
    int rval;
    char *p1;

    async_txblk(&port, phone, strlen(phone));
    checkcarrier = 0;
    rval = waitfor(45 * 18, "CONNECT", "BUSY", "NO CARRIER", "VOICE",
     "ERROR", "NO DIALTONE", NULL);
    if (rval == 0)
    {
        if ((p1 = CaptureBaudRate()) != NULL)
            SetParams(p1);
    }
    return (rval);
}

/*/////////////////////////////////////////////////////////
//  DrawBox                                              //
//:dra////////////////////////////////////////////////// */
void DrawBox(int row, int col, int nrows, int ncols, int color, int style)
{
    static char boxchars[][6] =
    {
        '

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -