/* ** === WtCom.C -- Communications module for WT */ #if defined(USES_BIOS) #include #endif #include #include #include "wt.h" #include "wtcom.h" #include "wtlog.h" #include "wtscn.h" #include "wtser.h" #include "wtsta.h" /*=====================*/ /*===== Variables =====*/ /*=====================*/ static int com_port = SER_COM1; /* Port number */ static int com_baud = SER_BD2400; /* Baud rate */ static int com_pari = SER_PAEV; /* Parity */ static int com_data = SER_WD7; /* Data word length */ static int com_stop = SER_ST1; /* Stop bit number */ static int com_hdx = 0; /* default: full duplex */ static byte com_ch; /* serial input char */ static char scn_buf[100]; /* serial input buffer */ static char *scn_ptr; /* serial input pointer */ static int scn_cnt = 0; /* number of chars */ static char dpy_buf[100]; /* serial input buffer */ static char *dpy_ptr; /* serial display pointer */ static int dpy_cnt = 0; /* number of chars */ /*************************************/ /* */ /* com_display(): show recent chars. */ /* */ /*************************************/ static void com_display(int cr) { *dpy_ptr = '\0'; display(dpy_buf,cr); dpy_ptr = dpy_buf; dpy_cnt = 0; } /* end com_display() */ /**************************************************/ /* */ /* com_setmisc(): Set parity, data and stop bits. */ /* */ /**************************************************/ static void com_setmisc(int pari, int data, int stop) { ser_setmisc(pari, data, stop); } /* end ser_setmisc() */ /*============================*/ /*===== Global Functions =====*/ /*============================*/ /***************************************/ /* */ /* com_init(): Initialize COM handler. */ /* */ /***************************************/ void com_init(void) { /* --- Initialize buffers --- */ dpy_ptr = dpy_buf; dpy_cnt = 0; scn_ptr = scn_buf; scn_cnt = 0; /* --- Initialize serial interface --- */ com_setport(com_port); com_setparms(); ser_int_init(); } /* end com_init() */ /************************************************************************/ /* */ /* com_setparms(void) */ /* */ /* sets the comm port up to parms as per current variables. */ /* */ /************************************************************************/ void com_setparms(void) { #ifdef USES_BIOS unsigned comb_parms; comb_parms = com_baud | com_pari | com_data | com_stop; _bios_serialcom(_COM_INIT, com_port, comb_parms); #else com_setmisc(com_pari, com_data, com_stop); /* com_setbaud(com_baud); !!! DEBUG! Remove later! */ #endif } /* end com_setparms() */ /************************************************************************/ /* */ /* com_setport(portparm) */ /* */ /* sets the comm port variable for the serial interface. */ /* */ /************************************************************************/ void com_setport(unsigned portparm) { com_port = portparm; ser_setport(portparm); } /* end com_setport() */ /***************************************************/ /* */ /* com_setbaud(): Set baud rate via ser_setbaud(). */ /* */ /***************************************************/ void com_setbaud(unsigned baudparm) { com_baud = baudparm; ser_setbaud(baudparm); } /* end ser_setbaud() */ /************************************************************************/ /* */ /* com_setpari(baudparm) */ /* */ /* sets the parity variable for the serial interface. */ /* */ /************************************************************************/ void com_setpari(unsigned pariparm) { com_pari = pariparm; } /* end com_setpari() */ /************************************************************************/ /* */ /* com_setdata(dataparm) */ /* */ /* sets the data word length variable for the serial interface. */ /* */ /************************************************************************/ void com_setdata(unsigned dataparm) { com_data = dataparm; } /* end com_setdata() */ /************************************************************************/ /* */ /* com_sethdx(hdx) */ /* */ /* Turn half duplex on or off. */ /* */ /************************************************************************/ void com_sethdx(unsigned hdxparm) { com_hdx = hdxparm; } /* end com_sethdx() */ /************************************************************************/ /* */ /* com_setstop(stopparm) */ /* */ /* sets the stop bit number variable for the serial interface. */ /* */ /************************************************************************/ void com_setstop(unsigned stopparm) { com_stop = stopparm; } /* end com_setstop() */ /************************************/ /* */ /* com_update(): process COM input. */ /* */ /************************************/ int com_update(void) { int chars_waiting; chars_waiting = ser_int_icount(); if (chars_waiting == 0) return 0; for (; chars_waiting; chars_waiting--) { com_ch = (byte) ser_int_getc(); if (isprint(com_ch)) { if (com_ch == '*') sta_star(); *dpy_ptr++ = com_ch; if (++dpy_cnt > 80) com_display(1); *scn_ptr++ = com_ch; if (++scn_cnt > 80) { *scn_ptr = '\0'; scn_interp(scn_buf); scn_ptr = scn_buf; scn_cnt = 0; } } else if (com_ch == '\r') { com_display(1); *scn_ptr = '\0'; scn_interp(scn_buf); scn_ptr = scn_buf; scn_cnt = 0; } } /* end for */ if (dpy_cnt) com_display(0); return 1; } /* end com_update() */ /******************************************************/ /* com_xputs(): send translated string to serial port */ /******************************************************/ void com_xputs(char *s) { if (com_hdx) { display(s, 1); } while (*s) { if (s[0]=='^' && isalpha(s[1])) { ser_int_putc(CTRL(s[1])); s++; } else { ser_int_putc(s[0]); } s++; } } /* end com_xputs() */ /* EOF(WtCom.C) */