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

📄 smalterm.c

📁 用C++写的RS232串口异步通讯功能模块
💻 C
字号:

/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*      S M A L T E R M  --  D e m o   D r i v e r   f o r   M C o m m 5     *
*                          A s y n c   R o u t i n e s                      *
*                                                                           *
*              Mike Dumdei, 6 Holly Lane, Texarkana TX 75503                *
*                   Split Up the Middle BBS, 903 838-6713                   *
*                                                                           *
*               (Link with comm_s.lib for external functions)               *
*               cl smalterm.c /link comm_s          (Microsoft C)           *
*               tcc smalterm.c comm_s.lib           (Turbo C)               *
*               ztc -b smalterm.c comm_s.lib        (Zortech C)             *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
#include <stdio.h>
#include <fcntl.h>
#if !defined(__TURBOC__)
    #include <sys\types.h>
#endif
#include <sys\stat.h>
#include <io.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <process.h>
#include <stdarg.h>
#if defined(__ZTC__)
  #define   MSDOS           1
  #define   stricmp         strcmpl
#endif
#include <dos.h>
#include <bios.h>

#include "comm.h"                            /* header for async functions */
#include "ansidrv.h"                   /* header for ANSI display routines */
#define KEY_INT
#include "keys.h"                                 /* key definition header */
#if defined(RED)
    #undef RED
#endif
#include "colors.h"                  /* vid mode & color definition header */
#include "extra.h"                               /* extra functions header */

#if defined (__TURBOC__)                                        /* Turbo C */
  #define   NO_FILES(x)     findfirst((x), &findbuf, 0)
  #define   find_t          ffblk
  #define   KBHIT           bioskey(1)
  #define   KBREAD          bioskey(0)
  #include  <dir.h>
#else                                            /* Microsoft C, Zortech C */
  #include  <direct.h>
  #define   NO_FILES(x)     _dos_findfirst((x), _A_NORMAL, &findbuf)
  #define   KBHIT           _bios_keybrd(_KEYBRD_READY)
  #define   KBREAD          _bios_keybrd(_KEYBRD_READ)
#endif

#define POP         0
#define PUSH        1              /* used in screen save/restore function */
#define RXBUFSZ     4096                            /* rx ring buffer size */
#define TXBUFSZ     1050                            /* tx ring buffer size */
#define LOST_CARRIER -1
#define NO_INPUT     -1
#define ESC_PRESSED  -2
#define TIMED_OUT    -3

#define TRUE          1
#define FALSE         0
#define REG     register

typedef unsigned char uchar;
typedef unsigned long ulong;
typedef unsigned int uint;


/*      f u n c t i o n   d e c l a r a t i o n s     */
extern int main(int argc,char * *argv);
static int proc_keypress(int ch);
static int proc_rxch(int ch);
static int proc_fkey(int keycd);
static int watch_cd(void );
static int rcls(void);
static int toggle_log(void );
static int toggle_echo(void );
static int toggle_lfs(void );
static int toggle_dtr(void );
static int dial_nbr(void );
static int shell_to_dos(void );
static int host_mode(void );
static int shell_remote(void );
static int run_batch(int keycd);
static int exit_term(void );
static int do_help(void );
static int async_tx_str(char *str);
static int async_tx_echo(char *str);
static int screen_pushpop(int flag);
static int chg_parms(void );
static int rx_timeout(int Tenths);
static int waitfor(char *str, int ticks);
static int waitforOK(int ticks );
static int prompt(char *kbuf,char *promptmsg,int maxchars);
static int comprompt(char *kbuf,char *promptmsg,int maxchars);
static int hang_up(void );

/*      g l o b a l   v a r i a b l e s     */

ASYNC   *port;                               /* pointer to async structure */
 /* default to COM1 */
char    com_str[5] = "COM1";           /* text for port ("COM1" or "COM2") */
int     IOadrs = 0x3f8;                      /* comm port base I/O address */
char    irqm = IRQ4;                         /* mask for selected IRQ line */
char    vctrn = VCTR4;                        /* comm interrupt vector nbr */

FILE    *logfil = NULL;                                 /* log file handle */
char    dialstr[40];                           /* dial string storage area */
int     ChkgKbd = 1;              /* watch for ESC during rcv with timeout */
int     ChkgCarrier = 0;        /* monitor carrier during rcv with timeout */
char    buf[200];                                    /* gen purpose buffer */
int     lfs = 0, echo = 0, dtr = 1, autoans = 0;          /* various flags */
struct find_t findbuf;                        /* struct for NO_FILES macro */
int     cyn, hred, grn, hgrn, wht, hblu;           /* text color variables */
int     hostcnt = 0;                        /* toggle to host mode counter */

/*
            * * * *    M A I N    * * * *
*/
main(int argc, char **argv)
{
    static char params[10] = "1200N81";              /* default parameters */
    char        buf[100];
    int         got_port = FALSE;
    unsigned    i, ch;

    initvid();                                /* initialize video routines */
    if (v_mode == CO80)
    {
        cyn = CYN, hred = H_RED, grn = GRN, hgrn = H_GRN,
        wht = WHT, hblu = H_BLU;
    }
    else
    {
        cyn = WHT, hred = H_WHT, grn = WHT, hgrn = H_WHT,
        wht = WHT, hblu = H_WHT;
    }
    v_color = cyn;
    cls();                                             /* clear the screen */

    /*  D I S P L A Y   S I G N O N  */
    v_color = hred;
    d_str("SMALTERM - Sample driver for MCOMM5 comm routines\n");
    v_color = grn;
    d_str("    Mike Dumdei, 6 Holly Lane, Texarkana TX 75503\n");
    d_str("    Split Up the Middle BBS     903 838-6713\n");
    v_color = hred;
    d_str("Usage: smalterm {COM1 | COM2} {param str EX: 2400N81}\n\n");
    v_color = cyn;

    /*  P R O C E S S   C O M M A N D   L I N E   A R G S  */
    for (i = 1; i < 3; i++)        /* do it twice so args can be any order */
    {                              /*  or have one arg and not the other   */
        if (argc > i)
        {
            if (!got_port && !stricmp(argv[i], "COM1"))
                got_port = TRUE;
            else if (!got_port && !stricmp(argv[i], "COM2"))
            {
                got_port = TRUE, strcpy(com_str, "COM2");
                IOadrs = 0x2f8, irqm = IRQ3, vctrn = VCTR3;
            }
            else if (strlen(argv[i]) < 9)   /* assume a valid param string */
                strcpy(params, argv[i]);
        }
    }

    /*  O P E N   T H E   C O M M   P O R T  */
    port = malloc(sizeof(ASYNC));
    AllocRingBuffer(port, RXBUFSZ, TXBUFSZ, 1);    /* alloc FAR ring bufrs */
    if ((ch = async_open(port, IOadrs, irqm, vctrn, params)) != 0)
    {
        /* couldn't open the port code */
        strsum(buf, "SMALTERM: Couldn't open ", com_str, " using ",
              params, " for parameters -- ABORTING\n\n", NULL);
        d_str(buf);
        strsum(buf, "Error code = ", itoa(ch, &buf[50], 10), "\n\n", NULL);
        d_str(buf);
        exit(ch);
    }

    /* opened OK code */

    d_str(strsum(buf, "SMALTERM: ", com_str, " -- PORT OPENED\n\n", NULL));
    d_str("Press F1 for HELP screen\n");           /* tell how to get help */
    /* display status line */
    SETWND(0, 0, 23, 79);                           /* set the window size */
    d_strnat(24, 0, '

⌨️ 快捷键说明

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