home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / src_cpp / src / blaster.cpp next >
Encoding:
C/C++ Source or Header  |  1993-08-14  |  2.2 KB  |  98 lines

  1. // Copyright 1993, Mark T. Pflaging
  2. // Implementation for class SoundBlaster.
  3. //
  4. // Portions were borrowed from Jeff Bird's (cejjb@marlin.jcu.edu.au)
  5. // Sound Blaster Freedom routines dated    12 Feb 92
  6. //
  7. #include "sb.hpp"
  8.  
  9. #include <string.h>
  10. #include <ctype.h>
  11.  
  12. SoundBlaster::SoundBlaster() : IOaddr(0x220), IRQ(7), DMAchan(1), Type(SBPro)
  13. {
  14.     // Set arguments to reasonable values (Soundblaster defaults)
  15.     if(!Get_Params()) {
  16.         cerr << "BLASTER environment variable not set." << endl;
  17. //        exit(1);
  18.         Type = NULL;
  19.         return;
  20.     }
  21.  
  22.     if(!Reset()) {
  23.         cerr << "Could not find Soundblaster!" << endl;
  24. //        exit(1);
  25.         Type = NULL;
  26.         return;
  27.     }
  28.     cout << "Found Soundblaster at address " << hex << IOaddr << dec
  29.         << ", IRQ " << IRQ << ", DMA " << DMAchan
  30.         << "." << endl;
  31. }
  32.  
  33. // Reset() returns True if successful!
  34. Boolean SoundBlaster::Reset()
  35. {
  36.     unsigned myport = IOaddr + 6;
  37.     outportb(myport, 1);
  38.     inportb(myport);
  39.     inportb(myport);
  40.     inportb(myport);
  41.     inportb(myport);
  42.     outportb(myport, 0);
  43.     myport += 4;
  44.     int count = 100;
  45.     Boolean found = False;
  46.     while (count) {
  47.         if (inportb(myport) == 0xAA) {
  48.             found = True;
  49.             break;
  50.         }
  51.         count --;
  52.     }
  53.     return found;
  54. }
  55.  
  56. Boolean SoundBlaster::Get_Params()
  57. {
  58.     char *t, *t1, *blaster;
  59.  
  60.  
  61.     // Attempt to read environment variable
  62.     t = getenv("BLASTER");
  63.  
  64.     // Is the environment variable set?
  65.     if(t == NULL)
  66.     return False;
  67.  
  68.     // Duplicate the string so that we don't trash our environment
  69.     blaster = strdup(t);
  70.  
  71.     // Now parse the BLASTER variable
  72.     t = strtok(blaster," \t");
  73.     while(t)
  74.     {
  75.     switch(toupper(t[0]))
  76.     {
  77.         case 'A':                               // I/O address
  78.         IOaddr = (int)strtol(t+1,&t1,16);
  79.         break;
  80.         case 'I':                               // Hardware IRQ
  81.         IRQ = atoi(t+1);
  82.         break;
  83.         case 'D':                               // DMA channel
  84.         DMAchan = atoi(t+1);
  85.         break;
  86.         case 'T':                               // Soundblaster type
  87.         Type = atoi(t+1);
  88.         break;
  89.         default:
  90.         cout << "Unknown BLASTER option " << t[0] << "." << endl;
  91.         break;
  92.     }
  93.     t = strtok(NULL," \t");
  94.     }
  95.     free(blaster);
  96.     return True;
  97. }
  98.