home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / osborne / mdioc.osb < prev    next >
Text File  |  1983-09-09  |  3KB  |  182 lines

  1. /*
  2.     Osbourne Modem I/O Routines
  3.     These routines are the Osbourne
  4.     versions of the routines needed
  5.     to make TELNET work.
  6.     To make TELNET work with the Osb 1
  7.     make the obvious modifications to 
  8.     telnet.c and recompile.
  9.  
  10.     by:    Dan Sunday
  11.         7473 Broken Staff
  12.         Columbia, MD 21044
  13.  
  14.         (301)-730-6838
  15.  
  16.     date:    4-23-82
  17.  
  18.     Note:    by suitably resetting the
  19.         io byte assignments in this
  20.         package, I and Dave Richardson
  21.         have successfully used the
  22.         modio.c routines to get TELNET
  23.         working on the TRS-80 Model 2
  24.         using Pickles & Trout
  25. */
  26. #include "a:osbdscio.h"
  27.  
  28.  
  29. /*
  30.     Routine to return true if input is present
  31.     at the modem port.
  32. */
  33.  
  34. miready()
  35. {
  36.     char c;
  37.     char *iob,sviob;
  38.  
  39.     iob = 3;
  40.     sviob = *iob;    /* save io byte */
  41.     *iob = 1;    /* console:= serial port */
  42.     c = bios(2);    /* get console status */
  43.     *iob = sviob;    /* restore io byte */
  44.     return c;    /* return input status */
  45. }
  46.  
  47.  
  48. /*
  49.     Routine to return true if modem is ready 
  50.     to output a byte.
  51. */
  52.  
  53. moready()
  54. {
  55.     char c;
  56.     char *iob,sviob;
  57.  
  58.     iob = 3;
  59.     sviob = *iob;    /* save io byte */
  60.     *iob = 0x40;    /* list device:= serial port */
  61.     c = bios(16);    /* get list device status */
  62.     *iob = sviob;    /* restore io byte */
  63.     return c;    /* return output status */
  64. }
  65.  
  66. /*
  67.     Get a byte from the modem:
  68. */
  69.  
  70. mgetch()
  71. {
  72.     char c;
  73.     char *iob,sviob;    /* I/O Byte */
  74.     unsigned n;    /* time-out counter */
  75.  
  76.     for (n=20000; !miready() && n; n--)
  77.        if (kbabort())
  78.         return ABORT;    /* Abort Input */
  79.     if (!n) return TIMOUT;    /* Read Time Out */
  80.  
  81.     iob = 3;
  82.     sviob = *iob;    /* save io byte */
  83.     *iob = 1;    /* console:= serial port */
  84.     c = bios(3,0);    /* get input char */
  85.     *iob = sviob;    /* restore io byte */
  86.     return c;    /* return input */
  87. }
  88.  
  89.  
  90. /*
  91.     Output a byte to the modem:
  92. */
  93.  
  94.  
  95. mputch(c)
  96. char c;
  97. {
  98.     char *iob,sviob;
  99.  
  100.     while (!moready())
  101.         if (kbabort())
  102.         return ABORT;    /* Abort Output */
  103.  
  104.     iob = 3;
  105.     sviob = *iob;    /* save io byte */
  106.     *iob = 0x40;    /* list:= serial port */
  107.     bios(5,c);    /* output char */
  108.     *iob = sviob;    /* restore io byte */
  109.     return OK;    /* A-OK */
  110. }
  111.  
  112.  
  113. mputs(s)
  114. char *s;
  115. {
  116.     while (*s)
  117.         mputch(*s++);
  118. }
  119. /*-----------------------------------------*/
  120. /*
  121.     Return true if keyboard hit and SPECIAL
  122.     typed:
  123. */
  124.  
  125. kbabort()
  126. {
  127.     if (kbready() && getch() == SPECIAL)
  128.         return ABORT;
  129.     return OK;
  130. }
  131.  
  132.  
  133.  
  134. kbready()
  135. {
  136.     return bios(2);
  137. }
  138.  
  139.  
  140.  
  141. /*
  142.     Get a character from the keyboard:
  143.     (Uses a direct BIOS instead of going through
  144.     the BDOS. By naming this the same as the library
  145.     version of "getchar", we insure that THIS version
  146.     is used by things like "gets" instead of the library
  147.     version.)
  148. */
  149.  
  150. getchar()
  151. {
  152.     char c;
  153.     c = getch();
  154.     if (c == '\r') c = '\n';
  155.     putchar(c);
  156.     return c;
  157. }
  158.  
  159.  
  160. getch()
  161. {
  162.     return bios(3);
  163. }
  164.  
  165.  
  166. /*
  167.     Write a character to the console.
  168. */
  169.  
  170. putchar(c)
  171. char c;
  172. {
  173.     if (c == '\n') putch2('\r');
  174.     putch2(c);
  175. }
  176.  
  177. putch2(c)
  178. char c;
  179. {
  180.     bios(4,c);
  181. }
  182.