/* Copyright (C) Magna Carta Software, Inc. 1988-1990. All Rights Reserved. Z80SIO00.C -- CCT00.C re-written to support the Z-80 SIO CAPABILITY: Dumb terminal program. 1) Uses polled reception. 2) Data transfer rate can be set at run time. 3) Data format can be adjusted at run time. 4) Received data translation. 5) Translated serial output is used. All other options must be changed in the source code and the source recompiled to change them. */ #include #include #include #include #include /* MANIFEST CONSTANTS AND MACROS */ #define MENU ALT_M /* key for command summary */ #define AST 0X302 /* control port addr. of AST CC-232 channel */ /* FUNCTION PROTOTYPES */ void do_data_menu(COMM_PORT * p); long do_speed_menu(COMM_PORT * p); short menu(COMM_PORT *p); void term(COMM_PORT *p); /* GLOBAL VARIABLES */ BYTE zrxbuf[2048]; /* RECEIVE BUFFER FOR Z-80 SIO */ int vers = 0; /* DEFINE SOME SPECIAL FEATURES OF THE Z80 SIO IN A STRUCTURE */ UARTZ80SIO uz80 = { AST + 6, /* offset of clock reg. from base */ 0X30F, /* offset of interrupt id. register */ X16, /* USART reference clock speed */ {0,0,0,0,0,0,0,0} /* USART virtual write register array */ }; COMM_PORT z80; #include "menus.c" /* ------------------------ PROGRAM BEGINS HERE --------------------------- */ int main(void) { /* ASSIGN THE Z80 SIO USART DEFINED ABOVE TO THE COMM_PORT STRUCTURE */ z80.uart.uz80sio = uz80; /* Z-80 SIO INITIALIZATION */ uz80_init(&z80, 0X302, AST, 2400L, 8, PARITY_NONE, 1); printf("CCT Z-80 SIO Version %d: Press Alt-M for a list of commands\n", vers); term(&z80); printf("\nEnd of CCT Z-80 SIO%d\n", vers); set_rts(&z80, LOW); set_dtr(&z80, LOW); return (0); } /* 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 */ /* THESE LINES CONTROL THE RECEIVED DATA FORMAT */ set_rx_xlat(p, EOL, FALSE); set_rx_xlat(p, LOCAL_ECHO, ON); /* THESE LINES CONTROL THE TRANSMITTED DATA FORMAT */ set_tx_xlat(p, ASCII_ONLY, TRUE); set_tx_xlat(p, CASE, FALSE); for (;;) { /* CHECK SERIAL PORT FOR BYTE */ c_getc(p); /* CHECK KEYBOARD FOR A KEY PRESS */ if ( (c = inkey()) != EOF) { if (c == MENU) { if (menu(p) == 1) break; } else c_putc(p, c); } } } #define DATA_FORMAT 'D' /* key to set speed */ #define DATA_SPEED 'S' /* key to set speed */ #define EXIT 'Q' /* key to exit from main */ short menu(COMM_PORT *p) { short c, retval = 0, DONE = FALSE; static char *menus[] = { "\tD. Data Format", "\tS. Data Transfer Rate.", "\tQ. EXIT from COMM.", NULL }; char **p_menu; c = !EXIT; while (!DONE) { puts("\n\n"); for (p_menu = menus; *p_menu != NULL; p_menu++) printf("%s\n", *p_menu); printf("\n\t\t Enter selection (CR to quit menu) : "); if ( (c = getch()) == CR) break; /* return to term */ c = toupper(c); switch (c) { case EXIT: retval = 1; DONE = TRUE; break; case DATA_FORMAT: do_data_menu(p); break; case DATA_SPEED: do_speed_menu(p); break; default: puts("Invalid choice\n\007"); DONE = TRUE; break; } } puts("\nExiting menu"); return (retval); /* will be zero except if EXIT */ }