home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / DIVERSEN / DOS32V3B / LIB / GUS.ASM < prev    next >
Assembly Source File  |  1995-03-08  |  27KB  |  770 lines

  1. ;--------------------------------------------------------------------------;
  2. ;    DOS32    32BIT  DOS  EXTENDER  LIBRARY  Gravis Ultrasound Routines    ;
  3. ;                                                                          ;
  4. ; Written by Adam Seychell                                                 ;
  5. ;                                                                          ;
  6. ;                                                                          ;
  7. ;  Last modified    3rd March 1995                                           ;
  8. ;                                                                          ;
  9. ;--------------------------------------------------------------------------;
  10. ; Note  The "GF1" is the Ultrasounds programable Synthesizer chip for the
  11. ;  32 multi-timbral digital 16bit CD quality voices with independed volume
  12. ;  ramping, panning.
  13. ;
  14. .386
  15. .Model flat
  16. .Code
  17.  
  18.  
  19. Include GUS.INC                       ; Define all the publics symbols
  20.  
  21.  
  22. outp    MACRO port,value
  23.         mov     al,value
  24.         mov     edx,dword ptr port
  25.         out     dx,al
  26. ENDM
  27.  
  28. FALSE    equ    0
  29. TRUE     equ     1
  30.  
  31.  
  32. ;╒═════════════════════════════════════════════════════════════════════════╕
  33. ;│           THE GRAVIS UILTRASOUND PORT ADDRESS VARIBLES                  │
  34. ;│                                                                         │
  35. ;│  These 12 data vaibles below contian the ultrasounds port addresses.    │
  36. ;│  See the SDK for what each port does. These varibles will be initalized │
  37. ;│  on the first successful call to the Ultrasound_Reset routine in this   │
  38. ;│  library.                                                               │
  39. ;│  * Do not use these port address varibles until they are initalized as  │
  40. ;│  otherwise they will contian wrong values.                              │
  41. ;└─────────────────────────────────────────────────────────────────────────┘
  42. align 4
  43.     The_Ultrasound_port_Addresses                               LABEL dword
  44. GF1_Voice_Select        dw  102h        ; GF1 Synthesizer
  45. GF1_REG_Select          dw  103h
  46. GF1_Data_Low            dw  104h
  47. GF1_Data_High           dw  105h
  48. GF1_IRQ_status          dw  006h
  49. GF1_DRAM                dw  107h
  50. GF1_TIMER_Ctrl          dw  008h
  51. GF1_TIMER_Data          dw  009h
  52. Midi_control            dw  100h        ; MIDI Interface
  53. Midi_Data               dw  101h
  54. Mix_control             dw  000h        ; BOARD CONTROL ONLY
  55. IRQDMA_Ctrl             dw  00Bh
  56. Ultrasound_ports_ends                                          LABEL dword
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. dma_reg_list            db  0,1,0,2,0,3,4,5
  65. irq_reg_list            db  0,0,1,3,0,2,0,4,0,0,0,5,6,0,0,7
  66. GUS_Base_port           dw  0h
  67. ULTRASND_string         db 'ULTRASND='
  68. GUSdetected_flag        db  False
  69.  
  70.  
  71. ;╒═════════════════════════════════════════════════════════════════════════╕
  72. ;│           GET THE DEFAULT SETTING OF THE GRAVIS UILTRASOUND             │
  73. ;│                                                                         │
  74. ;│                                                                         │
  75. ;│  Looks for the environment varible "ULTRASND" for the default settings  │
  76. ;│  of the Ultrasound.                                                     │
  77. ;│                                                                         │
  78. ;│   IN:  nothing                                                          │
  79. ;│                                                                         │
  80. ;│  OUT:   Carry is set if couldn't find environment or it has invalid     │
  81. ;│         settings.                                                       │
  82. ;│                                                                         │
  83. ;│         Otherwise the carry flag is cleared and;                        │
  84. ;│      BL = GF1  IRQ number  ( IRQ is either 0,2,3,5,7,11,12 or 15 )      │
  85. ;│      BH = MIDI IRQ number                                               │
  86. ;│      CL = DMA Playback channel  ( DMA is either 0,1,3,5,6 or 7 )        │
  87. ;│      CH = DMA Record channel                                            │
  88. ;│      DX = Port Address ( 210h,220h,230h,240h,250h or 260h )             │
  89. ;│                                                                         │
  90. ;└─────────────────────────────────────────────────────────────────────────┘
  91. GetUltraConfig PROC PASCAL USES EAX EDI
  92.  
  93. local   Base_port       :WORD
  94. local   dma_control     :BYTE
  95. local   irq_control     :BYTE
  96.  
  97.     ;
  98.     ; Search for the string "ULTRASND="  in the environment area
  99.     ;
  100.         Mov     Ax,0EE02h
  101.         Int     31h                             ; Returns EDI -> environment
  102.         cld
  103. Loop_Envir:
  104.         Mov     esi,Offset ULTRASND_string
  105.         mov     ecx,9
  106.         repe    cmpsb
  107.         je   Found_string
  108.         xor     al,al
  109.         repne   scasb
  110.         cmp     byte ptr [edi],0
  111.         jne  Loop_Envir
  112.         jmp  No_ULTRASND
  113.  
  114.  
  115. Found_string:                       ; EDI -> first char of string
  116.  
  117.  
  118.         mov     ebx,[edi]              ; OK, Found the string 'ULTRASND='
  119.         mov     eax,ebx                ; check for the valid paramters
  120.         and     ebx,0ffff00ffh
  121.         cmp     ebx,02C300032h         ; '2x0,'
  122.         jne  No_ULTRASND
  123.         shr     eax,8
  124.         call    get_digit               ; eax = char digit in al
  125.         mov     DX,ax                   ; load port address
  126.         shl     edx,4
  127.         add     dx,200h
  128.         sub     al,1h          ; port must be between  210h .. 260h
  129.         cmp     al,5h
  130.         ja  No_ULTRASND
  131.         add     edi,4
  132.  
  133.                         ;*****  Get playback DMA channel ****
  134.         xor     ecx,ecx
  135.         mov     al,[edi]
  136.         call    get_digit
  137.         cmp     dma_reg_list[eax],0
  138.         je  No_ULTRASND
  139.         mov     CL,AL
  140.         inc     edi
  141.         cmp     byte ptr [edi],','
  142.         jne  No_ULTRASND
  143.  
  144.                         ;*****  Get record DMA channel  ****
  145.         inc     edi
  146.         mov     al,[edi]
  147.         call    get_digit
  148.         cmp     dma_reg_list[eax],0
  149.         je  No_ULTRASND
  150.         mov     CH,AL
  151.         inc     edi
  152.         cmp     byte ptr [edi],','
  153.         jne  No_ULTRASND
  154.  
  155.                     ; **** Get IRQ numnber GF1 ****
  156.         xor     ebx,ebx
  157.         inc     edi
  158.         cmp     byte ptr [edi],'1'
  159.         jne J61
  160.           mov    BL,10
  161.           inc    edi
  162. J61:    mov     al,[edi]
  163.         call    get_digit
  164.         add     al,bl
  165.         cmp     al,15
  166.         ja  No_ULTRASND
  167.         cmp     IRQ_reg_list[eax],0         ; check for valid IRQ number
  168.         je  No_ULTRASND
  169.         mov     BL,AL
  170.         inc     edi
  171.         cmp     byte ptr [edi],','
  172.         jne  No_ULTRASND
  173.  
  174.                      ;  **** Get MIDI IRQ numnber *****
  175.  
  176.         inc     edi
  177.         cmp     byte ptr [edi],'1'
  178.         jne J62
  179.          mov    BH,10
  180.          inc    edi
  181. J62:     mov     al,[edi]
  182.         call    get_digit
  183.         add     al,bh
  184.         cmp     al,15
  185.         ja  No_ULTRASND
  186.         cmp     IRQ_reg_list[eax],0         ; check for valid IRQ number
  187.         je  No_ULTRASND
  188.         mov     BH,AL
  189.                                                 ;CHECK FOR STRING ENDING
  190.         inc     edi
  191.         cmp     byte ptr [edi],','
  192.         je got_it
  193.         cmp     byte ptr [edi],' '
  194.         je got_it
  195.         cmp     byte ptr [edi],0
  196.         jne  No_ULTRASND
  197.  
  198. got_it:
  199.         clc
  200.         ret
  201.  
  202.  
  203. No_ULTRASND:
  204.         stc
  205.         ret
  206.  
  207.  
  208. get_digit:
  209.         sub     al,'0'
  210.         jc No_digi
  211.         cmp     al,9
  212.         ja No_digi
  213.         movzx   eax,al
  214.         ret 0
  215. No_digi:
  216.         add     esp,4   ; ignore pushed EIP
  217.         stc
  218.         ret
  219.  
  220. GetUltraConfig ENDP
  221.  
  222.  
  223.  
  224.  
  225.  
  226. comment %
  227. ╒══════════════════════════════════════════════════════════════════════════╕
  228. │    COMPLETELY RESET THE GRAVIS ULTRASOUND                                │
  229. │                                                                          │
  230. │                                                                          │
  231. │ INPUT:                                                                   │
  232. │       BL = GF1  IRQ number  ( IRQ must be 0,2,3,5,7,11,12 or 15 )        │
  233. │       BH = MIDI IRQ number                                               │
  234. │       CL = DMA Playback channel  ( DMA must be 0,1,3,5,6 or 7 )          │
  235. │       CH = DMA Record channel                                            │
  236. │       DX = Base port address of the Ultrasound ( must be 2x0h )          │
  237. │                                                                          │
  238. │                                                                          │
  239. │ OUTPUT:                                                                  │
  240. │    The function will fail if an illeagal DMA or IRQ number is selected   │
  241. │    and/or if the card has was not detected at the specified bass address │
  242. │                                                                          │
  243. │      If function successful the carry is cleared and                     │
  244. │       the card is fully reset and all 32 voices are initalised           │
  245. │       EDI = DRAM installed on the ultrasound                             │
  246. │                                                                          │
  247. │ Other registers of the GF1 are set as follows                            │
  248. │        LINE OUT enabled                                                  │
  249. │        MIC  IN  disabled                                                 │
  250. │        LINE IN  disabled                                                 │
  251. │                                                                          │
  252. │NOTES:                                                                    │
  253. │     o    This routine will probe the ultrasound on port address DX       │
  254. │     o    This function should only need to be used once by your program. │
  255. │     o    Both PICs ( 8259's ) mask registers might be modified.          │
  256. │     o    If the IRQ number is ZERO then the Ultrasound is programmed     │
  257. │          with that IRQ disabled.                                         │
  258. │     o    If the DMA channel is ZERO then the Ultrasound is programmed    │
  259. │          with that DMA disabled.                                         │
  260. │     o    EDI will contain the amount of RAM ( in bytes ) installed on the│
  261. │           Ultrasound however it dos not do a complete RAM test. It will  │
  262. │           always return 0KB, 256KB ,512KB, 768KB or 1024KB.              │
  263. │                                                                          │
  264. └───────────────────────────────────────────────────────────────────────── %
  265. Ultrasound_Reset PROC  PASCAL Uses EAX EBX ECX EDX ESI
  266.  
  267. local   dma_control     :BYTE
  268. local   irq_control     :BYTE
  269. local   gf1             :Byte
  270. local   midi            :Byte
  271. local   dram            :Byte
  272. local   adci            :Byte
  273.  
  274.  
  275.         pushad
  276.  
  277.         cmp     GUSdetected_flag, TRUE         ; Don't detect if a GUS has
  278.         je @@skip_detection                    ; already been detected.
  279.  
  280.  
  281.      ;
  282.      ; check if DX = 2x0h.  where x = 1,2,3,4,5,,,F
  283.      ;
  284.         mov     eax,edx
  285.         and     ax,0F0Fh
  286.         cmp     ax,0200h
  287.         jne  invalid_setting
  288.         mov     al,dl
  289.         and     al,0F0h
  290.         jz  invalid_setting
  291.  
  292.         call    Ultrasound_probe          ; See if there's an ultrasound
  293.         jc  invalid_setting
  294.  
  295.  
  296. @@skip_detection:
  297.  
  298.         and     bx,0f0fh
  299.         and     cx,0707h
  300.         mov     GF1,bl              ; Save IRQ's
  301.         mov     midi,bh
  302.  
  303.      ;****   convert IRQ numbers into register value   *****
  304.                 movzx   edx,bl
  305.                 and     dl,dl
  306.                 jz  Zero_irq1
  307.                 mov     dl,irq_reg_list[edx]
  308.                 and     dl,dl
  309.                 jz  invalid_setting
  310. Zero_irq1:      mov     irq_control,dl
  311.  
  312.                 movzx   edx,bh
  313.                 and     dl,dl
  314.                 jz  Zero_irq2
  315.                 mov     dl,irq_reg_list[edx]
  316.                 and     dl,dl
  317.                 jz  invalid_setting
  318.                 shl     dl,3
  319. Zero_irq2:      or      irq_control,dl
  320.  
  321.                 cmp     bh,bl                        ; Chech if both IRQ
  322.                 jne diff_irqs                        ;   are equal then
  323.                 and     bl,bl                       ;( Except when zero)
  324.                 jz  diff_irqs
  325.                 and     irq_control,0111b            ; Clear Channel 2 IRQ
  326.                 or      irq_control,40h              ; and turn on bit 6
  327. diff_irqs:
  328.  
  329.      ;****   convert DMA number into register value   *****
  330.                 movzx   edx,cl
  331.                 and     dl,dl
  332.                 jz  Zero_dma2
  333.                 mov     dl,dma_reg_list[edx]
  334.                 and     dl,dl
  335.                 jz  invalid_setting
  336. Zero_dma1:      mov     dma_control,dl
  337.  
  338.                 movzx   edx,ch
  339.                 and     dl,dl
  340.                 jz  Zero_dma2
  341.                 mov     dl,dma_reg_list[edx]
  342.                 and     dl,dl
  343.                 jz  invalid_setting
  344.                 shl     dl,3
  345. Zero_dma2:      or      dma_control,dl
  346.  
  347.                 cmp     ch,cl                        ; Chech if both DMAs
  348.                 jne diff_dmas                        ;   are equal then
  349.                 and     cl,cl                       ;( Except when zero)
  350.                 jz  diff_irqs
  351.                 and     dma_control,0111b            ; Clear Channel 2 DMA
  352.                 or      dma_control,40h              ; and turn on bit 6.
  353. diff_dmas:
  354.  
  355.  
  356.  
  357.         cli                         ; must not be disterbed
  358.  
  359. ; The code below sets the DMA and IRQ  settings of the Ultrasound
  360. ;  It was sort of taken from the file RESET.C  of GUS SDK  V2.10
  361.  
  362.         mov     ecx,200h            ; delay a bit
  363.         loop $
  364.  
  365.  
  366. ;/* Set up for Digital ASIC */
  367.         mov    dx,GUS_base_port
  368.         add     dx,0fh
  369.         mov     al,5
  370.         out     dx,al           ; Seems to be a undocumented register
  371.  
  372.         outp    mix_control,00001011b
  373.         outp    IRQDMA_Ctrl,0
  374.  
  375.         mov     dx,GUS_base_port
  376.         add     dx,0fh
  377.         mov     al,0
  378.         out     dx,al
  379.  
  380. ;/* First do DMA control register */
  381.     outp        mix_control,00001011b
  382.     mov         dx,IRQDMA_Ctrl
  383.     mov         al,dma_control
  384.     or          al,80h
  385.     out         dx,al
  386.  
  387. ;/* IRQ CONTROL REG */
  388.     outp        mix_control,01001011b
  389.     outp        IRQDMA_Ctrl,irq_control
  390.  
  391. ;/* First do DMA control register */
  392.     outp        mix_control,00001011b
  393.     outp        IRQDMA_Ctrl,dma_control
  394.  
  395. ;/* IRQ CONTROL REG */
  396.     outp        mix_control,01001011b
  397.     outp        IRQDMA_Ctrl,irq_control
  398.  
  399. ;/* IRQ CONTROL, ENABLE IRQ */
  400. ;/* just to Lock out writes to irq\dma register ... */
  401.         outp    GF1_Voice_Select,0
  402.  
  403. ;/* enable output & irq, disable line & mic input */
  404.     outp        mix_control,0001001b
  405.  
  406. ;/* outp just to Lock out writes to irq\dma register ... */
  407.         outp    GF1_Voice_Select,0
  408.  
  409.  
  410.  
  411. ;
  412. ; Unmask the IRQ lines  for the GF1 and MIDI IRQ settings
  413. ;
  414.  ; NOTE: the pin labled IRQ 2 on the BUS connects to IRQ 9 of the PIC
  415.  ; controllers. The IRQ 2 on the PIC is used for slave.
  416.  ; The ultrasound SDK ( Software Development Kit ) says that the GUS can use
  417.  ; IRQ 2 this means you must actualy hook IRQ 9.
  418.  
  419.         in      al,0A1h
  420.         mov     ah,al
  421.         in      al,21h
  422.         mov     cl,GF1                 ; Get GF1 IRQ
  423.         cmp cl , 2                     ; gota put right IRQ 2
  424.         jne j3
  425.            mov cl,9
  426.     j3:
  427.         mov     ebx,1
  428.         shl     ebx,cl
  429.         not     ebx
  430.         and     eax,ebx
  431.         mov     cl,MIDI                ; Get MIDI IRQ
  432.         cmp cl , 2                     ; gota put right IRQ 2
  433.         jne j4
  434.            mov cl,9
  435.     j4:
  436.         mov     ebx,1
  437.         shl     ebx,cl
  438.         not     ebx
  439.         and     eax,ebx
  440.         out     021h,al
  441.         mov     al,ah
  442.         out     0A1h,al
  443.         sti
  444.  
  445.  
  446.    ;
  447.    ;   Get amount of RAM installed on the sound card (return into EDI)
  448.    ;
  449.         xor     edi,edi
  450. GetSizeloop:
  451.         mov     ecx,edi                           ; Set DRAM  I/O address
  452.         call    UltraSetDRAM_address
  453.         in      al,dx                           ; see if the DRAM locaion
  454.         mov     cl,al                           ; can store some data
  455.         not     al
  456.         out     dx,al
  457.         in      al,dx
  458.         cmp     al,cl
  459.         jz   NoDRAM
  460.         add     edi,40000h
  461.         cmp     edi,100000h                     ; the GF1 can only hold 1MB
  462.         jb  GetSizeloop
  463.  
  464. NoDRAM: add     edi,3ffffh                      ; align EDI on 256KB
  465.         and     edi,NOT 3ffffh
  466.  
  467.  
  468. ;*** Initalise the UltraSound  ****
  469.         call Ultrasound_Init
  470.  
  471.         clc
  472.         ret
  473.  
  474.  
  475. invalid_setting:                            ; jump here on error
  476.          stc
  477.          ret
  478.  
  479. ;=================== Ultrasound reseted ============================
  480. Ultrasound_Reset ENDP
  481.  
  482.  
  483. comment %
  484. ╒══════════════════════════════════════════════════════════════════════════╕
  485. │           INITALIZE  THE  ULTRASOUND'S  VOICES                           │
  486. │                                                                          │
  487. │                                                                          │
  488. │                                                                          │
  489. │   IN:  nothing                                                           │
  490. │                                                                          │
  491. │  OUT:   All 32 voices have initalized , cleared buffered IRQ's           │
  492. │        enables line out                                                  │
  493. │  Each of the 32 voices are set as follows                                │
  494. │                                                                          │
  495. │Frequency     = 0                                                         │
  496. │Voice stoped                                                              │
  497. │Bi-directional looping off                                                │
  498. │IRQs disabled                                                             │
  499. │Current Volume = 0                                                        │
  500. │Active Number of Voices = 14                                              │
  501. │                                                                          │
  502. │NOTE:                                                                     │
  503. │     o    This function will only be successful on a successful call      │
  504. │          to the "Ultrasound_Reset" routine                               │
  505. └──────────────────────────────────────────────────────────────────────────┘%
  506. Ultrasound_Init PROC PASCAL
  507.  
  508.          cmp     GUSdetected_flag, TRUE         ; do only if gus has
  509.          jc GUSok                               ; been previously detected
  510.          stc
  511.          ret
  512.  
  513. GUSok:
  514.         pushad
  515.  
  516. ;/* Pull a reset on the GF1 */
  517.         mov     al,04Ch
  518.         mov     cl,00000000b
  519.         call    Set_GF1_ByteRegister
  520.  
  521. ;/* Wait a little while ... */
  522.         mov     ecx,10
  523. J56:     call   GF1_delay
  524.         loop J56
  525.  
  526. ;/* Release Reset */
  527.        mov     al,04Ch
  528.         mov     cl,00000001b
  529.         call    Set_GF1_ByteRegister
  530.  
  531. ;/* Wait a little while ... */
  532.         mov     ecx,10
  533. J57:    call   GF1_delay
  534.        loop J57
  535.  
  536. ;/* Reset the MIDI port also */
  537.         mov     edx,dword ptr midi_control
  538.         mov     al,00000011b
  539.         out     dx,al
  540.  
  541.         mov     ecx,10
  542. J58:    call   GF1_delay
  543.         loop J58
  544.  
  545.         xor     al,al
  546.         out     dx,al
  547.  
  548. ;/* Clear all interrupts. */
  549.         mov     al,41h                  ;DRAM  DMA Control Register
  550.         mov     cl,0
  551.         call    Set_GF1_ByteRegister
  552.         mov     al,045h                   ;Timer  Control Register
  553.         mov     cl,00h
  554.         call    Set_GF1_ByteRegister
  555.         mov     al,049h                   ;Sampling  Control Register
  556.         mov     cl,00h
  557.         call    Set_GF1_ByteRegister
  558.  
  559.         mov     al,0Eh              ; set active voices to 32
  560.         mov     cl, 31 or 0C0h
  561.         call    Set_GF1_ByteRegister
  562.  
  563.  
  564. ;/* Clear interrupts on voices. */
  565. ;/* Reading the status ports will clear the irqs. */
  566.         mov     edx,dword ptr GF1_IRQ_status      ; Read
  567.         in      al,dx
  568.         mov     al,041h                       ;DRAM  DMA Control Register
  569.         call    read_GF1_ByteRegister
  570.         mov    al,049h                 ; Sampling  Control Register
  571.         call    read_GF1_ByteRegister
  572. ClrFIFO:mov     al,08Fh                 ;IRQ source Register
  573.         call    read_GF1_ByteRegister
  574.         and     al,11000000b
  575.         cmp     al,11000000b            ; keep on reading to clear IRQ's
  576.         jne ClrFIFO
  577.  
  578.  
  579.          mov    BL,0
  580.     stop_loop:
  581.                 outp    GF1_Voice_Select,BL  ; select voice to operate with
  582.                 mov     al,00h                   ; set Voice control
  583.                 mov     cl,00000010b               ; (Stoped voice )
  584.                 call    Set_GF1_ByteRegister
  585.                 mov     al,0Dh                 ; set Volume Ramp control
  586.                 mov     cl,00000010b                ; ( stoped ramping)
  587.             call    Set_GF1_ByteRegister
  588.                 mov     al,09h                   ; Current Volume fully off
  589.             xor     ecx,ecx
  590.             call    Set_GF1_WordRegister
  591.                 call   GF1_delay        ; /* Wait 4.8 micos. or more. */
  592.  
  593.         inc    bl
  594.         cmp    bl,32
  595.         jb stop_loop
  596.  
  597.  
  598.         mov     edx,dword ptr GF1_IRQ_status      ; Read
  599.         in      al,dx
  600.         mov     al,041h                  ;DRAM  DMA Control Register
  601.         call    read_GF1_ByteRegister
  602.         mov    al,049h                 ; Sampling  Control Register
  603.         call    read_GF1_ByteRegister
  604. Cl2FIFO:mov     al,08Fh                 ;IRQ source Register
  605.         call    read_GF1_ByteRegister
  606.         and     al,11000000b
  607.         cmp     al,11000000b            ; keep on reading to clear IRQ's
  608.         jne Cl2FIFO
  609.  
  610.         mov     al,0Eh              ; set active voices to 14 again
  611.         mov     cl, 13 or 0C0h
  612.         call    Set_GF1_ByteRegister
  613.  
  614.  
  615.         ;/* Set up GF1 Chip for interrupts & enable DACs. */
  616.         mov     al,04Ch
  617.         mov     cl,00000111b
  618.         call    Set_GF1_ByteRegister
  619.  
  620.         clc
  621.         popad
  622.         ret
  623. Ultrasound_Init ENDP
  624.  
  625.  
  626.  
  627.  
  628. ;--------------------- end of ultrasound services ----------------------
  629.  
  630.  
  631.  
  632. ; Some little procedures that are used by the Ultrasound services
  633. read_GF1_ByteRegister proc
  634.         mov     edx,dword ptr GF1_Reg_Select
  635.         out     dx,al
  636.         add     dl,2
  637.         in      al,dx
  638.         ret
  639. read_GF1_ByteRegister endp
  640.  
  641. Set_GF1_ByteRegister proc
  642.         mov     edx,dword ptr GF1_Reg_Select
  643.         out     dx,al
  644.         add     dl,2
  645.         mov     al,cl
  646.         out     dx,al
  647.         ret
  648. Set_GF1_ByteRegister endp
  649.  
  650. Set_GF1_WordRegister proc
  651.         mov     edx,dword ptr GF1_Reg_Select
  652.         out     dx,al
  653.         inc     dl
  654.         mov     eax,ecx
  655.         out     dx,ax
  656.         ret
  657. Set_GF1_WordRegister endp
  658.  
  659.  
  660.  
  661. ;/***************************************************************
  662. ; * This function is used as a 1.6*3 microsecond (or longer) delay.
  663. ; * This is needed when trying to change any of the 'self-modifying
  664. ; * bits in the voice registers.
  665. ; ***************************************************************/
  666. GF1_delay        PROC 
  667.         push    edx
  668.         mov     ah,7h
  669. J55:     mov     dx,GF1_DRAM        ; dummy port Read
  670.         in      al,dx
  671.         dec     ah
  672.         jnz  J55
  673.         pop     edx
  674.         ret
  675. GF1_delay ENDP
  676.  
  677. ;============================================================================
  678. ;
  679. ; Probe for an Ultrasound
  680. ;
  681. ; Expects      DX  = Ultrasound base port address
  682. ;
  683. ; Returns      Carry clear if detected a GUS at this port address
  684. ;               otherwise carry is set.
  685. ;
  686. ;============================================================================
  687. Ultrasound_Probe PROC PASCAL USES ECX EDX EAX
  688.  
  689.   cmp     GUSdetected_flag, TRUE         ; Don't detect if a GUS has aleady
  690.   je skip_detection                      ; been detected because some how
  691.                                          ; I don't think too many pople are
  692.                                          ; going to be unpluging thier GUS
  693.                                          ; half way through a game.
  694.  
  695.         mov     GUS_Base_Port,DX
  696.                                  ; Take the Ultrasound out of a reset state
  697.         add     dx,103h          ; because it's in a reset state at power up.
  698.         mov     al,04Ch
  699.         out     dx,al
  700.         add     dl,2
  701.         mov     al,00000111b
  702.         out     dx,al
  703.         mov     ecx,100h              ; delay a bit ????
  704.         loop $
  705.  
  706.  
  707.         xor      ecx,ecx                        ; Set location 0 to 055h
  708.         call    UltraSetDRAM_address
  709.         mov     al,055h
  710.         out     dx,al
  711.  
  712.         inc     ecx                             ; Set location 1 to 0AAh
  713.         call    UltraSetDRAM_address
  714.         mov     al,0AAh
  715.         out     dx,al
  716.  
  717.         xor      ecx,ecx                        ; Read  location 0 and
  718.         call     UltraSetDRAM_address           ; compare it to 055h.
  719.         in       al,dx
  720.         cmp      al,055h
  721.         jne No_GUS_Found_here
  722.         mov     GUSdetected_flag,True         ; Set the GUS detected flag
  723.    ;
  724.    ; OK, there is a GUS. Time to initalize the port address varibles.
  725.    ;
  726.               mov     ax,GUS_Base_Port
  727.             mov     ecx,offset The_Ultrasound_port_Addresses
  728. PAdrLoop:     add     [ecx],ax
  729.               add     ecx,2
  730.               cmp     ecx,offset Ultrasound_ports_ends
  731.               jb PAdrLoop
  732.  
  733. skip_detection:
  734.         clc
  735.         ret
  736.  
  737. No_GUS_Found_here:
  738.         stc
  739.         ret
  740.  
  741. Ultrasound_Probe ENDP
  742.  
  743. ;----------------------------------------------------------
  744. ; Procedure to set the DRAM I/O address of the Ultrasound
  745. ;
  746. ; Expects       ECX with address
  747. ;
  748. UltraSetDRAM_address PROC
  749.         mov     DX,GUS_Base_Port
  750.         add     dx,103h
  751.         mov     al,043h                 ; DRAM I/O reg  bits 0..15
  752.         out     dx,al
  753.         inc     dl
  754.         mov     eax,ecx
  755.         out     dx,ax
  756.         dec     dl
  757.         mov     al,044h                 ; DRAM I/O reg bits 16..19
  758.         out     dx,al
  759.         add     dl,2
  760.         shr     eax,16
  761.         out     dx,al
  762.         add     dl,2                    ; set DX to  DRAM port
  763.         ret
  764. UltraSetDRAM_address ENDP
  765.  
  766.  
  767.  
  768. ;********************* END OF THE ULTRASOUND ROUTINES *********************
  769. END
  770.