home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / MIDICOM.LZH / MC_DRIVE.R / DRIVER.MID / MC_DRIVE.C next >
C/C++ Source or Header  |  1993-10-23  |  2KB  |  130 lines

  1. #include <tos.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #include "mc_drive.h"
  6.  
  7. typedef struct
  8. {
  9.   char  *ibuf;  /* Zeiger auf den buffer */
  10.   int   size;    /* groesse des Buffers   */
  11.   int   nw;    /* naechste Leseposition    */
  12.   int   nl;    /* naechste Schreibposition */
  13.   int   blow;    /* untere Wassermarke       */
  14.   int   bhig;    /* obere Wassermarke        */
  15. } io_rec;
  16.  
  17. /* header file for dealing with the cookie jar */
  18. #define BP _BasPag
  19.  
  20. char            midi_buf[25000];
  21. io_rec             *midi_io={NULL};
  22. extern long        INTC;
  23.  
  24. io_rec *INSTALL(long size,char *buff);
  25.  
  26. static void MSEND(int LEN,char *buff);
  27. static void MIDEIN(void);
  28.  
  29. int mdstat(void)
  30. {
  31.  int nl,nw;
  32.  nl=midi_io->nl; nw=midi_io->nw;
  33.  if ((INTC!=0) || (nl!=nw)) return(-1);
  34.  else return(0);
  35. }
  36.  
  37. int fil_request(void)
  38. {
  39.  int nl,nw,size;
  40.  long fuellung;
  41.  
  42.  nl=midi_io->nl; nw=midi_io->nw;
  43.  
  44.  if ((INTC==0) && (nl==nw)) return(0);
  45.  else
  46.  {
  47.     size=midi_io->ibuf[++nw];
  48.     size<<=8;
  49.     size|=midi_io->ibuf[++nw];
  50.     if ((size<24) || (size>4400)) return(1);
  51.  
  52.     fuellung=(nw<nl) ? (nl-nw) :(midi_io->size-nw+nl);
  53.     if (fuellung>(size-10)) return(1);
  54.     else return(0);
  55.  }
  56. }
  57.  
  58. long   LESE(int len,char *buff)
  59. {
  60. int i=0;
  61. long err1=0,err2=0;
  62.  
  63. do 
  64. {
  65.     if (midi_io->nw!=midi_io->nl)
  66.     {
  67.         midi_io->nw++;
  68.         if (midi_io->nw==midi_io->size) midi_io->nw=0;
  69.         buff[i]=midi_io->ibuf[midi_io->nw];
  70.         i++;
  71.         err1=0;
  72.     }
  73.     else err1++;
  74. } while ((err1<500) && (i<len));
  75.  
  76. err2=INTC;
  77. if ((err1>=500) || (err2!=0)) return(err1|err2);
  78.                               else return(0);
  79.  
  80. static long install_cookies(void)
  81. {
  82.     COOKIE  *cokie;
  83.     long    found=0;
  84.     int        i=16;
  85.         
  86.     cokie=*CJAR;
  87.     if (!cokie)
  88.     {
  89.         *CJAR=cokie=Malloc(i*8);
  90.         if (cokie)
  91.         {
  92.             cokie->tag.aslong = 0;
  93.             cokie->value=i;
  94.         }
  95.     }
  96.     if (cokie) 
  97.     {
  98.         while (cokie->tag.aslong != 0) 
  99.         {
  100.             if (!strncmp(cokie->tag.aschar, "MCDR",4))
  101.             {
  102.                 cokie->value=(long)&port;
  103.                 found=1;
  104.             }
  105.             cokie++;
  106.         }
  107.         if (!found)
  108.         {
  109.             strncpy(cokie->tag.aschar,"MCDR",4);
  110.             found=cokie->value;
  111.             cokie->value=(long) &port;
  112.             cokie++;
  113.             cokie->tag.aslong = 0; 
  114.             cokie->value=found; 
  115.         }
  116.     return(0);
  117.     }
  118.     return(-1);
  119. }
  120.  
  121. void main(void)
  122. {
  123.     Cconws("Schnittstellentreiber\r\n");
  124.     Cconws("     --MIDI--\r\n");
  125.     Cconws("  für MIDI_COM.ACC\r\n");
  126.     midi_io=INSTALL(sizeof(midi_buf),midi_buf);
  127.     (void)Supexec(install_cookies);
  128.     Ptermres(256L + BP->p_tlen + BP->p_dlen + BP->p_blen, 0);
  129. }