home *** CD-ROM | disk | FTP | other *** search
- // Copyright 1993, Mark T. Pflaging
- // Implementation for class SoundBlaster.
- //
- // Portions were borrowed from Jeff Bird's (cejjb@marlin.jcu.edu.au)
- // Sound Blaster Freedom routines dated 12 Feb 92
- //
- #include "sb.hpp"
-
- #include <string.h>
- #include <ctype.h>
-
- SoundBlaster::SoundBlaster() : IOaddr(0x220), IRQ(7), DMAchan(1), Type(SBPro)
- {
- // Set arguments to reasonable values (Soundblaster defaults)
- if(!Get_Params()) {
- cerr << "BLASTER environment variable not set." << endl;
- // exit(1);
- Type = NULL;
- return;
- }
-
- if(!Reset()) {
- cerr << "Could not find Soundblaster!" << endl;
- // exit(1);
- Type = NULL;
- return;
- }
- cout << "Found Soundblaster at address " << hex << IOaddr << dec
- << ", IRQ " << IRQ << ", DMA " << DMAchan
- << "." << endl;
- }
-
- // Reset() returns True if successful!
- Boolean SoundBlaster::Reset()
- {
- unsigned myport = IOaddr + 6;
- outportb(myport, 1);
- inportb(myport);
- inportb(myport);
- inportb(myport);
- inportb(myport);
- outportb(myport, 0);
- myport += 4;
- int count = 100;
- Boolean found = False;
- while (count) {
- if (inportb(myport) == 0xAA) {
- found = True;
- break;
- }
- count --;
- }
- return found;
- }
-
- Boolean SoundBlaster::Get_Params()
- {
- char *t, *t1, *blaster;
-
-
- // Attempt to read environment variable
- t = getenv("BLASTER");
-
- // Is the environment variable set?
- if(t == NULL)
- return False;
-
- // Duplicate the string so that we don't trash our environment
- blaster = strdup(t);
-
- // Now parse the BLASTER variable
- t = strtok(blaster," \t");
- while(t)
- {
- switch(toupper(t[0]))
- {
- case 'A': // I/O address
- IOaddr = (int)strtol(t+1,&t1,16);
- break;
- case 'I': // Hardware IRQ
- IRQ = atoi(t+1);
- break;
- case 'D': // DMA channel
- DMAchan = atoi(t+1);
- break;
- case 'T': // Soundblaster type
- Type = atoi(t+1);
- break;
- default:
- cout << "Unknown BLASTER option " << t[0] << "." << endl;
- break;
- }
- t = strtok(NULL," \t");
- }
- free(blaster);
- return True;
- }
-