/***********************************************************************/ /* File KSPIC.C - S4 Drivers for Nimbus Piconet; interface from Kermit calls to Mike Maloney standard interface for SIM. Chris Kennington 9th July 1985 */ /* All procedures in this file map down into calls to the functions described In Mike Maloney's "Nimbus Piconet interface specification" of 1st July 1985. Preferred Piconet addresses for SIMs are 1-8; user is asked to select between these before program starts. */ #include "a:ctype.h" #define CR 0x0d extern int p_break(), p_close(), p_flush(), p_getc(), p_open(), p_init(), p_putc(), p_speed(), p_status(), p_xonxoff(); /* MikeM procs */ static int picsim = 0, status; static char alive = 0; /* initialized flag */ static char awake = 0; /* awake flag */ static char parity = 0; static char speed = 1; static int picspeed[] = {110,300,600,1200,2400,4800,9600,19200,0}; /* all valid speeds: 0 1 2 3 4 5 6 7 */ static char partab[] = { /* character-parity table, 7-bit chars; 0 if even, 1 if odd. */ 0,1,1,0, 1,0,0,1, 1,0,0,1, 0,1,1,0, /* 0-15, 00-0f */ 1,0,0,1, 0,1,1,0, 0,1,1,0, 1,0,0,1, /* 16-31, 10-1f */ 1,0,0,1, 0,1,1,0, 0,1,1,0, 1,0,0,1, /* 32-47, 20-2f */ 0,1,1,0, 1,0,0,1, 1,0,0,1, 0,1,1,0, /* 48-63, 30-3f */ 1,0,0,1, 0,1,1,0, 0,1,1,0, 1,0,0,1, /* 64-79, 40-4f */ 0,1,1,0, 1,0,0,1, 1,0,0,1, 0,1,1,0, /* 80-95, 50-5f */ 0,1,1,0, 1,0,0,1, 1,0,0,1, 0,1,1,0, /* 96-111, 60-6f */ 1,0,0,1, 0,1,1,0, 0,1,1,0, 1,0,0,1 /* 112-127, 70-7f */ }; /* end of parity table */ static kill() /* tidy return to MSDOS */ { printf(" Hit any char to return to MSDOS"); while (kbdin() == 0) ; kermkill(1); } /* end of kill() */ static char par(c,p) /* return with parity */ /* strips to 7 bits, then adds correct parity; even if p=0, else odd */ char c, p; { char b, d; c &= 0x7f; b = (partab[c] == 0) ? 0 : 0x80; if (p != 0) b ^= 0x80; d = b | c; return(d); } /* end of par() */ s4break(len) /* send break - official */ char len; { int time; if ( (alive == 0) || (awake == 0) ) { printf(" not in contact "); return(-1); } time = len << 7; /* sec/8 => msec */ p_break(picsim,time); outc(' '); return(0); } /* end of s4break() */ s4env() /* return environment value */ /* Environment codes are:- 0 - 480Z, via SIO4; 1 - 480Z, via IDC; 2 - Nimbus, via DCC; 3 - Nimbus, via RS422 Aux; 4 - Nimbus, via Piconet SIM; 5 - either, via Network Comms Server (n.y.i.). (see KDATA.C for texts used on bottom header) */ { return(4); } /* end of s4env() */ s4get(n,buff) /* read some character, maybe */ char n, *buff; { awake = 1; if ( (p_getc(picsim,buff)) != 0 ) return(0); else return(1); } /* end of s4get() */ s4get7(n,buff) /* read some 7-character, maybe */ char n, *buff; { awake = 1; if ( (p_getc(picsim,buff)) != 0 ) return(0); else { *buff &= 0x7f; return(1); } } /* end of s4get7() */ s4go() /* fire up piconet comms */ { int i; char c, *addr; awake = 1; if (alive != 0) return(0); while (picsim == 0) { printf("\nRMKermit: Enter Piconet SIM address (1-8): "); while ( (c = kbdin()) == 0 ) ; if (c == CR) picsim = 1; else if (isdigit(c) == 0) continue; /* invalid entry */ else { c &= 0x0007; /* range 0 - 7 */ picsim = (c == 0) ? 8 : c; /* address in binary */ printf("Address is %d",picsim); } } if ( (addr = malloc (1610)) == 0 ) { printf("\nNo store for comms.\n"); goto Kill; } else { if ( (i = p_open(picsim,'I',1600,addr)) != 0 ) { printf("\nCannot open comms, error-code %xx.\n",i); goto Kill; } if ( (i = p_init(picsim,0x0066,0x0010,0x004c,0x0000,0,0)) != 0 ) { /* these parameters are cookbook from Mike M.; control-line handling is not guaranteed. */ printf("\nCannot initialize Piconet, error-code %xx.\n",i); goto Kill; } alive = 1; } return(0); Kill: /* error so terminate */ txtout(" Hit any char to return to MSDOS "); while (kbdin() == 0) ; kermkill(1); } /* end of s4go() */ s4put(n,buff) /* send some chars */ char n, *buff; { char c; awake = 1; c = *buff; switch(parity) { default: /* 0 or > 3 (impossible) */ break; case 1: /* 1 = odd */ c = par(c,1); break; case 2: /* 2 = even */ c = par(c,0); break; case 3: /* 3 = mark */ c |= 0x80; break; } /* end switch */ if (p_putc(picsim,c) == 0) return(1); else return(0); } /* end of s4put */ s4set(facil,wr5) /* set facilities - dummy */ int facil; char wr5; { char x; parity = (facil & 0x0300) >> 8; x = ( (facil & 0x0002) == 0 ) ? 0 : 0xff; p_xonxoff(picsim,x); return(0); } /* end of s4set() */ s4sleep() /* dummy deactivate */ { awake = 0; return(0); } s4speed(kspeed) /* set line-speed */ char kspeed; /* 480Z speed-code */ { int i, spd; speed = kspeed; if (alive != 0) { spd = picspeed[kspeed]; if ( (i = p_speed(picsim,spd,spd)) != 0 ) { printf("\nCannot set speed, error-code %xx.\n",i); kermkill(1); } } return(0); } /* end of s4speed() */ s4status() /* return status-byte (in int) */ { return(p_status(picsim)); } /* end of s4status() */ s4stop() /* close down communications */ { if (alive = 0) return(0); alive = awake = 0; p_close(picsim); return(0); } /* end of s4stop() */ s4test() /* return status - dummy */ { return(0); } /* end of s4test() */ /****************** END of file KSMIKE.C *******************************/