Скачать Tone - Sound Module for PC Speaker

29.05.1991
Скачать файл (1,62 Кб)

Program ToneTest;
USES Tone;
begin
   ErrorBeep;
   Delay(500);
   AttentionBeep;
   Delay(500);
   BoundsBeep;
   Delay(500);
   Beep(440, 250);
end.
UNIT Tone;  {$S-,R-,D-,L-}

(* TONE.PAS - Sound Module for Turbo Pascal 6.0 - Turbo Vision
 * Written by Richard R. Sands
 * Compuserve ID 70274,103
 * January 1991
 *
 * NOTE: Do Not Overlay
 *)

INTERFACE

Procedure Sound(Hz:Word);
   Procedure NoSound;
   Procedure Delay(MS : Word);
 
   Procedure Beep(Hz, MS:Word);
     { Same as
               Sound(Hz);
               Delay(MS);
               NoSound;       ...but with more efficient code. }
 
   Procedure BoundsBeep;
     { Used for signalling a boundry or invalid command }
 
   Procedure ErrorBeep;
     { Used for signalling an error condition }
 
   Procedure AttentionBeep;
     { Used for signalling the user }

IMPLEMENTATION

VAR
    OneMS : Word;
 
{ ------------------------------------------------------------- }
Procedure Beep(Hz, MS:Word); assembler;
     { Make the Sound at Frequency Hz for MS milliseconds }
  ASM
    MOV  BX,Hz
    MOV  AX,34DDH
    MOV  DX,0012H
    CMP  DX,BX
    JNC  @Stop
    DIV  BX
    MOV  BX,AX
    IN	  AL,61H
    TEST AL,3
    JNZ  @99
    OR	  AL,3
    OUT  61H,AL
    MOV  AL,0B6H
    OUT  43H,AL
 @99:
    MOV  AL,BL
    OUT  42H,AL
    MOV  AL,BH
    OUT  42H,AL
 @Stop:
 {$IFOPT G+}
    PUSH MS
 {$ELSE }
    MOV  AX, MS   { push delay time }
    PUSH AX
  {$ENDIF }
    CALL Delay    { and wait... }
 
    IN   AL, $61  { Now turn off the speaker }
    AND  AL, $FC
    OUT  $61, AL
  end;
 
{ ------------------------------------------------------------- }
Procedure BoundsBeep; assembler;
  asm
  {$IFOPT G+ }
.......................