home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
BEEHIVE
/
COMMS
/
YAMBEE.ARC
/
BYAM5.C
< prev
next >
Wrap
Text File
|
1990-09-20
|
6KB
|
295 lines
/*
>>:yam5.c 02-Jun-83
*
Customised by Bob Logan 12-Feb-85 for the Microbee & auto dialling modems.
For automatic dialling function, define AUTODIAL
Automatic dialling for ETI 644a modem implimented by using the PIO A port
DTR is controlled by pin 24 on RS232 socket of bee (relay 1 in modem)
The modem uses bits 0 to 3 of the A port for modem control.
Bit 0 = relay 1 Bit 1 = relay 2 Bit 2 = relay 3 Bit 3 = TX on/off
The Yamphone.t file must not contain numbers before the start of the phone no.
eg. tesseract (02)-651-1404 b300
The only legal characters in the phone no are '(' ')' & '-' All the rest must
be numbers.
*/
#include "yam.h"
setbaud(nbaud)
unsigned nbaud;
{
if (nbaud == 1200) {
hibaud(); /* Rset$1200 */
Baudrate = 1200;
return(FALSE);
}
else if (nbaud == 300) {
lobaud(); /* Rset$300 */
Baudrate = 300;
return(FALSE);
}
return(TRUE); /* to indicate invalid baudrate */
}
readbaud()
{
Baudrate=DEFBAUD;
}
onhook() /* DTR line pin 24 on RS232 socket */
{
offbee(); /* set DTR line low (turn modem off line) */
outp(dial_port,0x0D); /* close 2 & 4, open 3 */
/* (bit 3 turns transmitter off) */
}
online()
{
onbee(); /* set DTR line high (turn modem on line) */
outp(dial_port,0x05); /* close 2 & 4, open 3. Turn on TX*/
}
bye() /* turn modem off then on to clear line */
{
offbee();
milibee(1600); /* 1.6 second delay on bee */
onbee();
}
#ifdef AUTODIAL
userinit()
{
offbee(); /* just to make sure */
}
dial(name)
char *name;
{
int pulse_count;
char *s;
while (1) /* loop for redial */
{
printf("Calling %s",name);
bye(); /* off/on line (open/close relay 1) */
outp(dial_port,0x0D)╗ /¬ closσ relay≤ 2 ª 4, */
milibee(1800); /* 1.8 sec delay for dialtone */
outp(dial_port,0x0E)╗ /¬ closσ relay≤ │ ª 4, */
/* open 2 (dialling mode) */
milibee(1000); /* 1 sec delay for settling time */
/* find start of phone number retrived from yamphone.t */
s = name;
while(!isdigit(*s)) /* search for start of phone no */
++s;
printf("Now dialling ");
/* dial each digit in phone number, skipping '(', ')' & '-' */
while( (isdigit(*s)) || (*s == 40) || (*s == 41) || (*s == 45) ) {
if((*s == 40) || (*s == 41) || (*s == 45))
goto skip_dash;
if(*s == 48) { /* looking for decimal 0 */
pulse_count = -9; /* want 10 pulses for 0 */
}else{
pulse_count = 1;
}
/* output to port, number of pulses indicated by phone digit */
/* abort if key is pressed while dialling */
while(pulse_count++ <= (*s - 48)) {
if(kbhit()) { /* if key pressed */
onhook(); /* disconnect modem and */
printf("\n");
return OK; /* return to menu */
}
outp(dial_port,0x0A); /* open dialling relay */
milibee(60); /* wait 60 m/s */
outp(dial_port,0x0E); /* close dialling relay */
milibee(40); /* wait 40 m/s */
}
printf("%d ",(pulse_count - 2));/* show what we dialled */
milibee(1000); /* 1000 m/s interdigit delay */
skip_dash:
++s; /* move to next digit */
}
/* set baud rate as per file */
if((s=cisubstr(name, "\tb")))
if(!setbaud(atoi(s+2)))
printf(" Baudrate set to %u: ", Baudrate);
printf("\n\nHit space to stop auto-dialling & enter option.%c\n",BELL);
outp(dial_port,0x0D); /* put modem on line */
/* wait 8 seconds for key press then redial number if no key hit */
while (pulse_count++ < (1000 * 8)) {
if(kbhit()) { /* get answer */
if(!ask()) {
printf("\n");
return OK;
}else{
break; /* repeat dialling */
}
}
milibee(1);
}
} /* repeat dialling */
}
/* function to decide what now ? */
ask()
{
char inkey;
while (1) { /* loop until correct response entered */
printf("\nEnter option: (Answer line. Hold dialling. Quit) .\b");
inkey = (tolower(getchar()));
switch(inkey) {
case 'q':
onhook(); /* disconnect modem & return */
return OK;
case 'a':
outp(dial_port,0x05); /* turn transmitter on */
printf("\n");
term(); /* enter terminal mode */
return OK;
case 'h':
onhook();
printf("\nHolding for redial. Hit space key to continue.");
while (inkey = (getchar()) != ' ')
;
printf("\n\n");
return (ERROR); /* repeat dialling */
}
}
}
#endif /* autodial */
#ifndef READLINE
readline(decisecs)
int decisecs;
{
MODEMON
if(MIREADY)
return MICHAR;
while(--decisecs>=0) {
if(MIREADY)
return MICHAR;
CONSOLON
if(CIREADY) {
CICHAR; /* dismiss character */
return TIMEOUT;
}
MODEMON
if(MIREADY)
return MICHAR;
for(Timeout=T1pause; --Timeout; )
if(MIREADY)
return MICHAR;
}
return TIMEOUT;
}
#endif /* !READLINE */
sendline(data)
char data;
{
int n;
n = Tpause; /* don't wait all day, 0.5 sec will do */
MODEMON
while(!MOREADY && n--)
;
MODATA(data);
}
purgeline()
{
MODEMON
while(MIREADY)
MICHAR;
}
/* default "autodial" routine */
#ifndef AUTODIAL
dial(name)
char *name;
{
char *s;
if((s=cisubstr(name, "\tb")))
if(!setbaud(atoi(s+2)))
printf("Baudrate set to %u: ", Baudrate);
printf("%s\n", name);
return OK;
}
#endif /* !AUTODIAL */
linetest (n)
int n;
{
int x,e;
int c;
char lstc;
srand(n);
printf(" Line test at %d Baud\n",Baudrate);
CONSOLON
while (CIREADY)
CICHAR;
purgeline();
for (e=0;--n;) {
if (moment(KTIME))
break;
lstc = rand();
sendline(lstc);
c = readline(10);
if (c == TIMEOUT)
printf("\nTimeout error");
else {
if (c==lstc)
putchar('.');
else {
e++;
putchar('*');
readline(10);
}
if (!(n&63))
putchar('\n');
}
}
printf("\n %d Errors detected\n",e);
}
loop (n) /* loop back mode for doing line tests */
int n;
{
CONSOLON
while (CIREADY)
CICHAR;
printf("Line looped, Hit any key to exit\n");
while (!moment(KTIME) && --n) {
sendline( readline(10));
(n&63) ? putchar('.') : putchar('\n');
}
putch('\n');
}
/* end of YAM5.C */