home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / sound / sb_dma / sb_dsp.asm < prev    next >
Assembly Source File  |  1992-03-12  |  6KB  |  207 lines

  1. ;---------------------------------------------------------------------------
  2. ; SB_DSP.ASM -- Programmer's library for the Sound Blaster DSP interface
  3. ; ver 1.0  (Thursday, March 12, 1992)
  4. ;---------------------------------------------------------------------------
  5. ;  Copyright (C) 1992, Heath I Hunnicutt
  6. ;---------------------------------------------------------------------------
  7. ;       This document may be freely distributed if no fee is assigned and
  8. ;  the document is not altered.
  9. ;       It is unlawful to use this program code, or any derivation of it,
  10. ;  for commercial gain of any sort.
  11. ;---------------------------------------------------------------------------
  12. ;  By: heathh@cco.caltech.edu -or- heathh@tybalt.cco.caltech.edu
  13. ;       aka hihunn@through.ugcs.caltech.edu (NOT preferred)
  14. ;---------------------------------------------------------------------------
  15. ;  Requires: Sound Blaster sound card or compatible
  16. ;            Turbo Assembler from Borland
  17. ;            A DMA library such as dma_code.asm by me
  18. ;---------------------------------------------------------------------------
  19. ;  Acknoweledgements: Brian Smith -- UNIX device driver source
  20. ;---------------------------------------------------------------------------
  21. ;  Legal: SoundBlaster is a trademark of Creative Labs, Inc.
  22. ;         Turbo Assembler is a trademark of Borland International.
  23. ;---------------------------------------------------------------------------
  24. ;  Warning: Be sure that there is a card installed before calling these
  25. ;           routines.
  26. ;---------------------------------------------------------------------------
  27.  
  28.                         IDEAL
  29.                         MODEL small
  30.  
  31.                         DATASEG
  32. SB_IO_Port  DW 0220h    ;These values are kept here to avoid add
  33. DSP_Reset   DW 0226h    ;instructions in code that may be time-
  34. DSP_RDData  DW 022Ah    ;sensitive.
  35. DSP_Command DW 022Ch
  36. DSP_RDAvail DW 022Eh
  37.  
  38. DSP_WRData EQU DSP_Command      ;Aliases for the same variable name
  39. DSP_Status EQU DSP_Command
  40.  
  41.                         CODESEG
  42.  
  43. PUBLIC _dsp_reset,_dsp_voice,_set_SB_address,_dsp_dma_prepare,_dsp_time
  44.  
  45. MACRO await_DSP
  46. LOCAL @@Wait_Ready
  47.      push ax dx
  48. @@Wait_Ready:
  49.      mov  dx,[DSP_Status]
  50.      in   al,dx
  51.      and  al,128
  52.       jnz @@Wait_Ready
  53.      pop  dx ax
  54. ENDM MACRO
  55.  
  56.  
  57. MACRO ten_microsec_delay
  58. LOCAL @@KT                 ;If you know of a better, more accurate,
  59.      push cx               ;more reliable, just plain smarter, way
  60.      mov  cx,20000         ;to do this, PLEASE TELL ME.
  61. @@KT:                      ;
  62.      nop                   ;(The idea is to kill 10 microseconds.)
  63.      loop @@KT             ;
  64.      pop  cx               ;email: heathh@cco.caltech.edu
  65. ENDM ten_microsec_delay
  66.  
  67. ;---------------------------------------------------------------------------
  68. ; void far dsp_time(int pacing)
  69. ;---------------------------------------------------------------------------
  70. ; pacing = 255 - (1,000,000 / frequency)
  71. ;---------------------------------------------------------------------------
  72. PROC _dsp_time FAR
  73. ARG delay:WORD
  74.      push bp
  75.      mov  bp,sp
  76.      push ax dx
  77.  
  78.      await_DSP
  79.      mov  dx,[DSP_Command]
  80.      mov  al,040h
  81.      out  dx,al
  82.  
  83.      await_DSP
  84.      mov  dx,[DSP_Command]
  85.      mov  ax,[delay]
  86.      out  dx,al
  87.      pop  dx ax
  88.      pop  bp
  89.      ret
  90. ENDP _dsp_time
  91.  
  92.  
  93. ;---------------------------------------------------------------------------
  94. ; void far dsp_reset(void)
  95. ;---------------------------------------------------------------------------
  96. PROC _dsp_reset FAR
  97.      push ax dx
  98.  
  99.      mov  dx,[DSP_Reset]
  100.      mov  al,1
  101.      out  dx,al
  102.  
  103.      ten_microsec_delay
  104.  
  105.      mov  al,0
  106.      out  dx,al
  107.  
  108. @@Wait_Ready:
  109.      mov  dx,[DSP_RDAvail]
  110.      in   al,dx
  111.      and  al,128
  112.        jz @@Wait_Ready
  113.      mov  dx,[DSP_RDData]
  114.      in   al,dx
  115.      cmp  al,0AAh
  116.       jne @@Wait_Ready
  117.  
  118.      mov  ax,165
  119.      push ax
  120.      call _dsp_time
  121.      pop  ax
  122.      pop  dx ax
  123.      ret
  124. ENDP _dsp_reset
  125.  
  126. ;---------------------------------------------------------------------------
  127. ; void far dsp_dma_prepare(int Dir,int Length)
  128. ;---------------------------------------------------------------------------
  129. ; Dir = 0 for Microphone Input, 1 for Speaker Output
  130. ; Length = Length of data to be sampled/played
  131. ;---------------------------------------------------------------------------
  132. PROC _dsp_dma_prepare FAR
  133. ARG Dir:WORD,Len:WORD
  134.      push bp
  135.      mov  bp,sp
  136.      push ax dx
  137.  
  138.      await_DSP
  139.      mov  al,24h
  140.      cmp  [Dir],0
  141.        jz @@Is_Read
  142.      mov  al,14h
  143. @@Is_Read:
  144.      mov  dx,[DSP_Command]
  145.      out  dx,al
  146.      await_DSP
  147.      mov  ax,[Len]
  148.      out  dx,al
  149.      await_DSP
  150.      mov  al,ah
  151.      out  dx,al
  152.  
  153.      pop  dx ax
  154.      pop  bp
  155.      ret
  156. ENDP _dsp_dma_prepare
  157.  
  158. ;---------------------------------------------------------------------------
  159. ; void far dsp_voice(Activity)
  160. ;---------------------------------------------------------------------------
  161. ; Activity = 0 for silent, 1 for audible
  162. ;---------------------------------------------------------------------------
  163. PROC _dsp_voice FAR
  164. ARG Which:WORD
  165.      push bp
  166.      mov  bp,sp
  167.      push dx ax
  168.  
  169.      await_DSP
  170.      mov  ax,[Which]
  171.      and  al,1                  ;Want a 1/0 parameter
  172.      xor  al,1
  173.      shl  al,1
  174.      or   al,0D1h
  175.      mov  dx,[DSP_Command]
  176.      out  dx,al
  177.      pop  ax dx
  178.      pop  bp
  179.      ret
  180. ENDP _dsp_voice
  181.  
  182. ;---------------------------------------------------------------------------
  183. ; void far set_SB_address(int base)
  184. ;---------------------------------------------------------------------------
  185. ; Sets base port of SoundBlaster that other functions refer to.
  186. ; Most likely value (and the default): 0x220
  187. ;---------------------------------------------------------------------------
  188. PROC _set_SB_address FAR
  189. ARG Port:WORD
  190.      push bp
  191.      mov  bp,sp
  192.      push ax
  193.      mov  ax,[Port]
  194.      mov  [SB_IO_Port],ax
  195.      add  ax,6
  196.      mov  [DSP_Reset],ax
  197.      add  ax,4
  198.      mov  [DSP_RDData],ax
  199.      add  ax,2
  200.      mov  [DSP_Command],ax
  201.      add  ax,2
  202.      mov  [DSP_RDAvail],ax
  203.      pop  ax
  204.      pop  bp
  205.      ret
  206. ENDP _set_SB_address
  207. END