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 / YAM.ARC / YAM5.C < prev    next >
Text File  |  1990-09-20  |  18KB  |  930 lines

  1. /*
  2. >>:yam5.c 02-Jun-83
  3. *
  4. * This version implements parameterized #define in Sendline() routine
  5. *
  6. * Modem related functions. If your(modem supports baudrate setting,
  7. * and hangup, write your own routines here.
  8. * If your modem supports an autocall, put that routine here also
  9. * define MODEMSTUFF to suppress default baud rate related functions.
  10. * define AUTOCALL in your autocall routine to suppress the default
  11. * which merely prints the phone number and recommended baud rate.
  12. *
  13. * LOOP & TEST are used for loopback testing of the communications
  14. *           line.
  15. *
  16. * LOOP simply loop comm input to comm output as each character
  17. *    is processed, (or a timeout occurs) a '.' is printed to
  18. *    console.  This is simply to let you monitor what is
  19. *    going on. Slow dots = timeouts = nothing doing. 
  20. *    Speedy dots = chars echoed.
  21. *
  22. *   usage 'LOOPn' where n is a number of characters (or timeouts)
  23. *           to stay in the loop . Keyboard bashing exits
  24. *           (n ommitted = 65535).
  25. *
  26. * TEST performs loopback tests (sending a char & reading the next
  27. *    received char to see if the same) on the line that is
  28. *    terminated in a loop, either physically (at modem) or
  29. *    by other end being in 'LOOP'.
  30. *    Successfully received chars output a '.' to console,
  31. *    while errors echo an '*', and timeouts say so.
  32. *
  33. *  usage 'TESTn' where n is number of characters to send to
  34. *          line, keyboard bashing also exits.  Final
  35. *          message is number of errors (not timeouts)
  36. *          received.
  37. */
  38.  
  39. #include "yam.h"
  40.  
  41. #ifdef SORCERER
  42. #define MODEMSTUFF
  43. /*
  44. * set baud rate for modem driven by Sorcerer + bitrate chip
  45. */
  46.  
  47. setbaud(nbaud)
  48. unsigned nbaud;
  49. {
  50.     char baudcmd, *i;
  51.     switch(nbaud)
  52.     {
  53.     case  300: baudcmd=0x80; break;
  54.     case 1200: baudcmd=0xc0; break;
  55.     default:
  56.         return ERROR;
  57.     }
  58.  
  59.     i = mwa() + 0x45;
  60.  
  61.     Sport = 0xfd;
  62.     Dport = 0xfc;
  63.     Somask = 0x01;
  64.     Simask = 0x02;
  65.  
  66.     outp(Sport,0xfb);    /* 8 bits, 1 stop, no parity */
  67.  
  68.     *i = (baudcmd);
  69.     Baudrate=nbaud;
  70.     return 0;
  71. }
  72.  
  73. readbaud()
  74. {
  75.     Baudrate=DEFBAUD;
  76. }
  77.  
  78. /* Bye disconnects the line and allows another call */
  79.  
  80. bye()
  81. {
  82.     sleep(40/CLKMHZ);    /* wait two seconds */
  83.     setbaud(Baudrate);
  84. }
  85.  
  86. /* onhook disconnects the line for good */
  87.  
  88. onhook()
  89.  
  90. {}    /* no way to go on hook with this setup */
  91.  
  92. /* online connects the line    */
  93.  
  94. online()
  95. {}    /* not implemented    */
  96.  
  97. #endif    /* Sorcerer    */
  98.  
  99. #ifdef MONROE
  100. #define MODEMSTUFF
  101. /*
  102. * set baud rate for modem driven from MONROE
  103. */
  104. setbaud (nbaud)
  105. unsigned nbaud;
  106. {
  107.     char command;
  108.     unsigned baud,count;
  109.  
  110.     count=command=0;        /* to detect an error  */
  111.     baud=nbaud;            /* save for later       */
  112.  
  113.  
  114.  
  115.     /* Select required SIO range factor
  116.     and also test for legal baudrates */
  117.  
  118.     switch(baud)
  119.     {
  120.     case(110)    :
  121.     case(134)    :
  122.     case(150)    :
  123.     case(300)    :
  124.         command=0xce;
  125.         count=23437;
  126.         break;
  127.  
  128.     case(0600)    :
  129.     case(1200)    :
  130.     case(1800)    :
  131.     case(2000)    :
  132.     case(2400)    :
  133.     case(3600)    :
  134.     case(4800)    :
  135.     case(7200)    :
  136.     case(9600)    :
  137.         command=0x4e;
  138.         count=9375;    /* prescaling because can't handle */
  139.         baud/=10;    /* numbers like 1.5 million */
  140.         break;
  141.  
  142.     case(19200) :
  143.         command=0x0e;
  144.         count=15000;
  145.         baud/=100;
  146.         break;
  147.  
  148.     default    :
  149.         return ERROR;
  150.     }
  151.  
  152.     count=(count/baud) + (((count%baud) > (baud/2)) ? 1 : 0);
  153.             /* divide with rounding */
  154.  
  155.     outp(Sport,04);             /* select SIO divisor    */
  156.     outp(Sport,command);
  157.  
  158.     outp(CTCPRT,0x45);
  159.     outp(CTCPRT,count);         /* set CTC to required count    */
  160.  
  161.     Baudrate=nbaud;
  162.     return OK;
  163. }
  164.  
  165. readbaud ()
  166. {
  167.     Baudrate=DEFBAUD;
  168. }
  169.  
  170. /* Bye disconnects the line and allows another call */
  171. bye ()
  172. {
  173.     outp(Dport, 03);     /* send a ctrl C    */
  174.     sleep(40/CLKMHZ);    /* wait two seconds */
  175.     setbaud(Baudrate);
  176. }
  177.  
  178. /* onhook disconnects the line for good */
  179. onhook ()
  180. {
  181.     /* no way to go on hook with this setup */
  182. }
  183.  
  184. /* online connects modem to the line */
  185. online ()
  186. {
  187.     /* no way to go online with this setup */
  188. }
  189.  
  190. #endif /* MONROE */
  191.  
  192.  
  193. #ifdef SANYO
  194. #define MODEMSTUFF
  195. /*
  196. * set baud rate for modem driven from SANYO
  197. * Requires MBC-1000 to be jumpered for 4800 baud
  198. * Other software baud-rate pairs may be programmed
  199. * here instead of 4800 & 1200 baud. e.g. if MBC-1000
  200. * is programmed for 1200 baud these rates become
  201. * 1200 & 300 baud respectively.
  202. */
  203. setbaud (nbaud)
  204. unsigned nbaud;
  205. {
  206.  
  207. unsigned command;
  208.  
  209.     switch (nbaud)
  210.     {
  211.     case(4800) : command = 0x4e; break;  /* U8251 div 16 */
  212.     case(1200) : command = 0x4f; break;  /* U8251 div 64 */
  213.     default       : return ERROR;
  214.     }
  215.  
  216.     outp(Sport,0x80);    /* mode, set synch, one synch */
  217.     outp(Sport,0x00);    /* synch */
  218.     outp(Sport,0x00);    /* control */
  219.     outp(Sport,0x00);    /* control */
  220.  
  221.     outp(Sport,0x40);    /* reset U8251 control */
  222.     outp(Sport,command); /* send required command */
  223.  
  224.     outp(Sport,MI_ERROR_RESET);        /* reset all errors control */
  225.  
  226.  
  227.     Baudrate=nbaud;
  228.     return OK;
  229. }
  230.  
  231. readbaud ()
  232. {
  233.     Baudrate=DEFBAUD;
  234. }
  235.  
  236. /* Bye disconnects the line and allows another call */
  237. bye ()
  238. {
  239.     outp(Dport, 03);     /* send a ctrl C    */
  240.     sleep(40/CLKMHZ);    /* wait two seconds */
  241.     setbaud(Baudrate);
  242. }
  243.  
  244. /* onhook disconnects the line for good */
  245. onhook ()
  246. {
  247.     /* no way to go on hook with this setup */
  248. }
  249.  
  250. /* online connects modem to the line */
  251. online ()
  252. {
  253.     /* no way to go online with this setup */
  254. }
  255.  
  256. #endif /* SANYO */
  257.  
  258.  
  259. #ifdef OKI
  260. #define MODEMSTUFF
  261. /*
  262. * set baud rate for modem driven from Oki-if800
  263. */
  264. setbaud (nbaud)
  265. unsigned nbaud;
  266. {
  267.  
  268. unsigned command;
  269.  
  270.     switch (nbaud)
  271.     {
  272.     case(110)  : command = 0; break;
  273.     case(150)  : command = 1; break;
  274.     case(300)  : command = 2; break;
  275.     case(600)  : command = 3; break;
  276.     case(1200) : command = 4; break;
  277.     case(2400) : command = 5; break;
  278.     case(4800) : command = 6; break;
  279.     case(9600) : command = 7; break;
  280.     default       : return ERROR;
  281.     }
  282.  
  283.     outp(0x22,command);        /* Boy did I have fun finding this
  284.                     port number. Documents superb!!??##  */
  285.  
  286. /*  Initialize the U8251 chip    */
  287.  
  288.     outp(Sport,0x80);    /* mode, set synch, one synch */
  289.     outp(Sport,0x00);    /* synch */
  290.     outp(Sport,0x00);    /* control */
  291.     outp(Sport,0x00);    /* control */
  292.  
  293.     outp(Sport,0x40);    /* reset U8251 control */
  294.     outp(Sport,0x4e);    /* send /16 8d, 1s, np */
  295.  
  296.     outp(Sport,MI_ERROR_RESET);        /* reset all errors control */
  297.  
  298.  
  299.     Baudrate=nbaud;
  300.     return OK;
  301. }
  302.  
  303. readbaud ()
  304. {
  305.     Baudrate=DEFBAUD;
  306. }
  307.  
  308. /* Bye disconnects the line and allows another call */
  309. bye ()
  310. {
  311.     outp(Dport, 03);     /* send a ctrl C    */
  312.     sleep(40/CLKMHZ);    /* wait two seconds */
  313.     setbaud(Baudrate);
  314. }
  315.  
  316. /* onhook disconnects the line for good */
  317. onhook ()
  318. {
  319.     /* no way to go on hook with this setup */
  320. }
  321.  
  322. /* online connects modem to the line */
  323. online ()
  324. {
  325.     /* no way to go online with this setup */
  326. }
  327.  
  328. #endif /* OKI */
  329.  
  330.  
  331. #ifdef U2651
  332. #define MODEMSTUFF
  333. /*
  334. * set baud rate for modem driven by 2651 UART
  335. */
  336. setbaud(nbaud)
  337. unsigned nbaud;
  338. {
  339.     char command;
  340.     char baudcmd;
  341.  
  342.     command=0;
  343.  
  344.     switch(nbaud) {
  345.     case    50: baudcmd=  0; break;
  346.     case    75: baudcmd=  1; break;
  347.     case   110: baudcmd=  2; break;
  348.     case   134: baudcmd=  3; break;
  349.     case   150: baudcmd=  4; break;
  350.     case   300: baudcmd=  5; break;
  351.     case   600: baudcmd=  6; break;
  352.     case  1200: baudcmd=  7; break;
  353.     case  1800: baudcmd=  8; break;
  354.     case  2000: baudcmd=  9; break;
  355.     case  2400: baudcmd= 10; break;
  356.     case  3600: baudcmd= 11; break;
  357.     case  4800: baudcmd= 12; break;
  358.     case  7200: baudcmd= 13; break;
  359.     case  9600: baudcmd= 14; break;
  360.     case 19200: baudcmd= 15; break; 
  361.  
  362.     default:
  363.         return ERROR;
  364.     }
  365.  
  366.     MODEMON
  367.     outp(MPORT, MODE1);
  368.     outp(MPORT, MODE2 + baudcmd);
  369.     outp(CPORT, Commbyte);        /* just to be safe */
  370.     Baudrate = nbaud;
  371.     return OK;
  372. }
  373.  
  374. readbaud()
  375. {
  376.     char nbaud;
  377.  
  378.     MODEMON
  379.  
  380.     nbaud = inp(MPORT);        /* throw away first mode byte */
  381.     nbaud = inp(MPORT) & 0X0F;    /* low nibble has baud rate */
  382.     Commbyte = inp(CPORT);        /* get current command byte */
  383.  
  384.     switch(nbaud) {
  385.     case  0: Baudrate=   50; break;
  386.     case  1: Baudrate=   75; break;
  387.     case  2: Baudrate=  110; break;
  388.     case  3: Baudrate=  134; break;
  389.     case  4: Baudrate=  150; break;
  390.     case  5: Baudrate=  300; break;
  391.     case  6: Baudrate=  600; break;
  392.     case  7: Baudrate= 1200; break;
  393.     case  8: Baudrate= 1800; break;
  394.     case  9: Baudrate= 2000; break;
  395.     case 10: Baudrate= 2400; break;
  396.     case 11: Baudrate= 3600; break;
  397.     case 12: Baudrate= 4800; break;
  398.     case 13: Baudrate= 7200; break;
  399.     case 14: Baudrate= 9600; break;
  400.     case 15: Baudrate=19200; break;
  401.     }
  402. }
  403.  
  404. /* Bye disconnects the line and allows another call */
  405. bye()
  406. {
  407.     onhook();            /* turn of DTR */
  408.     sleep(20/CLKMHZ);        /* wait one second */
  409.     online();            /* turn on DTR */
  410. }
  411.  
  412. /* onhook disconnects the line for good */
  413. onhook()
  414. {
  415.     if(Commbyte & 0x02){
  416.         MODEMON
  417.         outp(CPORT, Commbyte -= 0x02);
  418.     }
  419. }
  420.  
  421. /* online connects the modem to line */
  422. online()
  423. {
  424.     if(!(Commbyte & 0x02)){
  425.         MODEMON
  426.         outp(CPORT, Commbyte += 0x02);
  427.     }
  428. }
  429. #endif  /* U2651 */
  430.  
  431. #ifdef TUART
  432. #define MODEMSTUFF
  433. /*
  434. * set baud rate for modem driven by Cromenco TUART
  435. */
  436. setbaud(nbaud)
  437. unsigned nbaud;
  438. {
  439.     char command, baudcmd;
  440.     command=0;
  441.     switch(nbaud) {
  442.     case   110: baudcmd=0001; break;
  443.     case   150: baudcmd=0202; break;
  444.     case   300: baudcmd=0204; break;
  445.     case  1200: baudcmd=0210; break;
  446.     case  2400: baudcmd=0220; break;
  447.     case  4800: baudcmd=0240; break;
  448.     case  9600: baudcmd=0300; break;
  449.     case 19200: baudcmd=0220; command=020; break;
  450.     case 38400: baudcmd=0240; command=020; break;
  451.     default:
  452.         return ERROR;
  453.     }
  454.     outp(Sport, baudcmd);
  455.     outp(Sport+2, command);
  456.     Baudrate=nbaud;
  457.     return 0;
  458. }
  459. readbaud()
  460. {
  461.     Baudrate=DEFBAUD;
  462. }
  463.  
  464. /* Bye disconnects the line and allows another call */
  465. bye()
  466. {
  467.     outp(Sport+2, 03);    /* turn on break */
  468.     sleep(40/CLKMHZ);    /* wait two seconds */
  469.     setbaud(Baudrate);
  470. }
  471.  
  472. /* onhook disconnects the line for good */
  473. onhook()
  474. {}    /* no way to go on hook with this setup */
  475. #endif /* TUART */
  476.  
  477. #ifdef Z89
  478. #define MODEMSTUFF
  479. /*
  480. * Routine to set baud rate for 8250 driven modem port
  481. */
  482. setbaud(nbaud)
  483. unsigned nbaud;
  484. {
  485.     unsigned bcmd;
  486.  
  487.     if(nbaud==0)
  488.         return ERROR;
  489.     bcmd= 57600;        /* 1.8432 Mhz clock */
  490.     bcmd /= (nbaud/2);    /* this must be done unsigned! */
  491.     outp(Dport+3, 0203);    /* enable divisor latch */
  492.     outp(Dport, bcmd);
  493.     outp(Dport+1, (bcmd>>8));
  494.  
  495.     /* 8 data bits, 1 stop bit (2 if 110 baud), disable divisor latch */
  496.  
  497.     outp(Dport+3, nbaud==110? 07:03);
  498.  
  499.     /* turn on dtr and rts, also output2 is baudrate is 1200 or more */
  500.  
  501.     outp(Dport+4, nbaud>=1200?017:03);
  502.     Baudrate=nbaud;
  503. /*
  504.     printf("bcmd=%d bcmdms=0%o bcmdls=0%o\n",bcmd,(bcmd>>8),(bcmd&0377));
  505. */
  506.     return OK;
  507. }
  508. /* fetch the baudrate from the modem port */
  509. readbaud()
  510. {
  511.     char dp3;
  512.     unsigned div;
  513.  
  514.     dp3=inp(Dport+3);
  515.     outp(Dport+3, 0200|dp3);
  516.     div= inp(Dport) | (inp(Dport+1)<<8);    /* fetch divisor */
  517.     outp(Dport+3, dp3);            /* restore uart modes */
  518.     Baudrate=57600;            /* be sure all this remains unsigned */
  519.     Baudrate /= div;
  520.     Baudrate <<= 1;
  521. }
  522.  
  523. /* Bye hangs up the line and then resets for another call */
  524. bye()
  525. {
  526.     onhook();
  527.     sleep(40/CLKMHZ);
  528.     setbaud(Baudrate);
  529. }
  530.  
  531. /* onhook goes off line for good */
  532. onhook()
  533. {
  534.     outp(Dport+4, 0);
  535. }
  536.  
  537. #endif /* Z89 (8250) */
  538.  
  539. #ifdef TRS2
  540. #define MODEMSTUFF
  541. /*
  542.  * baud rate cannot be changed within yam on
  543.  * TRS 80 MOD II with Aton CP/M
  544.  */
  545. setbaud(nbaud)
  546. unsigned nbaud;
  547. {
  548.     switch(nbaud) {
  549.     case   110: break;
  550.     case   150: break;
  551.     case   300: break;
  552.     case   600: break;
  553.     case  1200: break;
  554.     case  2400: break;
  555.     case  4800: break;
  556.     case  9600: break;
  557.     default:
  558.         return ERROR;
  559.     }
  560.     printf("Set baud at system level.\n");
  561.     Baudrate=nbaud;
  562.     return 0;
  563. }
  564.  
  565. readbaud()
  566. {
  567.     Baudrate=DEFBAUD;
  568. }
  569.  
  570. /* Bye disconnects the line and allows another call */
  571. bye()
  572. {
  573.     onhook();
  574.     sleep(40/CLKMHZ);    /* wait two seconds */
  575.     setbaud(Baudrate);
  576. }
  577.  
  578. /* onhook disconnects the line for good */
  579. onhook()
  580. {}
  581.  
  582. online()
  583. {}
  584.  
  585. #endif /* TRS2 */
  586.  
  587. #ifdef TRS3
  588. #define MODEMSTUFF
  589.  
  590. setbaud(nbaud)
  591. unsigned nbaud;
  592. {
  593.     char command, baudcmd;
  594.     command=0;
  595.  
  596.     switch(nbaud) {
  597.     case    50: baudcmd =  0; break;
  598.     case    75: baudcmd =  1; break;
  599.     case   110: baudcmd =  2; break;
  600.     case   134: baudcmd =  3; break;
  601.     case   150: baudcmd =  4; break;
  602.     case   300: baudcmd =  5; break;
  603.     case   600: baudcmd =  6; break;
  604.     case  1200: baudcmd =  7; break;
  605.     case  1800: baudcmd =  8; break;
  606.     case  2000: baudcmd =  9; break;
  607.     case  2400: baudcmd = 10; break;
  608.     case  3600: baudcmd = 11; break;
  609.     case  4800: baudcmd = 12; break;
  610.     case  7200: baudcmd = 13; break;
  611.     case  9600: baudcmd = 14; break;
  612.     case 19200: baudcmd = 15; break;
  613.  
  614.     default: return ERROR;
  615.     }
  616.  
  617.     outp(0xe9,baudcmd*16+baudcmd);
  618.     Baudrate=nbaud;
  619.     return 0;
  620. }
  621.  
  622. readbaud()
  623. {
  624.     Baudrate=DEFBAUD;
  625. }
  626.  
  627. bye()
  628. {
  629.     sleep(40/CLKMHZ);
  630.     setbaud(Baudrate);
  631. }
  632.  
  633. onhook()
  634. {}
  635.  
  636. online()
  637. {}
  638.  
  639. #endif    /* TRS3 */
  640.  
  641. #ifdef 8251
  642. #define MODEMSTUFF
  643.  
  644. setbaud()
  645. {}        /* Baud rate set in hardware on many 8251 implemenetations */
  646.  
  647. onhook()
  648. {}        /* No way to set onhook on many 8251 implementations */
  649.  
  650. online()
  651. {}        /* No way to set off hook on many 8251 implementations */
  652.  
  653. bye()
  654. {}        /* No way to drop line on many 8251 implementtations */
  655.  
  656. readbaud()
  657. {
  658.     Baudrate=DEFBAUD;    /* Set to default baudrate */
  659. }
  660.  
  661. #endif /* 8251 */
  662.  
  663. #ifndef MODEMSTUFF
  664. setbaud()
  665. {}    /* INSERT ROUTINE HERE IF AVAILABLE */
  666. onhook()
  667. {}    /* INSERT ROUTINE HERE IF AVAILABLE */
  668. online()
  669. {}    /* INSERT ROUTINE HERE IF AVAILABLE */
  670. bye()
  671. {}    /* INSERT ROUTINE HERE IF AVAILABLE */
  672. readbaud()
  673. {
  674.     Baudrate=DEFBAUD;
  675. }
  676. #endif /* !MODEMSTUFF */
  677.  
  678. /*
  679.  * Readline from MODEM13.C rewritten to allow much higher
  680.  * baud rates.
  681.  * Timeout is in deciseconds (1/10th's)
  682.  * For top speed, character ready is checked in many places.
  683.  * returns TIMEOUT if kbd character is ready.
  684.  *
  685.  * There are three versions of readline, the first is used if
  686.  * there is a separate register for error conditions. The second
  687.  * is used if error condx are in the same register asrx data ready.
  688.  * The last, and quickest, does not check error conditions.
  689.  */
  690. #ifdef MIERROR
  691. /* version for separate error register. NOT TESTED */
  692. readline(decisecs)
  693.  
  694. int decissecs;
  695.  
  696. {
  697.     if(MIREADY) {
  698.         if(MIERROR)
  699.             goto fubar;
  700.         else
  701.             return MICHAR;
  702.     }
  703.     while(--decisecs>=0) {
  704.         if(MIREADY) {
  705.             if(MIERROR)
  706.                 goto fubar;
  707.             else
  708.                 return MICHAR;
  709.         }
  710.  
  711. #ifdef CDO
  712.         if(CDO)
  713.             return TIMEOUT;
  714. #endif
  715.         if(CIREADY) {
  716.             CICHAR;        /* dismiss character */
  717.             return TIMEOUT;
  718.         }
  719.         for(Timeout=T1pause; --Timeout; )
  720.             if(MIREADY) {
  721.                 if(MIERROR)
  722.                     goto fubar;
  723.                 else
  724.                     return MICHAR;
  725.             }
  726.     }
  727.     return TIMEOUT;
  728. fubar:
  729.     MICHAR;        /* throw the turkey away */
  730.     MI_ERROR_RESET;
  731.     return ERROR;
  732. }
  733.  
  734. #define READLINE
  735. #endif /* MIERROR */
  736.  
  737. #ifdef MIREADYERROR
  738. /* Version for 8250, 8251, 2651, etc. with all bits in one register */
  739. readline(decisecs)
  740.  
  741. int decisecs;
  742.  
  743. {
  744.     MODEMON
  745.     if((Mstatus=inp(Sport))&MIREADYMASK)
  746.         goto getit;
  747.     while(--decisecs>=0) {
  748.         if((Mstatus=inp(Sport))&MIREADYMASK)
  749.             goto getit;
  750. #ifdef CDO
  751.         if(CDO)
  752.             return TIMEOUT;
  753. #endif /* CDO */
  754.         if((Mstatus=inp(Sport))&MIREADYMASK)
  755.             goto getit;
  756.         CONSOLON
  757.         if(CIREADY) {
  758.             CICHAR;        /* dismiss character */
  759.             return TIMEOUT;
  760.         }
  761.         MODEMON
  762.         if((Mstatus=inp(Sport))&MIREADYMASK)
  763.             goto getit;
  764.         for(Timeout=T1pause; --Timeout; )
  765.             if((Mstatus=inp(Sport))&MIREADYMASK) {
  766. getit:
  767.                 if(Mstatus&MIERRORMASK) {
  768.                     modreset();    /* reset error bits */
  769.                     Mstatus &= MIERRORMASK;
  770.                     return ERROR;
  771.                 }
  772.                 else
  773.                     return MICHAR;
  774.             }
  775.     }
  776.     return TIMEOUT;
  777. }
  778.  
  779. modreset()
  780.  
  781. {
  782. #ifdef CPORT
  783.  
  784.     if(!(Commbyte & MI_ERROR_RESET)){
  785.         outp(CPORT, (Commbyte += MI_ERROR_RESET)); /* reset error */
  786.     }
  787.     else{
  788.         outp(CPORT, Commbyte);
  789.     }
  790.     outp(CPORT, (Commbyte -= MI_ERROR_RESET));    /* clear reset */
  791.  
  792. #else /* CPORT */
  793.  
  794. #ifdef MI_ERROR_RESET
  795.  
  796.     outp(Sport,MI_ERROR_RESET);        /* clear error on U8251     */
  797.  
  798. #endif /* MI_ERROR_RESET */
  799.  
  800. #endif /* CPORT */
  801.  
  802.     MICHAR;                    /* throw away bad char */
  803. }
  804.  
  805. #define READLINE
  806.  
  807. #endif /* MIREADYERROR */
  808.  
  809. #ifndef READLINE
  810. readline(decisecs)
  811.  
  812. int decisecs;
  813.  
  814. {
  815.     MODEMON
  816.     if(MIREADY)
  817.         return MICHAR;
  818.     while(--decisecs>=0) {
  819.         if(MIREADY)
  820.             return MICHAR;
  821.         CONSOLON
  822.         if(CIREADY) {
  823.             CICHAR;        /* dismiss character */
  824.             return TIMEOUT;
  825.         }
  826.  
  827.         MODEMON
  828.         if(MIREADY)
  829.             return MICHAR;
  830.         for(Timeout=T1pause; --Timeout; )
  831.             if(MIREADY)
  832.                 return MICHAR;
  833.     }
  834.     return TIMEOUT;
  835. }
  836. #endif /* !READLINE */
  837.  
  838. sendline(data)
  839. char data;
  840.  
  841. {
  842.     int    n;
  843.     n = Tpause;    /* don't wait all day, 0.5 sec will do */
  844.  
  845.     MODEMON
  846.     while(!MOREADY && n--)
  847.         ;
  848.     MODATA(data);
  849. }
  850.  
  851. purgeline()
  852.  
  853. {
  854.     MODEMON
  855.     while(MIREADY)
  856.         MICHAR;
  857. }
  858.  
  859. /* default "autodial" routine */
  860. #ifndef AUTODIAL
  861. dial(name)
  862. char *name;
  863.  
  864. {
  865.     char *s;
  866.     if((s=cisubstr(name, "\tb")))
  867.         if(!setbaud(atoi(s+2)))
  868.             printf("Baudrate set to %u: ", Baudrate);
  869.     printf("%s\n", name);
  870.     return OK;
  871. }
  872. #endif /* !AUTODIAL */
  873.  
  874.  
  875. linetest (n)
  876. int n;
  877.  
  878. {
  879.     int x,e;
  880.     int c;
  881.     char lstc;
  882.  
  883.     srand(n);
  884.     printf(" Line test at %d Baud\n",Baudrate);
  885.     CONSOLON
  886.     while (CIREADY)
  887.         CICHAR;
  888.     purgeline();
  889.     for (e=0;--n;) {
  890.         if (moment(KTIME))
  891.             break;
  892.         lstc = rand();
  893.         sendline(lstc);
  894.         c = readline(10);
  895.  
  896.         if (c == TIMEOUT)
  897.             printf("\nTimeout error");
  898.         else {
  899.             if (c==lstc)
  900.                 putchar('.');
  901.             else {
  902.                 e++;
  903.                 putchar('*');
  904.                 readline(10);
  905.             }
  906.  
  907.             if (!(n&63))
  908.             putchar('\n');
  909.         }
  910.     }
  911.     printf("\n %d Errors detected\n",e);
  912. }
  913.  
  914. loop (n)    /* loop back mode for doing line tests */
  915. int n;
  916.  
  917. {
  918.     CONSOLON
  919.     while (CIREADY)
  920.         CICHAR;
  921.     printf("Line looped, Hit any key to exit\n");
  922.     while (!moment(KTIME) && --n) {
  923.         sendline( readline(10));
  924.         (n&63) ? putchar('.') : putchar('\n');
  925.     }
  926.     putch('\n');
  927. }
  928.  
  929. /* end of YAM5.C  */
  930.