//
//    SNDMOD HEADER AND DEF'S
//

#define     S_THUNDER1             0                      
#define     S_THUNDER2             1 
#define     S_THUNDER3             2 
#define     S_WINDLOOP1            3 
#define     S_WAVELOOP1            4 
#define     S_LAVALOOP1            5 
#define     S_FIRELOOP1            6 
#define     S_STONELOOP1           7 
#define     S_BATSLOOP             8 
#define     S_PLRWEAPON0           9 
#define     S_PLRWEAPON1           10 
#define     S_PLRWEAPON2           11 
#define     S_PLRWEAPON3           12 
#define     S_PLRWEAPON4           13 
#define     S_KSNARL1              14 
#define     S_KSNARL2              15 
#define     S_KSNARL3              16 
#define     S_KSNARL4              17 
#define     S_KPAIN1               18 
#define     S_KPAIN2               19 
#define     S_KDIE1                20 
#define     S_KDIE2                21 
#define     S_DEMON1               22 
#define     S_DEMON2               23 
#define     S_DEMON3               24 
#define     S_DEMON4               25 
#define     S_DEMON5               26 
#define     S_DEMONDIE1            27 
#define     S_DEMONDIE2            28 
#define     S_MSNARL1              29 
#define     S_MSNARL2              30 
#define     S_MSNARL3              31 
#define     S_MSNARL4              32 
#define     S_MPAIN1               33 
#define     S_MDEATH1              34 
#define     S_RIP1                 35 
#define     S_RIP2                 36 
#define     S_RIP3                 37 
#define     S_SKELHIT1             38 
#define     S_SKELHIT2             39 
#define     S_SKELETONDIE          40 
#define     S_SKELSEE              41   
#define     S_GUARDIAN1            42  
#define     S_GUARDIAN2            43 
#define     S_GUARDIANPAIN1        44 
#define     S_GUARDIANPAIN2        45 
#define     S_GUARDIANDIE          46 
#define     S_WISP                 47 
#define     S_WISP2                48 
#define     S_SPLASH1              49 
#define     S_SPLASH2              50 
#define     S_SPLASH3              51 
#define     S_SPLASH4              52 
#define     S_SPLASH5              53 
#define     S_WILLOWDIE            54 
#define     S_JUDY1                55 
#define     S_JUDYDIE              56 
#define     S_CHAIN1               57               
#define     S_FLAME1               58 
#define     S_CLUNK                59
#define     S_DEMONTHROW           60
#define     S_DOOR1                61
#define     S_DOOR2                62
#define     S_DOOR3                63 
#define     S_CREAKDOOR1           64 
#define     S_CREAKDOOR2           65 
#define     S_CREAKDOOR3           66 
#define     S_STING1               67 
#define     S_STING2               68 
#define     S_POTION1              69 
#define     S_GENTHROW             70 
#define     S_GENSWING             71 
#define     S_ARROWHIT             72 
#define     S_WALLHIT1             73 
#define     S_GONG                 74 
#define     S_SPELL1               75 
#define     S_FREEZE               76 
#define     S_FREEZEDIE            77 
#define     S_TRAP1                78 
#define     S_TRAP2                79 
#define     S_RATS1                80 
#define     S_RATS2                81 
#define     S_WINDLOOP2            82 
#define     S_BREATH1              83 
#define     S_BREATH2              84 
#define     S_PUSH1                85   
#define     S_PUSH2                86      
#define     S_PLRPAIN1             87             
#define     S_PLRPAIN2             88 
#define     S_GORE1                89 
#define     S_GORE2                90 
#define     S_GORE1A               91 
#define     S_GORE1B               92 
#define     S_DEADSTEP             93 
#define     S_HEARTBEAT            94 
#define     S_SOFTCHAINWALK        95 
#define     S_SOFTCREAKWALK        96  
#define     S_LOUDCHAINWALK        97  
#define     S_SCARYDUDE            98  
#define     S_WATERY               99  
#define     S_GLASSBREAK1          100 
#define     S_GLASSBREAK2          101 
#define     S_GLASSBREAK3          102
#define     S_TREASURE1            103 
#define     S_SWORD1               104 
#define     S_SWORD2               105 
#define     S_SWORDCLINK1          106 
#define     S_SWORDCLINK2          107 
#define     S_SWORDCLINK3          108 
#define     S_SWORDCLINK4          109 
#define     S_SOCK1                110 
#define     S_SOCK2                111 
#define     S_SOCK3                112 
#define     S_SOCK4                113 
#define     S_KOBOLDHIT            114 
#define     S_FIREBALL             115 
#define     S_PULLCHAIN1           116 
#define     S_PICKUPAXE            117 
#define     S_EXPLODE              118 
#define     S_BARRELBREAK          119 
#define     S_WARP                 120 
#define     S_PICKUPFLAG           121 
#define     S_DROPFLAG             122 
#define     S_LAUGH                123 
#define     S_DRINK                124 
#define     S_PAGE                 125 
#define     S_BOTTLES              126 
#define     S_CRACKING             127 
#define     S_PLRDIE1              128
#define     S_AGM_ATTACK           129     
#define     S_AGM_PAIN1            130
#define     S_AGM_PAIN2            131
#define     S_AGM_PAIN3            132
#define     S_AGM_DIE1             133
#define     S_AGM_DIE2             134
#define     S_AGM_DIE3             135
#define     S_GRONDEATHA           136
#define     S_GRONDEATHB           137
#define     S_GRONDEATHC           138  
#define     S_HGM_DIE1             139  
#define     S_HGM_DIE2             140  
#define     S_HGM_DIE3             141  
#define     S_GRONPAINA            142
#define     S_HGM_PAIN1            143  
#define     S_HGM_PAIN2            144  
#define     S_FIRESWING            145
#define     S_FIREWEAPONLOOP       146
#define     S_ENERGYWEAPONLOOP     147
#define     S_ENERGYSWING          148
#define     S_BIGGLASSBREAK1       149
#define     S_BIGGLASSBREAK2       150
#define     S_BIGGLASSBREAK3       151
#define     S_IMPGROWL1            152
#define     S_IMPGROWL2            153
#define     S_IMPGROWL3            154
#define     S_IMPDIE1              155
#define     S_IMPDIE2              156
#define     S_SWINGDOOR            157
#define     S_NUKESPELL            158
#define     S_DOORSPELL            159
#define     S_FIRESPELL            160
#define     S_GENERALMAGIC1        161
#define     S_GENERALMAGIC2        162
#define     S_GENERALMAGIC3        163
#define     S_GENERALMAGIC4        164
#define     S_HAWKSOUND            165
#define     S_OWL SOUND            166
#define     S_STEPSSOUND           167





                                    
                                   
                                    
#define  _OFF              0        
#define  _ON               1
#define  _STANDARD_MUSIC   1
#define  _DIG_MIDI_MUSIC   2
#define  _LOOP_MUSIC       3   

#define  MAX_AUX_TIMERS       4
#define  MAX_ACTIVE_SAMPLES   10
#define  MAX_ACTIVE_SONGS     4
//num of array elements in ambsoundarray[]
#define MAX_AMB_SOUNDS       6
#define  MAX_ACTIVE_FXLOOPS   4

#define  MAX_SND_LOOPS        8

#define  DIG_MIDI 2
#define  MIDI     1
#define  DIGI     0

#define  MENUSONG   0
#define  DEATHSONG   1

#define BASE_SONG   0
#define EMB_SONG        1
#define SPICE_SONG  2

#define  WINDSNDBIT        1
#define  WAVESNDBIT        2
#define  WATERSNDBIT       4
#define  LAVASNDBIT        8
#define  GRATESNDBIT       16
#define  CARTSNDBIT        32
#define  FIRE1SNDBIT       64
#define  FIRE2SNDBIT       128

typedef struct 
{
	int      playing;
	unsigned SOSHandle;
	unsigned number;         
	long     priority;
	long     x,y;
} SampleType;


struct ambsounds {
	int soundnum;       //the actual sound number S_x
	int hsound;     //the handle returned by hmi
};

#ifdef SND_CALLER

	//int lavasnd=-1,
	//     batsnd=-1,
	//     cartsnd=-1;

		

	VOID _far _loadds timerevent(VOID);

	//Callback functions
	VOID _far cdecl sosDIGISampleCallback(  WORD, WORD, WORD  );
	VOID _far sosMIDISongCallback( WORD );
   VOID _far cdecl _loadds sosMIDITriggerCallback(  WORD, BYTE, BYTE );

	//
	//defs for hmi Setup
	//
	// profile structure
	typedef  struct   _tagINIInstance
			{

				WORD  wFlags;           // misc. flags
				BYTE  szName[ 128 ];    // name of .ini file

				PSTR  pData;            // pointer to .ini file in memory
				WORD  wSize;            // size, in bytes, of file
				WORD  wMaxSize;         // maximum size in bytes of the .ini

				PSTR  pCurrent;         // current location in file
				WORD  wCurrent;         // current location in file

				PSTR  pSection;         // pointer to section start

				PSTR  pItemPtr;         // pointer to the start of line w/item 
				PSTR  pItem;            // pointer to last item
				PSTR  pList;            // pointer to last item location, for list
												// management.
				PSTR  pListPtr;         // pointer for raw string list

			} _INI_INSTANCE;

	// equates
	#define  _INI_SECTION_START   '['
	#define  _INI_SECTION_END     ']'
	#define  _INI_EQUATE          '='
	#define  _INI_SPACE           ' '
	#define  _INI_TAB             0x9
	#define  _INI_STRING_START    '"'
	#define  _INI_STRING_END      '"'
	#define  _INI_EOL             0x0d
	#define  _INI_CR              0x0d
	#define  _INI_LF              0x0a
	#define  _INI_HEX_INDICATOR   'x'
	#define  _INI_LIST_SEPERATOR  ','
	
	// amount of bytes to allocate in addition to file size so that the
	// .ini file may be modified by the application.
	#define  _INI_EXTRA_MEMORY    1024

	// various flags for .ini structure
	#define  _INI_MODIFIED        0x8000


	// function prototypes
	BOOL  cdecl hmiINIOpen              ( _INI_INSTANCE * sInstance, PSTR szName );
	BOOL  cdecl hmiINIClose             ( _INI_INSTANCE * sInstance );
	BOOL  cdecl hmiINILocateSection     ( _INI_INSTANCE * sInstance, PSTR szName );
	BOOL  cdecl hmiINILocateItem        ( _INI_INSTANCE * sInstance, PSTR szItem );
	BOOL  cdecl hmiINIGetDecimal        ( _INI_INSTANCE * sInstance, WORD * wValue );
	BOOL  cdecl hmiINIGetItemDecimal    ( _INI_INSTANCE * sInstance, PSTR szItem, WORD * wValue );

	BOOL  cdecl sosEZGetConfig( PSTR );
	
	WORD  wMIDIDeviceID,wDIGIDeviceID;


	//
	//          DIGI SPECIFIC
	//
    #define  _SOS_DMA_BUFFERSIZE     0x1000
	#define  _SOS_SAMPLE_RATE        11025
	#define  _SOS_FILL_TIMER_RATE    100

	#define  _SAMPLE0                 0x1000
	#define  _SAMPLE1                 0x1001
	#define  _SAMPLE2                 0x1002
	#define  _SAMPLE3                 0x1003
	#define  _SAMPLE4                 0x1004
	#define  _SAMPLE5                 0x1005
	#define  _SAMPLE6                 0x1006
	#define  _SAMPLE7                 0x1007
	#define  _SAMPLE8                 0x1008
	#define  _SAMPLE9                 0x1009
	#define  _SAMPLE10                0x100a
	#define  _SAMPLE11                0x100b
	#define _LSAMPLE1                   0x100c
	#define _LSAMPLE2                   0x100d

	UINT  PanArray[] = {
		//REAR to HARD LEFT (angle = 0->512)   
	0x8000,0x7000,0x6000,0x5000,0x4000,0x3000,0x2000,0x1000,0x0000,
		//HARD LEFT to CENTER (angle = 513-1024)
	0x1000,0x20f0,0x2000,0x3000,0x4000,0x5000,0x6000,0x7000,0x8000, 
		//CENTER to HARD RIGHT (angle = 1025-1536)
	0x70f0,0x8000,0x9000,0xa000,0xb000,0xc000,0xd000,0xe000,0xf000,   
		//HARD RIGHT to REAR (angle = 1537-2047)
	0xffff,0xf000,0xe000,0xd000,0xc000,0xb000,0xa000,0x9000,0x8000
	};

	volatile    SampleType  SampleRay[MAX_ACTIVE_SAMPLES];
	BYTE        ActiveSampleBits = 0x00;

	volatile    SampleType  FXLoopRay[MAX_ACTIVE_FXLOOPS];

	_SOS_CAPABILITIES sSOSDeviceCaps;
	_SOS_HARDWARE     sDIGIHardware;
	_SOS_INIT_DRIVER  sSOSInitDriver = {
		_SOS_DMA_BUFFERSIZE,
		_NULL,
		_TRUE,
		_SOS_SAMPLE_RATE,
		19,
		0L,
		_NULL,
		_NULL,
		_NULL,
		_SOS_NORMAL_TIMER
		};

	_SOS_INIT_DRIVER  sSOSInitDriver1 = {
		_SOS_DMA_BUFFERSIZE,
		_NULL,
		_TRUE,
		_SOS_SAMPLE_RATE,
		19,
		0L,
		_NULL,
		_NULL,
		_NULL,
		_SOS_NORMAL_TIMER
		};


	_SOS_START_SAMPLE sSOSSampleData[12] = {

		{  _NULL, 0L, 0, _CENTER_CHANNEL, 0x7fff,
			_SAMPLE0, sosDIGISampleCallback, 0, _VOLUME | _PANNING | _LOOPING, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L },

		{  _NULL, 0L, 0, _CENTER_CHANNEL, 0x7fff,
			_SAMPLE1, sosDIGISampleCallback, 0, _VOLUME | _PANNING | _LOOPING, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L },

		{  _NULL, 0L, 0, _CENTER_CHANNEL, 0x7fff,
			_SAMPLE2, sosDIGISampleCallback, 0, _VOLUME | _PANNING | _LOOPING, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L },

		{  _NULL, 0L, 0, _CENTER_CHANNEL, 0x7fff,
			_SAMPLE3, sosDIGISampleCallback, 0, _VOLUME | _PANNING | _LOOPING, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L },

		{  _NULL, 0L, 0, _CENTER_CHANNEL, 0x7fff,
			_SAMPLE4, sosDIGISampleCallback, 0, _VOLUME | _PANNING | _LOOPING, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L },

		{  _NULL, 0L, 0, _CENTER_CHANNEL, 0x7fff,
			_SAMPLE5, sosDIGISampleCallback, 0, _VOLUME | _PANNING | _LOOPING, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L },
		
		{  _NULL, 0L, 0, _CENTER_CHANNEL, 0x7fff,
			_SAMPLE6, sosDIGISampleCallback, 0, _VOLUME | _PANNING | _LOOPING, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L },

		{  _NULL, 0L, 0, _CENTER_CHANNEL, 0x7fff,
			_SAMPLE7, sosDIGISampleCallback, 0, _VOLUME | _PANNING | _LOOPING, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L },

		{  _NULL, 0L, 0, _CENTER_CHANNEL, 0x7fff,
			_SAMPLE8, sosDIGISampleCallback, 0, _VOLUME | _PANNING | _LOOPING, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L },

		{  _NULL, 0L, 0, _CENTER_CHANNEL, 0x7fff,
			_SAMPLE9, sosDIGISampleCallback, 0, _VOLUME | _PANNING | _LOOPING, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L },
		
		{  _NULL, 0L, 0, _CENTER_CHANNEL, 0x7fff,
			_SAMPLE10, sosDIGISampleCallback, 0, _VOLUME | _PANNING | _LOOPING, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L },

		{  _NULL, 0L, 0, _CENTER_CHANNEL, 0x7fff,
			_SAMPLE11, sosDIGISampleCallback, 0, _VOLUME | _PANNING | _LOOPING, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L },

	};

//array for loop and pending loop MUSIC
	_SOS_START_SAMPLE LoopSampleData[2] =
		{  
			{_NULL, 0L, -1, _CENTER_CHANNEL, 0x7fff,
			_LSAMPLE1, sosDIGISampleCallback, 0, _LOOPING | _VOLUME, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L},

			{_NULL, 0L, -1, _CENTER_CHANNEL, 0x7fff,
			_LSAMPLE2, sosDIGISampleCallback, 0, _LOOPING | _VOLUME, 
			0L, 0L, 0L, 0L, 0, 0, 0, 0x8000, 0, 0, 0, 0, 
			0L, 0, 0, 0L, 0L, 0L},
		};


	WORD     LoopHandles[2];
	WORD     LoopPending=0,LoopIndex=0,looptoggle=0,loopmusepauseflag=0;
	WORD     Metronome;

	DWORD    *DigiList;
	DWORD    *LoopList;
	DWORD    *SongList;
	DWORD    SeekIndex;

	//
	//    MIDI SPECIFIC
	//
	_SOS_MIDI_HARDWARE         sMIDIHardware;
	_SOS_MIDI_INIT_DRIVER      sSOSMIDIInitDriver;
	_SOS_MIDI_DIGI_INIT_DRIVER sSOSMIDIDIGIInitDriver;

//midimusic vars
	WORD        Metronome;
	WORD        SongPending,BranchPending;

	WORD     hSOSSongHandles[MAX_ACTIVE_SONGS];
	BYTE     ActiveSongBits = 0x00;

	BYTE     *m_bnkptr,*d_bnkptr,*digi_bnkptr;
	BYTE _huge *lpMIDISong;

	_SOS_MIDI_INIT_SONG        sSOSInitSongs[MAX_ACTIVE_SONGS];

	_SOS_MIDI_TRACK_DEVICE   sSOSTrackMap[MAX_ACTIVE_SONGS] = { 
		{
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, 
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, 
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, 
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK
		}, 
		{
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, 
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, 
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, 
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK
		}, 
		{
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, 
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, 
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, 
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK
		}, 
		{
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, 
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, 
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, 
		_MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK, _MIDI_MAP_TRACK
		} 
	};


	//
	//    MISC/COMMON STUFF
	//
	WORD     hSOSDriverHandles[3];
	WORD     hSOSDriverHandles1;
	
	WORD     SD_Started=0;
	BOOL     Midi_Loaded,Digi_Loaded,DigMidi_Loaded;
	WORD     wError,wIndex;

	WORD     hSoundFile  =  -1;       // Handle for Sound F/X file
	WORD     hLoopFile   =  -1;       // Handle for Loop file
	WORD     hSongFile   =  -1;
	WORD     hMiscHandle =  -1;


	
	//
	//    TIMER STUFF
	//
	WORD     hTimerT_ClockHandle;    // Handle for the game timer (TotalClock)
	WORD     hTimerDig_FillHandle;   // Handle for the sSOSInitDriver.lpFillHandler 
	WORD     hTimerRec_FillHandle;   // Handle for the sSOSInitDriver.lpFillHandler 

	WORD     AuxTimerList[MAX_AUX_TIMERS];
	BYTE     ActiveTimerBits = 0x00;

	WORD     LoopSndsPlaying=0;
	

	struct ambsounds ambsoundarray[] = {
		0,0,
		S_WINDLOOP1,-1, 
		S_WINDLOOP2,-1,
		S_WAVELOOP1,-1, 
		S_LAVALOOP1,-1, 
		S_WATERY,-1, 
		S_STONELOOP1,-1,
		S_BATSLOOP,-1
	};  

		


	//
	//          GLOBAL VARIABLES
	//
	WORD     SoundMode,wDIGIVol;
	WORD     MusicMode,wMIDIVol;
	WORD     use_rec_driver,voicecom_enabled;


	//
	//          EXTERN STUFF
	//
	extern keytimerstuff();
	extern volatile long totalclock;
	extern long posx[],posy[];

	//JSA temp int to show vol and pan
	int gVol,gPan;

#else


extern int  Metronome,SongPending,BranchPending;
extern int  hSOSSongHandles[];


extern int  SoundMode,wDIGIVol,MusicMode,wMIDIVol,use_dig_midi,
				LoopPending,LoopIndex,looptoggle,LoopSndsPlaying,
				gPan,gVol;

extern SampleType SampleRay[],FXLoopRay[];

extern struct ambsounds ambsoundarray[];
extern int lavasnd,batsnd,cartsnd;


#endif



