home *** CD-ROM | disk | FTP | other *** search
/ The Equalizer BBS / equalizer-bbs-collection_2004.zip / equalizer-bbs-collection / DEMOSCENE-STUFF / TIMESRC.ZIP / LOW_GUS.ASM < prev    next >
Assembly Source File  |  1994-02-24  |  16KB  |  616 lines

  1. ; Low level Gravis Ultrasound interface by Tran (a.k.a. Thomas Pytel)
  2.  
  3.         .386p
  4. code32  segment para public use32
  5.         assume cs:code32, ds:code32
  6.  
  7. include pmode.inc
  8. include low_data.inc
  9.  
  10. public  _gus_data
  11.  
  12. public  voltbl          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13.  
  14. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  15. ; DATA
  16. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  17. align 4
  18. aclbeg          dd      32 dup(?)       ; actual channel loop begin          |
  19. aclend          dd      32 dup(?)       ; actual channel loop end            |
  20. acfreq          dw      32 dup(?)       ; actual channel frequency value     |
  21. acpan           db      32 dup(?)       ; actual channel pan position        |
  22. acvol           db      32 dup(?)       ; actual channel volume (high byte)  |
  23.  
  24. vcacoff         db      16 dup(0)       ; virtual channel offset in actual
  25.  
  26. ormgusirqvect   dd      ?               ; old real mode GF1 IRQ vector
  27.  
  28. freqfactor      dw      ?, 0            ; frequency calculation factor
  29.  
  30. gusport102      dw      ?               ; GUS port + 102h
  31. gusport103      dw      ?               ; GUS port + 103h
  32. gusport104      dw      ?               ; GUS port + 104h
  33. gusport107      dw      ?               ; GUS port + 107h
  34.  
  35. rmgusirqbuf     db      21 dup(?)       ; buffer for rm GF1 IRQ callback code
  36.  
  37. port103val      db      43h             ; value to set on exit from IRQ
  38. irqm0tbl        dw      0c089h,0a0e6h   ; opcodes for IRQ levels (0-7,8-15)
  39. gusirqvaltbl    db      0,0,41h,43h,0,42h,0,44h,0,0,0,45h,46h,0,0,47h
  40. voltbl          db      004h,0a0h,0b0h,0c0h,0c8h,0d0h,0d8h,0e0h
  41.                 db      0e4h,0e8h,0ech,0f0h,0f2h,0f4h,0f6h,0f8h
  42. freqfactortbl   dw      44100,38587,34300,30870,28063,25725,23746,22050
  43.                 dw      20580,19293
  44.  
  45. align 4
  46. _gus_data       dd      _gus_init, _gus_uninit, _gus_set_bps, _ret
  47.                 dd      _gus_set_voices, _gus_get_freq, _gus_put_data
  48.                 dd      _gus_get_data, _ret
  49.                 db      00000111b       ; info bitmap
  50.                                         ;  bit 0: 0=system RAM, 1=card RAM
  51.                                         ;  bit 1: port needed
  52.                                         ;  bit 2: IRQ number needed
  53.                                         ;  bit 3: DMA number needed
  54.                                         ;  bit 4: Mixing rate selectable
  55.                 db      'Gravis Ultrasound',0,'$'
  56.  
  57. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  58. ; CODE
  59. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  60.  
  61. ;-----------------------------------------------------------------------------
  62. @gusoutb        macro   index,value
  63.         mov al,&index
  64.         out dx,al
  65.         add dl,2
  66.         mov al,&value
  67.         out dx,al
  68.         sub dl,2
  69. endm
  70.  
  71. @gusoutw        macro   index,value
  72.         mov al,&index
  73.         out dx,al
  74.         inc edx
  75.         mov ax,&value
  76.         out dx,ax
  77.         dec edx
  78. endm
  79.  
  80. ;═════════════════════════════════════════════════════════════════════════════
  81. ; GUS timer IRQ entry
  82. irq:
  83.         push eax
  84.         mov al,20h
  85.         out 20h,al
  86. irqm0           dw      ?       ; out 0a0h,al | mov eax,eax
  87.         sti
  88.         cld
  89.         push ebx ecx edx esi edi ebp ds
  90.         mov ds,cs:_seldata
  91.         mov dx,gusport103               ; reenable GUS timer
  92.         @outb 45h
  93.         add dl,2
  94.         @outb 0
  95.         @outb 8
  96.  
  97.         call _low_rout
  98.  
  99. ;-----------------------------------------------------------------------------
  100.         mov dx,gusport103
  101.         mov ebp,15
  102. irql0:
  103.         xor cl,cl
  104.         xchg cl,_low_vccmnd[ebp]
  105.         or cl,cl
  106.         jz irql0c
  107.  
  108.         movzx edi,vcacoff[ebp]
  109.         lea edi,[ebp*2+edi]
  110.  
  111.         test cl,8
  112.         jz short irql0f0
  113.         xor vcacoff[ebp],1
  114.         mov eax,edi
  115.         dec edx
  116.         out dx,al
  117.         inc edx
  118.         mov bl,acvol[edi]
  119.         @gusoutb 7,4
  120.         @gusoutb 8,bl
  121.         @gusoutb 9,bl
  122.         @gusoutb 0dh,40h
  123.         xor edi,1
  124.         or cl,7
  125. irql0f0:
  126.  
  127.         mov eax,edi
  128.         dec edx
  129.         out dx,al
  130.         inc edx
  131.  
  132.         test cl,4
  133.         jz short irql0f1
  134.         mov bx,_low_vcfreq[ebp*2]
  135.         cmp bx,acfreq[edi*2]
  136.         je short irql0f1
  137.         mov acfreq[edi*2],bx
  138.         @gusoutw 1,bx
  139. irql0f1:
  140.  
  141.         test cl,2
  142.         jz short irql0f2
  143.         mov bl,_low_vcpan[ebp]
  144.         cmp bl,acpan[edi]
  145.         je short irql0f2
  146.         mov acpan[edi],bl
  147.         @gusoutb 0ch,bl
  148. irql0f2:
  149.  
  150.         test cl,8
  151.         jz irql0f3
  152.         mov esi,_low_vclbeg[ebp*4]
  153.         cmp esi,aclbeg[edi*4]
  154.         je short irql0f2f0
  155.         mov aclbeg[edi*4],esi
  156.         shrd bx,si,7
  157.         shr esi,7
  158.         @gusoutw 2,si
  159.         @gusoutb 3,bh
  160. irql0f2f0:
  161.         mov esi,_low_vclend[ebp*4]
  162.         cmp esi,aclend[edi*4]
  163.         je short irql0f2f1
  164.         mov aclend[edi*4],esi
  165.         shrd bx,si,7
  166.         shr esi,7
  167.         @gusoutw 4,si
  168.         @gusoutb 5,bh
  169. irql0f2f1:
  170.         mov esi,_low_vcsbeg[ebp*4]
  171.         shrd bx,si,7
  172.         shr esi,7
  173.         @gusoutw 0ah,si
  174.         @gusoutb 0bh,bh
  175.         @gusoutb 0,_low_vccntrl[ebp]
  176. irql0f3:
  177.  
  178.         test cl,1
  179.         jz short irql0f4
  180.         movzx esi,_low_vcvol[ebp]
  181.         shr esi,4
  182.         mov bl,voltbl[esi]
  183.         mov bh,acvol[edi]
  184.         mov ah,bh
  185.         cmp bh,bl
  186.         je short irql0f4
  187.         mov ch,40h
  188.         ja short irql0f3f0
  189.         xchg bl,bh
  190.         xor ch,ch
  191. irql0f3f0:
  192.         @gusoutb 7,bl
  193.         @gusoutb 8,bh
  194.         @gusoutb 9,ah
  195.         @gusoutb 0dh,ch
  196. irql0f4:
  197.  
  198.         mov dx,300h
  199.         db 7 dup(0ech)          ; in al,dx
  200.         mov dx,gusport103
  201.  
  202.         test cl,1
  203.         jz short irql0f5
  204.         movzx esi,_low_vcvol[ebp]
  205.         shr esi,4
  206.         mov al,voltbl[esi]
  207.         cmp al,ah
  208.         je short irql0f5
  209.         mov acvol[edi],al
  210.         @gusoutb 9,ah
  211.         @gusoutb 0dh,ch
  212. irql0f5:
  213.  
  214.         test cl,8
  215.         jz short irql0c
  216.         mov esi,_low_vcsbeg[ebp*4]
  217.         shrd bx,si,7
  218.         shr esi,7
  219.         @gusoutw 0ah,si
  220.         @gusoutb 0bh,bh
  221.         @gusoutb 0,_low_vccntrl[ebp]
  222.         xor edi,1
  223.         mov eax,edi
  224.         dec edx
  225.         out dx,al
  226.         inc edx
  227.         mov bl,4
  228.         xchg bl,acvol[edi]
  229.         @gusoutb 9,bl
  230.         @gusoutb 0dh,40h
  231.  
  232. irql0c:
  233.         sub ebp,1
  234.         jnc irql0
  235.  
  236.         @outb port103val
  237.  
  238. ;─────────────────────────────────────────────────────────────────────────────
  239. irqdone:
  240.         pop ds ebp edi esi edx ecx ebx eax
  241.         iretd
  242.  
  243. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  244. ; Initialize low level GUS system
  245. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  246. _gus_init:
  247.         pushad
  248.         mov ax,900h
  249.         int 31h
  250.         push ax
  251.  
  252.         mov dx,_low_port                ; set up all port vars
  253.         @outb 0bh
  254.         add dx,102h
  255.         mov gusport102,dx
  256.         inc edx
  257.         mov gusport103,dx
  258.         inc edx
  259.         mov gusport104,dx
  260.         add dl,3
  261.         mov gusport107,dx
  262.  
  263.         sub dl,4                        ; initialize GUS at full voices
  264.         @outb 4ch
  265.         add dl,2
  266.         @outb 0
  267.         mov ecx,10h
  268.         call initr0
  269.         @outb 1
  270.         sub dl,2
  271.         mov ecx,10h
  272.         call initr0
  273.         @gusoutb 41h,0
  274.         @gusoutb 45h,0
  275.         @gusoutb 49h,0
  276.         @outb 0eh
  277.         add dl,2
  278.         @outb 0dfh
  279.         sub dl,3
  280.  
  281.         mov bl,1fh                      ; set up all voices
  282. initl0:
  283.         mov al,bl
  284.         and al,7fh
  285.         out dx,al
  286.         inc edx
  287.         @gusoutw 9,0
  288.         @gusoutb 0,0
  289.         @gusoutb 0dh,3
  290.         @gusoutb 6,16
  291.         @outb 0ch
  292.         add dl,2
  293.         @outb 7
  294.         sub dl,3
  295.         mov ecx,1
  296.         call initr0
  297.         xor bl,80h
  298.         js initl0
  299.         sub bl,1
  300.         jnc initl0
  301.  
  302.         sub dx,0f3h                     ; damn, another undocumented port
  303.         @outb 5
  304.         sub dl,0fh
  305.         @outb 8
  306.         add dl,0bh
  307.         xor al,al
  308.         out dx,al
  309.         add dl,4
  310.         out dx,al
  311.         sub dl,0fh
  312.  
  313.         movzx ebx,_low_irq              ; set IRQ channels
  314.         @outb 4bh
  315.         add dl,0bh
  316.         mov al,gusirqvaltbl[ebx]
  317.         out dx,al
  318.         sub dl,0bh
  319.         @outb 9
  320.         add dx,103h
  321.  
  322.         @outb 43h                       ; how much RAM on the card
  323.         inc edx
  324.         @outw 0ffffh
  325.         dec edx
  326.         @outb 44h
  327.         add dl,2
  328.         xor esi,esi
  329.         mov cl,3
  330. initl1:
  331.         @outb cl
  332.         add dl,2
  333.         in al,dx
  334.         inc eax
  335.         mov ah,al
  336.         out dx,al
  337.         in al,dx
  338.         sub dl,2
  339.         cmp al,ah
  340.         jne short initl1d
  341.         add esi,40000h
  342.         add cl,4
  343.         test cl,10h
  344.         jz initl1
  345. initl1d:
  346.         mov _low_ram,esi
  347.         sub dl,2
  348.  
  349.         mov edi,offset aclbeg           ; set some beginning values
  350.         mov ecx,80
  351.         mov eax,0ffffffffh
  352.         rep stosd
  353.         mov eax,7070707h
  354.         mov cl,8
  355.         rep stosd
  356.         xor eax,eax
  357.         mov cl,8
  358.         rep stosd
  359.  
  360.         @gusoutb 4ch,3                  ; enable GUS normal operation
  361.  
  362.         @gusoutb 47h,0cch               ; start GUS timer at 60Hz
  363.         @outb 45h
  364.         add dl,2
  365.         @outb 8
  366.         sub dx,0fdh
  367.         @outb 4
  368.         inc edx
  369.         @outb 2
  370.  
  371.         cmp bl,2                        ; set and enable GF1 IRQ (BL=IRQ num)
  372.         jne short $+4
  373.         mov bl,9
  374.         cmp bl,7
  375.         seta al
  376.         movzx eax,al
  377.         mov ax,irqm0tbl[eax*2]
  378.         mov irqm0,ax
  379.         mov edx,offset irq
  380.         call _setirqvect
  381.         mov edi,offset rmgusirqbuf
  382.         call _rmpmirqset
  383.         mov ormgusirqvect,eax
  384.         xor al,al
  385.         call _setirqmask
  386.  
  387.         xor eax,eax                     ; initial clicks here, not at muz beg
  388.         mov _low_buf,eax
  389.         mov _low_rambase,eax
  390.         mov dword ptr _low_vcvol[0],eax
  391.         mov dword ptr _low_vcvol[4],eax
  392.         mov dword ptr _low_vcvol[8],eax
  393.         mov dword ptr _low_vcvol[12],eax
  394.         mov dword ptr _low_vccntrl[0],eax
  395.         mov dword ptr _low_vccntrl[4],eax
  396.         mov dword ptr _low_vccntrl[8],eax
  397.         mov dword ptr _low_vccntrl[12],eax
  398.         mov edi,offset _low_vcsbeg
  399.         mov ecx,32
  400.         rep stosd
  401.         mov ah,1
  402.         mov ecx,24
  403.         rep stosd
  404.         mov eax,7070707h
  405.         rep stosd
  406.         mov eax,8080808h
  407.         mov dword ptr _low_vccmnd[0],eax
  408.         mov dword ptr _low_vccmnd[4],eax
  409.         mov dword ptr _low_vccmnd[8],eax
  410.         mov dword ptr _low_vccmnd[12],eax
  411.  
  412.         pop ax
  413.         int 31h
  414.         popad
  415.         ret
  416.  
  417. ;-----------------------------------------------------------------------------
  418. initr0:
  419.         push ax dx
  420.         mov dx,300h
  421. initr0l0:
  422.         in al,dx
  423.         in al,dx
  424.         in al,dx
  425.         in al,dx
  426.         in al,dx
  427.         in al,dx
  428.         in al,dx
  429.         loop initr0l0
  430.         pop dx ax
  431.         ret
  432.  
  433. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  434. ; Uninitialize low level GUS system
  435. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  436. _gus_uninit:
  437.         push eax ebx edx
  438.         mov ax,900h
  439.         int 31h
  440.         push ax
  441.  
  442.         mov bl,_low_irq
  443.         cmp bl,2
  444.         jne short $+4
  445.         mov bl,9
  446.         mov eax,ormgusirqvect
  447.         call _rmpmirqfree
  448.         mov al,1
  449.         call _setirqmask
  450.  
  451.         mov dx,gusport103
  452.         @outb 4ch
  453.         add dl,2
  454.         @outb 0
  455.         sub dx,105h
  456.         @outb 0bh
  457.  
  458.         pop ax
  459.         int 31h
  460.         pop edx ebx eax
  461.         ret
  462.  
  463. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  464. ; Set beats per second
  465. ; In:
  466. ;   AL - beats per second (15-255)
  467. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  468. _gus_set_bps:
  469.         push ax bx dx
  470.         movzx bx,al
  471.         mov ax,900h
  472.         int 31h
  473.         push ax
  474.  
  475.         xor dx,dx
  476.         mov ax,3125
  477.         div bx
  478.         mov bl,al
  479.         neg bl
  480.         mov dx,gusport103
  481.         @gusoutb 47h,bl
  482.  
  483.         pop ax
  484.         int 31h
  485.         pop dx bx ax
  486.         ret
  487.  
  488. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  489. ; Set number of active voices
  490. ; In:
  491. ;   AL - number of voices (1-16)
  492. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  493. _gus_set_voices:
  494.         push ax edx
  495.         movzx edx,al
  496.         mov ax,900h
  497.         int 31h
  498.         push ax
  499.  
  500.         cmp dl,7
  501.         jae short $+4
  502.         mov dl,7
  503.         shl dl,1
  504.         mov ax,freqfactortbl[edx-14]
  505.         mov freqfactor,ax
  506.         dec edx
  507.         mov ah,dl
  508.         mov dx,gusport103
  509.         @outb 0eh
  510.         add dl,2
  511.         or ah,0c0h
  512.         @outb ah
  513.  
  514.         pop ax
  515.         int 31h
  516.         pop edx ax
  517.         ret
  518.  
  519. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  520. ; Convert actual frequency to GUS frequency number
  521. ; In:
  522. ;   EAX - frequency
  523. ; Out:
  524. ;   AX - GUS frequency number
  525. ;   EAX high word - ?
  526. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  527. _gus_get_freq:
  528.         push edx
  529.         xor edx,edx
  530.         shl eax,10
  531.         div dword ptr freqfactor
  532.         pop edx
  533.         ret
  534.  
  535. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  536. ; Put sample data into GUS ram
  537. ; In:
  538. ;   EBX - addx in GUS ram to put to
  539. ;   ECX - length in bytes to put
  540. ;   EDX -> sample data to put
  541. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  542. _gus_put_data:
  543.         push eax ebx ecx dx esi
  544.         mov esi,edx
  545.         mov dx,gusport104
  546. putdatal0:
  547.         dec edx
  548.         mov al,44h
  549.         mov port103val,al
  550.         out dx,al
  551.         add dl,2
  552.         shld eax,ebx,16
  553.         out dx,al
  554.         sub dl,2
  555.         mov al,43h
  556.         mov port103val,al
  557.         out dx,al
  558.         inc edx
  559. putdatal1:
  560.         mov ax,bx
  561.         out dx,ax
  562.         add dl,3
  563.         outsb
  564.         sub dl,3
  565.         inc bx
  566.         loopnz putdatal1
  567.         jecxz short putdatad
  568.         add ebx,10000h
  569.         jmp putdatal0
  570. putdatad:
  571.         pop esi dx ecx ebx eax
  572.         ret
  573.  
  574. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  575. ; Get sample data from GUS ram
  576. ; In:
  577. ;   EBX - addx in GUS ram to get from
  578. ;   ECX - length in bytes to get
  579. ;   EDX -> buffer for sample data
  580. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  581. _gus_get_data:
  582.         push eax ebx ecx dx edi
  583.         mov edi,edx
  584.         mov dx,gusport104
  585. getdatal0:
  586.         dec edx
  587.         mov al,44h
  588.         mov port103val,al
  589.         out dx,al
  590.         add dl,2
  591.         shld eax,ebx,16
  592.         out dx,al
  593.         sub dl,2
  594.         mov al,43h
  595.         mov port103val,al
  596.         out dx,al
  597.         inc edx
  598. getdatal1:
  599.         mov ax,bx
  600.         out dx,ax
  601.         add dl,3
  602.         insb
  603.         sub dl,3
  604.         inc bx
  605.         loopnz getdatal1
  606.         jecxz short getdatad
  607.         add ebx,10000h
  608.         jmp getdatal0
  609. getdatad:
  610.         pop edi dx ecx ebx eax
  611.         ret
  612.  
  613. code32  ends
  614.         end
  615.  
  616.