home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / bbs / mikes30c.arc / SOUND.ASM < prev    next >
Assembly Source File  |  1985-09-26  |  1KB  |  61 lines

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