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

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


#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     0x2000
	#define  _SOS_SAMPLE_RATE        11025
	//#define  _SOS_FILL_TIMER_RATE    40
	#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



