home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / mike40c / sound.asm < prev    next >
Encoding:
Assembly Source File  |  1986-10-24  |  1.1 KB  |  61 lines

  1. page,132
  2. title SOUND.ASM - SOUND PROCEDURES for MICROSOFT 'C' (4.0)
  3. ;    sound    Control PC Speaker
  4. ;       by Mike Elkins 
  5. ;
  6. ;    sound(len,freq)
  7. ;    int len        length of sound
  8. ;    int freq    frequency of sound
  9. ;
  10. _text     segment    byte public 'code'
  11.     assume    cs:_text
  12.  
  13.     public    _sound,SOUND
  14.  
  15. arg    struc
  16. oldbp    dw    ?
  17. retn    dw    ?
  18. len    dw    ?
  19. freq    dw    ?
  20. arg    ends
  21.  
  22. SOUND:
  23. _sound    proc    near
  24.  
  25.     push    bp
  26.     mov    bp,sp
  27.     push    ds
  28.     xor    ax,ax        ;set up for low memory stuff
  29.     mov    ds,ax
  30.  
  31.     mov    di,[bp].freq    ;put frequency in di
  32.     mov       al,0B6h       ;set up timer for sound
  33.     out    43h,al
  34.     mov    dx,14h        ;divide frequency by 1331000
  35.     div    di
  36.     out    42h,al        ;send frequency to timer
  37.     mov    al,ah
  38.     out    42h,al
  39.     in    al,61h        ;get current timer port value
  40.     push    ax        ;save it
  41.     or    al,3        ;turn on speaker
  42.      out    61h,al
  43.     mov    bx,[bp].len    ;wait loop
  44. loop:    mov    cx,280        ;wait 1 ms
  45. deloop:    loop    deloop
  46.     dec    bx
  47.     jnz    loop
  48.     jmp    off
  49.  
  50. off:     pop    ax        ;recover speaker port value
  51.     out    61h,al        ;turn speaker off
  52.  
  53.     pop    ds        ;put things back and return
  54.     pop    bp
  55.         ret
  56.  
  57.  
  58. _sound    endp
  59. _text        ends
  60.          end
  61.