]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/id_sd.c
id_sd.c ported and is able to compile. it needs it;s variables to be project 16 compl...
[16.git] / src / lib / id_sd.c
index 2a73fc690f377d82c186e41b2d0311c64081b285..8bd50e5914919023edb66144d19127f1de95ebb5 100755 (executable)
@@ -23,8 +23,9 @@
 //\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
+#if 0\r
+/*extern*/     void                    SDL_SetDS(void);\r
 /*extern*/     void interrupt  SDL_t0ExtremeAsmService(void),\r
                                                SDL_t0FastAsmService(void),\r
                                                SDL_t0SlowAsmService(void);\r
+#endif\r
+               void    SDL_IndicatePC(boolean on);\r
 \r
 //     Global variables\r
        boolean         SoundSourcePresent,\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
@@ -134,7 +130,9 @@ static      void                    (*SoundUserHook)(void);
 static boolean                 DigiMissed,DigiLastSegment;\r
 static memptr                  DigiNextAddr;\r
 static word                    DigiNextLen;\r
+               boolean                 pcindicate;\r
 \r
+#if 0\r
 //     SoundBlaster variables\r
 static boolean                                 sbNoCheck,sbNoProCheck;\r
 static volatile boolean                sbSamplePlaying;\r
@@ -159,6 +157,7 @@ static      byte                                    sbpOldFMMix,sbpOldVOCMix;
                byte                            ssOn,ssOff;\r
                volatile byte           far *ssSample;\r
                volatile dword  ssLengthLeft;\r
+#endif\r
 \r
 //     PC Sound variables\r
                volatile byte   pcLastSample,far *pcSound;\r
@@ -183,9 +182,9 @@ static      byte                    carriers[9] =  { 3, 4, 5,11,12,13,19,20,21},
 //     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
@@ -233,6 +232,7 @@ SDL_SetIntsPerSec(word ints)
        SDL_SetTimer0(1192030 / ints);\r
 }\r
 \r
+#ifndef SD_USECATA3DSETTIMERSPEED\r
 static void\r
 SDL_SetTimerSpeed(void)\r
 {\r
@@ -266,626 +266,130 @@ SDL_SetTimerSpeed(void)
                TimerRate = rate;\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
-{\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
-       }\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
-{\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
-       }\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
+SDL_SetTimerSpeed(void)\r
 {\r
-       dword   used;\r
-\r
-       sbIn(sbDataAvail);      // Ack interrupt to SB\r
+       word    rate;\r
 \r
-       if (sbNextSegPtr)\r
-       {\r
-               used = SDL_SBPlaySeg(sbNextSegPtr,sbNextSegLen);\r
-               if (sbNextSegLen <= used)\r
-                       sbNextSegPtr = nil;\r
-               else\r
-               {\r
-                       sbNextSegPtr += used;\r
-                       sbNextSegLen -= used;\r
-               }\r
-       }\r
+       if (MusicMode == smm_AdLib)\r
+               rate = TickBase * 8;\r
        else\r
-       {\r
-               SDL_SBStopSample();\r
-               SDL_DigitizedDone();\r
-       }\r
-\r
-       outportb(0x20,0x20);    // Ack interrupt\r
+               rate = TickBase * 2;\r
+       SDL_SetIntsPerSec(rate);\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
-       {\r
-               sbNextSegPtr = data + used;\r
-               sbNextSegLen = len - used;\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
+//     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 boolean\r
-SDL_CheckSB(int port)\r
+//static void interrupt\r
+void interrupt\r
+SDL_TimingService(void)\r
 {\r
-       int     i;\r
-\r
-       sbLocation = port << 4;         // Initialize stuff for later use\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
-\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
+       //TimerVal = _CX;\r
        __asm {\r
-#endif\r
-usecloop:\r
-asm    in      al,dx\r
-asm    loop usecloop\r
-#ifdef __WATCOMC__\r
-       }\r
-#endif\r
-\r
-       for (i = 0;i < 100;i++)\r
-       {\r
-               if (sbIn(sbDataAvail) & 0x80)           // If data is available...\r
-               {\r
-                       if (sbIn(sbReadData) == 0xaa)   // If it matches correct value\r
-                               return(true);\r
-                       else\r
-                       {\r
-                               sbLocation = -1;                        // Otherwise not a SoundBlaster\r
-                               return(false);\r
-                       }\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
-\r
-       if (port == 0)                                  // If user specifies default, use 2\r
-               port = 2;\r
-       if (port == -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
+               mov TimerVal,cx\r
        }\r
-       else\r
-               return(SDL_CheckSB(port));      // User specified address or default\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
-{\r
-       if (channel > 3)\r
-               Quit("SDL_SBSetDMA() - invalid SoundBlaster DMA channel");\r
+       TimerDone = 1;\r
 \r
-       sbDMA = channel;\r
-       sbDMAa1 = sba1Vals[channel];\r
-       sbDMAa2 = sba2Vals[channel];\r
-       sbDMAa3 = sba3Vals[channel];\r
+       outportb(0x20,0x20);                            // Ack interrupt\r
 }\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
 //\r
-//     SDL_StartSB() - Turns on the SoundBlaster\r
+//     SDL_InitDelay() - Sets up TimerDelay's for SDL_Delay()\r
 //\r
 ///////////////////////////////////////////////////////////////////////////\r
 static void\r
-SDL_StartSB(void)\r
+SDL_InitDelay(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
+       int             i;\r
+       word    timer;\r
 \r
-       sbWriteDelay();\r
-       sbOut(sbWriteCmd,0xd1);                         // Turn on DSP speaker\r
+       setvect(8,SDL_TimingService);           // Set to my timer 0 ISR\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
+       SDL_SetIntsPerSec(1000);                        // Time 1ms\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
+       for (i = 0,timer = 0;i < 10;i++)        // Do timing test 10 times\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
+               __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
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-//     SDL_ShutSB() - Turns off the SoundBlaster\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-static void\r
-SDL_ShutSB(void)\r
-{\r
-       SDL_SBStopSample();\r
-\r
-       if (SBProPresent)\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
-       }\r
-\r
-       setvect(sbIntVec,sbOldIntHand);         // Set vector back\r
-}\r
 #endif\r
-\r
-//     Sound Source Code\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-//     SDL_SSStopSample() - Stops a sample playing on the Sound Source\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-#ifdef _MUSE_\r
-void\r
-#else\r
-static void\r
+startloop:\r
+#ifdef __BORLANDC__\r
+               __asm {\r
 #endif\r
-SDL_SSStopSample(void)\r
-{\r
-asm    pushf\r
-asm    cli\r
-\r
-       (long)ssSample = 0;\r
-\r
-asm    popf\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-//     SDL_SSService() - Handles playing the next sample on the Sound Source\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-static void\r
-SDL_SSService(void)\r
-{\r
-       //boolean       gotit;\r
-       boolean doneflag=false;\r
-       byte    v;\r
-\r
-       while (ssSample)\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
+                       or              [TimerDone],0\r
+                       jnz             startloop                               // Make sure we're at the start\r
 #ifdef __BORLANDC__\r
-       }\r
+               }\r
 #endif\r
-               done:\r
+loop_:\r
 #ifdef __BORLANDC__\r
-       __asm {\r
+               __asm {\r
 #endif\r
-               mov     doneflag,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
-               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 (0xffff - TimerVal > timer)\r
+                       timer = 0xffff - TimerVal;\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
-{\r
-asm    pushf\r
-asm    cli\r
+       timer += timer / 2;                                     // Use some slop\r
+       TimerDelay10 =  timer / (1000 / 10);\r
+       TimerDelay25 =  timer / (1000 / 25);\r
+       TimerDelay100 = timer / (1000 / 100);\r
 \r
-       ssLengthLeft = len;\r
-       ssSample = (volatile byte far *)data;\r
+       SDL_SetTimer0(0);                                       // Reset timer 0\r
 \r
-asm    popf\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////\r
-//\r
-//     SDL_StartSS() - Sets up for and turns on the Sound Source\r
-//\r
-///////////////////////////////////////////////////////////////////////////\r
-static void\r
-SDL_StartSS(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
-\r
-       outportb(ssControl,ssOn);               // Enable SS\r
+       setvect(8,t0OldService);                        // Set back to old ISR\r
 }\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
 //\r
-//     SDL_ShutSS() - Turns off the Sound Source\r
+//     SDL_Delay() - Delays the specified amount of time\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_Delay(word delay)\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
-\r
-       lasttime = TimeCount;\r
-       while (TimeCount < lasttime + 4)\r
-       {}\r
+       if (!delay)\r
+               return;\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
-\r
-               mov             cx,32                   // Force FIFO overflow (FIFO is 16 bytes)\r
+               mov             cx,[delay]\r
 #ifdef __BORLANDC__\r
        }\r
 #endif\r
-outloop:\r
+loop_:\r
 #ifdef __BORLANDC__\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
+               test    [TimerDone],0   // Useless code - just for timing equivilency\r
+               jnz             done\r
+               loop    loop_\r
 #ifdef __BORLANDC__\r
        }\r
 #endif\r
-checkdone:\r
-#ifdef __BORLANDC__\r
-       __asm {\r
-#endif\r
-               mov     chkdone,1\r
-#ifdef __BORLANDC__\r
-       }\r
-#endif\r
-               end:\r
+done:\r
 #ifdef __WATCOMC__\r
        }\r
 #endif\r
-\r
-       if(!chkdone) present = true;                    // Yes - it's here!\r
-\r
-//checkdone:\r
-       SDL_ShutSS();\r
-       return(present);\r
-}\r
-\r
-static boolean\r
-SDL_DetectSoundSource(void)\r
-{\r
-       for (ssPort = 1;ssPort <= 3;ssPort++)\r
-               if (SDL_CheckSS())\r
-                       return(true);\r
-       return(false);\r
 }\r
 \r
 //\r
@@ -930,7 +434,7 @@ SDL_PCStopSample(void)
 asm    pushf\r
 asm    cli\r
 \r
-       (long)pcSound = 0;\r
+       /*(long)*/pcSound = 0;\r
 \r
        SDL_IndicatePC(false);\r
 \r
@@ -978,7 +482,7 @@ SDL_PCStopSound(void)
 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
@@ -987,7 +491,6 @@ asm out     0x61,al
 asm    popf\r
 }\r
 \r
-#if 0\r
 ///////////////////////////////////////////////////////////////////////////\r
 //\r
 //     SDL_PCService() - Handles playing the next sample in a PC sound\r
@@ -1041,7 +544,6 @@ SDL_PCService(void)
                }\r
        }\r
 }\r
-#endif\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
 //\r
@@ -1067,7 +569,7 @@ asm        popf
 //     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
@@ -1081,8 +583,8 @@ asm        mov     al,10   // bright green
 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
@@ -1107,17 +609,17 @@ SDL_PlayDigiSegment(memptr addr,word len)
        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
@@ -1139,24 +641,24 @@ asm      cli
        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
@@ -1164,7 +666,7 @@ SD_Poll(void)
                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
@@ -1181,7 +683,7 @@ SD_Poll(void)
 }\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
@@ -1191,18 +693,18 @@ SD_SetPosition(int leftpos,int rightpos)
        ||      (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
@@ -1210,11 +712,11 @@ SD_PlayDigitized(word which,int leftpos,int rightpos)
        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
@@ -1223,7 +725,7 @@ SD_PlayDigitized(word which,int leftpos,int rightpos)
        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
@@ -1233,7 +735,7 @@ SD_PlayDigitized(word which,int leftpos,int rightpos)
        if (!DigiLeft)\r
                DigiLastSegment = true;\r
 \r
-       SD_Poll();\r
+       SD_Poll(gvar);\r
 }\r
 \r
 void\r
@@ -1265,14 +767,14 @@ SDL_DigitizedDone(void)
 }\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
@@ -1294,42 +796,42 @@ SD_SetDigiDevice(SDSMode mode)
 \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
@@ -1349,69 +851,79 @@ alOut(byte n,byte b)
 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
@@ -1448,7 +960,7 @@ SDL_SetInstrument(int track,int which,Instrument far *inst,boolean percussive)
 \r
        alOut(which + alFeedCon,inst->nConn);   // DEBUG - I think this is right\r
 }\r
-#endif\r
+//#endif\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
 //\r
@@ -1466,7 +978,7 @@ SDL_ALStopSound(void)
 asm    pushf\r
 asm    cli\r
 \r
-       (long)alSound = 0;\r
+       /*(long)*/alSound = 0;\r
        alOut(alFreqH + 0,0);\r
 \r
 asm    popf\r
@@ -1505,9 +1017,9 @@ void
 #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
@@ -1526,7 +1038,7 @@ asm       cli
        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
@@ -1535,7 +1047,7 @@ asm       cli
 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
@@ -1560,21 +1072,37 @@ SDL_ALSoundService(void)
 \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
+//#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
 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
@@ -1596,7 +1124,7 @@ SDL_ALService(void)
                alTimeCount = sqHackTime = 0;\r
        }\r
 }\r
-#endif\r
+//#endif\r
 \r
 ///////////////////////////////////////////////////////////////////////////\r
 //\r
@@ -1667,9 +1195,9 @@ SDL_DetectAdLib(void)
        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
@@ -1703,19 +1231,20 @@ usecloop:
                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
@@ -1723,14 +1252,14 @@ asm     mov     al,ATR_OVERSCAN
 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
@@ -1773,17 +1302,33 @@ asm     out     dx,al
                }\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
@@ -1793,9 +1338,8 @@ asm       mov     al,3    // blue
 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
@@ -1845,7 +1389,19 @@ SDL_StartDevice(void)
        }\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
@@ -1854,12 +1410,12 @@ SDL_StartDevice(void)
 //\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
@@ -1894,7 +1450,7 @@ SD_SetSoundMode(SDMode mode)
                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
@@ -1948,20 +1504,20 @@ SD_SetMusicMode(SMMode mode)
 //\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
-       SDL_SetDS();\r
+//??   SDL_SetDS();\r
 \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
@@ -1970,30 +1526,30 @@ SD_Startup(void)
                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
@@ -2002,85 +1558,88 @@ SD_Startup(void)
 \r
        t0OldService = getvect(8);      // Get old timer 0 ISR\r
 \r
+       SDL_InitDelay();                        // SDL_InitDelay() uses t0OldService\r
+\r
+       setvect(8,SDL_t0Service);       // Set to my timer 0 ISR\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
@@ -2092,7 +1651,7 @@ SD_Startup(void)
 //\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
@@ -2115,7 +1674,7 @@ SD_Default(boolean gotit,SDMode sd,SMMode sm)
                        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
@@ -2143,21 +1702,21 @@ SD_Default(boolean gotit,SDMode sd,SMMode sm)
 //\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
@@ -2203,7 +1762,7 @@ SD_PositionSound(int leftvol,int rightvol)
 //\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
@@ -2222,7 +1781,7 @@ SD_PlaySound(soundnames sound)
 \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
@@ -2233,7 +1792,7 @@ SD_PlaySound(soundnames sound)
 \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
@@ -2245,14 +1804,14 @@ SD_PlaySound(soundnames sound)
                        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
@@ -2264,7 +1823,7 @@ SD_PlaySound(soundnames sound)
        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
@@ -2274,7 +1833,7 @@ SD_PlaySound(soundnames sound)
                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
@@ -2317,10 +1876,10 @@ SD_SoundPlaying(void)
 //\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
@@ -2449,6 +2008,7 @@ SD_MusicPlaying(void)
        return(result);\r
 }\r
 \r
+#if 0\r
 // SD ASS!\r
 void SDL_SetDS()\r
 {\r
@@ -2694,12 +2254,12 @@ void interrupt SDL_t0SlowAsmService(void)
        else\r
                outp(0x20,0x20);\r
 }\r
-\r
+#endif\r
 void SDL_IndicatePC(boolean ind)\r
 {\r
        pcindicate=ind;\r
 }\r
-\r
+#if 0\r
 void\r
 SDL_DigitizedDoneInIRQ(void)\r
 {\r
@@ -2793,4 +2353,4 @@ void alOutInIRQ(byte n,byte b)
                in      al,dx\r
        }\r
 }\r
-\r
+#endif\r