Annotation of src/whsndmod.c, revision 1.1

1.1     ! root        1: #define  SND_CALLER
        !             2: #define  GAME
        !             3: #include <malloc.h>
        !             4: #include "sos.h"
        !             5: #include "sosm.h"
        !             6: #include "icorp.h"
        !             7: #include <memcheck.h>
        !             8: 
        !             9: int  readfile(int, char *, long);
        !            10: #pragma aux readfile =\
        !            11:        "mov  ah,0x3f",\
        !            12:        "int 0x21",\
        !            13:        parm [ebx] [edx] [ecx]\
        !            14:        modify [eax];
        !            15: 
        !            16: 
        !            17: int  flag = 0;
        !            18: 
        !            19: extern int displaytime;
        !            20: 
        !            21: //JSA SPOOGE
        !            22: extern int musiclevel;
        !            23: extern int digilevel;
        !            24: extern int loopinstuff;
        !            25: extern int enchantedsoundhandle;
        !            26: 
        !            27: // local data for hmi INI
        !            28: static PSTR szHexNumbers = "0123456789ABCDEF";
        !            29: static WORD wMultiplier[] = {1, 16, 256, 4096, 65536, 1048576, 16777216, 268435456};
        !            30: // local function prototypes
        !            31: WORD hmiINIHex2Decimal(PSTR szHexValue);
        !            32: WORD hmiINIGetHexIndex(BYTE bValue);
        !            33: 
        !            34: //TEMP!!
        !            35: volatile unsigned joetime;
        !            36: 
        !            37: //krapo
        !            38: 
        !            39: #define  NUMLEVELS      17
        !            40: #define  SONGSPERLEVEL  4
        !            41: 
        !            42: typedef struct {
        !            43:      HANDLE hMIDISong;             // if != -1 then the file is playing
        !            44:      long offset;
        !            45:      long cache_ptr;
        !            46:      long cache_length;
        !            47:      char cache_lock;
        !            48: }    songbuffertype;
        !            49: songbuffertype sngbuf[NUMLEVELS][SONGSPERLEVEL];
        !            50: songbuffertype *sngbufptr[NUMLEVELS][SONGSPERLEVEL];
        !            51: 
        !            52: _SOS_MIDI_INIT_SONG hmiSongStructs[SONGSPERLEVEL];
        !            53: 
        !            54: extern int mapon;
        !            55: 
        !            56: int  oldsong = 0;
        !            57: 
        !            58: //****************
        !            59: //   CODE STARTS *
        !            60: //****************
        !            61: 
        !            62: 
        !            63: //
        !            64: //   Temporary method for storing a song in memory.
        !            65: 
        !            66: //mark
        !            67: 
        !            68: BOOL 
        !            69: loadlevelsongs(int which)
        !            70: {
        !            71:      int  i,
        !            72:           bytesread = 0;
        !            73: 
        !            74:      if (!MusicMode)
        !            75:           return (0);
        !            76: 
        !            77:      for (i = 0; i < SONGSPERLEVEL; i++) {
        !            78:           // set lock and try to allocate cache
        !            79:           sngbufptr[which][i]->cache_lock = 200;
        !            80:           allocache(&(sngbufptr[which][i]->cache_ptr), sngbufptr[which][i]->cache_length, &(sngbufptr[which][i]->cache_lock));
        !            81: 
        !            82: #if USINGALLOCATEPERMANENTTILE
        !            83:           sngbufptr[which][i]->cache_ptr = (void *) malloc(sngbufptr[which][i]->cache_length);
        !            84:           if (sngbufptr[which][i]->cache_ptr == _NULL)
        !            85: #endif
        !            86:                if (sngbufptr[which][i]->cache_ptr == 0L) {
        !            87:                     sngbufptr[which][i]->cache_lock = 0x00;
        !            88:                     return (0);
        !            89:                }
        !            90: 
        !            91:           // read data from file
        !            92:           lseek(hSongFile, sngbufptr[which][i]->offset, SEEK_SET);
        !            93:           bytesread = read(hSongFile, (void *) sngbufptr[which][i]->cache_ptr, sngbufptr[which][i]->cache_length);
        !            94:           if (bytesread != sngbufptr[which][i]->cache_length) {
        !            95:                sngbufptr[which][i]->cache_ptr = 0L;
        !            96:                sngbufptr[which][i]->cache_lock = 0x00;
        !            97:                return (0);
        !            98:           }
        !            99: 
        !           100:           // reset song structure
        !           101:           // memset( hmiSongStructs[i], 0, sizeof( _SOS_MIDI_INIT_SONG ) );
        !           102: 
        !           103:           // set up song structure
        !           104:           hmiSongStructs[i].lpSongData = (LPSTR) sngbufptr[which][i]->cache_ptr;
        !           105:           if (sosMIDIInitSong(&(hmiSongStructs[i]), &sSOSTrackMap[i], &(sngbufptr[which][i]->hMIDISong))) {
        !           106:                // return error "startsong() : sosMIDIInitSong failed!"
        !           107:                return (0);
        !           108:           }
        !           109:           hmiSongStructs[i].lpSongCallback = sosMIDISongCallback;
        !           110:      }
        !           111: 
        !           112:      oldsong = which;
        !           113: 
        !           114:      return (1);
        !           115: }
        !           116: 
        !           117: 
        !           118: VOID
        !           119: _far sosMIDISongCallback(WORD hSong)
        !           120: {
        !           121:      int  i;
        !           122: 
        !           123:      if (attacktheme) {
        !           124:           for (i = 0; i < SONGSPERLEVEL; i++) {
        !           125:                if (hSong == sngbufptr[oldsong][i]->hMIDISong) {
        !           126:                     sosMIDIResetSong(sngbufptr[oldsong][i]->hMIDISong, &hmiSongStructs[i]);
        !           127:                }
        !           128:           }
        !           129:           startsong(rand() % 2);
        !           130:           attacktheme = 0;
        !           131:      }
        !           132: 
        !           133: }
        !           134: 
        !           135: 
        !           136: BOOL 
        !           137: startsong(WORD which)
        !           138: {
        !           139:      int  i;
        !           140: 
        !           141:      if (!MusicMode)
        !           142:           return (0);
        !           143: 
        !           144:      // check to see if songs are playing and stop/fade if necessary
        !           145:      for (i = 0; i < SONGSPERLEVEL; i++) {
        !           146:           if (!sosMIDISongDone(sngbufptr[oldsong][i]->hMIDISong)) {
        !           147:                sosMIDIStopSong(sngbufptr[oldsong][i]->hMIDISong);
        !           148:                // sosMIDIUnInitSong(sngbufptr[oldsong][i]->hMIDISong);
        !           149:                // sngbufptr[oldsong][i]->hMIDISong=-1;
        !           150:           }
        !           151:      }
        !           152: 
        !           153: 
        !           154:      if ((wError = sosMIDIStartSong(sngbufptr[oldsong][which]->hMIDISong))) {
        !           155:           // return error "startsong() : sosMIDIStartSong failed!"
        !           156:           return (0);
        !           157:      }
        !           158:      // sprintf(displaybuf,"playing song %d", which);
        !           159:      // displaytime=250;
        !           160: 
        !           161:      if (which < 2)
        !           162:           attacktheme = 0;
        !           163: 
        !           164:      return (1);
        !           165: }
        !           166: //krapo
        !           167: 
        !           168: void 
        !           169: dolevelmusic(int which)
        !           170: {
        !           171:      int  i,
        !           172:           temp;
        !           173: 
        !           174:      if (!MusicMode)
        !           175:           return;
        !           176: 
        !           177:      if (which < 0 || which > NUMLEVELS-1) {
        !           178:           which=0;
        !           179:      }
        !           180: 
        !           181:      // check to see if songs are playing and stop/fade if necessary
        !           182:      for (i = 0; i < SONGSPERLEVEL; i++) {
        !           183:           if (!sosMIDISongDone(sngbufptr[oldsong][i]->hMIDISong)) {
        !           184:                sosMIDIStopSong(sngbufptr[oldsong][i]->hMIDISong);
        !           185:                // sosMIDIUnInitSong(sngbufptr[oldsong][i]->hMIDISong);
        !           186:                // sngbufptr[oldsong][i]->hMIDISong=-1;
        !           187:           }
        !           188:           if (which != 16)
        !           189:                sosMIDIUnInitSong(sngbufptr[oldsong][i]->hMIDISong);
        !           190:           sngbufptr[oldsong][i]->hMIDISong = -1;
        !           191:           sngbufptr[oldsong][i]->cache_lock = 0;
        !           192:      }
        !           193: 
        !           194:      loadlevelsongs(which);
        !           195:      startsong(0);
        !           196: }
        !           197: 
        !           198: 
        !           199: VOID
        !           200: SND_MenuMusic(void)
        !           201: {
        !           202:      // 15 levels the sixteenth set is the menu song!
        !           203:      dolevelmusic(NUMLEVELS - 1);
        !           204: }
        !           205: 
        !           206: 
        !           207: //
        !           208: //                         INTERNAL ROUTINES
        !           209: //
        !           210: 
        !           211: //////////////////////////////////////////////////////////////////////////////
        !           212: //                                                                          //
        !           213: //    SND_InitSOSTimer() : Registers the timerevent() function to be        //
        !           214: //          called by SOS.                                                  //
        !           215: //                                                                          //
        !           216: //////////////////////////////////////////////////////////////////////////////
        !           217: VOID
        !           218: SND_InitSOSTimer(VOID)
        !           219: {
        !           220:      if ((wError = sosTIMERRegisterEvent(120, (VOID(far *)) timerevent, &hTimerT_ClockHandle))) {
        !           221:           sosTIMERUnInitSystem(0);
        !           222:           sosDIGIUnInitSystem();
        !           223:           crash("TIMER FAILURE!");
        !           224:      }
        !           225: }
        !           226: 
        !           227: //////////////////////////////////////////////////////////////////////////////
        !           228: //                                                                          //
        !           229: //    timerevent() : Handles timer functions originally in game.c           //
        !           230: //                                                                          //
        !           231: //////////////////////////////////////////////////////////////////////////////
        !           232: VOID
        !           233: _far _loadds timerevent(VOID)
        !           234: {
        !           235:      joetime++;
        !           236:      totalclock++;
        !           237:      keytimerstuff();
        !           238: 
        !           239: 
        !           240: }
        !           241: 
        !           242: 
        !           243: //////////////////////////////////////////////////////////////////////////////
        !           244: //                                                                          //
        !           245: //    sosDIGISampleCallback(WORD,WORD,WORD) : Call back routine from SOS    //
        !           246: //          Digi functions. wCallSource indicates which process is complete //
        !           247: //          hSample is the particular sample handle.                        //
        !           248: //                                                                          //
        !           249: //////////////////////////////////////////////////////////////////////////////
        !           250: VOID
        !           251: _far cdecl sosDIGISampleCallback(WORD wDriverHandle, WORD wCallSource, WORD hSample)
        !           252: {
        !           253: //
        !           254: // recording driver will also use this callback for future!
        !           255: // will have to switch wDriverHandle as well...
        !           256: //
        !           257: 
        !           258:      switch (wCallSource) {
        !           259:      case _SAMPLE_DONE:
        !           260:           for (wIndex = 0; wIndex < MAX_ACTIVE_SAMPLES; wIndex++)
        !           261:                if (hSample == SampleRay[wIndex].SOSHandle)
        !           262:                     break;
        !           263:           sSOSSampleData[wIndex].wLoopCount = 0;
        !           264:           sSOSSampleData[wIndex].dwSampleSize = 0;
        !           265:           SampleRay[wIndex].SOSHandle = -1;
        !           266:           SampleRay[wIndex].playing = 0;
        !           267:           SampleRay[wIndex].priority = 0;
        !           268:           SampleRay[wIndex].number = -1;
        !           269:           break;
        !           270: 
        !           271:      }
        !           272: 
        !           273: }
        !           274: 
        !           275: 
        !           276: 
        !           277: 
        !           278: VOID
        !           279: SND_SetupTables(VOID)
        !           280: {
        !           281:      int  i,
        !           282:           j,
        !           283:           listindex = 0;
        !           284: 
        !           285: 
        !           286:      if (SoundMode) {
        !           287:           hSoundFile = open("JOESND", O_RDONLY | O_BINARY);
        !           288:           if (hSoundFile == -1) {
        !           289:                crash("COULDN'T OPEN JOESND!");
        !           290:           }
        !           291:           DigiList = malloc(0x1000);
        !           292:           if (DigiList == NULL) {
        !           293:                crash("malloc failed for DigiList");
        !           294:           }
        !           295:           lseek(hSoundFile, -4096L, SEEK_END);
        !           296:           readfile(hSoundFile, (void *) FP_OFF(DigiList), 4096);
        !           297:      }
        !           298: 
        !           299:      if (MusicMode) {
        !           300:           if (sMIDIHardware.wPort == 0x388) {
        !           301:                hSongFile = open("F_SONGS", O_RDONLY | O_BINARY);
        !           302:           }
        !           303:           else {
        !           304:                hSongFile = open("W_SONGS", O_RDONLY | O_BINARY);
        !           305:           }
        !           306: 
        !           307:           if (hSongFile == -1) {
        !           308:                crash("COULDN'T OPEN SONGS!");
        !           309:           }
        !           310:           SongList = malloc(0x1000);
        !           311:           if (SongList == NULL) {
        !           312:                crash("malloc failed for SongList");
        !           313:           }
        !           314:           lseek(hSongFile, -4096L, SEEK_END);
        !           315:           readfile(hSongFile, (void *) FP_OFF(SongList), 4096);
        !           316:      }
        !           317: 
        !           318:      // setup offset and length of all songs
        !           319:      for (i = 0; i < NUMLEVELS; i++) {
        !           320:           for (j = 0; j < SONGSPERLEVEL; j++) {
        !           321:                sngbufptr[i][j] = &sngbuf[i][j];
        !           322:                sngbufptr[i][j]->hMIDISong = -1;
        !           323:                sngbufptr[i][j]->offset = (SongList[listindex * 3] * 4096L);
        !           324:                sngbufptr[i][j]->cache_ptr = 0L;
        !           325:                sngbufptr[i][j]->cache_length = (WORD) (SongList[listindex * 3 + 1]);
        !           326:                sngbufptr[i][j]->cache_lock = 0x00;
        !           327:                listindex++;
        !           328:           }
        !           329:      }
        !           330: 
        !           331: 
        !           332:      return;
        !           333: }
        !           334: 
        !           335: 
        !           336: 
        !           337: //////////////////////////////////////////////////////////////////////////////
        !           338: //                                                                          //
        !           339: //    SND_LoadMidiIns(void) : Read melodic and percussive banks into mem.   //
        !           340: //          Conditional : GENERAL MIDI and WAVE synths don't need patches   //
        !           341: //                                                                          //
        !           342: //////////////////////////////////////////////////////////////////////////////
        !           343: void
        !           344: SND_LoadMidiIns(void)
        !           345: {
        !           346:      static WORD wLength;
        !           347: 
        !           348: //JSA_DEMO check port address to verify FM device
        !           349: 
        !           350:      if ((MusicMode == _STANDARD_MUSIC || MusicMode == _DIG_MIDI_MUSIC) &&
        !           351:          sMIDIHardware.wPort == 0x388) {
        !           352: //              (wMIDIDeviceID != _MIDI_MPU_401 && wMIDIDeviceID != _MIDI_MT_32
        !           353: //                  && wMIDIDeviceID!=_MIDI_AWE32) ) {
        !           354:           hMiscHandle = open("melodic.bnk", O_RDONLY);
        !           355:           if (hMiscHandle == -1)
        !           356:                crash("MELODIC BANK FILE FAILED!");
        !           357:           m_bnkptr = malloc(0x152c);
        !           358:           if (m_bnkptr == NULL) {
        !           359:                crash("malloc failed for m_bnkptr");
        !           360:           }
        !           361:           read(hMiscHandle, (void *) FP_OFF(m_bnkptr), 0x152c);
        !           362:           close(hMiscHandle);
        !           363:           if ((wError = sosMIDISetInsData(hSOSDriverHandles[MIDI], m_bnkptr, 0x00)))
        !           364:                crash("BAD SetInsData MEL!");
        !           365: 
        !           366:           hMiscHandle = open("drum.bnk", O_RDONLY);
        !           367:           if (hMiscHandle == -1)
        !           368:                crash("PERCUSSIVE BANK FILE FAILED!");
        !           369:           d_bnkptr = malloc(0x152c);
        !           370:           if (d_bnkptr == NULL) {
        !           371:                crash("malloc failed for d_bnkptr");
        !           372:           }
        !           373:           read(hMiscHandle, (void *) FP_OFF(d_bnkptr), 0x152c);
        !           374:           close(hMiscHandle);
        !           375:           if ((wError = sosMIDISetInsData(hSOSDriverHandles[MIDI], d_bnkptr, 0x00)))
        !           376:                printf("BAD SetInsData DRUM!");
        !           377:      }
        !           378: 
        !           379:      if (MusicMode == _DIG_MIDI_MUSIC) {
        !           380:           hMiscHandle = open("test.dig", O_RDONLY);
        !           381:           if (hMiscHandle == -1)
        !           382:                crash("DIGI_MIDI FILE FAILED!");
        !           383:           wLength = lseek(hMiscHandle, 0L, SEEK_END);
        !           384:           lseek(hMiscHandle, 0L, SEEK_SET);
        !           385:           digi_bnkptr = malloc(wLength);
        !           386:           if (digi_bnkptr == NULL) {
        !           387:                crash("malloc failed for digi_bnkptr");
        !           388:           }
        !           389:           read(hMiscHandle, (void *) FP_OFF(digi_bnkptr), wLength);
        !           390:           close(hMiscHandle);
        !           391:           if ((wError = sosMIDISetInsData(hSOSDriverHandles[DIG_MIDI], digi_bnkptr, 0x00)))
        !           392:                crash("BAD SetInsData digmidi!");
        !           393:      }
        !           394: }
        !           395: 
        !           396: //
        !           397: //                         PUBLIC ROUTINES
        !           398: //
        !           399: 
        !           400: 
        !           401: 
        !           402: VOID
        !           403: SND_DoBuffers(void)
        !           404: {
        !           405: 
        !           406: 
        !           407:      for (wIndex = 0; wIndex < MAX_ACTIVE_SAMPLES; wIndex++) {
        !           408:           sSOSSampleData[wIndex].lpSamplePtr = (LPSTR) malloc((long) 55000);
        !           409:           if (sSOSSampleData[wIndex].lpSamplePtr == _NULL)
        !           410:                crash("Could Not get a Sound Buffer!!");
        !           411:      }
        !           412: 
        !           413: }
        !           414: 
        !           415: VOID
        !           416: SND_UnDoBuffers(void)
        !           417: {
        !           418: 
        !           419:      for (wIndex = 0; wIndex < MAX_ACTIVE_SAMPLES; wIndex++) {
        !           420:           if (sSOSSampleData[wIndex].lpSamplePtr != NULL)
        !           421:                free((void *) FP_OFF(sSOSSampleData[wIndex].lpSamplePtr));
        !           422:      }
        !           423: 
        !           424: }
        !           425: 
        !           426: 
        !           427: //////////////////////////////////////////////////////////////////////////////
        !           428: //                                                                          //
        !           429: //       SND_Startup() : Initialize all SOS Drivers and start timer         //
        !           430: //             service.                                                     //
        !           431: //                                                                          //
        !           432: //////////////////////////////////////////////////////////////////////////////
        !           433: 
        !           434: extern
        !           435: _SOS_HARDWARE sDIGISettings;
        !           436: extern
        !           437: _SOS_MIDI_HARDWARE sMIDISettings;
        !           438: extern
        !           439: WORD wDIGIDevice,
        !           440:      wMIDIDevice;
        !           441: 
        !           442: VOID
        !           443: SND_Startup(VOID)
        !           444: {
        !           445: 
        !           446:      if (SD_Started)
        !           447:           return;
        !           448: 
        !           449:      wDIGIDeviceID = wDIGIDevice;
        !           450:      wMIDIDeviceID = wMIDIDevice;
        !           451:      memmove(&sDIGIHardware, &sDIGISettings, sizeof(sDIGIHardware));
        !           452:      memmove(&sMIDIHardware, &sMIDISettings, sizeof(sMIDIHardware));
        !           453: 
        !           454: //GET Volume values
        !           455:      wMIDIVol = (musiclevel << 3);
        !           456:      wDIGIVol = (digilevel << 11);
        !           457: 
        !           458: 
        !           459: //TIMERSYSTEM
        !           460: 
        !           461:      wError = sosTIMERInitSystem(_TIMER_DOS_RATE, _SOS_DEBUG_NORMAL);
        !           462:      if (wError != _ERR_NO_ERROR)
        !           463:           crash("Problem with Timer SysInit!");
        !           464: 
        !           465:      SND_InitSOSTimer();
        !           466: 
        !           467:      hSOSDriverHandles[DIGI] = -1;
        !           468:      hSOSDriverHandles[MIDI] = -1;
        !           469: 
        !           470:      if (wDIGIDeviceID == 0xffffffff)
        !           471:           SoundMode = _OFF;
        !           472:      if (wMIDIDeviceID == 0xffffffff)
        !           473:           MusicMode = _OFF;
        !           474: 
        !           475: //DIGISYSTEM
        !           476: 
        !           477:      if (SoundMode == _ON) {       // && wDIGIDeviceID!=0xffffffff) {
        !           478:           wError = sosDIGIInitSystem(_NULL, _SOS_DEBUG_NORMAL);
        !           479:           if (wError != _ERR_NO_ERROR)
        !           480:                crash("Error on Digi SysInit!");
        !           481:      }
        !           482: 
        !           483: //MIDISYSTEM
        !           484:      if (MusicMode == _STANDARD_MUSIC) {
        !           485:           if (wError = sosMIDIInitSystem(_NULL, _SOS_DEBUG_NORMAL)) {
        !           486:                sosTIMERUnInitSystem(0);
        !           487:                sosDIGIUnInitSystem();
        !           488:                crash("Could not Init Midi System!");
        !           489:           }
        !           490:      }
        !           491: 
        !           492: //MIDIDRIVER
        !           493:      if (MusicMode == _STANDARD_MUSIC) {
        !           494:           sSOSMIDIInitDriver.lpDriverMemory = _NULL;
        !           495: 
        !           496:           if ((wError = sosMIDIInitDriver(wMIDIDeviceID, &sMIDIHardware,
        !           497:                             &sSOSMIDIInitDriver, &hSOSDriverHandles[MIDI]))) {
        !           498:                sosMIDIUnInitSystem();
        !           499:                sosDIGIUnInitSystem();
        !           500:                sosTIMERUnInitSystem(0);
        !           501:                crash("Could not Init Midi Driver!\n");
        !           502:           }
        !           503: 
        !           504:           SND_LoadMidiIns();
        !           505:           sosMIDIEnableChannelStealing(_FALSE);
        !           506:           for (wIndex = 0; wIndex < MAX_ACTIVE_SONGS; wIndex++)
        !           507:                hSOSSongHandles[wIndex] = 0x7fff;
        !           508: 
        !           509:           Midi_Loaded = _TRUE;
        !           510:           sosMIDISetMasterVolume(wMIDIVol);
        !           511:      }
        !           512: 
        !           513: 
        !           514: //DIGIDRIVER
        !           515:      if (SoundMode == _ON) {       // && wDIGIDeviceID!=0xffffffff) {
        !           516: 
        !           517:           if ((wError = sosDIGIInitDriver(wDIGIDeviceID, &sDIGIHardware,
        !           518:                                 &sSOSInitDriver, &hSOSDriverHandles[DIGI]))) {
        !           519:                sosTIMERUnInitSystem(0);
        !           520:                sosDIGIUnInitSystem();
        !           521:                crash("Could not initialize Digi Driver!");
        !           522:           }
        !           523:           if ((wError = sosTIMERRegisterEvent(_SOS_FILL_TIMER_RATE, sSOSInitDriver.lpFillHandler,
        !           524:                                               &hTimerDig_FillHandle))) {
        !           525:                sosDIGIUnInitDriver(hSOSDriverHandles[DIGI], _TRUE, _TRUE);
        !           526:                sosTIMERUnInitSystem(0);
        !           527:                sosDIGIUnInitSystem();
        !           528:                crash("Could not register lpFillHandler!");
        !           529:           }
        !           530:           Digi_Loaded = _TRUE;
        !           531: 
        !           532:           sosDIGISetMasterVolume(hSOSDriverHandles[DIGI], wDIGIVol);
        !           533: 
        !           534:           for (wIndex = 0; wIndex < MAX_ACTIVE_SAMPLES; wIndex++)
        !           535:                SampleRay[wIndex].number = -1;
        !           536: 
        !           537:           // RAF NOV 17
        !           538:           // ADDED SMK STUFF
        !           539:           // smkinit(hSOSDriverHandles[DIGI]);
        !           540:      }
        !           541: 
        !           542:      // read in offset page list's
        !           543:      SND_SetupTables();
        !           544:      SD_Started = _TRUE;
        !           545: }
        !           546: 
        !           547: 
        !           548: //////////////////////////////////////////////////////////////////////////////
        !           549: //                                                                          //
        !           550: //       SND_Shutdown() : Un-Initialize all SOS Drivers and releases        //
        !           551: //             timer service(s).                                            //
        !           552: //                                                                          //
        !           553: //////////////////////////////////////////////////////////////////////////////
        !           554: VOID
        !           555: SND_Shutdown(VOID)
        !           556: {
        !           557:      int  i;
        !           558: 
        !           559:      if (!SD_Started)
        !           560:           return;
        !           561: 
        !           562:      if (SoundMode && Digi_Loaded) {
        !           563:           SND_DIGIFlush();
        !           564: 
        !           565:           sosTIMERRemoveEvent(hTimerDig_FillHandle);
        !           566:           flag = sosDIGIUnInitDriver(hSOSDriverHandles[DIGI], _TRUE, _TRUE);
        !           567:           if (hSoundFile != -1)
        !           568:                close(hSoundFile);
        !           569:           if (hLoopFile != -1)
        !           570:                close(hLoopFile);
        !           571:           if (hSongFile != -1)
        !           572:                close(hSongFile);
        !           573:           if (DigiList != NULL)
        !           574:                free(DigiList);
        !           575:           if (LoopList != NULL)
        !           576:                free(LoopList);
        !           577:           Digi_Loaded = _FALSE;
        !           578:      }
        !           579: 
        !           580:      if (MusicMode && Midi_Loaded) {
        !           581:           for (i = 0; i < SONGSPERLEVEL; i++) {
        !           582:                if (!sosMIDISongDone(sngbufptr[oldsong][i]->hMIDISong)) {
        !           583:                     sosMIDIStopSong(sngbufptr[oldsong][i]->hMIDISong);
        !           584:                     // sosMIDIUnInitSong(sngbufptr[oldsong][i]->hMIDISong);
        !           585:                     // sngbufptr[oldsong][i]->hMIDISong=-1;
        !           586:                }
        !           587:                sngbufptr[oldsong][i]->cache_lock = 0;
        !           588:                sosMIDIUnInitSong(sngbufptr[oldsong][i]->hMIDISong);
        !           589:                sngbufptr[oldsong][i]->hMIDISong = -1;
        !           590:           }
        !           591: 
        !           592: 
        !           593:           sosMIDIUnInitDriver(hSOSDriverHandles[MIDI], _TRUE);
        !           594:           if (m_bnkptr != NULL)
        !           595:                free(m_bnkptr);
        !           596:           if (d_bnkptr != NULL)
        !           597:                free(d_bnkptr);
        !           598:           if (digi_bnkptr != NULL)
        !           599:                free(digi_bnkptr);
        !           600:           if (lpMIDISong != NULL)
        !           601:                free((PSTR) FP_OFF(lpMIDISong));
        !           602:           Midi_Loaded = _FALSE;
        !           603:      }
        !           604: 
        !           605:      sosMIDIUnInitSystem();
        !           606: 
        !           607:      sosDIGIUnInitSystem();
        !           608: 
        !           609:      sosTIMERRemoveEvent(hTimerT_ClockHandle);
        !           610: 
        !           611:      sosTIMERUnInitSystem(0);
        !           612: 
        !           613:      SD_Started = _FALSE;
        !           614: 
        !           615: }
        !           616: 
        !           617: void
        !           618: SND_StopMusic(void)
        !           619: {
        !           620:      int  i;
        !           621: 
        !           622:      if (MusicMode && Midi_Loaded) {
        !           623:           for (i = 0; i < SONGSPERLEVEL; i++) {
        !           624:                if (!sosMIDISongDone(sngbufptr[oldsong][i]->hMIDISong)) {
        !           625:                     sosMIDIStopSong(sngbufptr[oldsong][i]->hMIDISong);
        !           626:                     // sosMIDIUnInitSong(sngbufptr[oldsong][i]->hMIDISong);
        !           627:                     // sngbufptr[oldsong][i]->hMIDISong=-1;
        !           628:                }
        !           629:                sngbufptr[oldsong][i]->cache_lock = 0;
        !           630:                sosMIDIUnInitSong(sngbufptr[oldsong][i]->hMIDISong);
        !           631:                sngbufptr[oldsong][i]->hMIDISong = -1;
        !           632:           }
        !           633:      }
        !           634: }
        !           635: 
        !           636: //////////////////////////////////////////////////////////////////////////////
        !           637: //                                                                          //
        !           638: //       SND_Mixer(WORD wSource,WORD wVolume) : Change Music or SFX Volume  //
        !           639: //                                                                          //
        !           640: //////////////////////////////////////////////////////////////////////////////
        !           641: VOID
        !           642: SND_Mixer(WORD wSource, WORD wVolume)
        !           643: {
        !           644:      if (wSource == MIDI) {
        !           645:           if (MusicMode) {
        !           646:                wMIDIVol = (wVolume << 3);
        !           647:                sosMIDISetMasterVolume((BYTE) wMIDIVol);
        !           648:           }
        !           649:      }
        !           650:      else {
        !           651:           if (SoundMode) {
        !           652:                wDIGIVol = (wVolume << 11);
        !           653:                sosDIGISetMasterVolume(hSOSDriverHandles[DIGI], wDIGIVol);
        !           654:           }
        !           655:      }
        !           656: }
        !           657: 
        !           658: 
        !           659: //WORD
        !           660: int
        !           661: SND_PlaySound(WORD sound, long x, long y, WORD Pan, WORD loopcount)
        !           662: {
        !           663:      WORD wVol,
        !           664:           flag = 0;
        !           665:      long sqrdist;
        !           666:      long prioritize;
        !           667: 
        !           668:      if (!SoundMode)
        !           669:           return (0);
        !           670:      // return((WORD)0);
        !           671: 
        !           672: 
        !           673:      prioritize = DigiList[(sound * 3) + 2];
        !           674: 
        !           675:      if (((x == 0) && (y == 0)) || ((player[pyrn].x == x) && (player[pyrn].y == y))) {
        !           676:           wVol = 0x7fff;
        !           677:           Pan = 0;
        !           678:      }
        !           679:      else {
        !           680:           sqrdist = labs(player[pyrn].x - x) + labs(player[pyrn].y - y);
        !           681:           if (sqrdist < 1500)
        !           682:                wVol = 0x7fff;
        !           683:           else if (sqrdist > 8500)
        !           684:                wVol = 0x1f00;
        !           685:           else
        !           686:                wVol = 39000 - (sqrdist << 2);
        !           687:      }
        !           688: 
        !           689: 
        !           690:      if (sound == S_STONELOOP1) {
        !           691:           for (wIndex = 0, flag = 0; wIndex < MAX_ACTIVE_SAMPLES; wIndex++)
        !           692:                if (sound == SampleRay[wIndex].number)
        !           693:                     return (0);
        !           694:      }
        !           695: 
        !           696:      for (wIndex = 0, flag = 0; wIndex < MAX_ACTIVE_SAMPLES; wIndex++)
        !           697:           if (!SampleRay[wIndex].playing) {
        !           698:                flag = 1;
        !           699:                break;
        !           700:           }
        !           701: 
        !           702:      // if(!flag && prioritize<9)               //none available low prio
        !           703:      if (!flag)
        !           704:           return (0);
        !           705: 
        !           706:      else if (!flag) {             // none avail but high prio
        !           707:           for (wIndex = 0; wIndex < MAX_ACTIVE_SAMPLES; wIndex++) {
        !           708:                if (SampleRay[wIndex].priority < 9 && sSOSSampleData[wIndex].wLoopCount != -1) {
        !           709:                     if (!sosDIGISampleDone(hSOSDriverHandles[DIGI], SampleRay[wIndex].SOSHandle) &&
        !           710:                         (sSOSSampleData[wIndex].dwSampleSize != 0)) {
        !           711:                          sosDIGIStopSample(hSOSDriverHandles[DIGI], SampleRay[wIndex].SOSHandle);
        !           712:                          sSOSSampleData[wIndex].wLoopCount = 0;
        !           713:                          sSOSSampleData[wIndex].dwSampleSize = 0;
        !           714:                          SampleRay[wIndex].SOSHandle = -1;
        !           715:                          SampleRay[wIndex].playing = 0;
        !           716:                          SampleRay[wIndex].priority = 0;
        !           717:                          SampleRay[wIndex].number = -1;
        !           718:                          break;
        !           719:                     }
        !           720:                }
        !           721:           }
        !           722:      }
        !           723: 
        !           724: 
        !           725:      sSOSSampleData[wIndex].dwSampleSize = (WORD) DigiList[(sound * 3) + 1];
        !           726: 
        !           727:      SeekIndex = (DigiList[(sound * 3) + 0] * 4096);
        !           728: 
        !           729:      lseek(hSoundFile, SeekIndex, 0x00);
        !           730:      memset((void *) FP_OFF(sSOSSampleData[wIndex].lpSamplePtr), '0', 55000);
        !           731:      read(hSoundFile, (void *) FP_OFF(sSOSSampleData[wIndex].lpSamplePtr), sSOSSampleData[wIndex].dwSampleSize);
        !           732: 
        !           733:      if (loopcount)
        !           734:           sSOSSampleData[wIndex].wLoopCount = loopcount;
        !           735: 
        !           736:      if (Pan)
        !           737:           Pan = ((getangle(player[pyrn].x - x, player[pyrn].y - y) + (2047 - player[pyrn].ang)) % 2047) >> 6;
        !           738: 
        !           739: //HILES this will put the enchanted weapons inthe right speaker
        !           740: //     if( sound == S_ENCHANTLOOP1 || sound == S_ENCHANTLOOP2 )
        !           741: //          sSOSSampleData[wIndex].wSamplePanLocation = 0xe000;
        !           742: //     else
        !           743:           sSOSSampleData[wIndex].wSamplePanLocation = PanArray[Pan];
        !           744:      sSOSSampleData[wIndex].wVolume = wVol;
        !           745:      SampleRay[wIndex].SOSHandle = sosDIGIStartSample(hSOSDriverHandles[DIGI], &sSOSSampleData[wIndex]);
        !           746:      SampleRay[wIndex].x = x;
        !           747:      SampleRay[wIndex].y = y;
        !           748:      SampleRay[wIndex].playing = 1;
        !           749:      SampleRay[wIndex].number = sound;
        !           750:      SampleRay[wIndex].priority = prioritize;
        !           751:      ActiveSampleBits |= (0x01 << wIndex);
        !           752: 
        !           753:      return (SampleRay[wIndex].SOSHandle);
        !           754: 
        !           755: }
        !           756: 
        !           757: 
        !           758: WORD
        !           759: SND_Sound(WORD sound)
        !           760: {
        !           761:      static WORD handle;
        !           762: 
        !           763:      if (!SoundMode)
        !           764:           return (-1);
        !           765:      return (SND_PlaySound(sound, 0, 0, 0, 0));
        !           766: 
        !           767: }
        !           768: 
        !           769: VOID
        !           770: SND_CheckLoops(void)
        !           771: {
        !           772: 
        !           773:      // special case loops
        !           774:      if (cartsnd != -1) {
        !           775:           SND_StopLoop(cartsnd);
        !           776:           cartsnd = -1;
        !           777:      }
        !           778:      if (lavasnd != -1) {
        !           779:           SND_StopLoop(lavasnd);
        !           780:           lavasnd = -1;
        !           781:      }
        !           782:      if (batsnd != -1) {
        !           783:           SND_StopLoop(batsnd);
        !           784:           batsnd = -1;
        !           785:      }
        !           786: 
        !           787:      if (enchantedsoundhandle != -1) {
        !           788:           SND_StopLoop(enchantedsoundhandle);
        !           789:      }
        !           790:      
        !           791: 
        !           792: 
        !           793:      // ambient sound array
        !           794:      for (wIndex = 0; wIndex < MAX_AMB_SOUNDS; wIndex++) {
        !           795:           if (ambsoundarray[wIndex].hsound != -1) {
        !           796:                SND_StopLoop(ambsoundarray[wIndex].hsound);
        !           797:                ambsoundarray[wIndex].hsound = -1;
        !           798:           }
        !           799:      }
        !           800: 
        !           801:      SND_DIGIFlush();
        !           802: 
        !           803: }
        !           804: 
        !           805: VOID
        !           806: SND_StopLoop(WORD which)
        !           807: {
        !           808: 
        !           809:      if (!SoundMode)
        !           810:           return;
        !           811: 
        !           812:      for (wIndex = 0; wIndex < MAX_ACTIVE_SAMPLES; wIndex++)
        !           813:           if (which == SampleRay[wIndex].SOSHandle)
        !           814:                break;
        !           815: 
        !           816:      sosDIGIStopSample(hSOSDriverHandles[DIGI], SampleRay[wIndex].SOSHandle);
        !           817:      sSOSSampleData[wIndex].wLoopCount = 0;
        !           818:      SampleRay[wIndex].SOSHandle = -1;
        !           819:      SampleRay[wIndex].playing = 0;
        !           820:      SampleRay[wIndex].number = -1;
        !           821: 
        !           822: }
        !           823: 
        !           824: 
        !           825: VOID
        !           826: SND_DIGIFLush(void)
        !           827: {
        !           828:      if (!SoundMode)
        !           829:           return;
        !           830: 
        !           831:      for (wIndex = 0; wIndex < MAX_ACTIVE_SAMPLES; wIndex++) {
        !           832:           if (SampleRay[wIndex].playing)
        !           833:                sosDIGIStopSample(hSOSDriverHandles[DIGI], SampleRay[wIndex].SOSHandle);
        !           834:           // if( sSOSSampleData[wIndex].lpSamplePtr != NULL )
        !           835:           // free((void *)FP_OFF(sSOSSampleData[wIndex].lpSamplePtr));
        !           836:           SampleRay[wIndex].SOSHandle = -1;
        !           837:           SampleRay[wIndex].playing = 0;
        !           838:           SampleRay[wIndex].number = -1;
        !           839:           ActiveSampleBits |= (0x01 << wIndex);
        !           840:      }
        !           841: }
        !           842: 
        !           843: 
        !           844: 
        !           845: //
        !           846: //    Sound Location Stuff
        !           847: //
        !           848: 
        !           849: 
        !           850: VOID
        !           851: SND_UpdateSoundLoc(WORD which, WORD Volume, WORD Pan)
        !           852: {
        !           853: 
        !           854:      gVol = Volume;
        !           855:      gPan = sosDIGISetPanLocation(hSOSDriverHandles[DIGI], SampleRay[which].SOSHandle, PanArray[Pan]);
        !           856:      sosDIGISetSampleVolume(hSOSDriverHandles[DIGI], SampleRay[which].SOSHandle, Volume);
        !           857: 
        !           858: }
        !           859: 
        !           860: 
        !           861: 
        !           862: // JOE START functions called often from external modules
        !           863: 
        !           864: //JSA 3/20/95
        !           865: //
        !           866: //    note: soundnum=sound to play; xplc is x location of source; yplc is y loc
        !           867: //
        !           868: 
        !           869: void
        !           870: playsound_loc(int soundnum, long xplc, long yplc)
        !           871: {
        !           872:      long sqrdist;
        !           873:      unsigned wVol,
        !           874:           wPan;
        !           875: 
        !           876:      SND_PlaySound(soundnum, xplc, yplc, 1, 0);
        !           877: }
        !           878: 
        !           879: void
        !           880: updatesound_loc(void)
        !           881: {
        !           882:      int  wIndex;
        !           883:      unsigned wVol,
        !           884:           wPan;
        !           885:      long sqrdist;
        !           886: 
        !           887:      if (!SoundMode)
        !           888:           return;
        !           889: 
        !           890:      for (wIndex = 0; wIndex < MAX_ACTIVE_SAMPLES; wIndex++)
        !           891:           if (SampleRay[wIndex].playing && SampleRay[wIndex].x && SampleRay[wIndex].y) {
        !           892:                if (sSOSSampleData[wIndex].dwSampleSize != 0) {
        !           893:                     sqrdist = labs(player[pyrn].x - SampleRay[wIndex].x) +
        !           894:                          labs(player[pyrn].y - SampleRay[wIndex].y);
        !           895: 
        !           896:                     if (sqrdist < 1500)
        !           897:                          wVol = 0x7fff;
        !           898:                     else if (sqrdist > 8500)
        !           899:                          wVol = 0x1f00;
        !           900:                     else
        !           901:                          wVol = 39000 - (sqrdist << 2);
        !           902: 
        !           903:                     wPan = ((getangle(player[pyrn].x - SampleRay[wIndex].x, player[pyrn].y - SampleRay[wIndex].y) + (2047 - player[pyrn].ang)) % 2047) >> 6;
        !           904:                     SND_UpdateSoundLoc(wIndex, wVol, wPan);
        !           905:                     // sprintf(displaybuf,"%dVol %x Pan %x Dist
        !           906:                     // %ld",SampleRay[wIndex].number,wVol,wPan,sqrdist);
        !           907:                     // displaytime=100;
        !           908:                }
        !           909: 
        !           910:           }
        !           911: 
        !           912: }
        !           913: 
        !           914: // Location Stuff End

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.