home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / sound / diverse / dsp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-20  |  1.3 KB  |  44 lines

  1. // DSP.CPP (Visual C++ 1.00) -- Plays sound on DSP in "direct 8 bit DAC mode"
  2. // Needs Soundblaster-compatible card at 0220h
  3.  
  4. #include <stdio.h>
  5. #include <conio.h>
  6. #include <dos.h>
  7.  
  8. void Play() {
  9.   printf("Press a key to stop...\n");
  10.   while (_inp(0x022C) & 0x80);    // ready to recieve command?
  11.   _outp(0x022C, 0xD1);            // speaker on
  12.   while(!_kbhit()) {
  13.     static int i;
  14.     while (_inp(0x022C) & 0x80);  // ready to recieve command?
  15.     _outp(0x022C, 0x10);          // direct 8 bit DAC mode
  16.     while (_inp(0x022C) & 0x80);  // ready to recieve data?
  17.     _outp(0x022C, i);             // send data
  18.     i += 4;
  19.   }
  20.   _bdos(0x0C, 0, 0);              // throw away the key
  21. }
  22.  
  23. int main() {
  24.   _bdos(0x0D, 0, 0);              // SOS (save our source)
  25.   _outp(0x0226, 1);               // reset = 1
  26.   for (int i = 0; i < 3 * 2; i++) {
  27.     _inp(0x61);                   // wait 3 us
  28.   }
  29.   _outp(0x0226, 0);               // reset = 0
  30.   for (i = 0; i < 100; i++) {
  31.     if (_inp(0x022E) & 0x80) {    // data available?
  32.       if (_inp(0x022A) == 0xAA) { // DSP ready?
  33.         Play();
  34.         return 0;
  35.       } else {
  36.         printf("DSP reset error\n");
  37.         return 1;
  38.       }
  39.     }
  40.   }
  41.   printf("DSP not found at 0220h\n");
  42.   return 1;
  43. }
  44.