home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT10 / SOUND.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  2.7 KB  |  76 lines

  1. ;***************************************************************
  2. ;  Program Sound ( Chapter 10 )
  3. ;
  4. ;  The program for outputting a sound of prescribed tone
  5. ;
  6. ;  Author: A.I.Sopin   Voronezh, Russia   1990 --- 1992
  7. ;  ------
  8. ;
  9. ;  Call from Assembler programs:
  10. ;
  11. ;       Call SOUND
  12. ;
  13. ;  Parameters passed through the registers:
  14. ;
  15. ;  Frequency    - DI register (from   21  to  65535  hertz)
  16. ;
  17. ;  Duration      -BX register (in hundredth of second)
  18. ;
  19. ;  Registers  AX, CX, DX, DS, ES, SI  are retained by the program 
  20. ;
  21. ;
  22. ;
  23. ;***************************************************************
  24. PUBLIC   SOUND
  25. CODE     SEGMENT
  26.          ASSUME CS:CODE
  27. SOUND    PROC   FAR
  28.          push   ax
  29.          push   cx
  30.          push   dx
  31.          push   ds
  32.          push   es
  33.          push   si
  34. ;-----------------------------------------------------------
  35.          in     al,61h            ;  Read current port mode B (8255)
  36.          mov    cl,al             ;  Save current mode
  37.          or     al,3              ;  Switch on speaker and timer
  38.          out    61h,al            ;
  39.          mov    al,0B6h           ;  set for channel  2 (8253)
  40.          out    43h,al            ;  command register  8253
  41.          mov    dx,14h            ;
  42.          mov    ax,4F38h          ;  divisor of frequency
  43.          div    di                ;
  44.          out    42h,al            ;  lower byte of frequency
  45.          mov    al,ah             ;
  46.          out    42h,al            ;  higher byte of frequency
  47. ;  Generation of sound delay 
  48.          mov    ax,91             ;  multiplier  -  AX register !
  49.          mul    bx                ;  AX =BX*91 (result in   DX:AX)
  50.          mov    bx,500            ;  divisor, dividend in   DX:AX
  51.          div    bx                ;  result in   AX, remainder in DX 
  52.          mov    bx,ax             ;  save result
  53.          mov    ah,0              ;  read time
  54.          int    1Ah               ;
  55.          add    dx,bx             ;
  56.          mov    bx,dx             ;
  57. Cycle:   int    1Ah               ;
  58.          cmp    dx,bx             ;  Has time gone ?
  59.          jne    Cycle             ;
  60.          in     al,61h            ;  Read mode of port B (8255)
  61.          mov    al,cl             ;  Previous mode 
  62.          and    al,0FCh           ;
  63.          out    61h,al            ;  Restore mode
  64. ;-----------------------------------------------------------
  65. ;  Restoring registers and exit
  66. Exit:    pop    si                ;
  67.          pop    es                ;
  68.          pop    ds                ;
  69.          pop    dx                ;
  70.          pop    cx                ;
  71.          pop    ax                ;
  72.          RETF                     ; exit from subroutine
  73. SOUND    ENDP
  74. CODE     ENDS
  75.          END
  76.