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