home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / disk22 / forson / sb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-13  |  4.1 KB  |  140 lines

  1. /***************************************
  2. * Agustín Guillén / Solo Programadores *
  3. * Desarrollado por David Welch         *
  4. ***************************************/
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <dos.h>
  9. //#include <malloc.h>
  10. #include <alloc.h>
  11. #include <string.h>
  12. #include <mem.h>
  13.  
  14. void dspwrite ( unsigned char );
  15. unsigned char dspread ( void );
  16. void sbsetup ( void );
  17. void sbsettc ( unsigned char );
  18. void sbhaltdma ( void );
  19. void sbplay ( unsigned short );
  20. void sbrec ( unsigned short );
  21. void spkon ( void );
  22. void spkoff ( void );
  23.  
  24. unsigned char *data;
  25. unsigned char *aligned;
  26. unsigned long aligned_physical;
  27. //------------------------------------------------------------------------------
  28. void dspwrite ( unsigned char c )
  29. {
  30.     while(inportb(0x022C)&0x80);
  31.     outportb(0x022C,c);
  32. }
  33. //------------------------------------------------------------------------------
  34. unsigned char dspread ( void )
  35. {
  36.     while(!(inportb(0x22E)&0x80));
  37.     return(inportb(0x22A));
  38. }
  39. //------------------------------------------------------------------------------
  40. void sbsetup ( void )
  41. {
  42.     unsigned long physical;
  43.     unsigned short x;
  44.     data=(unsigned char *)farmalloc(131000L);
  45.     if(data==NULL)
  46.     {
  47.         printf("Error en la reserva de memoria\n");
  48.         exit(1);
  49.     }
  50.     physical=((unsigned long)FP_OFF(data))+(((unsigned long)FP_SEG(data))<<4);
  51.     aligned_physical=physical+0x0FFFFL;
  52.     aligned_physical&=0xF0000L;
  53.     aligned=(unsigned char *)MK_FP((unsigned )((aligned_physical >> 4) & 0xFFFF),0);
  54.     inportb(0x022E);
  55.     outportb(0x0226,0x01);
  56.     inportb(0x0226);
  57.     inportb(0x0226);
  58.     inportb(0x0226);
  59.     inportb(0x0226);
  60.     outportb(0x0226,0x00);
  61.     for(x=0;x<100;x++)
  62.     {
  63.         if(inportb(0x022E)&0x80)
  64.         {
  65.             if(inportb(0x022A)==0xAA) break;
  66.         }
  67.     }
  68.     if(x==100)
  69.     {
  70.         printf("Sound Blaster no encontrada en la dirección 0220h\n");
  71.         exit(1);
  72.     }
  73. }
  74. //------------------------------------------------------------------------------
  75. void sbsettc ( unsigned char tc )
  76. // tc = constante de tiempo = 256L - (1000000UL/samples por segundo)
  77. {
  78.     inportb(0x022E);
  79.     dspwrite(0x40);
  80.     dspwrite(tc);
  81. }
  82. //------------------------------------------------------------------------------
  83. void sbhaltdma ( void )
  84. {
  85.     dspwrite(0xD0);
  86. }
  87. //------------------------------------------------------------------------------
  88. void spkon ( void )
  89. {
  90.     dspwrite(0xD1);
  91. }
  92. //------------------------------------------------------------------------------
  93. void spkoff ( void )
  94. {
  95.     dspwrite(0xD3);
  96. }
  97. //------------------------------------------------------------------------------
  98. void sbplay ( unsigned short len )
  99. {
  100.     len--;
  101.     outportb(0x0A,0x05);
  102.     outportb(0x0C,0x00);
  103.     outportb(0x0B,0x49);
  104.     outportb(0x02,(unsigned char)(aligned_physical&0xFF));
  105.     outportb(0x02,(unsigned char)((aligned_physical>>8)&0xFF));
  106.     outportb(0x83,(unsigned char)((aligned_physical>>16)&0xFF));
  107.     outportb(0x03,(unsigned char)(len&0xFF));
  108.     outportb(0x03,(unsigned char)((len>>8)&0xFF));
  109.     outportb(0x0A,0x01);
  110.     dspwrite(0x14);
  111.     dspwrite((unsigned char)(len&0xFF));
  112.     dspwrite((unsigned char)((len>>8)&0xFF));
  113. }
  114. //------------------------------------------------------------------------------
  115. void sbrec ( unsigned short len )
  116. {
  117.     len--;
  118.     outportb(0x0A,0x05);
  119.     outportb(0x0C,0x00);
  120.     outportb(0x0B,0x45);
  121.     outportb(0x02,(unsigned char)(aligned_physical&0xFF));
  122.     outportb(0x02,(unsigned char)((aligned_physical>>8)&0xFF));
  123.     outportb(0x83,(unsigned char)((aligned_physical>>16)&0xFF));
  124.     outportb(0x03,(unsigned char)(len&0xFF));
  125.     outportb(0x03,(unsigned char)((len>>8)&0xFF));
  126.     outportb(0x0A,0x01);
  127.     dspwrite(0x24);
  128.     dspwrite((unsigned char)(len&0xFF));
  129.     dspwrite((unsigned char)((len>>8)&0xFF));
  130. }
  131. //------------------------------------------------------------------------------
  132. unsigned short dmacount ( void )
  133. {
  134.     unsigned short x;
  135.     x=inportb(0x03);
  136.     x|=inportb(0x03)<<8;
  137.     if(x==0xFFFF) inportb(0x022E);
  138.     return(x);
  139. }
  140.