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

📄 tstcom.c

📁 汇编源代码大全2
💻 C
字号:
/*
 * tstcom.c  27 Oct 83  Craig Milo Rogers at USC/ISI
 *
 *	This program tests the COM1: communications package
 * by using it to convert the IBM PC into a simple "glass
 * TTY".  The simulation is enhanced if you are running the
 * ANSI terminal driver.  For production use this program
 * would have to be modified so DOS doesn't trap control-C,
 * etc.
 */

#define M_TSTCOM

#include "stdio.h"

#include "truth.h"
#include "beauty.h"

#define TNESCAPE 0036		/* "Telnet" escape char:  control-uparrow. */

#define RBUFLEN 4096		/* Receive buffer length. */
#define TBUFLEN 512		/* Transmit buffer length. */
static char rbuf1[RBUFLEN];	/* Receive data buffer. */
static char tbuf1[TBUFLEN];	/* Transmit data buffer. */
static char rbuf2[RBUFLEN];	/* Receive data buffer. */
static char tbuf2[TBUFLEN];	/* Transmit data buffer. */

main(argc,argv)
int argc;			/* Number of arguments. */
char *argv[];			/* Pointers to argument strings. */
{
    int divisor = 12;		/* Baud rage generator divisor for
				 * 9600 baud. */
    int c;			/* Holds a data character. */
    bool sawesc;		/* Indicates that ctrl-q was last char. */
    bool running;		/* FALSE indicates exit request. */
    int i;			/* Counter. */
    int unit;			/* COM: unit number. */

    int_ini();			/* Initialize the interrupt package. */

				/* Initialize COM1: and COM2:. */
    com_ini(1, divisor, tbuf1, TBUFLEN, rbuf1, RBUFLEN);
    com_ini(2, divisor, tbuf2, TBUFLEN, rbuf2, RBUFLEN);

    sawesc = FALSE;		/* Start off with normal data. */
    running = TRUE;		/* Running the glass tty. */
    unit = 1;			/* Start on COM1:. */

    while (running) {		/* Until we decide to exit: */
	if (kbhit() != 0) {	/* Got a character? */
	    c = getch();	/* Pick up the character. */
	    if (sawesc) {	/* Did we just see telnet escape? */
		sawesc = FALSE;	/* Cancel the saw-escape flag. */
		switch (c &0177) {	/* Dispatch to command processor. */

		case TNESCAPE:	/* A second escape char. */
		    com_putc(unit, c);	/* Pass it through. */
		    break;

		case 'b':	/* A request to send BREAK. */
		case 'B':
		    com_break(unit);
		    break;

		case 'c':	/* The "close" command. */
		case 'C':
		case 'e':	/* The "exit" command. */
		case 'E':
		case 'q':	/* The "quit" command. */
		case 'Q':
		    running = FALSE;
		    continue;

		case '1':	/* Switch to COM1:. */
		    unit = 1;
		    break;

		case '2':	/* Switch to COM2:. */
		    unit = 2;
		    break;

		default:	/* Complain about bad char. */
		    putch(0007);	/* Ring the "bell". */
		    break;
		}
	    } else {		/* Otherwise, didn't see escape prev. */
		switch (c &0177) {	/* Dispatch to character processor. */

		case TNESCAPE:		/* Process "Telnet" escape char. */
		    sawesc = TRUE;	/* Set saw-escape flag. */
		    break;

		case 0010:			/* Convert backspace */
		    com_putc(unit, 0177);	/*   into <DEL>. */
		    break;

		case 0177:			/* Convert <DEL> */
		    com_putc(unit, 0010);	/*   into backspace. */
		    break;

		default:		/* Otherwise, send to COM: as is. */
		    com_putc(unit, c);	/* Ignore errors. */
		}
	    }
	}
	for (i = com_icnt(unit); i > 0; i--) {
	    c = com_getc(unit);	/* Drain some COM1: characters. */

	    if ((c != 0) && (c != 0177)) {
					/* Ignore padding chars. */
		putch(c);		/* Display on screen. */
	    }
	}
    }

    com_trm(1);			/* Restore interrupt vectors, etc. */
    com_trm(2);
    int_trm();
}

⌨️ 快捷键说明

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