home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC/CD Gamer UK 10
/
PCGAMER10.bin
/
lem3d
/
sound
/
drivers
/
drivers.doc
< prev
next >
Wrap
Text File
|
1994-11-06
|
18KB
|
477 lines
; P.C. Sound card 'Generation 2' music & sound effect drivers
; (c) 1992-94 Tony Williams / Sound Images
; start date 01.05.92
; version 1.11x
; version date 27.10.94
; Overview
; --------
; The drivers are supplied as a binary image , which is intended to be loaded
; at the start of a normalised segment by the programmer . ( That means that
; the code is at address zero in the segment , on a paragraph boundary ) .
; All memory allocation etc. has to be controlled by the programmer , and no
; tests are made to determine whether the file is complete in memory , or has
; been overwritten .
; A separate file is supplied for each sound format supported , which can be
; accessed without knowledge of which sound card is being used . All functions
; of the driver are invisible to the programmer and problems which occur
; between different sound hardware are tackled within the driver . Obviously ,
; a simple internal bleeper cannot handle as many channels simultaneously as
; a sound card , but the driver code should make these problems unimportant
; to the programmer .
; Installing the drivers
; ----------------------
; BEWARE :-
; Auto-detection has been causing some problems . In discussion with several
; other musician/programmers it has been established that no guarantee can be
; given that auto-detection will work on all combinations of hardware in all
; machines . A figure of ninety-something percent success appears universal ,
; but it is always best to ask the user for some input for information on port
; addresses . The Soundblaster card has been the worst offender up to now ,
; but as sound cards become more and more sophisticated , I expect more and
; larger problems to arise ( Multi-Media / CD-ROMS etc. will all use differing
; irq's DMA channels ad-nauseam )
; In keeping with the aim of making things easy for the programmer (that's the
; theory , at least ) auto-detection is available , but can be overridden on
; any or all of the modules as the programmer chooses . I strongly advise a
; menu and a configuration file which can keep the players' choices . This is,
; in my opinion the most satisfactory ( and fool-proof ) option . For more
; details on auto-detection within the drivers , see the initialise function
; below .
; Accessing driver functions
; --------------------------
; At the start of the file ( at offsets 0 and 4 ) there are two entry points
; to the sound service routine . At offset zero is the entry point you should
; call via a CALL DWORD , and at offset 4 is the entry point to be called from
; a software interrupt . This version returns with an IRET so do not use this
; except via a software interrupt .
; The start of the file looks like this :-
;far_call_entry: call music_service ; service the call
; retf ; forced FAR return
;int_call_entry: call music_service
; iret ; INTERRUPT return
; Music_service is called with AH holding a function number - these are listed
; below . In most cases other parameters are passed in AL , and in a few extra
; parameters where necessary . In most cases , AL will return an error code .
; If AL returns a 0 ( zero ) then the function has been processed successfully .
; If AL holds any other value , there has been an error of some sort .
; See below for details .
; In all cases , all registers except AX are preserved . Expect AH to be
; corrupt unless specified as a returned parameter by the function .
;****************
;Driver functions
;****************
;-----------------------
;Function 0 - Initialise
;-----------------------
; entry : ah = 0
; dx = port address \
; ch = DMA channel if dx = zero driver will attempt auto-detect ,
; cl = irq level / ignoring these values
; exit : al = 0 if initialise ok
; al = 1 if initialise failed ( e.g sound card not available )
; al = 2 on Soundblaster if FM sound is ok , but DSP gave an error
; al = 3 on multi-channel Soundblaster driver found invalid samples file
; This function is very important ! Until this function has been successfully
; completed , NO OTHER FUNCTIONS WILL OPERATE . If another function is
; accessed without Initialisation , ax will return -2 .
; It is important to note that on the Roland LAPC-1 card , Initialise takes
; several seconds if a large bank of sounds has to be downloaded , using the
; MIDI bus ( 31250 baud serial ) .
; On some cards , an irq is generated for some data transfers . In these
; cases , the interrupt level is established during Initialise and the
; relevant irq is re-vectored . Be careful not to disable the irq in
; register 21h which may be used during sample playback etc.
; If Initialise is entered with zero in dx , auto-detection will be
; attempted , and ch/cl will be ignored .
; If dx holds any non-zero value , it is taken to be an I/O port address for
; the particular sound card . Be very careful here , as all the cards have a
; different I/O address ( except for Adlib compatibles ) and entering with a
; non-zero value which isn't the correct address will give you at best a
; silent output , and at worst , a crash or hang .
; The I/O port / irq / DMA available values are as follows .
; I/O port base address irq DMA
; Adlib 388h not used not used
; Roland 330h not used but not used
; various are available
; on the hardware
; Soundblaster 210h 2/3/5 or 7 (default) 1
; 220h (default)
; 230h
; 240h
; 250h
; 260h
; 270h
; Soundblaster Pro / 16
; 220h (default) 2/7/10 or 5 (default) 0/3 or
; 240h 1 (default)
; Gravis Ultrasound/Max
; If you are using Ultramid.exe then this will read the
; settings from the enviroment string.
; AWE 32
;-------------------
;Function 1 - Remove
;-------------------
; entry : ah = 1
; exit : al = 0 if removed ok
; al = 1 if remove encountered an error ( unlikely )
; ah = corrupt
; Where interrupt vectors have been altered for DMA or similar , Remove sets
; them back to the state they were in before Initialise , also prohibiting
; other functions . Note that Remove does not remove the driver from memory ,
; or the timer imterrupts , that is up to you , the game programmer .
;---------------------------
;Function 2 - Set Timer Rate
;---------------------------
; entry : ah = 2
; cx = timer rate constant
; exit : al = 0 if timer rate calculations were successful
; al = 1 if an error occurred , e.g timer rate out of range
; ah = corrupt
; It has always been a problem with music drivers in games that the game takes
; obvious priority over the music . e.g. if the game needs a particular rate
; timer interrupt , the music has be called at that speed . This obviously
; gives rise to big problems with musical tempo . These drivers use a
; semi-intelligent system which appears < so far > to the ear to play the
; music accurately at a large range of timer rates . I have not tested to
; extremes , but I expect most game programmers to prefer a 60Hz or 70Hz
; timer , which is the same rate as the monitor frame update . This would
; approximate to a timer constant of 4277h which is the default for the
; drivers . NOTE that this function only informs the driver the timer rate
; you are calling the sound update , it DOES NOT SET ANY HARDWARE TIMER
; REGISTERS OR VECTORS .
; This function finds it necessary to disable interrupts while it performs
; some calculations , to avoid being interrupted by the update routine which
; may attempt to play some music with the internal speed constants
; half-calculated . The state of the interrupt enable is preserved by PUSHF
; and POPF commands .
; For those who are unfamiliar with the timer hardware , the constant can be
; calculated thus : 1192180 < the timer clock rate > / call rate in Hz .
; There is obviously some difference between video cards / monitors , as I
; calculate my monitor to run at a rate equivalent to a 4277h timer constant ,
; which is why the drivers default to that , although the formula above gives
; a value of 4287h . It may be that the time between an interrupt request
; being generated and that interrupt being serviced is 'lost' . Anyone who
; knows more about this , please let me know .
; common values for CX on entry :-
; 70 Hz = 4287h (approx VGA video update rate)
; 60 Hz = 4D9Dh (approx EGA video update rate)
; 50 Hz = 5D23h (approx CGA / Tandy video update rate)
;-------------------
;Function 3 - Update
;-------------------
; entry : ah = 3
; exit : al = 0 if everything ok
; al = 1 if an error occurred , in most cases an error will stop
; all sound ( the exceptions would probably crash !! )
; ax = -2 if call attempts re-entry , i.e. routine interrupts itself .
; This is the "refresh" function which is mostly called at 50Hz on other
; machines . These drivers are designed to process all tunes and effects
; within this routine to avoid the problems which may occur when Update
; interrupts another music function .
;------------------------------
;Function 4 - Initialise a tune
;------------------------------
; entry : ah = 4
; al = tune number , from 1 upwards
; exit : al = 0 if everything ok
; al = 1 if an error occurred , usually tune number out of range
; This function "cues up" a tune to start the next time the driver is updated .
;---------------------------
;Function 6 - Stop all sound
;---------------------------
; entry : ah = 6
; exit : al = 0 if everything ok
; al = 1 if an error occurred . Very , very unlikely
; This function stops all tunes and sound effects .
;------------------------
;Function 7 - Stop a tune
;------------------------
; entry : ah = 7
; exit : al = 0 if everything ok
; al = 1 if an error occurred . Very , very unlikely
; This function stops the current tune but NOT sound effects .
;-------------------------------------
;Function 9 - Ask if a tune is playing
;-------------------------------------
; entry : ah = 9
; exit : al = number of the current tune
; al = 0 if NO tune is playing
; All this function does is : mov al,[current tune] , and returns .
;------------------------------------------------
;Function 11 - Count how many effects are running
;------------------------------------------------
; entry : ah = 11
; exit : al = how many effects are playing
; This function just counts how many tracks are running effects .
;-------------------------------------------
;Function 12 - fetch offset of format string
;-------------------------------------------
; entry : ah = 12
; exit : bx = offset within the segment where an ASCIIz string is , which tells
; you which format the driver supports (Adlib/Soundblaster etc.)
; al = 0 if function performed ok
;--------------------------------------------
;Function 13 - fetch offset of version string
;--------------------------------------------
; entry : ah = 13
; exit : bx = offset within the segment where an ASCIIz string is , which tells
; you which version of the driver this is ( v1.09 22.12.93 ) .
; al = 0 if function performed ok
;-----------------------------------------
;Function 14 - set the volume of an effect
;-----------------------------------------
; entry : ah = 14
; al = effect number
; cl = volume 0-7Fh
; exit : al = 0 if volume set
; al = 1 if effect is not running
; Sets the volume of the channel which is running the effect in AL .
;------------------------------
;Function 15 - start a fade-out
;------------------------------
; entry : ah = 15
; cx = number of update calls fade-out should take
; exit : al = 0 if calculated successfully
al = 1 if calculation gave an error
; The value in cx is used to calculate how much the volume should decrease each
; frame . This is only an approximate value , as different sound cards will
; sound different at different volumes , and the fade will definitely not sound
; the same on each card . In particular , it may seem that the sound is
; inaudible when the volume is still at around 20% . However , a simple fade is
; far preferable to a sudden stop , so try using a fade over a period of around
; 3 or 4 seconds , rather than just stopping the tune . To determine whether
; the fade has completed , use the ASK_TUNE function which will return a zero
; in AL when the tune has been faded completely and then switched off .
; WARNINGS : As this function uses a MASTER volume control , it fades out
; both tunes and sound effects .
; On certain sound cards , including Adlib , the extra processing
; needed to output volumes every frame may be considerable .
;---------------------------------------------
;Function 16 - set multi-channel playback rate
;---------------------------------------------
; entry : ah = 16
; cx = playback frequency in Hz ( default is 11025 )
; exit : al = 0 if playback rate set successfully
; al = 1 if driver is not multi-channel sample player
; al = 2 if calculation gave an error
; cx = playback frequency set by the driver in Hz . See note below .
; This function is specific to the Soundblaster multi-channel sample player ,
; and sets up the rate at which the samples are combined and output .
; The higher the rate , the better the sound , and the more processor time
; is used .
; N.B. The Adlib Gold Card ( and maybe others in the future ) can only play
; back at a few fixed rates . The driver finds the nearest available one to
; that requested .
; Available rates for Adlib Gold are 44100,22050,11025 and 7350 Hz .
; I suggest that 11025 Hz is a good compromise between processor time and
; sound quality ( and also should be supported by all future additions ! )
;----------------------------------
;Function 17 - play a single sample
;----------------------------------
; entry : ah = 17
; al = channel number 0-3
; es:di = REAL MODE segment:offset of sample
; cl = volume 0-7Fh
; N.B. sample data must NOT cross a segment boundary , as the
; processing overhead to check this would amount to around 500
; extra opcodes per frame . Yes , there is a good reason for
; having these awkward restrictions !!!!
; exit : al = 0 if sample started ok
; al = 1 if samples not supported on this format
; al = 2 if channel number out of range
; al = -1 if function was not in range of driver
; al = 3 if any other error
; the normal multi-channel stuff still applies
;---------------------------
;Function 18 - stop a sample
;---------------------------
; entry : ah = 18
; al = channel number 0-3
; Stop the sample currently playing on channel al
;-----------------------------------------
;Function 19 - get sample pointer position
;-----------------------------------------
; entry : ah = 19
; al = channel number 0-3
; exit : bx = current pointer within sample , of data next to be output
; returns bx as the address within the sample where the output routine has
; reached . This can be used to determine whether a particular channel is
; playing a sample , as the return value of -1 will always signify a channel
; which is stopped .
;---------------------------------
;Function 20 - set sample channels
;---------------------------------
; entry : ah = 20
; al = how many channels 1/2/4
; exit : al = 0 if channels set ok
; al = 1 if invalid number of channels requested
; The routine which combines samples can be set to handle 1 , 2 , or 4 channels
; at a time . There are some points to note here :-
; If output is set to 1 or 2 channels , the others are ignored , and no error
; is generated . Channels are processed in the normal way , except for the main
; output routine . Obviously more channels = more processing .
; This function silences all channels .
;------------------------------
;Function 21 - set sample pitch
;------------------------------
; entry : ah = 21
; al = channel 0-3
; bx = new frequency in Hertz
; cx = note frequency in Hertz (262 approximates to middle C
; 440 is international A )
; exit : al = 0 if pitch set ok
; al = 1 if calculation gave out-of-range value
; The output routine steps through the data at a rate calculated relative to
; processing speed , sample rate etc . This bodge just sets the sample rate
; value , which is usually fetched from the sample header , to any value
; you fancy , in Hertz .
;-------------------------------
;Function 22 - set master volume
;-------------------------------
; entry : ah = 22
; cx = volume level , maximum value is 256 , and minimum 0 .
; exit : al = 0 if volume set ok
; al = 1 if some sort of error occurred
; N.B. this function does not affect the volume of samples
This function only applies to the ordinary soundblaster and to none of the
other cards.
; end of DRIVERS.DOC file