home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / MIDICOM.LZH / MC_DRIVE.R / DRIVER.SER / MC_DRIVE.C < prev    next >
C/C++ Source or Header  |  1993-10-22  |  3KB  |  133 lines

  1. #include <tos.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include "mc_drive.h"
  6.  
  7.  
  8. #define DEVICE    1
  9. #define LESE_ABBRUCH 1000
  10. #define    r_buff  12000
  11. #define    s_buff_size  6000
  12. IOREC    *iorec;
  13.  
  14. /* header file for dealing with the cookie jar */
  15. #define BP _BasPag
  16.  
  17. extern void MSEND(int len,char *buf); /* schnell und trickreich in ASS */
  18. void MIDEIN(void);
  19.  
  20. static long install_buffers(void) 
  21. {
  22.     iorec=Iorec(0);
  23.     if (iorec->ibufsiz<r_buff)
  24.     {
  25.         iorec->ibuf=Malloc(r_buff);
  26.         iorec->ibufsiz=r_buff;
  27.     }
  28.     iorec->ibufhd=0;         /* nächste Schreibposition */
  29.        iorec->ibuftl=0;         /* nächste Leseposition    */
  30.     iorec->ibuflow=r_buff-40;        /* Marke für Xon           */
  31.        iorec->ibufhi=r_buff-10;         /* Marke für Xoff          */
  32.     
  33.     iorec=(IOREC *) (14+(long)(iorec));
  34.     if (iorec->ibufsiz<s_buff_size)
  35.     {
  36.         iorec->ibuf=Malloc(s_buff_size);
  37.         iorec->ibufsiz=s_buff_size;    /* Min = 4000 Bytes für Sende-Puffer*/
  38.    }
  39.     iorec->ibufhd=0;          /* nächste Schreibposition */
  40.        iorec->ibuftl=0;          /* nächste Leseposition    */
  41.     iorec->ibuflow=s_buff_size-40; /* Marke für Xon           */
  42.        iorec->ibufhi=s_buff_size-10;  /* Marke für Xoff          */
  43.     return(0);
  44. }
  45.  
  46. int fil_request(void)
  47. {
  48.  return(Bconstat (DEVICE));
  49. }
  50.  
  51. int mdstat(void)
  52. {
  53.  return(Bconstat (DEVICE));
  54. }
  55.  
  56. long   LESE(int len,char *buff)
  57. {
  58. int i=0;
  59. long err1=0;
  60. do 
  61. {
  62.   if (Bconstat(DEVICE)<0)
  63.   {
  64.    buff[i]=(char)Bconin(DEVICE);
  65.    i++;
  66.    err1=0;
  67.   }
  68.   else err1++;
  69. } while ((err1<LESE_ABBRUCH) && (i<len));
  70. if (err1>=LESE_ABBRUCH)  return(err1);
  71.                 else return(0);
  72. }
  73.  
  74.  
  75.  
  76. void MIDEIN(void)
  77. {
  78.   while (Bconstat(DEVICE)<0)
  79.   {
  80.    (void)Bconin(DEVICE);
  81.   }
  82. }
  83.  
  84. static long install_cookies(void)
  85. {
  86.     COOKIE  *cokie;
  87.     long    found=0;
  88.     int        i=16;
  89.         
  90.     cokie=*CJAR;
  91.     if (!cokie)
  92.     {
  93.         *CJAR=cokie=Malloc(i*8);
  94.         if (cokie)
  95.         {
  96.             cokie->tag.aslong = 0;
  97.             cokie->value=i;
  98.         }
  99.     }
  100.     if (cokie) 
  101.     {
  102.         while (cokie->tag.aslong != 0) 
  103.         {
  104.             if (!strncmp(cokie->tag.aschar, "MCDR",4))
  105.             {
  106.                 cokie->value=(long)&port;
  107.                 found=1;
  108.             }
  109.             cokie++;
  110.         }
  111.         if (!found)
  112.         {
  113.             strncpy(cokie->tag.aschar,"MCDR",4);
  114.             found=cokie->value;
  115.             cokie->value=(long) &port;
  116.             cokie++;
  117.             cokie->tag.aslong = 0; 
  118.             cokie->value=found; 
  119.         }
  120.     return(0);
  121.     }
  122.     return(-1);
  123. }
  124.  
  125. void main(void)
  126. {
  127.     Cconws("Schnittstellentreiber\r\n");
  128.     Cconws("    --Seriell--\r\n");
  129.     Cconws("  für MIDI_COM.ACC\r\n");
  130.     (void)Supexec(install_buffers);
  131.     (void)Supexec(install_cookies);
  132.     Ptermres(256L + BP->p_tlen + BP->p_dlen + BP->p_blen, 0);
  133. }