From: sparky4 Date: Wed, 13 Sep 2017 15:53:03 +0000 (-0500) Subject: catacomb3d and wolf3d base for sound with project 16's port of id_sd.c X-Git-Url: http://4ch.mooo.com/gitweb/?p=16.git;a=commitdiff_plain;h=d0908679d03eacbbbd67420ae2daa6a01f0a0bcc catacomb3d and wolf3d base for sound with project 16's port of id_sd.c --- diff --git a/makefile b/makefile index b0302b88..4dd26ebc 100755 --- a/makefile +++ b/makefile @@ -127,7 +127,7 @@ STKSIZ=32768 S_FLAGS=-sg -st -of+ -zu -zdf -zff -zgf -k$(STKSIZ) Z_FLAGS=-zk0 -zc#### -zp4 -ei# -zm O_FLAGS=-opnr -oe=24 -oil+ -outback -ohm -T_FLAGS=-bt=dos -wx -m$(MEMORYMODE) -0 -fpi87 $(D_FLAGS) -fo=.$(OBJ)## -e=65536 +T_FLAGS=-bt=dos -wx -m$(MEMORYMODE) -0 -fpi87 $(D_FLAGS) -fo=.$(OBJ)# -e=65536 DBUGFLAGS=-fm=$^&.meh -fd=$^& $(D_FLAGS) CPPFLAGS=-DTARGET_MSDOS=16 -DMSDOS=1 -DSTACKSIZE=$(STKSIZ) diff --git a/src/lib/16_pm.h b/src/lib/16_pm.h index bdf29a5d..a6001ec9 100755 --- a/src/lib/16_pm.h +++ b/src/lib/16_pm.h @@ -91,8 +91,8 @@ extern word ChunksInFile, PMSpriteStart,PMSoundStart; extern PageListStruct far *PMPages;*///moved to src/lib/typdefst.h -#define PM_GetSoundPage(v) PM_GetPage(PMSoundStart + (v)) -#define PM_GetSpritePage(v) PM_GetPage(PMSpriteStart + (v)) +#define PM_GetSoundPage(v) PM_GetPage(gvar->pm.fi.PMSoundStart + (v), gvar) +#define PM_GetSpritePage(v) PM_GetPage(gvar->pm.fi.PMSpriteStart + (v), gvar) #define PM_LockMainMem(gvar) PM_SetMainMemPurge(0, gvar) #define PM_UnlockMainMem(gvar) PM_SetMainMemPurge(3, gvar) diff --git a/src/lib/id_sd.c b/src/lib/id_sd.c index 2a73fc69..f98e88cb 100755 --- a/src/lib/id_sd.c +++ b/src/lib/id_sd.c @@ -23,8 +23,9 @@ // // ID Engine // ID_SD.c - Sound Manager for Wolfenstein 3D -// v1.2 +// v1.2w // By Jason Blochowiak +// Open Watcom port by sparky4 // // @@ -42,9 +43,6 @@ // (Use SM_SetSoundMode() to set) // MusicMode - What device is used for music // (Use SM_SetMusicMode() to set) -// DigiMode - What device is used for digitized sound effects -// (Use SM_SetDigiDevice() to set) -// // For Cache Mgr: // NeedsDigitized - load digitized sounds? // NeedsMusic - load music? @@ -52,7 +50,7 @@ #pragma hdrstop // Wierdo thing with MUSE - +#include //#ifdef _MUSE_ // Will be defined in ID_Types.h #include "src/lib/id_sd.h" @@ -62,19 +60,8 @@ #pragma hdrstop #pragma warn -pia -#ifdef nil -#undef nil -#endif -#define nil 0 - #define SDL_SoundFinished() {SoundNumber = SoundPriority = 0;} -// Macros for SoundBlaster stuff -#define sbOut(n,b) outportb((n) + sbLocation,b) -#define sbIn(n) inportb((n) + sbLocation) -#define sbWriteDelay() while (sbIn(sbWriteStat) & 0x80); -#define sbReadDelay() while (sbIn(sbDataAvail) & 0x80); - // Macros for AdLib stuff #define selreg(n) outportb(alFMAddr,n) #define writereg(n) outportb(alFMData,n) @@ -267,390 +254,7 @@ SDL_SetTimerSpeed(void) } } -#if 0 -// -// SoundBlaster code -// - -/////////////////////////////////////////////////////////////////////////// -// -// SDL_SBStopSample() - Stops any active sampled sound and causes DMA -// requests from the SoundBlaster to cease -// -/////////////////////////////////////////////////////////////////////////// -#ifdef _MUSE_ -void -#else -static void -#endif -SDL_SBStopSample(void) -{ - byte is; - -asm pushf -asm cli - - if (sbSamplePlaying) - { - sbSamplePlaying = false; - - sbWriteDelay(); - sbOut(sbWriteCmd,0xd0); // Turn off DSP DMA - - is = inportb(0x21); // Restore interrupt mask bit - if (sbOldIntMask & (1 << sbInterrupt)) - is |= (1 << sbInterrupt); - else - is &= ~(1 << sbInterrupt); - outportb(0x21,is); - } - -asm popf -} - -/////////////////////////////////////////////////////////////////////////// -// -// SDL_SBPlaySeg() - Plays a chunk of sampled sound on the SoundBlaster -// Insures that the chunk doesn't cross a bank boundary, programs the DMA -// controller, and tells the SB to start doing DMA requests for DAC -// -/////////////////////////////////////////////////////////////////////////// -static dword -SDL_SBPlaySeg(volatile byte huge *data,dword length) -{ - unsigned datapage; - dword dataofs,uselen; - - uselen = length; - datapage = FP_SEG(data) >> 12; - dataofs = ((FP_SEG(data) & 0xfff) << 4) + FP_OFF(data); - if (dataofs >= 0x10000) - { - datapage++; - dataofs -= 0x10000; - } - - if (dataofs + uselen > 0x10000) - uselen = 0x10000 - dataofs; - - uselen--; - - // Program the DMA controller -asm pushf -asm cli - outportb(0x0a,sbDMA | 4); // Mask off DMA on channel sbDMA - outportb(0x0c,0); // Clear byte ptr flip-flop to lower byte - outportb(0x0b,0x49); // Set transfer mode for D/A conv - outportb(sbDMAa2,(byte)dataofs); // Give LSB of address - outportb(sbDMAa2,(byte)(dataofs >> 8)); // Give MSB of address - outportb(sbDMAa1,(byte)datapage); // Give page of address - outportb(sbDMAa3,(byte)uselen); // Give LSB of length - outportb(sbDMAa3,(byte)(uselen >> 8)); // Give MSB of length - outportb(0x0a,sbDMA); // Re-enable DMA on channel sbDMA - - // Start playing the thing - sbWriteDelay(); - sbOut(sbWriteCmd,0x14); - sbWriteDelay(); - sbOut(sbWriteData,(byte)uselen); - sbWriteDelay(); - sbOut(sbWriteData,(byte)(uselen >> 8)); -asm popf - - return(uselen + 1); -} - -/////////////////////////////////////////////////////////////////////////// -// -// SDL_SBService() - Services the SoundBlaster DMA interrupt -// -/////////////////////////////////////////////////////////////////////////// -/*static*/ void interrupt -SDL_SBService(void) -{ - dword used; - - sbIn(sbDataAvail); // Ack interrupt to SB - - if (sbNextSegPtr) - { - used = SDL_SBPlaySeg(sbNextSegPtr,sbNextSegLen); - if (sbNextSegLen <= used) - sbNextSegPtr = nil; - else - { - sbNextSegPtr += used; - sbNextSegLen -= used; - } - } - else - { - SDL_SBStopSample(); - SDL_DigitizedDone(); - } - - outportb(0x20,0x20); // Ack interrupt -} - -/////////////////////////////////////////////////////////////////////////// -// -// SDL_SBPlaySample() - Plays a sampled sound on the SoundBlaster. Sets up -// DMA to play the sound -// -/////////////////////////////////////////////////////////////////////////// -#ifdef _MUSE_ -void -#else -static void -#endif -SDL_SBPlaySample(byte huge *data,dword len) -{ - dword used; - - SDL_SBStopSample(); - -asm pushf -asm cli - - used = SDL_SBPlaySeg(data,len); - if (len <= used) - sbNextSegPtr = nil; - else - { - sbNextSegPtr = data + used; - sbNextSegLen = len - used; - } - - // Save old interrupt status and unmask ours - sbOldIntMask = inportb(0x21); - outportb(0x21,sbOldIntMask & ~(1 << sbInterrupt)); - - sbWriteDelay(); - sbOut(sbWriteCmd,0xd4); // Make sure DSP DMA is enabled - - sbSamplePlaying = true; - -asm popf -} - -/////////////////////////////////////////////////////////////////////////// -// -// SDL_PositionSBP() - Sets the attenuation levels for the left and right -// channels by using the mixer chip on the SB Pro. This hits a hole in -// the address map for normal SBs. -// -/////////////////////////////////////////////////////////////////////////// -static void -SDL_PositionSBP(int leftpos,int rightpos) -{ - byte v; - - if (!SBProPresent) - return; - - leftpos = 15 - leftpos; - rightpos = 15 - rightpos; - v = ((leftpos & 0x0f) << 4) | (rightpos & 0x0f); - -asm pushf -asm cli - - sbOut(sbpMixerAddr,sbpmVoiceVol); - sbOut(sbpMixerData,v); - -asm popf -} - -/////////////////////////////////////////////////////////////////////////// -// -// SDL_CheckSB() - Checks to see if a SoundBlaster resides at a -// particular I/O location -// -/////////////////////////////////////////////////////////////////////////// -static boolean -SDL_CheckSB(int port) -{ - int i; - - sbLocation = port << 4; // Initialize stuff for later use - - sbOut(sbReset,true); // Reset the SoundBlaster DSP -asm mov dx,0x388 // Wait >4usec -asm in al, dx -asm in al, dx -asm in al, dx -asm in al, dx -asm in al, dx -asm in al, dx -asm in al, dx -asm in al, dx -asm in al, dx - - sbOut(sbReset,false); // Turn off sb DSP reset -asm mov dx,0x388 // Wait >100usec -asm mov cx,100 -#ifdef __WATCOMC__ - __asm { -#endif -usecloop: -asm in al,dx -asm loop usecloop -#ifdef __WATCOMC__ - } -#endif - - for (i = 0;i < 100;i++) - { - if (sbIn(sbDataAvail) & 0x80) // If data is available... - { - if (sbIn(sbReadData) == 0xaa) // If it matches correct value - return(true); - else - { - sbLocation = -1; // Otherwise not a SoundBlaster - return(false); - } - } - } - sbLocation = -1; // Retry count exceeded - fail - return(false); -} - -/////////////////////////////////////////////////////////////////////////// -// -// Checks to see if a SoundBlaster is in the system. If the port passed is -// -1, then it scans through all possible I/O locations. If the port -// passed is 0, then it uses the default (2). If the port is >0, then -// it just passes it directly to SDL_CheckSB() -// -/////////////////////////////////////////////////////////////////////////// -static boolean -SDL_DetectSoundBlaster(int port) -{ - int i; - - if (port == 0) // If user specifies default, use 2 - port = 2; - if (port == -1) - { - if (SDL_CheckSB(2)) // Check default before scanning - return(true); - - if (SDL_CheckSB(4)) // Check other SB Pro location before scan - return(true); - - for (i = 1;i <= 6;i++) // Scan through possible SB locations - { - if ((i == 2) || (i == 4)) - continue; - - if (SDL_CheckSB(i)) // If found at this address, - return(true); // return success - } - return(false); // All addresses failed, return failure - } - else - return(SDL_CheckSB(port)); // User specified address or default -} - -/////////////////////////////////////////////////////////////////////////// -// -// SDL_SBSetDMA() - Sets the DMA channel to be used by the SoundBlaster -// code. Sets up sbDMA, and sbDMAa1-sbDMAa3 (used by SDL_SBPlaySeg()). -// -/////////////////////////////////////////////////////////////////////////// -void -SDL_SBSetDMA(byte channel) -{ - if (channel > 3) - Quit("SDL_SBSetDMA() - invalid SoundBlaster DMA channel"); - - sbDMA = channel; - sbDMAa1 = sba1Vals[channel]; - sbDMAa2 = sba2Vals[channel]; - sbDMAa3 = sba3Vals[channel]; -} - -/////////////////////////////////////////////////////////////////////////// -// -// SDL_StartSB() - Turns on the SoundBlaster -// -/////////////////////////////////////////////////////////////////////////// -static void -SDL_StartSB(void) -{ - byte timevalue,test; - - sbIntVec = sbIntVectors[sbInterrupt]; - if (sbIntVec < 0) - Quit("SDL_StartSB: Illegal or unsupported interrupt number for SoundBlaster"); - - sbOldIntHand = getvect(sbIntVec); // Get old interrupt handler - setvect(sbIntVec,SDL_SBService); // Set mine - sbWriteDelay(); - sbOut(sbWriteCmd,0xd1); // Turn on DSP speaker - - // Set the SoundBlaster DAC time constant for 7KHz - timevalue = 256 - (1000000 / 7000); - sbWriteDelay(); - sbOut(sbWriteCmd,0x40); - sbWriteDelay(); - sbOut(sbWriteData,timevalue); - - SBProPresent = false; - if (sbNoProCheck) - return; - - // Check to see if this is a SB Pro - sbOut(sbpMixerAddr,sbpmFMVol); - sbpOldFMMix = sbIn(sbpMixerData); - sbOut(sbpMixerData,0xbb); - test = sbIn(sbpMixerData); - if (test == 0xbb) - { - // Boost FM output levels to be equivilent with digitized output - sbOut(sbpMixerData,0xff); - test = sbIn(sbpMixerData); - if (test == 0xff) - { - SBProPresent = true; - - // Save old Voice output levels (SB Pro) - sbOut(sbpMixerAddr,sbpmVoiceVol); - sbpOldVOCMix = sbIn(sbpMixerData); - - // Turn SB Pro stereo DAC off - sbOut(sbpMixerAddr,sbpmControl); - sbOut(sbpMixerData,0); // 0=off,2=on - } - } -} - -/////////////////////////////////////////////////////////////////////////// -// -// SDL_ShutSB() - Turns off the SoundBlaster -// -/////////////////////////////////////////////////////////////////////////// -static void -SDL_ShutSB(void) -{ - SDL_SBStopSample(); - - if (SBProPresent) - { - // Restore FM output levels (SB Pro) - sbOut(sbpMixerAddr,sbpmFMVol); - sbOut(sbpMixerData,sbpOldFMMix); - - // Restore Voice output levels (SB Pro) - sbOut(sbpMixerAddr,sbpmVoiceVol); - sbOut(sbpMixerData,sbpOldVOCMix); - } - - setvect(sbIntVec,sbOldIntHand); // Set vector back -} -#endif // Sound Source Code @@ -669,7 +273,7 @@ SDL_SSStopSample(void) asm pushf asm cli - (long)ssSample = 0; + /*(long)*/ssSample = 0; asm popf } @@ -714,7 +318,7 @@ SDL_SSService(void) v = *ssSample++; if (!(--ssLengthLeft)) { - (long)ssSample = 0; + /*(long)*/ssSample = 0; SDL_DigitizedDone(); } @@ -930,7 +534,7 @@ SDL_PCStopSample(void) asm pushf asm cli - (long)pcSound = 0; + /*(long)*/pcSound = 0; SDL_IndicatePC(false); @@ -978,7 +582,7 @@ SDL_PCStopSound(void) asm pushf asm cli - (long)pcSound = 0; + /*(long)*/pcSound = 0; asm in al,0x61 // Turn the speaker off asm and al,0xfd // ~2 @@ -987,7 +591,6 @@ asm out 0x61,al asm popf } -#if 0 /////////////////////////////////////////////////////////////////////////// // // SDL_PCService() - Handles playing the next sample in a PC sound @@ -1041,7 +644,6 @@ SDL_PCService(void) } } } -#endif /////////////////////////////////////////////////////////////////////////// // @@ -1067,7 +669,7 @@ asm popf // Stuff for digitized sounds // memptr -SDL_LoadDigiSegment(word page) +SDL_LoadDigiSegment(word page, global_game_variables_t *gvar) { memptr addr; @@ -1081,8 +683,8 @@ asm mov al,10 // bright green asm out dx,al #endif - addr = PM_GetSoundPage(page, gvar); - PM_SetPageLock(PMSoundStart + page,pml_Locked); + addr = PM_GetSoundPage(page); + PM_SetPageLock(gvar->pm.fi.PMSoundStart + page,pml_Locked, gvar); #if 0 // for debugging asm mov dx,STATUS_REGISTER_1 @@ -1117,7 +719,7 @@ SDL_PlayDigiSegment(memptr addr,word len) } void -SD_StopDigitized(void) +SD_StopDigitized(global_game_variables_t *gvar) { int i; @@ -1150,7 +752,7 @@ asm cli asm popf for (i = DigiLastStart;i < DigiLastEnd;i++) - PM_SetPageLock(i + PMSoundStart,pml_Unlocked); + PM_SetPageLock(i + gvar->pm.fi.PMSoundStart,pml_Unlocked, gvar); DigiLastStart = 1; DigiLastEnd = 0; } @@ -1181,7 +783,7 @@ SD_Poll(void) } void -SD_SetPosition(int leftpos,int rightpos) +SD_SetPosition(int leftpos,int rightpos, global_game_variables_t *gvar) { if ( @@ -1191,7 +793,7 @@ SD_SetPosition(int leftpos,int rightpos) || (rightpos > 15) || ((leftpos == 15) && (rightpos == 15)) ) - Quit("SD_SetPosition: Illegal position"); + Quit(gvar, "SD_SetPosition: Illegal position"); switch (DigiMode) { @@ -1202,7 +804,7 @@ SD_SetPosition(int leftpos,int rightpos) } void -SD_PlayDigitized(word which,int leftpos,int rightpos) +SD_PlayDigitized(word which,int leftpos,int rightpos, global_game_variables_t *gvar) { word len; memptr addr; @@ -1212,7 +814,7 @@ SD_PlayDigitized(word which,int leftpos,int rightpos) SD_StopDigitized(); if (which >= NumDigi) - Quit("SD_PlayDigitized: bad sound number"); + Quit(gvar, "SD_PlayDigitized: bad sound number"); SD_SetPosition(leftpos,rightpos); @@ -1307,19 +909,19 @@ SD_SetDigiDevice(SDSMode mode) } void -SDL_SetupDigi(void) +SDL_SetupDigi(global_game_variables_t *gvar) { memptr list; word far *p, pg; int i; - PM_UnlockMainMem(); - MM_GetPtr(&list,PMPageSize); - PM_CheckMainMem(); - p = (word far *)MK_FP(PM_GetPage(ChunksInFile - 1),0); + PM_UnlockMainMem(gvar); + MM_GetPtr(&list,PMPageSize, gvar); + PM_CheckMainMem(gvar); + p = (word far *)MK_FP(PM_GetPage(gvar->pm.fi.ChunksInFile - 1),0,gvar); _fmemcpy((void far *)list,(void far *)p,PMPageSize); - pg = PMSoundStart; + pg = gvar->pm.fi.PMSoundStart; for (i = 0;i < PMPageSize / (sizeof(word) * 2);i++,p += 2) { if (pg >= ChunksInFile - 1) @@ -1466,7 +1068,7 @@ SDL_ALStopSound(void) asm pushf asm cli - (long)alSound = 0; + /*(long)*/alSound = 0; alOut(alFreqH + 0,0); asm popf @@ -1505,7 +1107,7 @@ void #else static void #endif -SDL_ALPlaySound(AdLibSound far *sound) +SDL_ALPlaySound(AdLibSound far *sound, global_game_variables_t *gvar) { Instrument far *inst; byte huge *data; @@ -1526,7 +1128,7 @@ asm cli if (!(inst->mSus | inst->cSus)) { asm popf - Quit("SDL_ALPlaySound() - Bad instrument"); + Quit(gvar, "SDL_ALPlaySound() - Bad instrument"); } SDL_AlSetFXInst(&alZeroInst); // DEBUG @@ -1948,7 +1550,7 @@ SD_SetMusicMode(SMMode mode) // /////////////////////////////////////////////////////////////////////////// void -SD_Startup(void) +SD_Startup(global_game_variables_t *gvar) { int i; @@ -2037,7 +1639,7 @@ SD_Startup(void) ) port = (temp - 0x200) >> 4; else - Quit("SD_Startup: Unsupported address value in BLASTER"); + Quit(gvar, "SD_Startup: Unsupported address value in BLASTER"); break; case 'I': temp = strtol(env + 1,&env,10); @@ -2052,14 +1654,14 @@ SD_Startup(void) sbIntVec = sbIntVectors[sbInterrupt]; } else - Quit("SD_Startup: Unsupported interrupt value in BLASTER"); + Quit(gvar, "SD_Startup: Unsupported interrupt value in BLASTER"); break; case 'D': temp = strtol(env + 1,&env,10); if ((temp == 0) || (temp == 1) || (temp == 3)) SDL_SBSetDMA(temp); else - Quit("SD_Startup: Unsupported DMA value in BLASTER"); + Quit(gvar, "SD_Startup: Unsupported DMA value in BLASTER"); break; default: while (isspace(*env)) @@ -2203,7 +1805,7 @@ SD_PositionSound(int leftvol,int rightvol) // /////////////////////////////////////////////////////////////////////////// boolean -SD_PlaySound(soundnames sound) +SD_PlaySound(soundnames sound, global_game_variables_t *gvar) { boolean ispos; SoundCommon far *s; @@ -2222,7 +1824,7 @@ SD_PlaySound(soundnames sound) s = MK_FP(SoundTable[sound],0); if ((SoundMode != sdm_Off) && !s) - Quit("SD_PlaySound() - Uncached sound"); + Quit(gvar, "SD_PlaySound() - Uncached sound"); if ((DigiMode != sds_Off) && (DigiMap[sound] != -1)) { @@ -2245,7 +1847,7 @@ SD_PlaySound(soundnames sound) if (DigiPriority && !DigiNumber) { asm popf - Quit("SD_PlaySound: Priority without a sound"); + Quit(gvar, "SD_PlaySound: Priority without a sound"); } asm popf @@ -2264,7 +1866,7 @@ SD_PlaySound(soundnames sound) if (SoundMode == sdm_Off) return(false); if (!s->length) - Quit("SD_PlaySound() - Zero length sound"); + Quit(gvar, "SD_PlaySound() - Zero length sound"); if (s->priority < SoundPriority) return(false); diff --git a/src/lib/id_sd.h b/src/lib/id_sd.h index bc3151b7..ef22dc87 100755 --- a/src/lib/id_sd.h +++ b/src/lib/id_sd.h @@ -248,7 +248,7 @@ extern word SD_SoundPlaying(void); extern void SD_SetDigiDevice(SDSMode), SD_PlayDigitized(word which,int leftpos,int rightpos), - SD_StopDigitized(void), + SD_StopDigitized(global_game_variables_t *gvar), SD_Poll(void); #ifdef _MUSE_ // MUSE Goes directly to the lower level routines