//\r
// ID Engine\r
// ID_SD.c - Sound Manager for Wolfenstein 3D\r
-// v1.2\r
+// v1.2w\r
// By Jason Blochowiak\r
+// Open Watcom port by sparky4\r
//\r
\r
//\r
\r
#pragma hdrstop // Wierdo thing with MUSE\r
\r
+#include <dos.h>\r
\r
-\r
-//#ifdef _MUSE_ // Will be defined in ID_Types.h\r
+#ifndef _MUSE_ // Will be defined in ID_Types.h\r
#include "src/lib/id_sd.h"\r
-//#else\r
-//#include "ID_HEADS.H"\r
-//#endif\r
+#else\r
+#include "src/lib/16_head.h"\r
+#endif\r
#pragma hdrstop\r
#pragma warn -pia\r
\r
-#ifdef nil\r
-#undef nil\r
-#endif\r
-#define nil 0\r
-\r
#define SDL_SoundFinished() {SoundNumber = SoundPriority = 0;}\r
\r
-// Macros for SoundBlaster stuff\r
-#define sbOut(n,b) outportb((n) + sbLocation,b)\r
-#define sbIn(n) inportb((n) + sbLocation)\r
-#define sbWriteDelay() while (sbIn(sbWriteStat) & 0x80);\r
-#define sbReadDelay() while (sbIn(sbDataAvail) & 0x80);\r
-\r
// Macros for AdLib stuff\r
#define selreg(n) outportb(alFMAddr,n)\r
#define writereg(n) outportb(alFMData,n)\r
#define readstat() inportb(alFMStatus)\r
\r
+//#define SD_USECATA3DSETTIMERSPEED\r
+\r
// Imports from ID_SD_A.ASM\r
-/*extern*/ void SDL_SetDS(void),\r
- SDL_IndicatePC(boolean on);\r
-/*extern*/ void interrupt SDL_t0ExtremeAsmService(void),\r
- SDL_t0FastAsmService(void),\r
- SDL_t0SlowAsmService(void);\r
+/*extern*/ void SDL_SetDS(void);\r
+/*extern*/ void interrupt SDL_t0ExtremeAsmService(void);//,\r
+// SDL_t0FastAsmService(void),\r
+// SDL_t0SlowAsmService(void);\r
+ void SDL_IndicatePC(boolean on),\r
+ SDL_DigitizedDoneInIRQ();\r
\r
// Global variables\r
- boolean SoundSourcePresent,\r
- AdLibPresent,\r
- SoundBlasterPresent,SBProPresent,\r
+ boolean AdLibPresent,\r
NeedsDigitized,NeedsMusic,\r
SoundPositioned;\r
SDMode SoundMode;\r
word HackCount;\r
word *SoundTable; // Really * _seg *SoundTable, but that don't work\r
boolean ssIsTandy;\r
- word ssPort = 2;\r
int DigiMap[LASTSOUND];\r
\r
// Internal variables\r
static boolean SD_Started;\r
boolean nextsoundpos;\r
+ word/*boolean_+*/ TimerDone;\r
+ word TimerVal,TimerDelay10,TimerDelay25,TimerDelay100;\r
dword TimerDivisor,TimerCount;\r
static char *ParmStrings[] =\r
{\r
"noal",\r
- "nosb",\r
- "nopro",\r
- "noss",\r
- "sst",\r
- "ss1",\r
- "ss2",\r
- "ss3",\r
nil\r
};\r
static void (*SoundUserHook)(void);\r
static memptr DigiNextAddr;\r
static word DigiNextLen;\r
\r
-// SoundBlaster variables\r
-static boolean sbNoCheck,sbNoProCheck;\r
-static volatile boolean sbSamplePlaying;\r
-static byte sbOldIntMask = -1;\r
-static volatile byte huge *sbNextSegPtr;\r
-static byte sbDMA = 1,\r
- sbDMAa1 = 0x83,sbDMAa2 = 2,sbDMAa3 = 3,\r
- sba1Vals[] = {0x87,0x83,0,0x82},\r
- sba2Vals[] = {0,2,0,6},\r
- sba3Vals[] = {1,3,0,7};\r
-static int sbLocation = -1,sbInterrupt = 7,sbIntVec = 0xf,\r
- sbIntVectors[] = {-1,-1,0xa,0xb,-1,0xd,-1,0xf,-1,-1,-1};\r
-static volatile dword sbNextSegLen;\r
-static volatile SampledSound huge *sbSamples;\r
-static void interrupt (*sbOldIntHand)(void);\r
-static byte sbpOldFMMix,sbpOldVOCMix;\r
-\r
-// SoundSource variables\r
- boolean ssNoCheck;\r
- boolean ssActive;\r
- word ssControl,ssStatus,ssData;\r
- byte ssOn,ssOff;\r
- volatile byte far *ssSample;\r
- volatile dword ssLengthLeft;\r
-\r
// PC Sound variables\r
volatile byte pcLastSample,far *pcSound;\r
dword pcLengthLeft;\r
// Sequencer variables\r
boolean sqActive;\r
static word alFXReg;\r
-static ActiveTrack *tracks[sqMaxTracks],\r
- mytracks[sqMaxTracks];\r
-static word sqMode,sqFadeStep;\r
+static ActiveTrack *tracks[sqMaxTracks];//,\r
+//-- mytracks[sqMaxTracks];\r
+//--static word sqMode,sqFadeStep;\r
word far *sqHack,far *sqHackPtr,sqHackLen,sqHackSeqLen;\r
long sqHackTime;\r
\r
// Internal routines\r
void SDL_DigitizedDone(void);\r
\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_SetTimer0() - Sets system timer 0 to the specified speed\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-#pragma argsused\r
-static void\r
-SDL_SetTimer0(word speed)\r
-{\r
-#ifndef TPROF // If using Borland's profiling, don't screw with the timer\r
-asm pushf\r
-asm cli\r
-\r
- outportb(0x43,0x36); // Change timer 0\r
- outportb(0x40,speed);\r
- outportb(0x40,speed >> 8);\r
- // Kludge to handle special case for digitized PC sounds\r
- if (TimerDivisor == (1192030 / (TickBase * 100)))\r
- TimerDivisor = (1192030 / (TickBase * 10));\r
- else\r
- TimerDivisor = speed;\r
+//Assembly functions\r
+boolean alNoIRQ;\r
\r
-asm popf\r
-#else\r
- TimerDivisor = 0x10000;\r
-#endif\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_SetIntsPerSec() - Uses SDL_SetTimer0() to set the number of\r
-// interrupts generated by system timer 0 per second\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-static void\r
-SDL_SetIntsPerSec(word ints)\r
-{\r
- TimerRate = ints;\r
- SDL_SetTimer0(1192030 / ints);\r
-}\r
+int count_time=0;\r
+int count_fx=0;\r
+int extreme=0;\r
\r
-static void\r
-SDL_SetTimerSpeed(void)\r
+void SDL_turnOnPCSpeaker(word timerval)\r
{\r
- word rate;\r
- void interrupt (*isr)(void);\r
-\r
- if ((DigiMode == sds_PC) && DigiPlaying)\r
- {\r
- rate = TickBase * 100;\r
- isr = SDL_t0ExtremeAsmService;\r
- }\r
- else if\r
- (\r
- (MusicMode == smm_AdLib)\r
- || ((DigiMode == sds_SoundSource) && DigiPlaying)\r
- )\r
- {\r
- rate = TickBase * 10;\r
- isr = SDL_t0FastAsmService;\r
- }\r
- else\r
- {\r
- rate = TickBase * 2;\r
- isr = SDL_t0SlowAsmService;\r
- }\r
-\r
- if (rate != TimerRate)\r
- {\r
- setvect(8,isr);\r
- SDL_SetIntsPerSec(rate);\r
- TimerRate = rate;\r
+ __asm {\r
+ mov bx,timerval\r
+ mov al,0b6h\r
+ out 43h,al\r
+ mov al,bl\r
+ out 42h,al\r
+ mov al,bh\r
+ out 42h,al\r
+ in al,61h\r
+ or al,3\r
+ out 61h,al\r
}\r
}\r
\r
-#if 0\r
-//\r
-// SoundBlaster code\r
-//\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_SBStopSample() - Stops any active sampled sound and causes DMA\r
-// requests from the SoundBlaster to cease\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-#ifdef _MUSE_\r
-void\r
-#else\r
-static void\r
-#endif\r
-SDL_SBStopSample(void)\r
+void SDL_turnOffPCSpeaker()\r
{\r
- byte is;\r
-\r
-asm pushf\r
-asm cli\r
-\r
- if (sbSamplePlaying)\r
- {\r
- sbSamplePlaying = false;\r
-\r
- sbWriteDelay();\r
- sbOut(sbWriteCmd,0xd0); // Turn off DSP DMA\r
-\r
- is = inportb(0x21); // Restore interrupt mask bit\r
- if (sbOldIntMask & (1 << sbInterrupt))\r
- is |= (1 << sbInterrupt);\r
- else\r
- is &= ~(1 << sbInterrupt);\r
- outportb(0x21,is);\r
+ __asm {\r
+ in al,61h\r
+ and al,0fch\r
+ out 61h,al\r
}\r
-\r
-asm popf\r
}\r
\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_SBPlaySeg() - Plays a chunk of sampled sound on the SoundBlaster\r
-// Insures that the chunk doesn't cross a bank boundary, programs the DMA\r
-// controller, and tells the SB to start doing DMA requests for DAC\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-static dword\r
-SDL_SBPlaySeg(volatile byte huge *data,dword length)\r
+void SDL_setPCSpeaker(byte val)\r
{\r
- unsigned datapage;\r
- dword dataofs,uselen;\r
-\r
- uselen = length;\r
- datapage = FP_SEG(data) >> 12;\r
- dataofs = ((FP_SEG(data) & 0xfff) << 4) + FP_OFF(data);\r
- if (dataofs >= 0x10000)\r
- {\r
- datapage++;\r
- dataofs -= 0x10000;\r
+ __asm {\r
+ mov al,val\r
+ in al,61h\r
+ and al,0fch\r
+ or al,ah\r
+ out 61h,al\r
}\r
-\r
- if (dataofs + uselen > 0x10000)\r
- uselen = 0x10000 - dataofs;\r
-\r
- uselen--;\r
-\r
- // Program the DMA controller\r
-asm pushf\r
-asm cli\r
- outportb(0x0a,sbDMA | 4); // Mask off DMA on channel sbDMA\r
- outportb(0x0c,0); // Clear byte ptr flip-flop to lower byte\r
- outportb(0x0b,0x49); // Set transfer mode for D/A conv\r
- outportb(sbDMAa2,(byte)dataofs); // Give LSB of address\r
- outportb(sbDMAa2,(byte)(dataofs >> 8)); // Give MSB of address\r
- outportb(sbDMAa1,(byte)datapage); // Give page of address\r
- outportb(sbDMAa3,(byte)uselen); // Give LSB of length\r
- outportb(sbDMAa3,(byte)(uselen >> 8)); // Give MSB of length\r
- outportb(0x0a,sbDMA); // Re-enable DMA on channel sbDMA\r
-\r
- // Start playing the thing\r
- sbWriteDelay();\r
- sbOut(sbWriteCmd,0x14);\r
- sbWriteDelay();\r
- sbOut(sbWriteData,(byte)uselen);\r
- sbWriteDelay();\r
- sbOut(sbWriteData,(byte)(uselen >> 8));\r
-asm popf\r
-\r
- return(uselen + 1);\r
}\r
\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_SBService() - Services the SoundBlaster DMA interrupt\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-/*static*/ void interrupt\r
-SDL_SBService(void)\r
+void SDL_DoFX()\r
{\r
- dword used;\r
-\r
- sbIn(sbDataAvail); // Ack interrupt to SB\r
-\r
- if (sbNextSegPtr)\r
+ if(pcSound)\r
{\r
- used = SDL_SBPlaySeg(sbNextSegPtr,sbNextSegLen);\r
- if (sbNextSegLen <= used)\r
- sbNextSegPtr = nil;\r
- else\r
+ if(*pcSound!=pcLastSample)\r
{\r
- sbNextSegPtr += used;\r
- sbNextSegLen -= used;\r
+ pcLastSample=*pcSound;\r
+\r
+ if(pcLastSample)\r
+ SDL_turnOnPCSpeaker(pcLastSample*60);\r
+ else\r
+ SDL_turnOffPCSpeaker();\r
+ }\r
+ pcSound++;\r
+ pcLengthLeft--;\r
+ if(!pcLengthLeft)\r
+ {\r
+ pcSound=0;\r
+ SoundNumber=(soundnames)0;\r
+ SoundPriority=0;\r
+ SDL_turnOffPCSpeaker();\r
}\r
}\r
- else\r
- {\r
- SDL_SBStopSample();\r
- SDL_DigitizedDone();\r
- }\r
-\r
- outportb(0x20,0x20); // Ack interrupt\r
-}\r
\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_SBPlaySample() - Plays a sampled sound on the SoundBlaster. Sets up\r
-// DMA to play the sound\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-#ifdef _MUSE_\r
-void\r
-#else\r
-static void\r
-#endif\r
-SDL_SBPlaySample(byte huge *data,dword len)\r
-{\r
- dword used;\r
-\r
- SDL_SBStopSample();\r
-\r
-asm pushf\r
-asm cli\r
-\r
- used = SDL_SBPlaySeg(data,len);\r
- if (len <= used)\r
- sbNextSegPtr = nil;\r
- else\r
+ if(alSound && !alNoIRQ)\r
{\r
- sbNextSegPtr = data + used;\r
- sbNextSegLen = len - used;\r
+ if(*alSound)\r
+ {\r
+ alOut/*InIRQ*/(alFreqL,*alSound);\r
+ alOut/*InIRQ*/(alFreqH,alBlock);\r
+ }\r
+ else alOut/*InIRQ*/(alFreqH,0);\r
+ alSound++;\r
+ alLengthLeft--;\r
+ if(!alLengthLeft)\r
+ {\r
+ alSound=0;\r
+ SoundNumber=(soundnames)0;\r
+ SoundPriority=0;\r
+ alOut/*InIRQ*/(alFreqH,0);\r
+ }\r
}\r
\r
- // Save old interrupt status and unmask ours\r
- sbOldIntMask = inportb(0x21);\r
- outportb(0x21,sbOldIntMask & ~(1 << sbInterrupt));\r
-\r
- sbWriteDelay();\r
- sbOut(sbWriteCmd,0xd4); // Make sure DSP DMA is enabled\r
-\r
- sbSamplePlaying = true;\r
-\r
-asm popf\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_PositionSBP() - Sets the attenuation levels for the left and right\r
-// channels by using the mixer chip on the SB Pro. This hits a hole in\r
-// the address map for normal SBs.\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-static void\r
-SDL_PositionSBP(int leftpos,int rightpos)\r
-{\r
- byte v;\r
-\r
- if (!SBProPresent)\r
- return;\r
-\r
- leftpos = 15 - leftpos;\r
- rightpos = 15 - rightpos;\r
- v = ((leftpos & 0x0f) << 4) | (rightpos & 0x0f);\r
-\r
-asm pushf\r
-asm cli\r
-\r
- sbOut(sbpMixerAddr,sbpmVoiceVol);\r
- sbOut(sbpMixerData,v);\r
-\r
-asm popf\r
}\r
\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_CheckSB() - Checks to see if a SoundBlaster resides at a\r
-// particular I/O location\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-static boolean\r
-SDL_CheckSB(int port)\r
+void SDL_DoFast()\r
{\r
- int i;\r
-\r
- sbLocation = port << 4; // Initialize stuff for later use\r
+ count_fx++;\r
+ if(count_fx>=5)\r
+ {\r
+ count_fx=0;\r
\r
- sbOut(sbReset,true); // Reset the SoundBlaster DSP\r
-asm mov dx,0x388 // Wait >4usec\r
-asm in al, dx\r
-asm in al, dx\r
-asm in al, dx\r
-asm in al, dx\r
-asm in al, dx\r
-asm in al, dx\r
-asm in al, dx\r
-asm in al, dx\r
-asm in al, dx\r
+ SDL_DoFX();\r
\r
- sbOut(sbReset,false); // Turn off sb DSP reset\r
-asm mov dx,0x388 // Wait >100usec\r
-asm mov cx,100\r
-#ifdef __WATCOMC__\r
- __asm {\r
-#endif\r
-usecloop:\r
-asm in al,dx\r
-asm loop usecloop\r
-#ifdef __WATCOMC__\r
+ count_time++;\r
+ if(count_time>=2)\r
+ {\r
+ TimeCount++;\r
+ count_time=0;\r
+ }\r
}\r
-#endif\r
\r
- for (i = 0;i < 100;i++)\r
+ if(sqActive && !alNoIRQ)\r
{\r
- if (sbIn(sbDataAvail) & 0x80) // If data is available...\r
+ if(sqHackLen)\r
{\r
- if (sbIn(sbReadData) == 0xaa) // If it matches correct value\r
- return(true);\r
- else\r
+ do\r
{\r
- sbLocation = -1; // Otherwise not a SoundBlaster\r
- return(false);\r
+ if(sqHackTime>alTimeCount) break;\r
+ sqHackTime=alTimeCount+*(sqHackPtr+1);\r
+ alOut/*InIRQ*/(*(byte *)sqHackPtr,*(((byte *)sqHackPtr)+1));\r
+ sqHackPtr+=2;\r
+ sqHackLen-=4;\r
}\r
+ while(sqHackLen);\r
+ }\r
+ alTimeCount++;\r
+ if(!sqHackLen)\r
+ {\r
+ sqHackPtr=sqHack;\r
+ sqHackLen=sqHackSeqLen;\r
+ alTimeCount=0;\r
+ sqHackTime=0;\r
}\r
}\r
- sbLocation = -1; // Retry count exceeded - fail\r
- return(false);\r
-}\r
\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// Checks to see if a SoundBlaster is in the system. If the port passed is\r
-// -1, then it scans through all possible I/O locations. If the port\r
-// passed is 0, then it uses the default (2). If the port is >0, then\r
-// it just passes it directly to SDL_CheckSB()\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-static boolean\r
-SDL_DetectSoundBlaster(int port)\r
-{\r
- int i;\r
+//SS if(ssSample)\r
+//SS {\r
+//SS if(!(inp(ssStatus)&0x40))\r
+//SS {\r
+//SS outp(ssData,*ssSample++);\r
+//SS outp(ssControl,ssOff);\r
+//SS __asm push ax\r
+//SS __asm pop ax\r
+//SS outp(ssControl,ssOn);\r
+//SS __asm push ax\r
+//SS __asm pop ax\r
+//SS ssLengthLeft--;\r
+//SS if(!ssLengthLeft)\r
+//SS {\r
+//SS ssSample=0;\r
+//SS SDL_DigitizedDoneInIRQ();\r
+//SS }\r
+//SS }\r
+//SS }\r
\r
- if (port == 0) // If user specifies default, use 2\r
- port = 2;\r
- if (port == -1)\r
+ TimerCount+=TimerDivisor;\r
+ if(*((word *)&TimerCount+1))\r
{\r
- if (SDL_CheckSB(2)) // Check default before scanning\r
- return(true);\r
-\r
- if (SDL_CheckSB(4)) // Check other SB Pro location before scan\r
- return(true);\r
-\r
- for (i = 1;i <= 6;i++) // Scan through possible SB locations\r
- {\r
- if ((i == 2) || (i == 4))\r
- continue;\r
-\r
- if (SDL_CheckSB(i)) // If found at this address,\r
- return(true); // return success\r
- }\r
- return(false); // All addresses failed, return failure\r
+ *((word *)&TimerCount+1)=0;\r
+ t0OldService();\r
}\r
else\r
- return(SDL_CheckSB(port)); // User specified address or default\r
+ {\r
+ outp(0x20,0x20);\r
+ }\r
}\r
\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_SBSetDMA() - Sets the DMA channel to be used by the SoundBlaster\r
-// code. Sets up sbDMA, and sbDMAa1-sbDMAa3 (used by SDL_SBPlaySeg()).\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-void\r
-SDL_SBSetDMA(byte channel)\r
+// Timer 0 ISR for 700Hz interrupts\r
+void interrupt SDL_t0FastAsmService(void)\r
{\r
- if (channel > 3)\r
- Quit("SDL_SBSetDMA() - invalid SoundBlaster DMA channel");\r
-\r
- sbDMA = channel;\r
- sbDMAa1 = sba1Vals[channel];\r
- sbDMAa2 = sba2Vals[channel];\r
- sbDMAa3 = sba3Vals[channel];\r
+ SDL_DoFast();\r
}\r
\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_StartSB() - Turns on the SoundBlaster\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-static void\r
-SDL_StartSB(void)\r
+// Timer 0 ISR for 140Hz interrupts\r
+void interrupt SDL_t0SlowAsmService(void)\r
{\r
- byte timevalue,test;\r
-\r
- sbIntVec = sbIntVectors[sbInterrupt];\r
- if (sbIntVec < 0)\r
- Quit("SDL_StartSB: Illegal or unsupported interrupt number for SoundBlaster");\r
-\r
- sbOldIntHand = getvect(sbIntVec); // Get old interrupt handler\r
- setvect(sbIntVec,SDL_SBService); // Set mine\r
-\r
- sbWriteDelay();\r
- sbOut(sbWriteCmd,0xd1); // Turn on DSP speaker\r
-\r
- // Set the SoundBlaster DAC time constant for 7KHz\r
- timevalue = 256 - (1000000 / 7000);\r
- sbWriteDelay();\r
- sbOut(sbWriteCmd,0x40);\r
- sbWriteDelay();\r
- sbOut(sbWriteData,timevalue);\r
-\r
- SBProPresent = false;\r
- if (sbNoProCheck)\r
- return;\r
-\r
- // Check to see if this is a SB Pro\r
- sbOut(sbpMixerAddr,sbpmFMVol);\r
- sbpOldFMMix = sbIn(sbpMixerData);\r
- sbOut(sbpMixerData,0xbb);\r
- test = sbIn(sbpMixerData);\r
- if (test == 0xbb)\r
+ count_time++;\r
+ if(count_time>=2)\r
{\r
- // Boost FM output levels to be equivilent with digitized output\r
- sbOut(sbpMixerData,0xff);\r
- test = sbIn(sbpMixerData);\r
- if (test == 0xff)\r
- {\r
- SBProPresent = true;\r
-\r
- // Save old Voice output levels (SB Pro)\r
- sbOut(sbpMixerAddr,sbpmVoiceVol);\r
- sbpOldVOCMix = sbIn(sbpMixerData);\r
-\r
- // Turn SB Pro stereo DAC off\r
- sbOut(sbpMixerAddr,sbpmControl);\r
- sbOut(sbpMixerData,0); // 0=off,2=on\r
- }\r
+ TimeCount++;\r
+ count_time=0;\r
}\r
-}\r
\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_ShutSB() - Turns off the SoundBlaster\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-static void\r
-SDL_ShutSB(void)\r
-{\r
- SDL_SBStopSample();\r
+ SDL_DoFX();\r
\r
- if (SBProPresent)\r
+ TimerCount+=TimerDivisor;\r
+ if(*((word *)&TimerCount+1))\r
{\r
- // Restore FM output levels (SB Pro)\r
- sbOut(sbpMixerAddr,sbpmFMVol);\r
- sbOut(sbpMixerData,sbpOldFMMix);\r
-\r
- // Restore Voice output levels (SB Pro)\r
- sbOut(sbpMixerAddr,sbpmVoiceVol);\r
- sbOut(sbpMixerData,sbpOldVOCMix);\r
+ *((word *)&TimerCount+1)=0;\r
+ t0OldService();\r
}\r
-\r
- setvect(sbIntVec,sbOldIntHand); // Set vector back\r
+ else\r
+ outp(0x20,0x20);\r
}\r
-#endif\r
\r
-// Sound Source Code\r
\r
///////////////////////////////////////////////////////////////////////////\r
//\r
-// SDL_SSStopSample() - Stops a sample playing on the Sound Source\r
+// SDL_SetTimer0() - Sets system timer 0 to the specified speed\r
//\r
///////////////////////////////////////////////////////////////////////////\r
-#ifdef _MUSE_\r
-void\r
-#else\r
+#pragma argsused\r
static void\r
-#endif\r
-SDL_SSStopSample(void)\r
+SDL_SetTimer0(word speed)\r
{\r
+#ifndef TPROF // If using Borland's profiling, don't screw with the timer\r
asm pushf\r
asm cli\r
\r
- (long)ssSample = 0;\r
+ outportb(0x43,0x36); // Change timer 0\r
+ outportb(0x40,speed);\r
+ outportb(0x40,speed >> 8);\r
+ // Kludge to handle special case for digitized PC sounds\r
+ if (TimerDivisor == (1192030 / (TickBase * 100)))\r
+ TimerDivisor = (1192030 / (TickBase * 10));\r
+ else\r
+ TimerDivisor = speed;\r
\r
asm popf\r
+#else\r
+ TimerDivisor = 0x10000;\r
+#endif\r
}\r
\r
///////////////////////////////////////////////////////////////////////////\r
//\r
-// SDL_SSService() - Handles playing the next sample on the Sound Source\r
+// SDL_SetIntsPerSec() - Uses SDL_SetTimer0() to set the number of\r
+// interrupts generated by system timer 0 per second\r
//\r
///////////////////////////////////////////////////////////////////////////\r
static void\r
-SDL_SSService(void)\r
+SDL_SetIntsPerSec(word ints)\r
+{\r
+ TimerRate = ints;\r
+ SDL_SetTimer0(1192030 / ints);\r
+}\r
+\r
+#ifndef SD_USECATA3DSETTIMERSPEED\r
+static void\r
+SDL_SetTimerSpeed(void)\r
{\r
- //boolean gotit;\r
- boolean doneflag=false;\r
- byte v;\r
+ word rate;\r
+ void interrupt (*isr)(void);\r
\r
- while (ssSample)\r
+ if ((DigiMode == sds_PC) && DigiPlaying)\r
{\r
- __asm {\r
- mov dx,[ssStatus] // Check to see if FIFO is currently empty\r
- in al,dx\r
- test al,0x40\r
- jnz done // Nope - don't push any more data out\r
- jmp end\r
-#ifdef __BORLANDC__\r
+ rate = TickBase * 100;\r
+ isr = SDL_t0ExtremeAsmService;\r
}\r
-#endif\r
- done:\r
-#ifdef __BORLANDC__\r
- __asm {\r
-#endif\r
- mov doneflag,1\r
-#ifdef __BORLANDC__\r
+ else if\r
+ (\r
+ (MusicMode == smm_AdLib)\r
+ || ((DigiMode == sds_SoundSource) && DigiPlaying)\r
+ )\r
+ {\r
+ rate = TickBase * 10;\r
+ isr = SDL_t0FastAsmService;\r
}\r
-#endif\r
- end:\r
-#ifdef __WATCOMC__\r
+ else\r
+ {\r
+ rate = TickBase * 2;\r
+ isr = SDL_t0SlowAsmService;\r
}\r
-#endif\r
- if(!doneflag)\r
- {\r
- v = *ssSample++;\r
- if (!(--ssLengthLeft))\r
- {\r
- (long)ssSample = 0;\r
- SDL_DigitizedDone();\r
- }\r
\r
- __asm {\r
- mov dx,[ssData] // Pump the value out\r
- mov al,[v]\r
- out dx,al\r
-\r
- mov dx,[ssControl] // Pulse printer select\r
- mov al,[ssOff]\r
- out dx,al\r
- push ax\r
- pop ax\r
- mov al,[ssOn]\r
- out dx,al\r
-\r
- push ax // Delay a short while\r
- pop ax\r
- push ax\r
- pop ax\r
-done:;\r
- }\r
- }\r
+ if (rate != TimerRate)\r
+ {\r
+ setvect(8,isr);\r
+ SDL_SetIntsPerSec(rate);\r
+ TimerRate = rate;\r
}\r
}\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_SSPlaySample() - Plays the specified sample on the Sound Source\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-#ifdef _MUSE_\r
-void\r
#else\r
static void\r
-#endif\r
-SDL_SSPlaySample(byte huge *data,dword len)\r
+SDL_SetTimerSpeed(void)\r
{\r
-asm pushf\r
-asm cli\r
-\r
- ssLengthLeft = len;\r
- ssSample = (volatile byte far *)data;\r
+ word rate;\r
\r
-asm popf\r
+ if (MusicMode == smm_AdLib)\r
+ rate = TickBase * 8;\r
+ else\r
+ rate = TickBase * 2;\r
+ SDL_SetIntsPerSec(rate);\r
}\r
+#endif\r
\r
///////////////////////////////////////////////////////////////////////////\r
//\r
-// SDL_StartSS() - Sets up for and turns on the Sound Source\r
+// SDL_TimingService() - Used by SDL_InitDelay() to determine a timing\r
+// value for the current system that we're running on\r
//\r
///////////////////////////////////////////////////////////////////////////\r
-static void\r
-SDL_StartSS(void)\r
+//static void interrupt\r
+void interrupt\r
+SDL_TimingService(void)\r
{\r
- if (ssPort == 3)\r
- ssControl = 0x27a; // If using LPT3\r
- else if (ssPort == 2)\r
- ssControl = 0x37a; // If using LPT2\r
- else\r
- ssControl = 0x3be; // If using LPT1\r
- ssStatus = ssControl - 1;\r
- ssData = ssStatus - 1;\r
-\r
- ssOn = 0x04;\r
- if (ssIsTandy)\r
- ssOff = 0x0e; // Tandy wierdness\r
- else\r
- ssOff = 0x0c; // For normal machines\r
+ //TimerVal = _CX;\r
+ __asm {\r
+ mov TimerVal,cx\r
+ }\r
+ TimerDone = 1;\r
\r
- outportb(ssControl,ssOn); // Enable SS\r
+ outportb(0x20,0x20); // Ack interrupt\r
}\r
-\r
+#ifdef SD_USECATA3DSETTIMERSPEED\r
///////////////////////////////////////////////////////////////////////////\r
//\r
-// SDL_ShutSS() - Turns off the Sound Source\r
+// SDL_InitDelay() - Sets up TimerDelay's for SDL_Delay()\r
//\r
///////////////////////////////////////////////////////////////////////////\r
static void\r
-SDL_ShutSS(void)\r
-{\r
- outportb(ssControl,ssOff);\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-// SDL_CheckSS() - Checks to see if a Sound Source is present at the\r
-// location specified by the sound source variables\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-static boolean\r
-SDL_CheckSS(void)\r
+SDL_InitDelay(void)\r
{\r
- boolean present = false, chkdone=0;\r
- dword lasttime;\r
-\r
- // Turn the Sound Source on and wait awhile (4 ticks)\r
- SDL_StartSS();\r
+ int i;\r
+ word timer;\r
\r
- lasttime = TimeCount;\r
- while (TimeCount < lasttime + 4)\r
- {}\r
+ setvect(8,SDL_TimingService); // Set to my timer 0 ISR\r
\r
- __asm {\r
- mov dx,[ssStatus] // Check to see if FIFO is currently empty\r
- in al,dx\r
- test al,0x40\r
- jnz checkdone // Nope - Sound Source not here\r
+ SDL_SetIntsPerSec(1000); // Time 1ms\r
\r
- mov cx,32 // Force FIFO overflow (FIFO is 16 bytes)\r
+ for (i = 0,timer = 0;i < 10;i++) // Do timing test 10 times\r
+ {\r
+ __asm {\r
+ xor dx,dx // Zero DX\r
+ mov cx,0xffff // Put starting value in CX\r
+ mov [TimerDone],cx // TimerDone = false - 1\r
#ifdef __BORLANDC__\r
- }\r
+ }\r
#endif\r
-outloop:\r
+startloop:\r
#ifdef __BORLANDC__\r
- __asm {\r
+ __asm {\r
#endif\r
- mov dx,[ssData] // Pump a neutral value out\r
- mov al,0x80\r
- out dx,al\r
-\r
- mov dx,[ssControl] // Pulse printer select\r
- mov al,[ssOff]\r
- out dx,al\r
- push ax\r
- pop ax\r
- mov al,[ssOn]\r
- out dx,al\r
-\r
- push ax // Delay a short while before we do this again\r
- pop ax\r
- push ax\r
- pop ax\r
-\r
- loop outloop\r
-\r
- mov dx,[ssStatus] // Is FIFO overflowed now?\r
- in al,dx\r
- test al,0x40\r
- jz checkdone // Nope, still not - Sound Source not here\r
- jmp end\r
+ or [TimerDone],0\r
+ jnz startloop // Make sure we're at the start\r
#ifdef __BORLANDC__\r
- }\r
+ }\r
#endif\r
-checkdone:\r
+loop_:\r
#ifdef __BORLANDC__\r
- __asm {\r
+ __asm {\r
#endif\r
- mov chkdone,1\r
+ test [TimerDone],1 // See if TimerDone flag got hit\r
+ jnz done // Yep - drop out of the loop\r
+ loop loop_\r
#ifdef __BORLANDC__\r
- }\r
+ }\r
#endif\r
- end:\r
+done:\r
#ifdef __WATCOMC__\r
}\r
#endif\r
\r
- if(!chkdone) present = true; // Yes - it's here!\r
+ if (0xffff - TimerVal > timer)\r
+ timer = 0xffff - TimerVal;\r
+ }\r
+ timer += timer / 2; // Use some slop\r
+ TimerDelay10 = timer / (1000 / 10);\r
+ TimerDelay25 = timer / (1000 / 25);\r
+ TimerDelay100 = timer / (1000 / 100);\r
+\r
+ SDL_SetTimer0(0); // Reset timer 0\r
\r
-//checkdone:\r
- SDL_ShutSS();\r
- return(present);\r
+ setvect(8,t0OldService); // Set back to old ISR\r
}\r
-\r
-static boolean\r
-SDL_DetectSoundSource(void)\r
+#endif\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SDL_Delay() - Delays the specified amount of time\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+static void\r
+SDL_Delay(word delay)\r
{\r
- for (ssPort = 1;ssPort <= 3;ssPort++)\r
- if (SDL_CheckSS())\r
- return(true);\r
- return(false);\r
+ if (!delay)\r
+ return;\r
+\r
+ __asm {\r
+ mov cx,[delay]\r
+#ifdef __BORLANDC__\r
+ }\r
+#endif\r
+loop_:\r
+#ifdef __BORLANDC__\r
+ __asm {\r
+#endif\r
+ test [TimerDone],0 // Useless code - just for timing equivilency\r
+ jnz done\r
+ loop loop_\r
+#ifdef __BORLANDC__\r
+ }\r
+#endif\r
+done:\r
+#ifdef __WATCOMC__\r
+ }\r
+#endif\r
}\r
\r
//\r
asm pushf\r
asm cli\r
\r
- (long)pcSound = 0;\r
+ /*(long)*/pcSound = 0;\r
\r
SDL_IndicatePC(false);\r
\r
asm pushf\r
asm cli\r
\r
- (long)pcSound = 0;\r
+ /*(long)*/pcSound = 0;\r
\r
asm in al,0x61 // Turn the speaker off\r
asm and al,0xfd // ~2\r
asm popf\r
}\r
\r
-#if 0\r
///////////////////////////////////////////////////////////////////////////\r
//\r
// SDL_PCService() - Handles playing the next sample in a PC sound\r
}\r
}\r
}\r
-#endif\r
\r
///////////////////////////////////////////////////////////////////////////\r
//\r
// Stuff for digitized sounds\r
//\r
memptr\r
-SDL_LoadDigiSegment(word page)\r
+SDL_LoadDigiSegment(word page, global_game_variables_t *gvar)\r
{\r
memptr addr;\r
\r
asm out dx,al\r
#endif\r
\r
- addr = PM_GetSoundPage(page, gvar);\r
- PM_SetPageLock(PMSoundStart + page,pml_Locked);\r
+ addr = PM_GetSoundPage(page);\r
+ PM_SetPageLock(gvar->pm.fi.PMSoundStart + page,pml_Locked, gvar);\r
\r
#if 0 // for debugging\r
asm mov dx,STATUS_REGISTER_1\r
case sds_PC:\r
SDL_PCPlaySample(addr,len);\r
break;\r
- case sds_SoundSource:\r
- SDL_SSPlaySample(addr,len);\r
- break;\r
- case sds_SoundBlaster:\r
- SDL_SBPlaySample(addr,len);\r
- break;\r
+//SS case sds_SoundSource:\r
+//SS SDL_SSPlaySample(addr,len);\r
+//SS break;\r
+//SB case sds_SoundBlaster:\r
+//SB SDL_SBPlaySample(addr,len);\r
+//SB break;\r
}\r
}\r
\r
void\r
-SD_StopDigitized(void)\r
+SD_StopDigitized(global_game_variables_t *gvar)\r
{\r
int i;\r
\r
case sds_PC:\r
SDL_PCStopSample();\r
break;\r
- case sds_SoundSource:\r
- SDL_SSStopSample();\r
- break;\r
- case sds_SoundBlaster:\r
- SDL_SBStopSample();\r
- break;\r
+//SS case sds_SoundSource:\r
+//SS SDL_SSStopSample();\r
+//SS break;\r
+//SB case sds_SoundBlaster:\r
+//SB SDL_SBStopSample();\r
+//SB break;\r
}\r
\r
asm popf\r
\r
for (i = DigiLastStart;i < DigiLastEnd;i++)\r
- PM_SetPageLock(i + PMSoundStart,pml_Unlocked);\r
+ PM_SetPageLock(i + gvar->pm.fi.PMSoundStart,pml_Unlocked, gvar);\r
DigiLastStart = 1;\r
DigiLastEnd = 0;\r
}\r
\r
void\r
-SD_Poll(void)\r
+SD_Poll(global_game_variables_t *gvar)\r
{\r
if (DigiLeft && !DigiNextAddr)\r
{\r
DigiLeft -= DigiNextLen;\r
if (!DigiLeft)\r
DigiLastSegment = true;\r
- DigiNextAddr = SDL_LoadDigiSegment(DigiPage++);\r
+ DigiNextAddr = SDL_LoadDigiSegment(DigiPage++, gvar);\r
}\r
if (DigiMissed && DigiNextAddr)\r
{\r
}\r
\r
void\r
-SD_SetPosition(int leftpos,int rightpos)\r
+SD_SetPosition(int leftpos,int rightpos, global_game_variables_t *gvar)\r
{\r
if\r
(\r
|| (rightpos > 15)\r
|| ((leftpos == 15) && (rightpos == 15))\r
)\r
- Quit("SD_SetPosition: Illegal position");\r
+ Quit(gvar, "SD_SetPosition: Illegal position");\r
\r
switch (DigiMode)\r
{\r
- case sds_SoundBlaster:\r
- SDL_PositionSBP(leftpos,rightpos);\r
- break;\r
+//SB case sds_SoundBlaster:\r
+//SB SDL_PositionSBP(leftpos,rightpos);\r
+//SB break;\r
}\r
}\r
\r
void\r
-SD_PlayDigitized(word which,int leftpos,int rightpos)\r
+SD_PlayDigitized(word which,int leftpos,int rightpos, global_game_variables_t *gvar)\r
{\r
word len;\r
memptr addr;\r
if (!DigiMode)\r
return;\r
\r
- SD_StopDigitized();\r
+ SD_StopDigitized(gvar);\r
if (which >= NumDigi)\r
- Quit("SD_PlayDigitized: bad sound number");\r
+ Quit(gvar, "SD_PlayDigitized: bad sound number");\r
\r
- SD_SetPosition(leftpos,rightpos);\r
+ SD_SetPosition(leftpos,rightpos, gvar);\r
\r
DigiPage = DigiList[(which * 2) + 0];\r
DigiLeft = DigiList[(which * 2) + 1];\r
DigiLastEnd = DigiPage + ((DigiLeft + (PMPageSize - 1)) / PMPageSize);\r
\r
len = (DigiLeft >= PMPageSize)? PMPageSize : (DigiLeft % PMPageSize);\r
- addr = SDL_LoadDigiSegment(DigiPage++);\r
+ addr = SDL_LoadDigiSegment(DigiPage++, gvar);\r
\r
DigiPlaying = true;\r
DigiLastSegment = false;\r
if (!DigiLeft)\r
DigiLastSegment = true;\r
\r
- SD_Poll();\r
+ SD_Poll(gvar);\r
}\r
\r
void\r
}\r
\r
void\r
-SD_SetDigiDevice(SDSMode mode)\r
+SD_SetDigiDevice(SDSMode mode, global_game_variables_t *gvar)\r
{\r
boolean devicenotpresent;\r
\r
if (mode == DigiMode)\r
return;\r
\r
- SD_StopDigitized();\r
+ SD_StopDigitized(gvar);\r
\r
devicenotpresent = false;\r
switch (mode)\r
\r
if (!devicenotpresent)\r
{\r
- if (DigiMode == sds_SoundSource)\r
- SDL_ShutSS();\r
+//SS if (DigiMode == sds_SoundSource)\r
+//SS SDL_ShutSS();\r
\r
DigiMode = mode;\r
\r
- if (mode == sds_SoundSource)\r
- SDL_StartSS();\r
+//SS if (mode == sds_SoundSource)\r
+//SS SDL_StartSS();\r
\r
SDL_SetTimerSpeed();\r
}\r
}\r
\r
void\r
-SDL_SetupDigi(void)\r
+SDL_SetupDigi(global_game_variables_t *gvar)\r
{\r
memptr list;\r
word far *p,\r
pg;\r
int i;\r
\r
- PM_UnlockMainMem();\r
- MM_GetPtr(&list,PMPageSize);\r
- PM_CheckMainMem();\r
- p = (word far *)MK_FP(PM_GetPage(ChunksInFile - 1),0);\r
+ PM_UnlockMainMem(gvar);\r
+ MM_GetPtr(&list,PMPageSize, gvar);\r
+ PM_CheckMainMem(gvar);\r
+ p = (word far *)MK_FP(PM_GetPage(gvar->pm.fi.ChunksInFile - 1, gvar),0);\r
_fmemcpy((void far *)list,(void far *)p,PMPageSize);\r
- pg = PMSoundStart;\r
+ pg = gvar->pm.fi.PMSoundStart;\r
for (i = 0;i < PMPageSize / (sizeof(word) * 2);i++,p += 2)\r
{\r
- if (pg >= ChunksInFile - 1)\r
+ if (pg >= gvar->pm.fi.ChunksInFile - 1)\r
break;\r
pg += (p[1] + (PMPageSize - 1)) / PMPageSize;\r
}\r
- PM_UnlockMainMem();\r
- MM_GetPtr((memptr *)&DigiList,i * sizeof(word) * 2);\r
+ PM_UnlockMainMem(gvar);\r
+ MM_GetPtr(MEMPTRCONV DigiList,i * sizeof(word) * 2, gvar);\r
_fmemcpy((void far *)DigiList,(void far *)list,i * sizeof(word) * 2);\r
- MM_FreePtr(&list);\r
+ MM_FreePtr(&list, gvar);\r
NumDigi = i;\r
\r
for (i = 0;i < LASTSOUND;i++)\r
asm pushf\r
asm cli\r
\r
-asm mov dx,0x388\r
-asm mov al,[n]\r
-asm out dx,al\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm inc dx\r
-asm mov al,[b]\r
-asm out dx,al\r
+asm mov dx,0x388\r
+asm mov al,[n]\r
+asm out dx,al\r
+#if 0\r
+ SDL_Delay(TimerDelay10);\r
+#else\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+#endif\r
+\r
+asm mov dx,0x389\r
+asm mov al,[b]\r
+asm out dx,al\r
\r
asm popf\r
\r
-asm dec dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
+#if 0\r
+ SDL_Delay(TimerDelay25);\r
+#else\r
+asm mov dx,0x388\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
-asm in al,dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+asm in al, dx\r
+#endif\r
}\r
\r
-#if 0\r
+//#if 0\r
///////////////////////////////////////////////////////////////////////////\r
//\r
// SDL_SetInstrument() - Puts an instrument into a generator\r
//\r
///////////////////////////////////////////////////////////////////////////\r
-static void\r
+//static void\r
+void\r
SDL_SetInstrument(int track,int which,Instrument far *inst,boolean percussive)\r
{\r
byte c,m;\r
\r
alOut(which + alFeedCon,inst->nConn); // DEBUG - I think this is right\r
}\r
-#endif\r
+//#endif\r
\r
///////////////////////////////////////////////////////////////////////////\r
//\r
asm pushf\r
asm cli\r
\r
- (long)alSound = 0;\r
+ /*(long)*/alSound = 0;\r
alOut(alFreqH + 0,0);\r
\r
asm popf\r
#else\r
static void\r
#endif\r
-SDL_ALPlaySound(AdLibSound far *sound)\r
+SDL_ALPlaySound(AdLibSound far *sound, global_game_variables_t *gvar)\r
{\r
- Instrument far *inst;\r
+ Instrument __far *inst;\r
byte huge *data;\r
\r
SDL_ALStopSound();\r
if (!(inst->mSus | inst->cSus))\r
{\r
asm popf\r
- Quit("SDL_ALPlaySound() - Bad instrument");\r
+ Quit(gvar, "SDL_ALPlaySound() - Bad instrument");\r
}\r
\r
SDL_AlSetFXInst(&alZeroInst); // DEBUG\r
asm popf\r
}\r
\r
-#if 0\r
+//#if 0\r
///////////////////////////////////////////////////////////////////////////\r
//\r
// SDL_ALSoundService() - Plays the next sample out through the AdLib card\r
\r
if (!(--alLengthLeft))\r
{\r
- (long)alSound = 0;\r
+ /*(long)*/alSound = 0;\r
alOut(alFreqH + 0,0);\r
SDL_SoundFinished();\r
}\r
}\r
}\r
+//#endif\r
+\r
+#if 0\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SDL_SelectMeasure() - sets up sequencing variables for a given track\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+void\r
+SDL_SelectMeasure(ActiveTrack *track)\r
+{\r
+ track->seq = track->moods[track->mood];\r
+ track->nextevent = 0;\r
+}\r
#endif\r
\r
-#if 0\r
+//#if 0\r
void\r
SDL_ALService(void)\r
{\r
byte a,v;\r
word w;\r
\r
+ a=v=0;\r
+\r
if (!sqActive)\r
return;\r
\r
alTimeCount = sqHackTime = 0;\r
}\r
}\r
-#endif\r
+//#endif\r
\r
///////////////////////////////////////////////////////////////////////////\r
//\r
status1 = readstat();\r
alOut(2,0xff); // Set timer 1\r
alOut(4,0x21); // Start timer 1\r
-#if 0\r
SDL_Delay(TimerDelay100);\r
-#else\r
+\r
+#if 0\r
__asm {\r
mov dx,0x388\r
mov cx,100\r
return(false);\r
}\r
\r
-#if 0\r
///////////////////////////////////////////////////////////////////////////\r
//\r
// SDL_t0Service() - My timer 0 ISR which handles the different timings and\r
// dispatches to whatever other routines are appropriate\r
//\r
///////////////////////////////////////////////////////////////////////////\r
-static void interrupt\r
+//static void interrupt\r
+void interrupt\r
SDL_t0Service(void)\r
{\r
static word count = 1;\r
+ boolean myackflag = 0;\r
\r
-#if 1 // for debugging\r
+//00#if 0 // for debugging\r
asm mov dx,STATUS_REGISTER_1\r
asm in al,dx\r
asm mov dx,ATR_INDEX\r
asm out dx,al\r
asm mov al,4 // red\r
asm out dx,al\r
-#endif\r
+//00#endif\r
\r
HackCount++;\r
\r
if ((MusicMode == smm_AdLib) || (DigiMode == sds_SoundSource))\r
{\r
SDL_ALService();\r
- SDL_SSService();\r
+//SS SDL_SSService();\r
// if (!(++count & 7))\r
if (!(++count % 10))\r
{\r
}\r
}\r
\r
-asm mov ax,[WORD PTR TimerCount]\r
-asm add ax,[WORD PTR TimerDivisor]\r
-asm mov [WORD PTR TimerCount],ax\r
-asm jnc myack\r
- t0OldService(); // If we overflow a word, time to call old int handler\r
-asm jmp olddone\r
-myack:;\r
- outportb(0x20,0x20); // Ack the interrupt\r
-olddone:;\r
+ __asm {\r
+ mov ax,[WORD PTR TimerCount]\r
+ add ax,[WORD PTR TimerDivisor]\r
+ mov [WORD PTR TimerCount],ax\r
+ jnc myack\r
+ jmp end1\r
+#ifdef __BORLANDC__\r
+ }\r
+#endif\r
+myack:\r
+#ifdef __BORLANDC__\r
+ __asm {\r
+#endif\r
+ mov myackflag,1\r
+#ifdef __BORLANDC__\r
+ }\r
+#endif\r
+end1:\r
+#ifdef __WATCOMC__\r
+ }\r
+#endif\r
+ if(!myackflag)\r
+ t0OldService(); // If we overflow a word, time to call old int handler\r
+ else\r
+ outportb(0x20,0x20); // Ack the interrupt\r
\r
-#if 1 // for debugging\r
+//00#if 0 // for debugging\r
asm mov dx,STATUS_REGISTER_1\r
asm in al,dx\r
asm mov dx,ATR_INDEX\r
asm out dx,al\r
asm mov al,0x20 // normal\r
asm out dx,al\r
-#endif\r
+//00#endif\r
}\r
-#endif\r
\r
////////////////////////////////////////////////////////////////////////////\r
//\r
}\r
SoundNumber = SoundPriority = 0;\r
}\r
+#if 0\r
+static void\r
+SDL_SetTimerSpeed(void)\r
+{\r
+ word rate;\r
\r
+ if (MusicMode == smm_AdLib)\r
+ rate = TickBase * 8;\r
+ else\r
+ rate = TickBase * 2;\r
+ SDL_SetIntsPerSec(rate);\r
+}\r
+#endif\r
// Public routines\r
\r
///////////////////////////////////////////////////////////////////////////\r
//\r
///////////////////////////////////////////////////////////////////////////\r
boolean\r
-SD_SetSoundMode(SDMode mode)\r
+SD_SetSoundMode(SDMode mode, global_game_variables_t *gvar)\r
{\r
boolean result = false;\r
word tableoffset;\r
\r
- SD_StopSound();\r
+ SD_StopSound(gvar);\r
\r
#ifndef _MUSE_\r
if ((mode == sdm_AdLib) && !AdLibPresent)\r
SDL_ShutDevice();\r
SoundMode = mode;\r
#ifndef _MUSE_\r
- SoundTable = (word *)(&audiosegs[tableoffset]);\r
+ SoundTable = (word *)(&gvar->ca.audiosegs[tableoffset]);\r
#endif\r
SDL_StartDevice();\r
}\r
//\r
///////////////////////////////////////////////////////////////////////////\r
void\r
-SD_Startup(void)\r
+SD_Startup(global_game_variables_t *gvar)\r
{\r
int i;\r
\r
if (SD_Started)\r
return;\r
-\r
+#ifndef SD_USECATA3DSETTIMERSPEED\r
SDL_SetDS();\r
-\r
+#endif\r
ssIsTandy = false;\r
- ssNoCheck = false;\r
+//SS ssNoCheck = false;\r
alNoCheck = false;\r
- sbNoCheck = false;\r
- sbNoProCheck = false;\r
+//SB sbNoCheck = false;\r
+//SB sbNoProCheck = false;\r
#ifndef _MUSE_\r
for (i = 1;i < _argc;i++)\r
{\r
case 0: // No AdLib detection\r
alNoCheck = true;\r
break;\r
- case 1: // No SoundBlaster detection\r
- sbNoCheck = true;\r
- break;\r
- case 2: // No SoundBlaster Pro detection\r
- sbNoProCheck = true;\r
- break;\r
- case 3:\r
- ssNoCheck = true; // No Sound Source detection\r
- break;\r
+//SB case 1: // No SoundBlaster detection\r
+//SB sbNoCheck = true;\r
+//SB break;\r
+//SB case 2: // No SoundBlaster Pro detection\r
+//SB sbNoProCheck = true;\r
+//SB break;\r
+//SS case 3:\r
+//SS ssNoCheck = true; // No Sound Source detection\r
+//SS break;\r
case 4: // Tandy Sound Source handling\r
ssIsTandy = true;\r
break;\r
- case 5: // Sound Source present at LPT1\r
- ssPort = 1;\r
- ssNoCheck = SoundSourcePresent = true;\r
- break;\r
- case 6: // Sound Source present at LPT2\r
- ssPort = 2;\r
- ssNoCheck = SoundSourcePresent = true;\r
- break;\r
- case 7: // Sound Source present at LPT3\r
- ssPort = 3;\r
- ssNoCheck = SoundSourcePresent = true;\r
- break;\r
+//SS case 5: // Sound Source present at LPT1\r
+//SS ssPort = 1;\r
+//SS ssNoCheck = SoundSourcePresent = true;\r
+//SS break;\r
+//SS case 6: // Sound Source present at LPT2\r
+//SS ssPort = 2;\r
+//SS ssNoCheck = SoundSourcePresent = true;\r
+//SS break;\r
+//SS case 7: // Sound Source present at LPT3\r
+//SS ssPort = 3;\r
+//SS ssNoCheck = SoundSourcePresent = true;\r
+//SS break;\r
}\r
}\r
#endif\r
SoundUserHook = 0;\r
\r
t0OldService = getvect(8); // Get old timer 0 ISR\r
+#ifdef SD_USECATA3DSETTIMERSPEED\r
+ SDL_InitDelay(); // SDL_InitDelay() uses t0OldService\r
\r
+ setvect(8,SDL_t0Service); // Set to my timer 0 ISR\r
+#endif\r
LocalTime = TimeCount = alTimeCount = 0;\r
\r
- SD_SetSoundMode(sdm_Off);\r
+ SD_SetSoundMode(sdm_Off, gvar);\r
SD_SetMusicMode(smm_Off);\r
\r
- if (!ssNoCheck)\r
- SoundSourcePresent = SDL_DetectSoundSource();\r
+//SS if (!ssNoCheck)\r
+//SS SoundSourcePresent = SDL_DetectSoundSource();\r
\r
if (!alNoCheck)\r
{\r
AdLibPresent = SDL_DetectAdLib();\r
- if (AdLibPresent && !sbNoCheck)\r
- {\r
- int port = -1;\r
- char *env = getenv("BLASTER");\r
- if (env)\r
- {\r
- long temp;\r
- while (*env)\r
- {\r
- while (isspace(*env))\r
- env++;\r
-\r
- switch (toupper(*env))\r
- {\r
- case 'A':\r
- temp = strtol(env + 1,&env,16);\r
- if\r
- (\r
- (temp >= 0x210)\r
- && (temp <= 0x260)\r
- && (!(temp & 0x00f))\r
- )\r
- port = (temp - 0x200) >> 4;\r
- else\r
- Quit("SD_Startup: Unsupported address value in BLASTER");\r
- break;\r
- case 'I':\r
- temp = strtol(env + 1,&env,10);\r
- if\r
- (\r
- (temp >= 0)\r
- && (temp <= 10)\r
- && (sbIntVectors[temp] != -1)\r
- )\r
- {\r
- sbInterrupt = temp;\r
- sbIntVec = sbIntVectors[sbInterrupt];\r
- }\r
- else\r
- Quit("SD_Startup: Unsupported interrupt value in BLASTER");\r
- break;\r
- case 'D':\r
- temp = strtol(env + 1,&env,10);\r
- if ((temp == 0) || (temp == 1) || (temp == 3))\r
- SDL_SBSetDMA(temp);\r
- else\r
- Quit("SD_Startup: Unsupported DMA value in BLASTER");\r
- break;\r
- default:\r
- while (isspace(*env))\r
- env++;\r
- while (*env && !isspace(*env))\r
- env++;\r
- break;\r
- }\r
- }\r
- }\r
- SoundBlasterPresent = SDL_DetectSoundBlaster(port);\r
- }\r
+//SB if (AdLibPresent) && !sbNoCheck)\r
+//SB {\r
+//SB int port = -1;\r
+//SB char *env = getenv("BLASTER");\r
+//SB if (env)\r
+//SB {\r
+//SB long temp;\r
+//SB while (*env)\r
+//SB {\r
+//SB while (isspace(*env))\r
+//SB env++;\r
+//SB\r
+//SB switch (toupper(*env))\r
+//SB {\r
+//SB case 'A':\r
+//SB temp = strtol(env + 1,&env,16);\r
+//SB if\r
+//SB (\r
+//SB (temp >= 0x210)\r
+//SB && (temp <= 0x260)\r
+//SB && (!(temp & 0x00f))\r
+//SB )\r
+//SB port = (temp - 0x200) >> 4;\r
+//SB else\r
+//SB Quit(gvar, "SD_Startup: Unsupported address value in BLASTER");\r
+//SB break;\r
+//SB case 'I':\r
+//SB temp = strtol(env + 1,&env,10);\r
+//SB if\r
+//SB (\r
+//SB (temp >= 0)\r
+//SB && (temp <= 10)\r
+//SB && (sbIntVectors[temp] != -1)\r
+//SB )\r
+//SB {\r
+//SB sbInterrupt = temp;\r
+//SB sbIntVec = sbIntVectors[sbInterrupt];\r
+//SB }\r
+//SB else\r
+//SB Quit(gvar, "SD_Startup: Unsupported interrupt value in BLASTER");\r
+//SB break;\r
+//SB case 'D':\r
+//SB temp = strtol(env + 1,&env,10);\r
+//SB if ((temp == 0) || (temp == 1) || (temp == 3))\r
+//SB SDL_SBSetDMA(temp);\r
+//SB else\r
+//SB Quit(gvar, "SD_Startup: Unsupported DMA value in BLASTER");\r
+//SB break;\r
+//SB default:\r
+//SB while (isspace(*env))\r
+//SB env++;\r
+//SB while (*env && !isspace(*env))\r
+//SB env++;\r
+//SB break;\r
+//SB }\r
+//SB }\r
+//SB }\r
+//SB SoundBlasterPresent = SDL_DetectSoundBlaster(port);\r
+//SB }\r
}\r
\r
for (i = 0;i < 255;i++)\r
pcSoundLookup[i] = i * 60;\r
\r
- if (SoundBlasterPresent)\r
- SDL_StartSB();\r
+//SB if (SoundBlasterPresent)\r
+//SB SDL_StartSB();\r
\r
- SDL_SetupDigi();\r
+ SDL_SetupDigi(gvar);\r
\r
SD_Started = true;\r
}\r
//\r
///////////////////////////////////////////////////////////////////////////\r
void\r
-SD_Default(boolean gotit,SDMode sd,SMMode sm)\r
+SD_Default(boolean gotit,SDMode sd,SMMode sm, global_game_variables_t *gvar)\r
{\r
boolean gotsd,gotsm;\r
\r
sd = sdm_PC;\r
}\r
if (sd != SoundMode)\r
- SD_SetSoundMode(sd);\r
+ SD_SetSoundMode(sd, gvar);\r
\r
\r
if (gotsm) // Make sure requested music hardware is available\r
//\r
///////////////////////////////////////////////////////////////////////////\r
void\r
-SD_Shutdown(void)\r
+SD_Shutdown(global_game_variables_t *gvar)\r
{\r
if (!SD_Started)\r
return;\r
\r
SD_MusicOff();\r
- SD_StopSound();\r
+ SD_StopSound(gvar);\r
SDL_ShutDevice();\r
SDL_CleanDevice();\r
\r
- if (SoundBlasterPresent)\r
- SDL_ShutSB();\r
+//SB if (SoundBlasterPresent)\r
+//SB SDL_ShutSB();\r
\r
- if (SoundSourcePresent)\r
- SDL_ShutSS();\r
+//SS if (SoundSourcePresent)\r
+//SS SDL_ShutSS();\r
\r
asm pushf\r
asm cli\r
//\r
///////////////////////////////////////////////////////////////////////////\r
boolean\r
-SD_PlaySound(soundnames sound)\r
+SD_PlaySound(soundnames sound, global_game_variables_t *gvar)\r
{\r
boolean ispos;\r
SoundCommon far *s;\r
\r
s = MK_FP(SoundTable[sound],0);\r
if ((SoundMode != sdm_Off) && !s)\r
- Quit("SD_PlaySound() - Uncached sound");\r
+ Quit(gvar, "SD_PlaySound() - Uncached sound");\r
\r
if ((DigiMode != sds_Off) && (DigiMap[sound] != -1))\r
{\r
\r
SDL_PCStopSound();\r
\r
- SD_PlayDigitized(DigiMap[sound],lp,rp);\r
+ SD_PlayDigitized(DigiMap[sound],lp,rp, gvar);\r
SoundPositioned = ispos;\r
SoundNumber = sound;\r
SoundPriority = s->priority;\r
if (DigiPriority && !DigiNumber)\r
{\r
asm popf\r
- Quit("SD_PlaySound: Priority without a sound");\r
+ Quit(gvar, "SD_PlaySound: Priority without a sound");\r
}\r
asm popf\r
\r
if (s->priority < DigiPriority)\r
return(false);\r
\r
- SD_PlayDigitized(DigiMap[sound],lp,rp);\r
+ SD_PlayDigitized(DigiMap[sound],lp,rp, gvar);\r
SoundPositioned = ispos;\r
DigiNumber = sound;\r
DigiPriority = s->priority;\r
if (SoundMode == sdm_Off)\r
return(false);\r
if (!s->length)\r
- Quit("SD_PlaySound() - Zero length sound");\r
+ Quit(gvar, "SD_PlaySound() - Zero length sound");\r
if (s->priority < SoundPriority)\r
return(false);\r
\r
SDL_PCPlaySound((void far *)s);\r
break;\r
case sdm_AdLib:\r
- SDL_ALPlaySound((void far *)s);\r
+ SDL_ALPlaySound((void far *)s, gvar);\r
break;\r
}\r
\r
//\r
///////////////////////////////////////////////////////////////////////////\r
void\r
-SD_StopSound(void)\r
+SD_StopSound(global_game_variables_t *gvar)\r
{\r
if (DigiPlaying)\r
- SD_StopDigitized();\r
+ SD_StopDigitized(gvar);\r
\r
switch (SoundMode)\r
{\r
return(result);\r
}\r
\r
+//#if 0\r
+//\r
// SD ASS!\r
+//\r
+\r
+//variables for these assembly functions\r
+volatile boolean pcindicate;\r
+volatile unsigned/*boolean*/ MyDS;\r
+\r
void SDL_SetDS()\r
{\r
__asm {\r
}\r
}\r
\r
-void SDL_turnOnPCSpeaker(word timerval)\r
-{\r
- __asm {\r
- mov bx,timerval\r
- mov al,0b6h\r
- out 43h,al\r
- mov al,bl\r
- out 42h,al\r
- mov al,bh\r
- out 42h,al\r
- in al,61h\r
- or al,3\r
- out 61h,al\r
- }\r
-}\r
-\r
-void SDL_turnOffPCSpeaker()\r
-{\r
- __asm {\r
- in al,61h\r
- and al,0fch\r
- out 61h,al\r
- }\r
-}\r
-\r
-void SDL_setPCSpeaker(byte val)\r
-{\r
- __asm {\r
- mov al,val\r
- in al,61h\r
- and al,0fch\r
- or al,ah\r
- out 61h,al\r
- }\r
-}\r
-\r
-void SDL_DoFX()\r
-{\r
- if(pcSound)\r
- {\r
- if(*pcSound!=pcLastSample)\r
- {\r
- pcLastSample=*pcSound;\r
-\r
- if(pcLastSample)\r
- SDL_turnOnPCSpeaker(pcLastSample*60);\r
- else\r
- SDL_turnOffPCSpeaker();\r
- }\r
- pcSound++;\r
- pcLengthLeft--;\r
- if(!pcLengthLeft)\r
- {\r
- pcSound=0;\r
- SoundNumber=(soundnames)0;\r
- SoundPriority=0;\r
- SDL_turnOffPCSpeaker();\r
- }\r
- }\r
-\r
- if(alSound && !alNoIRQ)\r
- {\r
- if(*alSound)\r
- {\r
- alOutInIRQ(alFreqL,*alSound);\r
- alOutInIRQ(alFreqH,alBlock);\r
- }\r
- else alOutInIRQ(alFreqH,0);\r
- alSound++;\r
- alLengthLeft--;\r
- if(!alLengthLeft)\r
- {\r
- alSound=0;\r
- SoundNumber=(soundnames)0;\r
- SoundPriority=0;\r
- alOutInIRQ(alFreqH,0);\r
- }\r
- }\r
-\r
-}\r
-\r
-void SDL_DoFast()\r
-{\r
- count_fx++;\r
- if(count_fx>=5)\r
- {\r
- count_fx=0;\r
-\r
- SDL_DoFX();\r
-\r
- count_time++;\r
- if(count_time>=2)\r
- {\r
- TimeCount++;\r
- count_time=0;\r
- }\r
- }\r
-\r
- if(sqActive && !alNoIRQ)\r
- {\r
- if(sqHackLen)\r
- {\r
- do\r
- {\r
- if(sqHackTime>alTimeCount) break;\r
- sqHackTime=alTimeCount+*(sqHackPtr+1);\r
- alOutInIRQ(*(byte *)sqHackPtr,*(((byte *)sqHackPtr)+1));\r
- sqHackPtr+=2;\r
- sqHackLen-=4;\r
- }\r
- while(sqHackLen);\r
- }\r
- alTimeCount++;\r
- if(!sqHackLen)\r
- {\r
- sqHackPtr=sqHack;\r
- sqHackLen=sqHackSeqLen;\r
- alTimeCount=0;\r
- sqHackTime=0;\r
- }\r
- }\r
-\r
- if(ssSample)\r
- {\r
- if(!(inp(ssStatus)&0x40))\r
- {\r
- outp(ssData,*ssSample++);\r
- outp(ssControl,ssOff);\r
- __asm push ax\r
- __asm pop ax\r
- outp(ssControl,ssOn);\r
- __asm push ax\r
- __asm pop ax\r
- ssLengthLeft--;\r
- if(!ssLengthLeft)\r
- {\r
- ssSample=0;\r
- SDL_DigitizedDoneInIRQ();\r
- }\r
- }\r
- }\r
-\r
- TimerCount+=TimerDivisor;\r
- if(*((word *)&TimerCount+1))\r
- {\r
- *((word *)&TimerCount+1)=0;\r
- t0OldService();\r
- }\r
- else\r
- {\r
- outp(0x20,0x20);\r
- }\r
-}\r
+//\r
\r
// Timer 0 ISR for 7000Hz interrupts\r
void interrupt SDL_t0ExtremeAsmService(void)\r
outp(0x20,0x20);\r
}\r
\r
-// Timer 0 ISR for 7000Hz interrupts\r
-void interrupt __SDL_t0ExtremeAsmService()\r
-{\r
- if(pcindicate)\r
- {\r
- if(pcSound)\r
- {\r
- SDL_setPCSpeaker(((*pcSound++)&0x80)>>6);\r
- pcLengthLeft--;\r
- if(!pcLengthLeft)\r
- {\r
- pcSound=0;\r
- SDL_turnOffPCSpeaker();\r
- SDL_DigitizedDoneInIRQ();\r
- }\r
- }\r
- }\r
- extreme++;\r
- if(extreme>=10)\r
- {\r
- extreme=0;\r
- SDL_DoFast();\r
- }\r
- else\r
- outp(0x20,0x20);\r
-}\r
-\r
-// Timer 0 ISR for 700Hz interrupts\r
-void interrupt SDL_t0FastAsmService(void)\r
-{\r
- SDL_DoFast();\r
-}\r
-\r
-// Timer 0 ISR for 140Hz interrupts\r
-void interrupt SDL_t0SlowAsmService(void)\r
-{\r
- count_time++;\r
- if(count_time>=2)\r
- {\r
- TimeCount++;\r
- count_time=0;\r
- }\r
-\r
- SDL_DoFX();\r
-\r
- TimerCount+=TimerDivisor;\r
- if(*((word *)&TimerCount+1))\r
- {\r
- *((word *)&TimerCount+1)=0;\r
- t0OldService();\r
- }\r
- else\r
- outp(0x20,0x20);\r
-}\r
+//\r
\r
void SDL_IndicatePC(boolean ind)\r
{\r
}\r
}\r
\r
+#if 0\r
// Inside an interrupt handler interrupts should already be disabled\r
// so don't disable them again and cause V86 exceptions which cost\r
// aprox. 300 processor tics!\r
in al,dx\r
}\r
}\r
-\r
+#endif\r