home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / SOUND.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-05-30  |  2.0 KB  |  92 lines

  1.         page    58,132
  2. ;
  3. ; sound.asm
  4. ; contains: gsound()
  5. ;
  6. ;
  7.         include    model.h
  8.         include    prologue.h
  9.         name    sound
  10.         pseg    sound
  11.  
  12. ;==>--    void gsound(frequency,duration)
  13. ;
  14. ;;    ARGUMENTS:
  15. ;      (int)    freq    -    Frequency in Hertz
  16. ;      (int) duration -    Duration in 1/18.2 sec. intervals
  17. ;
  18. ;;    DESCRIPTION:
  19. ;      Generates sound, equivalent to SOUND command in basic.
  20. ;      sound(440,9) = Middle C, for about 1/2 second.
  21. ;
  22. ;;    AUTHOR:
  23. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  24. ;
  25. ;    MODIFICATIONS:
  26. ;      "" Wed 11-Jan-1989 10:53:53
  27. ;        Renamed from sound()
  28. ;;;
  29. bios_loc equ    40h
  30.  
  31.     cproc    gsound
  32.     push    ds
  33.     mov    cx,@ab[bp]        ;get freq
  34.     cmp    cx,0            ;if zero,
  35.     je    snd1            ;just delay in here..
  36.     mov    dx,12h
  37.     mov    ax,34dch
  38.     div    cx            ;calculate freq parameter
  39.     push    ax
  40.     call    spkron
  41.     pop    ax
  42. snd1:    mov    cx,@ab+2[bp]        ;get duration
  43.     cmp    cx,0            ;if 0, turn off spkr
  44.     je    snd3            ;and exit.
  45.     mov    ax,bios_loc        ;segment for timer location
  46.     mov    ds,ax
  47.     mov    si,06ch            ;offset
  48.     mov    ax,[si]            ;get timer tic to start
  49. snd2:    cmp    ax,[si]            ;wait til timer increments
  50.     je    snd2
  51.     inc    ax
  52.     loop    snd2            ;loop for CX ticks of timer
  53. snd3:    push    cx            ;counter = 0 either from countdown of
  54.                      ;snd2 loop or parameter
  55.     in    al,61h            ;8255 port B
  56.     and    al,11111100b        ;turn off speaker
  57.     out    61h,al
  58.     pop    cx
  59. sndx:    pop    ds
  60.     cproce
  61.  
  62.  
  63. ;==>--    void spkron(divisor)
  64. ;      unsigned divisor;    data to put in the timer.
  65. ;
  66. ;    This function is only called from sound()
  67. ;
  68. spkron proc near
  69.     push    bp
  70.     mov    bp,sp
  71.     mov    al,10110110b
  72.     out    43h,al
  73.     mov    ax,[bp+4]
  74.     cmp    ax,0        ; if zero, just exit
  75.     jz    spkronx
  76.     out    42h,al        ; else output low order part to port
  77.     jmp     short    fpf0        ; to satisfy the AT circuitry
  78. fpf0:    xchg    ah,al
  79.     out    42h,al        ; hi order part
  80.     jmp     short    fpf1        ; to satisfy the AT circuitry
  81. fpf1:    nop
  82.     in    al,61h        ; get current port data
  83.     jmp     short    fpf2        ; to satisfy the AT circuitry
  84. fpf2:    or    al,3        ; turn on 2 lo order bits for speaker
  85.     out    61h,al        ;  under control of timer port.
  86. spkronx:
  87.     pop    bp
  88.     ret
  89. spkron    endp
  90.     endps
  91.     end
  92.