/* Copyright (C) Magna Carta Software, Inc. 1988-1990. All Rights Reserved. Z80SIO02.C -- BISYNC transmission using the Z-80 SIO CAPABILITY: Dumb terminal program. COMPATIBILITY: TURBOC v1.5+, POWERC 1.2+, MSC v5.0+/QUICK C, WATCOM C. */ #include #include #include #include #include #include /* MANIFEST CONSTANTS AND MACROS */ #define MENU ALT_M /* key for command summary */ #define AST 0X300 /* base address of AST CC-232 */ /* FUNCTION PROTOTYPES */ void do_data_menu(COMM_PORT * p_port); long do_speed_menu(COMM_PORT * p_port); short menu(COMM_PORT *p); void term(COMM_PORT *p); void far interrupt uz80_bisync_txint(void); /* GLOBAL VARIABLES */ BYTE ztxbuf[2048]; /* RECEIVE BUFFER FOR Z-80 SIO */ BYTE zrxbuf[2048]; /* RECEIVE BUFFER FOR Z-80 SIO */ int vers = 2; #include "menus.c" #include "sioport.c" COMM_PORT * sio0 = &z80; /* ------------------------ PROGRAM BEGINS HERE --------------------------- */ int main(void) { z80.uart.uz80sio = uz80; bios_ed(7, 0); /* Z-80 SIO INITIALIZATION */ u2.uz80sio = uz80; if (c_open(&z80) == PORT_ALREADY_OPEN) { fprintf(stderr, "\aError: Cannot open port1"); mspause(1000); return (EOF); } uz80_set_reg(&z80, WR0, UZ80_TX_CRC_RESET); uz80_set_reg(&z80, WR2, 0); /* interrupt vector */ /* uz80_mod_reg(&z80, WR3, UZ80_AUTO_ENABLE, UZ80_AUTO_ENABLE); */ uz80_mod_reg(&z80, WR3, UZ80_SYNC_INHIBIT, UZ80_SYNC_INHIBIT); uz80_mod_reg(&z80, WR4, UZ80_STOPBITS_MASK, UZ80_STOPBITS0); uz80_mod_reg(&z80, WR4, UZ80_SYNC_MASK, UZ80_BISYNC); uz80_mod_reg(&z80, WR4, UZ80_CLOCK_MASK, X1); uz80_set_reg(&z80, WR6, 0X32); uz80_set_reg(&z80, WR7, 0X32); /* STATUS EFFECTS VECTOR, EXTERNAL INT. ENABLE, TX INT. ENABLE */ uz80_mod_reg(&z80, WR1, 0X7, 7); uz80_mod_reg(&z80, WR5, 0X6E, 0X6E); /* INSTALL THE INTERRUPT HANDLERS */ uz80_install_ipr(&z80, UZ80_RX_ALL, NULL, zrxbuf, sizeof(zrxbuf)); uz80_install_ipr(&z80, UZ80_TX_ALL, NULL, ztxbuf, sizeof(ztxbuf)); uz80_install_ipr(&z80, UZ80_ES, NULL, NULL, 0); install_isr(&z80, 2, (void far *) uz80_tx_int); 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); uz80_mod_reg(&z80, WR5, UZ80_TX_ENABLE, 0); deinit_port(&z80); return (0); } /* TERM -- The terminal emulation routine. Simply polls the COM port and the keyboard alternately for characters. */ void term(COMM_PORT *p_port) { short c; /* must be signed to detect a -1 return */ /* THESE LINES CONTROL THE RECEIVED DATA FORMAT */ set_rx_xlat(p_port, XLAT, TRUE); set_rx_xlat(p_port, EOL, FALSE); set_rx_xlat(p_port, LOCAL_ECHO, ON); /* THESE LINES CONTROL THE TRANSMITTED DATA FORMAT */ set_tx_xlat(p_port, XLAT, TRUE); set_tx_xlat(p_port, ASCII_ONLY, TRUE); for (;;) { /* CHECK SERIAL PORT FOR BYTE */ c = c_getc(p_port); /* CHECK KEYBOARD FOR A KEY PRESS */ if ( (c = inkey()) != EOF) { if (c == MENU) { if (menu(p_port) == 1) break; } else c_putc(p_port, 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 */ #define SEND_STR 'T' short menu(COMM_PORT *p_port) { short c, retval = 0, DONE = FALSE; static char *menus[] = { "\tD. Data Format", "\tS. Data Transfer Rate.", "\tT. Transmit a string", "\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_port); break; case DATA_SPEED: do_speed_menu(p_port); break; case SEND_STR: c_putn(p_port, 8L, "This is a test string"); DONE = TRUE; break; default: puts("Invalid choice\n\007"); DONE = TRUE; break; } } puts("\nExiting menu"); return (retval); /* will be zero except if EXIT */ } #define SCREEN ((WORD far *) 0XB8000800L) WORD far * s = SCREEN; WORD scol = 1; /* UZ80_BYSYNC_INT -- Interrupt handler for the Z-80 SIO/DART to perform BISYNC. Enables RX, TX, ES interrupts For use under the IBM architecture. */ void far interrupt uz80_bisync_txint(void) { static WORD ch; static BYTE c, rx_lastchar, tx_lastchar, rr1; static volatile BYTE far *b_ptr; outp(z80.ubase_addr, 2); /* toggle the reg. ptr. to RR2 */ c = (BYTE) (inp(z80.ubase_addr) & 0XE); /* TX BUFFER EMPTY */ if (c == 0) { if (z80.txbuftail == z80.txbufhead) { z80.f_txbusy = FALSE; /* IF END OF MESSAGE. RESET EOM LATCH IN ORDER TO SEND CRC */ if (tx_lastchar == ETX) uz80_set_reg(&z80, WR0, UZ80_TX_EOM_RESET); /* Nothing to send so reset TX interrupt pending */ uz80_set_reg(&z80, WR0, UZ80_TX_RESET); } else { /* IF START OF MESSAGE, INCLUDE IN CRC CALCULATION */ if (tx_lastchar == STX) uz80_mod_reg(&z80, WR5, UZ80_TX_CRC_ENABLE, UZ80_TX_CRC_ENABLE); outp(z80.udata_reg_addr, *z80.txbuftail); /* send byte */ tx_lastchar = *z80.txbuftail++; if (z80.txbuftail > z80.txbufend) z80.txbuftail = z80.txbuf; *s++ = (0XF << 8) | '.'; } } /* EXTERNAL STATUS CHANGE (DCD, CTS, or SYNC) */ if (c == 2) { ch = inp(z80.ubase_addr); if (ch & 0X40) { *s++ = (scol << 8) | 't'; /* TX underrun */ /* uz80_set_reg(&z80, WR0, UZ80_TX_EOM_RESET); */ } uz80_set_reg(&z80, WR0, UZ80_ES_RESET); if (ch & 0X10) *s++ = (scol << 8) | 'h'; /* HUNT */ else { *s++ = (scol << 8) | 's'; /* SYNC */ *s++ = (++scol << 8) | ch; } } /* RX CHARACTER AVAILABLE */ if (c == 4) { if (inp(z80.ubase_addr) & 1) { /* IF a char is ready get it */ b_ptr = z80.rxbufhead + 1; if (b_ptr > z80.rxbufend) b_ptr = z80.rxbuf; if (!(b_ptr == z80.rxbuftail)) { /* buffer is full */ *z80.rxbufhead = rx_lastchar = (BYTE) inp(z80.udata_reg_addr); z80.rxbufhead = b_ptr; } } } /* SPECIAL RECEIVE CONDITION (Parity error, RX Overrrun, CRC Error */ else if (c == 6) { outp(AST+3,1); /* read register 1 for int type */ rr1 = (BYTE) (inp(AST+3) & 0XF0); if (rr1 & 0X10) { /* parity error */ *s++ = (0XF << 8) | 'p'; uz80_set_reg(&z80, WR0, UZ80_ER_RESET); } if (rr1 & 0X20) { /* receiver overrun error */ *s++ = (0XF << 8) | 'o'; uz80_set_reg(&z80, WR0, UZ80_ER_RESET); if (inp(AST+3) & 1) inp(AST+3); /* IF a char is ready get it */ } else if (rr1 & 0X40) { /* receiver framing error */ *s++ = (0XF << 8) | 'f'; uz80_set_reg(&z80, WR0, UZ80_ER_RESET); if (inp(AST+3) & 1) inp(AST+1); /* IF a char is ready get it */ } } if (s > SCREEN + 2048) { s = SCREEN; scol++; scol %= 0X10; } disable(); outp(EOINT, 0X20); /* Send EOI to 8259 */ }