/* Copyright (C) Magna Carta Software, Inc. 1987-1990. All Rights Reserved. C WINDOWS TOOLKIT/C COMMUNICATIONS TOOLKIT. Using the two together. */ #define USE_CWT #include #include #include void main(void); /* WINDOWS CONSTANTS (SAME AS EXAMPLE1.C IN CWT */ WINDOW *w1; BORDER b1; COLORS c1; /* COMMUNICATIONS CONSTANTS (same as CCT01.C in CCT) */ #define MENU ALT_M /* key for menu */ short menu(void); void term(COMM_PORT *p); COMM_PORT port1; BYTE rxbuf[2048]; /* RECEIVE BUFFER */ short vers = 1; /* REQUIRED FOR THIS JOINT EXAMPLE */ short wconoutc(COMM_PORT *p, short c); WINDOW *w_current; FORMAT form1 = { FALSE, /* raw mode? */ 4, /* tab size */ LF2CRLF, /* end-of-line-formatting */ DELETE, /* backspace */ FALSE, /* case use */ {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1} }; void main(void) { /* FIRST SET UP CWT */ init_video(); /* initialize video */ if (cga.active) SNOW=TRUE; preserve_screen(80, 25); create_window(&w1, 80, 25); border_window(w1, &b1, DOUBLE, DOUBLE, yellow, blue); clear_window(w1, &c1, white, blue, SP); w1->p_format = &form1; w_prints(w1, CENTER, 0, bright + white, blue, "[ CCT & CWT TERMINAL EMULATOR ]"); /* NOW SET UP CCT (THIS IS TAKEN STRAIGHT FROM CCT01.C */ init_port(&port1, COM1, 2400L, DATABITS8, PARITY_NONE, STOPBITS1); install_ipr(&port1, RECEIVE, NULL, rxbuf, sizeof(rxbuf)); install_isr(&port1, 4, NULL); set_rx_xlat(&port1, LOCAL_ECHO, TRUE); /* NOW MAKE THEM WORK TOGETHER */ /* First tell CCT which window to write to (there is only one in this case) If there were more, we could change the window that w_current points to at any point in our program. */ w_current = w1; /* Next, tell CCT which function to use to write to w_current We use "wconoutc" (defined below). */ port1.c_out = wconoutc; /* NOW DISPLAY IT ON THE SCREEN */ display_window(w1, 0, 0, 1); w_cursor(w_current, 0, 0); w_printf(w_current, YELLOW, BLUE, "CCT-COMM Version %d: Press Alt-M for a list of commands\n", vers); term(&port1); w_cursor(w_current, 0, 0); w_printf(w_current, YELLOW, BLUE, "\nEnd of CCT-COMM%d\n", vers); deinit_port(&port1); /* ESSENTIAL -- DEINSTALL INTERRUPTS, ETC. */ /* HIDE THE WINDOW, RESTORING THE UNDERLYING SCREEN */ hide_window(w1); } /* WCONOUTC -- Outputs the character 'c' to a C WINDOWS TOOLKIT window. */ short wconoutc(COMM_PORT *p, short c) { p = p; /* This just nukes a compiler warning */ w_putc(w_current, w_current->p_colors->fc, w_current->p_colors->bc, c); return (0); } /* TAKEN FROM CCT01.C */ /* TERM -- The terminal emulation routine. Simply polls the COM port and the keyboard alternately for characters. */ void term(COMM_PORT *p) { short c; /* must be signed to detect a -1 return */ for (;;) { /* CHECK SERIAL PORT FOR BYTE */ c = c_getc(p); /* CHECK KEYBOARD FOR A KEY PRESS */ if ( (c = inkey()) != EOF) { if (c == MENU) { if (menu()) break; } else c_putc(p, c); } } } #define EXIT 'Q' /* key to exit from main */ short menu(void) { int c, retval = 0; static char *menus[] = { "\tQ. EXIT from TERM.", NULL /* null string terminates list */ }; char **p_menu; c = !EXIT; while (c != EXIT && c != LF) { w_puts(w_current, WHITE, BLUE, "\n\n"); for (p_menu = menus; *p_menu != NULL; p_menu++) w_printf(w_current, WHITE, BLUE, "%s\n", *p_menu); w_printf(w_current, WHITE, BLUE, "\n\t\t Enter selection (CR to quit menu) : "); c = getchar(); c = toupper(c); switch (c) { case EXIT: retval = 1; break; default: break; } } w_puts(w_current, WHITE, BLUE, "\nExiting menu"); return (retval); /* will be zero except if EXIT */ }