home *** CD-ROM | disk | FTP | other *** search
/ Sound, Music & MIDI Collection 2 / SMMVOL2.bin / DOS / SS_PLAY / FUNK106.ZIP / FUNK_S.ZIP / DMA_T.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-10-01  |  10.7 KB  |  357 lines

  1. ideal
  2. p386
  3. model small
  4.  
  5. segment code32 public 'code' use32
  6. assume cs:code32,ds:code32,fs:code32,gs:code32,ss:code32
  7. include "dos32.inc"
  8.  
  9. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  10. ; Structures                               ;
  11. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  12.  
  13. struc tinit_settings
  14.   config_marker        db "unislite config file - don't edit me - 2",26
  15.   card_type            db 0    ;? ; 0 = SB; 1 = SBPRO; 2 = GUS ; 3 = AWE32
  16.   PORT_no              dw 220h ;?
  17.   IRQ_no               db 07h  ;?
  18.   DMA_no               db 01h  ;?
  19. ends
  20.  
  21. struc tDMA_info
  22.   dma_base             dw ?
  23.   page                 db ?
  24.   offs                 dw ?
  25.   dma_page_Reg         dw ?
  26. ends
  27.  
  28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  29. ; Data                                     ;
  30. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  31.  
  32. sample_name            db "snd\charms.snd",0
  33. file_handle_779        dw ?
  34. file_buffer            = 500000
  35.  
  36. init_settings          tinit_settings <>
  37.  
  38. DAC_mix_buffer_size    dw ?
  39. DAC_mix_buffer_size_AD dw ?
  40. DAC_sampling_rate      dw ?
  41. DMA_info               tDMA_info <>
  42. DMA_page_table         db 87h,83h,81h,82h
  43.  
  44. SB_BASE                dw 0
  45. SB_RESET               dw 6h
  46. SB_READ_DATA           dw 0ah
  47. SB_WRITE_DATA          dw 0ch
  48. SB_DATA_AVAIL          dw 0eh
  49.  
  50. SB_set_size            dd ?
  51.  
  52. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  53. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  56. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  57. ;                                                                     ;
  58. ; DAC Code                                                            ;
  59. ;                                                                     ;
  60. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  61. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  62. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  63. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  64. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  65.  
  66. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  67. ;                                                                     ;
  68. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  69. proc SB_detect
  70.   mov    ax,[word init_settings.PORT_no]
  71.   add    [word SB_BASE],ax
  72.   add    [word SB_RESET],ax
  73.   add    [word SB_READ_DATA],ax
  74.   add    [word SB_WRITE_DATA],ax
  75.   add    [word SB_DATA_AVAIL],ax
  76.   mov    al,1
  77.   mov    dx,[word SB_RESET]
  78.   out    dx,al
  79.   in     al,dx
  80.   in     al,dx
  81.   in     al,dx
  82.   in     al,dx
  83.   xor    al,al
  84.   mov    dx,[word SB_RESET]
  85.   out    dx,al
  86.   mov    cl,64h
  87. @@DataWait:
  88.   mov    dx,[word SB_BASE]
  89.   mov    dx,[word SB_DATA_AVAIL]
  90.   in     al,dx
  91.   test   al,80h
  92.   jnz    @@YesData
  93.   dec    cl
  94.   jnz    @@DataWait
  95.   jmp    @@exit
  96. @@YesData:
  97.   mov    dx,[word SB_READ_DATA]
  98.   in     al,dx
  99.   cmp    al,0AAh
  100.   je     @@YepSB
  101.   dec    cl
  102.   jnz    @@DataWait
  103.   jmp    @@exit
  104. @@YepSB:
  105.   clc
  106.   ret
  107. @@exit:
  108.   stc
  109.   ret
  110. endp
  111.  
  112. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  113. ;                                                                      ;
  114. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  115. proc SB_write_dac
  116.   push   eax
  117.   mov    dx,[word SB_WRITE_DATA]
  118. @@Wait_Ready:
  119.   in     al,dx
  120.   and    al,80h
  121.   jnz    @@Wait_Ready
  122.   pop    eax
  123.   out    dx,al
  124.   ret
  125. endp
  126.  
  127. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  128. ;  al = addr  ah = data      SBPRO mixxer                              ;
  129. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  130. proc SB_write_mixer
  131.   mov    dx,[word SB_BASE]
  132.   add    dx,4
  133.   push   edx
  134.   out    dx,al
  135.   pop    edx
  136.   inc    dx
  137.   mov    al,ah
  138.   out    dx,al
  139.   ret
  140. endp
  141.  
  142. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  143. ;                                                                      ;
  144. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  145. proc DAC_resolve_dma_addr
  146.   mov    eax,offset file_buffer
  147.   add    eax,[dword CODE32_addr]
  148.   mov    [word dma_info.offs],ax
  149.   shr    eax,16
  150.   mov    [byte dma_info.page],al
  151.   movzx  ebx,[byte init_settings.DMA_no]
  152.   mov    al,[byte ebx+DMA_page_table]
  153.   xor    ah,ah
  154.   mov    [word dma_info.dma_page_reg],ax
  155.   movzx  ebx,[byte init_settings.DMA_no]
  156.   shl    bl,1
  157.   mov    [word dma_info.dma_base],bx
  158.   ret
  159. endp
  160.  
  161. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  162. ;                                                                      ;
  163. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  164. proc SB_set_size_slow
  165.   mov    al,14h                                   ; DMA_8_BIT_DAC
  166.   call   SB_write_dac
  167.   mov    ax,[word DAC_mix_buffer_size_AD]
  168.   call   SB_write_dac
  169.   mov    al,ah
  170.   call   SB_write_dac
  171.   ret
  172. endp
  173.  
  174. proc SB_set_size_fast
  175.   mov    al,48h                                   ; DMA_8_BIT_DAC (FAST)
  176.   call   SB_write_dac
  177.   mov    ax,[word DAC_mix_buffer_size_AD]
  178.   call   SB_write_dac
  179.   mov    al,ah
  180.   call   SB_write_dac
  181.   mov    al,91h
  182.   call   SB_write_dac
  183.   ret
  184. endp
  185.  
  186. proc SB_send_block_to_DMA
  187.   mov    al,4
  188.   add    al,[byte init_settings.DMA_no]
  189.   out    0Ah,al                                   ; mask reg bit
  190.   xor    al,al
  191.   out    0Ch,al                                   ; clr byte ptr
  192.   mov    al,48h                                   ; set DMA to "send data"
  193.   add    al,[byte init_settings.DMA_no]
  194.   out    0Bh,al                                   ;set mode reg
  195.   mov    dx,[word dma_info.dma_base]
  196.   mov    ax,[word dma_info.offs]
  197.   out    dx,al                                    ; set base address low
  198.   mov    al,ah
  199.   out    dx,al                                    ; set base address high
  200.   inc    dx                                       ; point to length
  201.   mov    ax,[word DAC_mix_buffer_size_AD]
  202.   out    dx,al                                    ; set length low
  203.   mov    al,ah
  204.   out    dx,al                                    ; set length high
  205.   mov    al,[byte DMA_info.page]
  206.   mov    dx,[word DMA_info.dma_page_reg]
  207.   out    dx,al                                    ; set DMA page reg
  208.   mov    al,[byte init_settings.DMA_no]
  209.   out    0Ah,al                                   ; unmask (activate) dma channel
  210.   call   [dword SB_set_size]
  211.   ret
  212. endp
  213.  
  214. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  215. ;                                                                          ;
  216. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  217. proc SB_init
  218.   call   DAC_resolve_dma_addr
  219. ;  call   DAC_clear_sam_buffer
  220. ;  mov    bl,[byte init_settings.IRQ_no]
  221. ;  call   getirqvector
  222. ;  mov    [dword DAC_old_irq_ofs],edx
  223. ;  mov    [word DAC_old_irq_sel],cx
  224.   cmp    [byte init_settings.card_type],1
  225.   je     @@set_for_SBPRO
  226. ;  mov    [byte DAC_shift_value],1
  227.   mov    [word DAC_sampling_rate],22000
  228.   mov    [word DAC_mix_buffer_size],32000      ; 220
  229.   mov    [word DAC_mix_buffer_size_AD],32000-1 ; 220-1
  230.   lea    eax,[SB_set_size_slow]
  231.   mov    [dword SB_set_size],eax
  232. ;  mov    bl,[byte init_settings.IRQ_no]
  233. ;  lea    edx,[SB_virtualmixxer]
  234. ;  mov    cx,cs
  235. ;  call   setirqvector
  236.   xor    edx,edx                                       ;set sampling rate
  237.   mov    eax,0F4240h
  238.   movzx  ecx,[word DAC_sampling_rate]
  239.   div    ecx
  240.   neg    al
  241.   push   eax
  242.   jmp    @@done_set
  243. @@set_for_SBPRO:
  244. ;  mov    [byte DAC_shift_value],2
  245.   mov    ax,130eh                                      ;set for stereo
  246.   call   SB_write_mixer
  247.   mov    ax,0ff22h                                     ;set master volume
  248.   call   SB_write_mixer
  249.   mov    ax,0ff04h                                     ;set VOL volume
  250.   call   SB_write_mixer
  251.   mov    ax,0ff2eh                                     ;set line volume
  252.   call   SB_write_mixer
  253.   mov    [word DAC_sampling_rate],44000
  254.   mov    [word DAC_mix_buffer_size],220
  255.   mov    [word DAC_mix_buffer_size_AD],440-1
  256.   lea    eax,[SB_set_size_fast]
  257.   mov    [dword SB_set_size],eax
  258. ;  mov    bl,[byte init_settings.IRQ_no]
  259. ;  lea    edx,[SBPRO_virtualmixxer]
  260. ;  mov    cx,cs
  261. ;  call   setirqvector
  262.   xor    edx,edx                                       ;set sampling rate (hi speed)
  263.   mov    eax,0f424000h
  264.   movzx  ecx,[word DAC_sampling_rate]
  265.   div    ecx
  266.   mov    bx,0ffffh
  267.   sub    bx,ax
  268.   mov    bl,bh
  269.   push   ebx
  270.   mov    [word DAC_sampling_rate],22000
  271. @@done_set:
  272.   mov    al,40h                                        ;TIME_CONSTANT
  273.   call   SB_write_dac
  274.   pop    eax
  275.   call   SB_write_dac
  276.   mov    al,0D1h                                       ;SPEAKER_ON
  277.   call   SB_write_dac
  278.   cli
  279.   in     al,21h
  280.   mov    bl,1
  281.   mov    cl,[byte init_settings.IRQ_no]
  282.   shl    bl,cl
  283.   not    bl
  284.   and    al,bl
  285.   out    21h,al
  286.   call   SB_send_block_to_DMA
  287.   sti
  288.   ret
  289. endp
  290.  
  291. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  292. ;                                                                          ;
  293. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  294. proc SB_deinit
  295.   cli
  296.   cmp    [byte init_settings.card_type],1
  297.   jne    @@dont_reset
  298.   mov    ax,110eh                                      ;set for mono
  299.   call   SB_write_mixer
  300.   call   SB_detect
  301. @@dont_reset:
  302.   mov    al,0D0h                                       ;HALT_DMA
  303.   call   SB_write_dac
  304.   mov    bl,1
  305.   mov    cl,[byte init_settings.IRQ_no]
  306.   shl    bl,cl
  307.   in     al,21h
  308.   or     al,bl
  309.   out    21h,al
  310. ;  mov    bl,[byte init_settings.IRQ_no]
  311. ;  mov    edx,[dword DAC_old_irq_ofs]
  312. ;  mov    cx,[word DAC_old_irq_sel]
  313. ;  call   setirqvector
  314.   sti
  315.   ret
  316. endp
  317.  
  318. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  319. ;                                                                         ;
  320. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  321. start32:
  322.   call   debug
  323.   cld
  324.   call   SB_detect
  325.   or     al,al
  326.   jc     @@card_not_found
  327.  
  328.   mov    ax,3d00h
  329.   lea    edx,[sample_name]                          ; open
  330.   int    21h
  331.   jc     @@card_not_found
  332.   mov    [word file_handle_779],ax
  333.   mov    bx,ax
  334.  
  335.   mov    ah,3fh
  336.   mov    edx,offset file_buffer
  337.   mov    ecx,32000
  338.   int    21h
  339.  
  340.   mov    bx,[word file_handle_779]
  341.   mov    ah,3eh                                   ; close
  342.   int    21h
  343.  
  344.   call   SB_init
  345.  
  346.   mov    ax,10h
  347.   dosint 16h
  348.  
  349.   call   SB_deinit
  350. @@card_not_found:
  351.   mov    ax,4c00h
  352.   int    21h
  353.  
  354. ends
  355.  
  356. end
  357.