home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / FUNK108A.ZIP / DOS32V30.ZIP / EXAMPLES / GUSFILL.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-05-27  |  7.3 KB  |  276 lines

  1. ;**************************************************************************
  2. ;  EG7.ASM
  3. ;
  4. ;  This example program does sends some stuff to/from the GUS via DMA.
  5. ;  Please note that this program requires the GUS.ASM and DMA.ASM library
  6. ;
  7. ;
  8. ;
  9. ;   to compile;
  10. ;
  11. ;   tasm gusfill      or     ml /c gusfill.asm
  12. ;   dlink gusfill ..\lib\dma ..\lib\gus
  13. ;
  14. ;
  15. ; Written by Adam Seychell
  16. ;**************************************************************************
  17. .386
  18. .model  flat
  19. .stack 200h
  20.  
  21. include  macros.386
  22. include  dma.inc
  23. include  gus.inc
  24.  
  25.  
  26. GF1_clock               equ 617400
  27.  
  28. .DATA
  29.  
  30. DMA_buffer_phys         dD ?
  31. DMA_buffer_addr         dD ?
  32. DMA_DRAM_Address        dD ?
  33. GUS_MEMORY              dD ?
  34. DMAplay_Chan            dB ?
  35. DMASamp_Chan            dB ?
  36. DMAPlay_TC              dB ?
  37. IRQ                     dB ?
  38.  
  39.  
  40. .CODE
  41.  
  42. The_Start:        ;**************** ENTRY POINT OF THE PROGRAM ************
  43.  
  44.  
  45.  
  46. ;********* Allocate a 16KB DMA buffer  ***************
  47.         mov     ax,0EE41h
  48.         int     31h
  49.         jc  exit
  50.         mov     DMA_buffer_addr,edx
  51.         mov     DMA_buffer_phys,ebx
  52.  
  53.  
  54.  
  55.  
  56. ;********* Get the Default GUS settings from the "ULTRASND=" string *********
  57.  
  58.         Call    GetUltraConfig
  59.         jnc Got_EnvString
  60.             writeln 'Cannot find ''ULTRASND='' environment string or has invalid settings'
  61.             mov     ax,4C00h
  62.             int     21h
  63.  
  64. Got_EnvString:
  65.         mov     DMAplay_Chan,CL                     ; save DMA channels
  66.         mov     DMASamp_Chan,CH
  67.         mov     IRQ,BL
  68.  
  69.  
  70. ;************  Fully reset the Ultraosund *************************
  71.          call    Ultrasound_Reset           ; Expects DX=port
  72.          jnc  got_ultra
  73.             writeln 'Could not detect and Ultrasound on this computer '
  74.             mov     ax,4C00h
  75.             int     21h
  76. got_ultra:
  77.  
  78.                                             ; Save memory installed
  79.         mov     GUS_MEMORY,EDI
  80.  
  81.  
  82.         writeln  'Filling Ultrasound''s DRAM via DMA ( # = 16Kb ).'
  83.  
  84.  
  85.  
  86. ;************** Set the Ultrasounds IRQ vevctor *****************
  87.         mov     edx,offset GUS_ISR
  88.         mov     cx,cs                           ; CX:EDX = selectro:offset
  89.         mov     bl,IRQ                          ; Convert IRQ to interrupt
  90.         cmp     bl,8                            ; number
  91.         jb Jpic1
  92.         add     bl,60h
  93. Jpic1:  add     bl,8
  94.         mov     ax,0205h
  95.         int     31h
  96.  
  97.  
  98.  
  99.  
  100. ; ****** program the 8237 DMA contoller  *************
  101.         mov     al,01011000b             ; DMA mode register
  102.         mov     ah,DMAPlay_Chan          ; Channel number ( 0..7 )
  103.         mov     ecx,04000h               ; Bytes to transfer
  104.         mov     ebx,DMA_buffer_PHYS      ; Physical base address
  105.         call    DMA_setup                ; Do it ( see DMA.ASM )
  106.  
  107. ; Note: Mode reg bit 4 is set for DMA auto initalizing mode.
  108. ; This means that the Address and Count registers don't have to be
  109. ;reprogramed after the DMA has finished transfering.
  110.  
  111.  
  112.         mov     DMA_DRAM_Address,0
  113.  
  114.  
  115. FILL_GUS_LOOP:
  116.        ;********* Set the GUS's DMA DRAM staring address register *****
  117.  
  118.         mov     dx,GF1_Reg_select
  119.         mov     al,042h                       ; Set DMA Start Address
  120.         out     dx,al
  121.  
  122.         mov     eax,DMA_DRAM_address
  123.         test    DMAPlay_chan,100b
  124.         jz _8bitDMA
  125.            ; ---- do 16 bit DMA address translation ( see the SDK ) -----
  126.           mov     edi,eax
  127.           shr     eax,1
  128.           and     eax,01ffffh     ; zero out bit 17..19
  129.           and     edi,0c0000h     ; get bits 18 and 19
  130.           or      eax,edi
  131. _8bitDMA:
  132.         shr     eax,4
  133.         mov     dx,GF1_data_LOW
  134.         out     dx,ax                   ; Set the damn register
  135.  
  136.   ;********* Set the GF1 DMA Control Register  ****************
  137.  
  138.         mov     al,041h                ;Set DRAM  DMA Control Register
  139.         mov     dx,GF1_Reg_Select
  140.         out     dx,al
  141.  
  142.         mov     ah,DMAPlay_chan
  143.         and     ah,100b
  144.         mov     al,00100001b       ; Read, 650KB/s, 16bit data, 16/8bit DMA
  145.         or      al,ah
  146.         mov     dx,GF1_Data_HIGH
  147.         out     dx,al
  148.  
  149.  ; The DMA cycle will now start
  150.  
  151.  
  152.  
  153.  
  154.  
  155. ;********************** Wait around for the DMA to finish **************
  156.                    mov     ecx,500000h
  157. waitTC:            test    DMAPlay_TC,1
  158.                 loopz  waitTC
  159.                 jz   timoutERROR
  160.                 mov     DMAPlay_TC,0
  161.  
  162.  
  163.         mov     dl,'#'
  164.         mov     ah,2
  165.         int     21h
  166.  
  167.         add     DMA_DRAM_address,4000h
  168.         mov     eax,GUS_MEMORY
  169.         cmp     eax,DMA_DRAM_address
  170.         ja FILL_GUS_LOOP
  171.  
  172. ;************************* Stop DRAM  DMA cycle ********************
  173.         mov     al,041h                ; Set DRAM DMA Control Register
  174.         Mov     dx,GF1_reg_select
  175.         out     dx,al
  176.  
  177.         mov     dx,GF1_data_HIGH
  178.         mov     al,00000000b           ; stop IRQ's
  179.         out     dx,al
  180.  
  181.         writeln
  182.  
  183.  
  184. exit:
  185.  
  186. ; ****** program the 8237 DMA contollers  *************
  187.     ; Must turn of auto initalizing ????
  188.     ;   Sometimes my computer goes to about 1/8th of it's speed
  189.     ;   when if DMA auto initalizing bit is left on. Only a hardware reset
  190.     ;   will make it go back to normal.
  191.  
  192.         mov     al,00001000b             ; DMA mode register
  193.         mov     ah,DMAPlay_Chan          ; Channel number ( 0..7 )
  194.         call    DMA_setup
  195.  
  196. ; ****** Terminate Program  *************
  197.         mov     ax,4C00h
  198.         int     21h
  199.  
  200.  
  201.  
  202.  
  203. timoutERROR:
  204.         writeln 'ERROR:  got no IRQ form GUS'
  205.         jmp exit
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.    ;******************** Gravis ultrasound IRQ handler ********************
  214. GUS_ISR  PROC
  215.         push    ds                              ; Save all registers used
  216.         pushad
  217.  
  218.         mov     ax,_TEXT                        ; Load DS with data selector
  219.         mov     ds,ax
  220.  
  221.  ;
  222.  ; First determine if IRQ was form DMA Terminal Count or it was
  223.  ; from one of the Voices. Note: we should never get an IRQ from
  224.  ; a Voice since none of the GF1 voices registers have been programmed.
  225.  ; Only the DRAM DMA IRQ thingy has been programmed.
  226.  
  227.         mov     dx,GF1_IRQ_status
  228.         in      al,dx
  229.         test    al,10000000b             ; look for a DMA TC IRQ
  230.         jnz was_DMA_TC
  231.  
  232.      ;
  233.      ; Must read the IRQ source register to clear the FIFO interrupts
  234.      ;
  235.             mov     dx,GF1_REG_Select
  236.              mov     al,08fh
  237.              out     dx,al
  238.              mov     dx,GF1_DATA_High
  239.              in      al,dx
  240.              jmp  exit_ISR
  241.  
  242.  
  243.  
  244. was_DMA_TC:
  245.     ;
  246.     ;  Read DRAM DMA controll register to allow more DRAM DMA IRQs.
  247.     ;   Reading this register will clear the IRQ pending bit so
  248.     ;   another DRAM DMA IRQ can occurr.
  249.  
  250.         mov     dx,GF1_REG_Select
  251.         mov     al,041h             ; DRAM  DMA Control Register
  252.         out     dx,al
  253.         mov     dx,GF1_DATA_High    ; read
  254.         in      al,dx
  255.         or      DMAPlay_TC,1
  256.  
  257.  
  258. exit_ISR:
  259.         mov     al,020h                 ; EOI to both PICs (8259)
  260.         out     20h,al
  261.         out     0A0h,al
  262.         popad
  263.         pop     ds
  264.         iretd
  265.  
  266. GUS_ISR ENDP
  267. ;******************** End of Gravis ultrasound IRQ handler ******************
  268.  
  269.  
  270.  
  271.  
  272.  
  273.  
  274. END The_Start
  275.