+//#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
+ while (sqHackLen && (sqHackTime <= alTimeCount))\r
+ {\r
+ w = *sqHackPtr++;\r
+ sqHackTime = alTimeCount + *sqHackPtr++;\r
+ asm mov dx,[w]\r
+ asm mov [a],dl\r
+ asm mov [v],dh\r
+ alOut(a,v);\r
+ sqHackLen -= 4;\r
+ }\r
+ alTimeCount++;\r
+ if (!sqHackLen)\r
+ {\r
+ sqHackPtr = (word far *)sqHack;\r
+ sqHackLen = sqHackSeqLen;\r
+ alTimeCount = sqHackTime = 0;\r
+ }\r
+}\r
+//#endif\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SDL_ShutAL() - Shuts down the AdLib card for sound effects\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+static void\r
+SDL_ShutAL(void)\r
+{\r
+asm pushf\r
+asm cli\r
+\r
+ alOut(alEffects,0);\r
+ alOut(alFreqH + 0,0);\r
+ SDL_AlSetFXInst(&alZeroInst);\r
+ alSound = 0;\r
+\r
+asm popf\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SDL_CleanAL() - Totally shuts down the AdLib card\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+static void\r
+SDL_CleanAL(void)\r
+{\r
+ int i;\r
+\r
+asm pushf\r
+asm cli\r
+\r
+ alOut(alEffects,0);\r
+ for (i = 1;i < 0xf5;i++)\r
+ alOut(i,0);\r
+\r
+asm popf\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SDL_StartAL() - Starts up the AdLib card for sound effects\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+static void\r
+SDL_StartAL(void)\r
+{\r
+ alFXReg = 0;\r
+ alOut(alEffects,alFXReg);\r
+ SDL_AlSetFXInst(&alZeroInst);\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SDL_DetectAdLib() - Determines if there's an AdLib (or SoundBlaster\r
+// emulating an AdLib) present\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+static boolean\r
+SDL_DetectAdLib(void)\r
+{\r
+ byte status1,status2;\r
+ int i;\r
+\r
+ alOut(4,0x60); // Reset T1 & T2\r
+ alOut(4,0x80); // Reset IRQ\r
+ status1 = readstat();\r
+ alOut(2,0xff); // Set timer 1\r
+ alOut(4,0x21); // Start timer 1\r
+ SDL_Delay(TimerDelay100);\r
+\r
+#if 0\r
+ __asm {\r
+ mov dx,0x388\r
+ mov cx,100\r
+#ifdef __BORLANDC__\r
+ }\r
+#endif\r
+usecloop:\r
+#ifdef __BORLANDC__\r
+ __asm {\r
+#endif\r
+ in al,dx\r
+ loop usecloop\r
+ }\r
+#endif\r
+\r
+ status2 = readstat();\r
+ alOut(4,0x60);\r
+ alOut(4,0x80);\r
+\r
+ if (((status1 & 0xe0) == 0x00) && ((status2 & 0xe0) == 0xc0))\r
+ {\r
+ for (i = 1;i <= 0xf5;i++) // Zero all the registers\r
+ alOut(i,0);\r
+\r
+ alOut(1,0x20); // Set WSE=1\r
+ alOut(8,0); // Set CSM=0 & SEL=0\r
+\r
+ return(true);\r
+ }\r
+ else\r
+ return(false);\r
+}\r
+\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
+void interrupt\r
+SDL_t0Service(void)\r
+{\r
+static word count = 1;\r
+ boolean myackflag = 0;\r
+\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 mov al,ATR_OVERSCAN\r
+asm out dx,al\r
+asm mov al,4 // red\r
+asm out dx,al\r
+//00#endif\r
+\r
+ HackCount++;\r
+\r
+ if ((MusicMode == smm_AdLib) || (DigiMode == sds_SoundSource))\r
+ {\r
+ SDL_ALService();\r
+//SS SDL_SSService();\r
+// if (!(++count & 7))\r
+ if (!(++count % 10))\r
+ {\r
+ LocalTime++;\r
+ TimeCount++;\r
+ if (SoundUserHook)\r
+ SoundUserHook();\r
+ }\r
+// if (!(count & 3))\r
+ if (!(count % 5))\r
+ {\r
+ switch (SoundMode)\r
+ {\r
+ case sdm_PC:\r
+ SDL_PCService();\r
+ break;\r
+ case sdm_AdLib:\r
+ SDL_ALSoundService();\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ else\r
+ {\r
+ if (!(++count & 1))\r
+ {\r
+ LocalTime++;\r
+ TimeCount++;\r
+ if (SoundUserHook)\r
+ SoundUserHook();\r
+ }\r
+ switch (SoundMode)\r
+ {\r
+ case sdm_PC:\r
+ SDL_PCService();\r
+ break;\r
+ case sdm_AdLib:\r
+ SDL_ALSoundService();\r
+ break;\r
+ }\r
+ }\r
+\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
+//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 mov al,ATR_OVERSCAN\r
+asm out dx,al\r
+asm mov al,3 // blue\r
+asm out dx,al\r
+asm mov al,0x20 // normal\r
+asm out dx,al\r
+//00#endif\r
+}\r
+\r
+////////////////////////////////////////////////////////////////////////////\r
+//\r
+// SDL_ShutDevice() - turns off whatever device was being used for sound fx\r
+//\r
+////////////////////////////////////////////////////////////////////////////\r
+static void\r
+SDL_ShutDevice(void)\r
+{\r
+ switch (SoundMode)\r
+ {\r
+ case sdm_PC:\r
+ SDL_ShutPC();\r
+ break;\r
+ case sdm_AdLib:\r
+ SDL_ShutAL();\r
+ break;\r
+ }\r
+ SoundMode = sdm_Off;\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SDL_CleanDevice() - totally shuts down all sound devices\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+static void\r
+SDL_CleanDevice(void)\r
+{\r
+ if ((SoundMode == sdm_AdLib) || (MusicMode == smm_AdLib))\r
+ SDL_CleanAL();\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SDL_StartDevice() - turns on whatever device is to be used for sound fx\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+static void\r
+SDL_StartDevice(void)\r
+{\r
+ switch (SoundMode)\r
+ {\r
+ case sdm_AdLib:\r
+ SDL_StartAL();\r
+ break;\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
+// SD_SetSoundMode() - Sets which sound hardware to use for sound effects\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+boolean\r
+SD_SetSoundMode(SDMode mode, global_game_variables_t *gvar)\r
+{\r
+ boolean result = false;\r
+ word tableoffset;\r
+\r
+ SD_StopSound(gvar);\r
+\r
+#ifndef _MUSE_\r
+ if ((mode == sdm_AdLib) && !AdLibPresent)\r
+ mode = sdm_PC;\r
+\r
+ switch (mode)\r
+ {\r
+ case sdm_Off:\r
+ NeedsDigitized = false;\r
+ result = true;\r
+ break;\r
+ case sdm_PC:\r
+ tableoffset = STARTPCSOUNDS;\r
+ NeedsDigitized = false;\r
+ result = true;\r
+ break;\r
+ case sdm_AdLib:\r
+ if (AdLibPresent)\r
+ {\r
+ tableoffset = STARTADLIBSOUNDS;\r
+ NeedsDigitized = false;\r
+ result = true;\r
+ }\r
+ break;\r
+ }\r
+#else\r
+ result = true;\r
+#endif\r
+\r
+ if (result && (mode != SoundMode))\r
+ {\r
+ SDL_ShutDevice();\r
+ SoundMode = mode;\r
+#ifndef _MUSE_\r
+ SoundTable = (word *)(&gvar->ca.audiosegs[tableoffset]);\r
+#endif\r
+ SDL_StartDevice();\r
+ }\r
+\r
+ SDL_SetTimerSpeed();\r
+\r
+ return(result);\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_SetMusicMode() - sets the device to use for background music\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+boolean\r
+SD_SetMusicMode(SMMode mode)\r
+{\r
+ boolean result = false;\r
+\r
+ SD_FadeOutMusic();\r
+ while (SD_MusicPlaying())\r
+ ;\r
+\r
+ switch (mode)\r
+ {\r
+ case smm_Off:\r
+ NeedsMusic = false;\r
+ result = true;\r
+ break;\r
+ case smm_AdLib:\r
+ if (AdLibPresent)\r
+ {\r
+ NeedsMusic = true;\r
+ result = true;\r
+ }\r
+ break;\r
+ }\r
+\r
+ if (result)\r
+ MusicMode = mode;\r
+\r
+ SDL_SetTimerSpeed();\r
+\r
+ return(result);\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_Startup() - starts up the Sound Mgr\r
+// Detects all additional sound hardware and installs my ISR\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+void\r
+SD_Startup(global_game_variables_t *gvar)\r
+{\r
+ int i;\r
+\r
+ if (SD_Started)\r
+ return;\r
+#ifndef SD_USECATA3DSETTIMERSPEED\r
+// SDL_SetDS();\r
+#endif\r
+ ssIsTandy = false;\r
+//SS ssNoCheck = false;\r
+ alNoCheck = false;\r
+//SB sbNoCheck = false;\r
+//SB sbNoProCheck = false;\r
+#ifndef _MUSE_\r
+ for (i = 1;i < _argc;i++)\r
+ {\r
+ switch (US_CheckParm(_argv[i],ParmStrings))\r
+ {\r
+ case 0: // No AdLib detection\r
+ alNoCheck = true;\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
+//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
+\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, gvar);\r
+ SD_SetMusicMode(smm_Off);\r
+\r
+//SS if (!ssNoCheck)\r
+//SS SoundSourcePresent = SDL_DetectSoundSource();\r
+\r
+ if (!alNoCheck)\r
+ {\r
+ AdLibPresent = SDL_DetectAdLib();\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
+//SB if (SoundBlasterPresent)\r
+//SB SDL_StartSB();\r
+\r
+//++++ SDL_SetupDigi(gvar);\r
+\r
+ SD_Started = true;\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_Default() - Sets up the default behaviour for the Sound Mgr whether\r
+// the config file was present or not.\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+void\r
+SD_Default(boolean gotit,SDMode sd,SMMode sm, global_game_variables_t *gvar)\r
+{\r
+ boolean gotsd,gotsm;\r
+\r
+ gotsd = gotsm = gotit;\r
+\r
+ if (gotsd) // Make sure requested sound hardware is available\r
+ {\r
+ switch (sd)\r
+ {\r
+ case sdm_AdLib:\r
+ gotsd = AdLibPresent;\r
+ break;\r
+ }\r
+ }\r
+ if (!gotsd)\r
+ {\r
+ if (AdLibPresent)\r
+ sd = sdm_AdLib;\r
+ else\r
+ sd = sdm_PC;\r
+ }\r
+ if (sd != SoundMode)\r
+ SD_SetSoundMode(sd, gvar);\r
+\r
+\r
+ if (gotsm) // Make sure requested music hardware is available\r
+ {\r
+ switch (sm)\r
+ {\r
+ case sdm_AdLib:\r
+ gotsm = AdLibPresent;\r
+ break;\r
+ }\r
+ }\r
+ if (!gotsm)\r
+ {\r
+ if (AdLibPresent)\r
+ sm = smm_AdLib;\r
+ }\r
+ if (sm != MusicMode)\r
+ SD_SetMusicMode(sm);\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_Shutdown() - shuts down the Sound Mgr\r
+// Removes sound ISR and turns off whatever sound hardware was active\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+void\r
+SD_Shutdown(global_game_variables_t *gvar)\r
+{\r
+ if (!SD_Started)\r
+ return;\r
+\r
+ SD_MusicOff();\r
+ SD_StopSound(gvar);\r
+ SDL_ShutDevice();\r
+ SDL_CleanDevice();\r
+\r
+//SB if (SoundBlasterPresent)\r
+//SB SDL_ShutSB();\r
+\r
+//SS if (SoundSourcePresent)\r
+//SS SDL_ShutSS();\r
+\r
+ asm pushf\r
+ asm cli\r
+\r
+ SDL_SetTimer0(0);\r
+\r
+ setvect(8,t0OldService);\r
+\r
+ asm popf\r
+\r
+ SD_Started = false;\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_SetUserHook() - sets the routine that the Sound Mgr calls every 1/70th\r
+// of a second from its timer 0 ISR\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+void\r
+SD_SetUserHook(void (* hook)(void))\r
+{\r
+ SoundUserHook = hook;\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_PositionSound() - Sets up a stereo imaging location for the next\r
+// sound to be played. Each channel ranges from 0 to 15.\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+void\r
+SD_PositionSound(int leftvol,int rightvol)\r
+{\r
+ LeftPosition = leftvol;\r
+ RightPosition = rightvol;\r
+ nextsoundpos = true;\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_PlaySound() - plays the specified sound on the appropriate hardware\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+boolean\r
+SD_PlaySound(soundnames sound, global_game_variables_t *gvar)\r
+{\r
+ boolean ispos;\r
+ SoundCommon far *s;\r
+ int lp,rp;\r
+\r
+ lp = LeftPosition;\r
+ rp = RightPosition;\r
+ LeftPosition = 0;\r
+ RightPosition = 0;\r
+\r
+ ispos = nextsoundpos;\r
+ nextsoundpos = false;\r
+\r
+ if (sound == -1)\r
+ return(false);\r
+\r
+ s = MK_FP(SoundTable[sound],0);\r
+ if ((SoundMode != sdm_Off) && !s)\r
+ Quit(gvar, "SD_PlaySound() - Uncached sound");\r
+\r
+ if ((DigiMode != sds_Off) && (DigiMap[sound] != -1))\r
+ {\r
+ if ((DigiMode == sds_PC) && (SoundMode == sdm_PC))\r
+ {\r
+ if (s->priority < SoundPriority)\r
+ return(false);\r
+\r
+ SDL_PCStopSound();\r
+\r
+ SD_PlayDigitized(DigiMap[sound],lp,rp, gvar);\r
+ SoundPositioned = ispos;\r
+ SoundNumber = sound;\r
+ SoundPriority = s->priority;\r
+ }\r
+ else\r
+ {\r
+ asm pushf\r
+ asm cli\r
+ if (DigiPriority && !DigiNumber)\r
+ {\r
+ asm popf\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, gvar);\r
+ SoundPositioned = ispos;\r
+ DigiNumber = sound;\r
+ DigiPriority = s->priority;\r
+ }\r
+\r
+ return(true);\r
+ }\r
+\r
+ if (SoundMode == sdm_Off)\r
+ return(false);\r
+ if (!s->length)\r
+ Quit(gvar, "SD_PlaySound() - Zero length sound");\r
+ if (s->priority < SoundPriority)\r
+ return(false);\r
+\r
+ switch (SoundMode)\r
+ {\r
+ case sdm_PC:\r
+ SDL_PCPlaySound((void far *)s);\r
+ break;\r
+ case sdm_AdLib:\r
+ SDL_ALPlaySound((void far *)s, gvar);\r
+ break;\r
+ }\r
+\r
+ SoundNumber = sound;\r
+ SoundPriority = s->priority;\r
+\r
+ return(false);\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_SoundPlaying() - returns the sound number that's playing, or 0 if\r
+// no sound is playing\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+word\r
+SD_SoundPlaying(void)\r
+{\r
+ boolean result = false;\r
+\r
+ switch (SoundMode)\r
+ {\r
+ case sdm_PC:\r
+ result = pcSound? true : false;\r
+ break;\r
+ case sdm_AdLib:\r
+ result = alSound? true : false;\r
+ break;\r
+ }\r
+\r
+ if (result)\r
+ return(SoundNumber);\r
+ else\r
+ return(false);\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_StopSound() - if a sound is playing, stops it\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+void\r
+SD_StopSound(global_game_variables_t *gvar)\r
+{\r
+ if (DigiPlaying)\r
+ SD_StopDigitized(gvar);\r
+\r
+ switch (SoundMode)\r
+ {\r
+ case sdm_PC:\r
+ SDL_PCStopSound();\r
+ break;\r
+ case sdm_AdLib:\r
+ SDL_ALStopSound();\r
+ break;\r
+ }\r
+\r
+ SoundPositioned = false;\r
+\r
+ SDL_SoundFinished();\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_WaitSoundDone() - waits until the current sound is done playing\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+void\r
+SD_WaitSoundDone(void)\r
+{\r
+ while (SD_SoundPlaying())\r
+ ;\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_MusicOn() - turns on the sequencer\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+void\r
+SD_MusicOn(void)\r
+{\r
+ sqActive = true;\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_MusicOff() - turns off the sequencer and any playing notes\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+void\r
+SD_MusicOff(void)\r
+{\r
+ word i;\r
+\r
+\r
+ switch (MusicMode)\r
+ {\r
+ case smm_AdLib:\r
+ alFXReg = 0;\r
+ alOut(alEffects,0);\r
+ for (i = 0;i < sqMaxTracks;i++)\r
+ alOut(alFreqH + i + 1,0);\r
+ break;\r
+ }\r
+ sqActive = false;\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_StartMusic() - starts playing the music pointed to\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+void\r
+SD_StartMusic(MusicGroup far *music)\r
+{\r
+ SD_MusicOff();\r
+asm pushf\r
+asm cli\r
+\r
+ if (MusicMode == smm_AdLib)\r
+ {\r
+ sqHackPtr = sqHack = music->values;\r
+ sqHackSeqLen = sqHackLen = music->length;\r
+ sqHackTime = 0;\r
+ alTimeCount = 0;\r
+ SD_MusicOn();\r
+ }\r
+\r
+asm popf\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_FadeOutMusic() - starts fading out the music. Call SD_MusicPlaying()\r
+// to see if the fadeout is complete\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+void\r
+SD_FadeOutMusic(void)\r
+{\r
+ switch (MusicMode)\r
+ {\r
+ case smm_AdLib:\r
+ // DEBUG - quick hack to turn the music off\r
+ SD_MusicOff();\r
+ break;\r
+ }\r
+}\r
+\r
+///////////////////////////////////////////////////////////////////////////\r
+//\r
+// SD_MusicPlaying() - returns true if music is currently playing, false if\r
+// not\r
+//\r
+///////////////////////////////////////////////////////////////////////////\r
+boolean\r
+SD_MusicPlaying(void)\r
+{\r
+ boolean result;\r
+\r
+ switch (MusicMode)\r
+ {\r
+ case smm_AdLib:\r
+ result = false;\r
+ // DEBUG - not written\r
+ break;\r
+ default:\r
+ result = false;\r
+ }\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
+ mov ax,ds\r
+ mov [cs:MyDS],ds\r
+ ret\r
+ }\r
+}\r
+\r
+//\r
+\r
+// Timer 0 ISR for 7000Hz interrupts\r
+void interrupt SDL_t0ExtremeAsmService(void)\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
+//\r
+\r
+void SDL_IndicatePC(boolean ind)\r
+{\r
+ pcindicate=ind;\r
+}\r
+\r
+void\r
+SDL_DigitizedDoneInIRQ(void)\r
+{\r
+ if (DigiNextAddr)\r
+ {\r
+ SDL_PlayDigiSegment(DigiNextAddr,DigiNextLen/*,true*/);\r
+ DigiNextAddr = nil;\r
+ DigiMissed = false;\r
+ }\r
+ else\r
+ {\r
+ if (DigiLastSegment)\r
+ {\r
+ DigiPlaying = false;\r
+ DigiLastSegment = false;\r
+ if ((DigiMode == sds_PC) && (SoundMode == sdm_PC))\r
+ {\r
+ SDL_SoundFinished();\r
+ }\r
+ else\r
+ {\r
+ DigiNumber = (soundnames) 0;\r
+ DigiPriority = 0;\r
+ }\r
+ SoundPositioned = false;\r
+ }\r
+ else\r
+ DigiMissed = true;\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
+\r
+//static\r
+void alOutInIRQ(byte n,byte b)\r
+{\r
+ __asm {\r
+ mov dx,0x388\r
+ mov al,[n]\r
+ out dx,al\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ inc dx\r
+ mov al,[b]\r
+ out dx,al\r
+\r
+ dec dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ in al,dx\r
+ }\r