home *** CD-ROM | disk | FTP | other *** search
/ PC Loisirs 18 / cd.iso / sharewar / mikm202 / source / drvsb / sbio.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-18  |  2.3 KB  |  163 lines

  1. /*
  2.     Basic Soundblaster access & detection routines
  3.     ==============================================
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <dos.h>
  9. #include <conio.h>
  10. #include "mtypes.h"
  11. #include "sbio.h"
  12. #include "mdriver.h"
  13.  
  14.  
  15.  
  16.  
  17. void SB_MixerStereo(void)
  18. /*
  19.     Enables stereo output for DSP versions 3.00 >= ver < 4.00
  20. */
  21. {
  22.     outportb(MIXER_ADDRESS,0xe);
  23.     outportb(MIXER_DATA,inportb(MIXER_DATA)|2);
  24. }
  25.  
  26.  
  27.  
  28. void SB_MixerMono(void)
  29. /*
  30.     Disables stereo output for DSP versions 3.00 >= ver < 4.00
  31. */
  32. {
  33.     outportb(MIXER_ADDRESS,0xe);
  34.     outportb(MIXER_DATA,inportb(MIXER_DATA)&0xfd);
  35. }
  36.  
  37.  
  38.  
  39. BOOL SB_WaitDSPWrite(void)
  40. /*
  41.     Waits until the DSP is ready to be written to.
  42.  
  43.     returns FALSE on timeout
  44. */
  45. {
  46.     UWORD timeout=32767;
  47.  
  48.     while(timeout--){
  49.         if(!(inportb(DSP_WRITE_STATUS)&0x80)) return 1;
  50.     }
  51.     return 0;
  52. }
  53.  
  54.  
  55.  
  56. BOOL SB_WaitDSPRead(void)
  57. /*
  58.     Waits until the DSP is ready to read from.
  59.  
  60.     returns FALSE on timeout
  61. */
  62. {
  63.     UWORD timeout=32767;
  64.  
  65.     while(timeout--){
  66.         if(inportb(DSP_DATA_AVAIL)&0x80) return 1;
  67.     }
  68.     return 0;
  69. }
  70.  
  71.  
  72.  
  73. BOOL SB_WriteDSP(UBYTE data)
  74. /*
  75.     Writes byte 'data' to the DSP.
  76.  
  77.     returns FALSE on timeout.
  78. */
  79. {
  80.     if(!SB_WaitDSPWrite()) return 0;
  81.     outportb(DSP_WRITE_DATA,data);
  82.     return 1;
  83. }
  84.  
  85.  
  86.  
  87. UWORD SB_ReadDSP(void)
  88. /*
  89.     Reads a byte from the DSP.
  90.  
  91.     returns 0xffff on timeout.
  92. */
  93. {
  94.     if(!SB_WaitDSPRead()) return 0xffff;
  95.     return(inportb(DSP_READ_DATA));
  96. }
  97.  
  98.  
  99.  
  100. void SB_SpeakerOn(void)
  101. /*
  102.     Enables DAC speaker output.
  103. */
  104. {
  105.     SB_WriteDSP(0xd1);
  106. }
  107.  
  108.  
  109.  
  110. void SB_SpeakerOff(void)
  111. /*
  112.     Disables DAC speaker output
  113. */
  114. {
  115.     SB_WriteDSP(0xd3);
  116. }
  117.  
  118.  
  119.  
  120. void SB_ResetDSP(void)
  121. /*
  122.     Resets the DSP.
  123. */
  124. {
  125.     int t;
  126.     // reset the DSP by sending 1, (delay), then 0
  127.     outportb(DSP_RESET,1);
  128.     for(t=0;t<8;t++) inportb(DSP_RESET);
  129.     outportb(DSP_RESET,0);
  130. }
  131.  
  132.  
  133.  
  134. BOOL SB_Ping(void)
  135. /*
  136.     Checks if a SB is present at the current baseport by
  137.     resetting the DSP and checking if it returned the value 0xaa.
  138.  
  139.     returns: TRUE   => SB is present
  140.              FALSE  => No SB detected
  141. */
  142. {
  143.     SB_ResetDSP();
  144.     return(SB_ReadDSP()==0xaa);
  145. }
  146.  
  147.  
  148.  
  149. UWORD SB_GetDSPVersion(void)
  150. /*
  151.     Gets SB-dsp version. returns 0xffff if dsp didn't respond.
  152. */
  153. {
  154.     UWORD hi,lo;
  155.  
  156.     if(!SB_WriteDSP(0xe1)) return 0xffff;
  157.  
  158.     hi=SB_ReadDSP();
  159.     lo=SB_ReadDSP();
  160.  
  161.     return((hi<<8)|lo);
  162. }
  163.