home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / sound / digpak / sbapi.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1994-02-21  |  5.0 KB  |  231 lines

  1. UNIT SBAPI;
  2.  
  3. INTERFACE
  4.  
  5. USES SBDRV,DOS;
  6.  
  7.  
  8. {
  9.   C definition of sound structure and PASCAL derivative.
  10.   (code was adapted from code for C)
  11.   typedef struct
  12.  {
  13.     unsigned char far *sound; // Far address of audio data.
  14.     unsigned int     sndlen;  // Length of audio sample.
  15.     int far *IsPlaying;       // Address of play status flag.
  16.     int     frequency;        // Playback frequency.
  17. { SNDSTRUC; }
  18.  
  19. TYPE SoundRec = RECORD
  20.         SoundData : Pointer;
  21.         SndLen    : Word;
  22.         IsPlaying : ^Integer;
  23.         Frequency : Integer;
  24.         END;
  25.    
  26. VAR 
  27.   SBAvailable : BOOLEAN;
  28.  
  29. PROCEDURE PlaySound(VAR TheSound : SoundRec);
  30. FUNCTION SoundPlaying : BOOLEAN ;
  31. FUNCTION AudioPendingStatus : INTEGER;
  32. PROCEDURE MassageAudio(VAR TheSound : SoundRec);
  33. PROCEDURE PlayMassagedAudio(VAR TheSound : SoundRec);
  34. PROCEDURE StopSound;
  35. PROCEDURE PostSound(VAR TheSound : SoundRec; VAR Result : INTEGER);
  36. FUNCTION DetectBlaster(VAR PortBase,IRQ : Word)  : BOOLEAN;
  37.  
  38. IMPLEMENTATION
  39.  
  40. { Save vector for INT 66h If SoundBlaster driver load fails }
  41. CONST DummyISR : Word = $CF; {IRET}
  42.       
  43.  
  44. VAR 
  45.   TIrq,ThePort : Word;
  46.       SaveExit : Pointer;
  47.     Orig66Vec  : Pointer;
  48.  
  49. {$F+}
  50. Procedure SBApiExitProc;  
  51.   BEGIN
  52.     If SBAvailable THEN 
  53.        UnLoadSoundDriver
  54.     ELSE
  55.       SetIntVec($66,Orig66Vec);
  56.     EXITPROC := SaveExit;
  57.   END;
  58. {$F-}
  59.  
  60.  
  61.  
  62.  
  63. {$L SBDETECT.OBJ}
  64. FUNCTION DetectBlaster(VAR PortBase,IRQ : Word) : Boolean; external;
  65.  
  66.  
  67. {Function #1: DigPlay, Play an 8 bit digitized sound.
  68.  
  69.     INPUT:  AX = 688h    Command number.
  70.         DS:SI        Point to a sound structure that
  71.                  describes the sound effect to be played.}
  72.  
  73.  
  74. PROCEDURE PlaySound(VAR TheSound : SoundRec); assembler;
  75.  
  76.    Asm
  77.      PUSH DS
  78.      PUSH SI
  79.      LDS SI, TheSound
  80.      MOV AX, $688
  81.      INT $66
  82.      POP SI
  83.      POP DS
  84.   End;
  85.  
  86.  
  87. {       INPUT:  AX = 689h
  88.     OUTPUT: AX = 0       No sound is playing.
  89.            = 1       Sound effect currently playing.
  90.         DX = 0       No sound is looping.
  91.            = 1       A sound effect is looping.
  92.         BX = version Starting with version 3.1, the BX register
  93.                  of the SoundStatus call will return the
  94.                  version number.  The version number is in
  95.                  decimal, and multiplied times 100.  Meaning
  96.                  a return of 310, is equal to version 3.10.
  97.                  Versions before 3.1, did not set the BX
  98.                  register to anything, so you should zero
  99.                  out the BX register before you check the
  100.                  version number.  If the BX register is still
  101.                  zero, then the DigPak driver loaded is less
  102.                  than 3.1. }
  103.  
  104.  
  105. FUNCTION SoundPlaying : BOOLEAN ; assembler;
  106.  
  107.   Asm
  108.     MOV AX,$0689
  109.     INT $66
  110.   End;
  111.  
  112.  
  113. { Function #3: MassageAudio, Preformat audio data into output hardware format.
  114.  
  115.     INPUT:  AX = 68Ah
  116.         DS:SI        Point to address of sound structure. }
  117.  
  118. PROCEDURE MassageAudio(VAR TheSound : SoundRec); assembler;
  119.                                   
  120.   Asm
  121.    PUSH DS
  122.    PUSH SI
  123.    LDS SI , TheSound
  124.    MOV AX, $068A
  125.    INT $66
  126.    POP SI
  127.    POP DS
  128.   End;
  129.  
  130. { Function #4: DigPlay2, Play preformatted audio data.
  131.  
  132.     INPUT:  AX = 68Bh
  133.         DS:SI        Point to address of sound structure.}
  134.  
  135. PROCEDURE PlayMassagedAudio(VAR TheSound : SoundRec); assembler;
  136.  
  137.   Asm
  138.    PUSH DS
  139.    PUSH SI
  140.    LDS SI , TheSound
  141.    MOV AX, $068B
  142.    INT $66
  143.    POP SI
  144.    POP DS
  145.   End;
  146.  
  147. {Function #8: StopSound, stop currently playing sound.
  148.  
  149.     INPUT: AX = 68Fh
  150.     OUTPUT: None.
  151.  
  152.           Will cause any currently playing sound effect to be
  153.           terminated. }
  154.  
  155. PROCEDURE StopSound; assembler;
  156.  
  157.   Asm
  158.    MOV AX, $68F
  159.    INT $66
  160.   End;
  161.  
  162. {FUNCTION #14: PostAudioPending
  163.  
  164.     INPUT: AX = 695h
  165.            DS:SI -> sound structure, preformated data.
  166.  
  167.     OUTPUT: AX = 0  Sound was started playing.
  168.         AX = 1  Sound was posted as pending to play.
  169.         AX = 2  Already a sound effect pending, this one not posted.}
  170.  
  171.  
  172. PROCEDURE PostSound(VAR TheSound : SoundRec; VAR Result : INTEGER); assembler;
  173.  
  174.    Asm
  175.     PUSH DS
  176.     PUSH SI
  177.     PUSH ES
  178.     PUSH DI
  179.     MOV AX, $0695
  180.     LDS SI, TheSound
  181.     INT $66
  182.     LES DI,Result
  183.     STOSW           { Pass the outcome in the AX register back to Result}
  184.     POP DI
  185.     POP ES
  186.     POP SI
  187.     POP DS
  188.    End;
  189.  
  190.  
  191. {FUNCTION #15: AudioPendingStatus
  192.  
  193.     INPUT:  AX = 696h
  194.  
  195.     OUTPUT: AX = 0 No sound is playing.
  196.         AX = 1 Sound playing, sound pending.
  197.         AX = 2 Sound playing, no sound pending. }
  198.  
  199. FUNCTION AudioPendingStatus : INTEGER; assembler;
  200.  
  201.   Asm
  202.    MOV AX, $0696
  203.    INT $66
  204.   End;
  205.  
  206.  
  207.  
  208. BEGIN
  209.   { Preserve original int 66H vector }
  210.   GetIntVec($66,Orig66Vec);
  211.   SaveExit := EXITPROC;
  212.   EXITPROC := @SBApiExitProc;
  213.  
  214.   { If SoundBlaster Detected }
  215.   If DetectBlaster(ThePort,TIrq) THEN
  216.      BEGIN
  217.       { Load the detected Port address and IRQ to the driver code }
  218.        PokeBlaster(ThePort,TIrq);
  219.        SBAvailable := LoadSoundDriver(ReportSB);
  220.      END
  221.   ELSE
  222.     BEGIN
  223.      SBAvailable := FALSE;
  224.  
  225.      { Set 66h interrupt vector to an IRET so that procedures can be }
  226.      { called with out locking the computer }
  227.      SetIntVec($66,@DummyISR);
  228.     END;
  229.  
  230. END.
  231.