home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / hellsrc.zip / GS.ASM < prev    next >
Assembly Source File  |  1993-09-29  |  19KB  |  716 lines

  1. ; GUS lowlevel interface.
  2.  
  3.         .386p
  4. code32  segment para public use32
  5.         assume cs:code32, ds:code32
  6.  
  7. include pmode.inc
  8.  
  9. public  _gusrout, _gusport, _gusirq, _gusram
  10. public  _vccmnd, _vccntrl, _vcsbeg, _vclbeg, _vclend, _vcfreq, _vcpan, _vcvol
  11. public  _gustimerfreq, _gusnumvoices
  12.  
  13. public  _gs_init, _gs_uninit, _gs_putram, _gs_getram
  14.  
  15. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  16. ; DATA
  17. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  18. align 4
  19. EXTRACRAP       = 1                     ; 0=no extras, 1=yes extras
  20.  
  21. aclbeg          dd      32 dup(?)       ; actual channel loop begin          |
  22. aclend          dd      32 dup(?)       ; actual channel loop end            |
  23. acfreq          dw      32 dup(?)       ; actual channel frequency value     |
  24. acpan           db      32 dup(?)       ; actual channel pan position        |
  25. acvol           db      32 dup(?)       ; actual channel volume (high byte)  |
  26.                                         ;                                    |
  27. _vccmnd         db      16 dup(?)       ; virtual channel command bits       |
  28.                                         ;  bit 0: volume change
  29.                                         ;  bit 1: balance change
  30.                                         ;  bit 2: frequency change
  31.                                         ;  bit 3: sample note-on
  32. _vccntrl        db      16 dup(?)       ; virtual channel voice control
  33.                                         ;  bit 3: enable loop
  34.                                         ;  bit 4: bi-directional loop
  35.                                         ;  bit 6: 0=forward, 1=reverse
  36. _vcsbeg         dd      16 dup(?)       ; virtual channel sample begin
  37. _vclbeg         dd      16 dup(?)       ; virtual channel loop begin
  38. _vclend         dd      16 dup(?)       ; virtual channel loop end
  39. _vcfreq         dw      16 dup(?)       ; virtual channel frequency value
  40. _vcpan          db      16 dup(?)       ; virtual channel pan position
  41. _vcvol          db      16 dup(?)       ; virtual channel volume (high byte)
  42.  
  43. vcacoff         db      16 dup(0)       ; virtual channel offset in actual
  44.  
  45. ormgusirqvect   dd      ?               ; old real mode GF1 IRQ vector
  46.  
  47. gusport102      dw      ?               ; GUS port + 102h
  48. gusport103      dw      ?               ; GUS port + 103h
  49. gusport104      dw      ?               ; GUS port + 104h
  50. gusport107      dw      ?               ; GUS port + 107h
  51.  
  52. _gusrout        dd      _ret            ; routine to call on every timer tick
  53. _gusport        dw      220h
  54. _gusirq         db      11
  55. _gusram         db      0               ; 1=256k, 2=512k, 3=768k, 4=1024k
  56. _gustimerfreq   db      0cch            ; =256-((1000000/Hz)/320)
  57. _gusnumvoices   db      0dfh            ; =((Voices*2)-1)|0xc0
  58.  
  59. rmgusirqbuf     db      21 dup(?)       ; buffer for rm GF1 IRQ callback code
  60.  
  61. port103val      db      43h             ; value to set on exit from IRQ
  62. irqm0tbl        dw      0c089h,0a0e6h
  63. gusirqvaltbl    db      0,0,41h,43h,0,42h,0,44h,0,0,0,45h,46h,0,0,47h
  64. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  65. ; CODE
  66. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  67.  
  68. ;-----------------------------------------------------------------------------
  69. @gusoutb        macro   index,value
  70.         mov al,&index
  71.         out dx,al
  72.         add dl,2
  73.         mov al,&value
  74.         out dx,al
  75.         sub dl,2
  76. endm
  77.  
  78. @gusoutw        macro   index,value
  79.         mov al,&index
  80.         out dx,al
  81.         inc edx
  82.         mov ax,&value
  83.         out dx,ax
  84.         dec edx
  85. endm
  86.  
  87. ;═════════════════════════════════════════════════════════════════════════════
  88. ; GUS timer IRQ entry
  89. irq:
  90.         push eax
  91.         mov al,20h
  92.         out 20h,al
  93. irqm0           dw      ?       ; out 0a0h,al | mov eax,eax
  94.         sti
  95.         cld
  96.         push ebx ecx edx esi edi ebp ds
  97.         mov ds,cs:_seldata
  98.         mov dx,gusport103               ; reenable GUS timer
  99.         @outb 45h
  100.         add dl,2
  101.         @outb 0
  102.         @outb 8
  103.  
  104.         call _gusrout
  105.  
  106. ;-----------------------------------------------------------------------------
  107.         mov dx,gusport103
  108.         mov ebp,15
  109. irql0:
  110.         xor cl,cl
  111.         xchg cl,_vccmnd[ebp]
  112.         or cl,cl
  113.         jz irql0c
  114.  
  115.         movzx edi,vcacoff[ebp]
  116.         lea edi,[ebp*2+edi]
  117.  
  118.         test cl,8
  119.         jz short irql0f0
  120.         xor vcacoff[ebp],1
  121.         mov eax,edi
  122.         dec edx
  123.         out dx,al
  124.         inc edx
  125.         mov bl,acvol[edi]
  126.         @gusoutb 7,4
  127.         @gusoutb 8,bl
  128.         @gusoutb 9,bl
  129.         @gusoutb 0dh,40h
  130.         xor edi,1
  131.         or cl,7
  132. irql0f0:
  133.  
  134.         mov eax,edi
  135.         dec edx
  136.         out dx,al
  137.         inc edx
  138.  
  139.         test cl,4
  140.         jz short irql0f1
  141.         mov bx,_vcfreq[ebp*2]
  142.         cmp bx,acfreq[edi*2]
  143.         je short irql0f1
  144.         mov acfreq[edi*2],bx
  145.         @gusoutw 1,bx
  146. irql0f1:
  147.  
  148.         test cl,2
  149.         jz short irql0f2
  150.         mov bl,_vcpan[ebp]
  151.         cmp bl,acpan[edi]
  152.         je short irql0f2
  153.         mov acpan[edi],bl
  154.         @gusoutb 0ch,bl
  155. irql0f2:
  156.  
  157.         test cl,8
  158.         jz irql0f3
  159.         mov esi,_vclbeg[ebp*4]
  160.         cmp esi,aclbeg[edi*4]
  161.         je short irql0f2f0
  162.         mov aclbeg[edi*4],esi
  163.         shrd bx,si,7
  164.         shr esi,7
  165.         @gusoutw 2,si
  166.         @gusoutb 3,bh
  167. irql0f2f0:
  168.         mov esi,_vclend[ebp*4]
  169.         cmp esi,aclend[edi*4]
  170.         je short irql0f2f1
  171.         mov aclend[edi*4],esi
  172.         shrd bx,si,7
  173.         shr esi,7
  174.         @gusoutw 4,si
  175.         @gusoutb 5,bh
  176. irql0f2f1:
  177.         mov esi,_vcsbeg[ebp*4]
  178.         shrd bx,si,7
  179.         shr esi,7
  180.         @gusoutw 0ah,si
  181.         @gusoutb 0bh,bh
  182.         @gusoutb 0,_vccntrl[ebp]
  183. irql0f3:
  184.  
  185.         test cl,1
  186.         jz short irql0f4
  187.         mov bl,_vcvol[ebp]
  188.         mov bh,acvol[edi]
  189.         mov ah,bh
  190.         cmp bh,bl
  191.         je short irql0f4
  192.         mov ch,40h
  193.         ja short irql0f3f0
  194.         xchg bl,bh
  195.         xor ch,ch
  196. irql0f3f0:
  197.         @gusoutb 7,bl
  198.         @gusoutb 8,bh
  199.         @gusoutb 9,ah
  200.         @gusoutb 0dh,ch
  201. irql0f4:
  202.  
  203.         mov dx,300h
  204.         db 7 dup(0ech)          ; in al,dx
  205.         mov dx,gusport103
  206.  
  207.         test cl,1
  208.         jz short irql0f5
  209.         mov al,_vcvol[ebp]
  210.         cmp al,ah
  211.         je short irql0f5
  212.         mov acvol[edi],al
  213.         @gusoutb 9,ah
  214.         @gusoutb 0dh,ch
  215. irql0f5:
  216.  
  217.         test cl,8
  218.         jz short irql0c
  219.         mov esi,_vcsbeg[ebp*4]
  220.         shrd bx,si,7
  221.         shr esi,7
  222.         @gusoutw 0ah,si
  223.         @gusoutb 0bh,bh
  224.         @gusoutb 0,_vccntrl[ebp]
  225.         xor edi,1
  226.         mov eax,edi
  227.         dec edx
  228.         out dx,al
  229.         inc edx
  230.         mov bl,4
  231.         xchg bl,acvol[edi]
  232.         @gusoutb 9,bl
  233.         @gusoutb 0dh,40h
  234.  
  235. irql0c:
  236.         sub ebp,1
  237.         jnc irql0
  238.  
  239.         @outb port103val
  240.  
  241. ;─────────────────────────────────────────────────────────────────────────────
  242. irqdone:
  243.         pop ds ebp edi esi edx ecx ebx eax
  244.         iretd
  245.  
  246. ;─────────────────────────────────────────────────────────────────────────────
  247. ; A small delay, In: ECX - number of times to do delay
  248. gusdelay:
  249.         push ax dx
  250.         mov dx,300h
  251. gusdelayl0:
  252.         in al,dx
  253.         in al,dx
  254.         in al,dx
  255.         in al,dx
  256.         in al,dx
  257.         in al,dx
  258.         in al,dx
  259.         loop gusdelayl0
  260.         pop dx ax
  261.         ret
  262.  
  263. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  264. ; Shove some crap into GUS ram
  265. ; In:
  266. ;   EBX - addx in GUS ram to shove into
  267. ;   ECX - amount of crap to shove
  268. ;   EDX -> actual crap to shove
  269. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  270. _gs_putram:
  271.         push eax ebx ecx dx esi
  272.         mov esi,edx
  273.         mov dx,gusport104
  274. gsputraml0:
  275.         dec edx
  276.         mov al,44h
  277.         mov port103val,al
  278.         out dx,al
  279.         add dl,2
  280.         shld eax,ebx,16
  281.         out dx,al
  282.         sub dl,2
  283.         mov al,43h
  284.         mov port103val,al
  285.         out dx,al
  286.         inc edx
  287. gsputraml1:
  288.         mov ax,bx
  289.         out dx,ax
  290.         add dl,3
  291.         outsb
  292.         sub dl,3
  293.         inc bx
  294.         loopnz gsputraml1
  295.         jecxz short gsputramd
  296.         add ebx,10000h
  297.         jmp gsputraml0
  298. gsputramd:
  299.         pop esi dx ecx ebx eax
  300.         ret
  301.  
  302. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  303. ; Rip some crap outta GUS ram
  304. ; In:
  305. ;   EBX - addx in GUS ram to rip from
  306. ;   ECX - amount of crap to rip
  307. ;   EDX -> buffer for ripped crap
  308. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  309. _gs_getram:
  310.         push eax ebx ecx dx edi
  311.         mov edi,edx
  312.         mov dx,gusport104
  313. gsgetraml0:
  314.         dec edx
  315.         mov al,44h
  316.         mov port103val,al
  317.         out dx,al
  318.         add dl,2
  319.         shld eax,ebx,16
  320.         out dx,al
  321.         sub dl,2
  322.         mov al,43h
  323.         mov port103val,al
  324.         out dx,al
  325.         inc edx
  326. gsgetraml1:
  327.         mov ax,bx
  328.         out dx,ax
  329.         add dl,3
  330.         insb
  331.         sub dl,3
  332.         inc bx
  333.         loopnz gsgetraml1
  334.         jecxz short gsgetramd
  335.         add ebx,10000h
  336.         jmp gsgetraml0
  337. gsgetramd:
  338.         pop edi dx ecx ebx eax
  339.         ret
  340.  
  341. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  342. ; Initialize GUS sound system
  343. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  344. _gs_init:
  345.         pushad
  346.         mov ax,900h
  347.         int 31h
  348.         push ax
  349.  
  350.         mov dx,_gusport                 ; set up all port vars
  351.         @outb 0bh
  352.         add dx,102h
  353.         mov gusport102,dx
  354.         inc edx
  355.         mov gusport103,dx
  356.         inc edx
  357.         mov gusport104,dx
  358.         add dl,3
  359.         mov gusport107,dx
  360.  
  361.         sub dl,4                        ; initialize GUS
  362.         @outb 4ch
  363.         add dl,2
  364.         @outb 0
  365.         mov ecx,10h
  366.         call gusdelay
  367.         @outb 1
  368.         sub dl,2
  369.         mov ecx,10h
  370.         call gusdelay
  371.         @gusoutb 41h,0
  372.         @gusoutb 45h,0
  373.         @gusoutb 49h,0
  374.         @outb 0eh
  375.         add dl,2
  376.         @outb _gusnumvoices
  377.         sub dl,3
  378.  
  379.         mov bl,1fh                      ; set up all voices
  380. gsinitl0:
  381.         mov al,bl
  382.         and al,7fh
  383.         out dx,al
  384.         inc edx
  385.         @gusoutw 9,0
  386.         @gusoutb 0,0
  387.         @gusoutb 0dh,3
  388.         @gusoutb 6,16
  389.         @outb 0ch
  390.         add dl,2
  391.         @outb 7
  392.         sub dl,3
  393.         mov ecx,1
  394.         call gusdelay
  395.         xor bl,80h
  396.         js gsinitl0
  397.         sub bl,1
  398.         jnc gsinitl0
  399.  
  400.         sub dx,0f3h                     ; damn, another undocumented port
  401.         @outb 5
  402.         sub dl,0fh
  403.         @outb 8
  404.         add dl,0bh
  405.         xor al,al
  406.         out dx,al
  407.         add dl,4
  408.         out dx,al
  409.         sub dl,0fh
  410.  
  411.         movzx ebx,_gusirq               ; set IRQ channels
  412.         @outb 4bh
  413.         add dl,0bh
  414.         mov al,gusirqvaltbl[ebx]
  415.         out dx,al
  416.         sub dl,0bh
  417.         @outb 9
  418.         add dx,103h
  419.  
  420.         @outb 43h                       ; how much RAM on the card
  421.         inc edx
  422.         @outw 0ffffh
  423.         dec edx
  424.         @outb 44h
  425.         add dl,2
  426.         mov cl,3
  427. gsinitl1:
  428.         @outb cl
  429.         add dl,2
  430.         in al,dx
  431.         inc eax
  432.         mov ah,al
  433.         out dx,al
  434.         in al,dx
  435.         sub dl,2
  436.         cmp al,ah
  437.         jne short gsinitl1d
  438.         inc _gusram
  439.         add cl,4
  440.         test cl,10h
  441.         jz gsinitl1
  442. gsinitl1d:
  443.         sub dl,2
  444.  
  445.         mov edi,offset aclbeg           ; set some beginning values
  446.         mov ecx,80
  447.         mov eax,0ffffffffh
  448.         rep stosd
  449.         mov eax,7070707h
  450.         mov cl,8
  451.         rep stosd
  452.         xor eax,eax
  453.         mov cl,12
  454.         rep stosd
  455.  
  456.         @gusoutb 4ch,3                  ; enable GUS normal operation
  457.  
  458.         @gusoutb 47h,_gustimerfreq      ; start GUS timer
  459.         @outb 45h
  460.         add dl,2
  461.         @outb 8
  462.         sub dx,0fdh
  463.         @outb 4
  464.         inc edx
  465.         @outb 2
  466.  
  467.         cmp bl,2                        ; set and enable GF1 IRQ (BL=IRQ num)
  468.         jne short $+4
  469.         mov bl,9
  470.         cmp bl,7
  471.         seta al
  472.         movzx eax,al
  473.         mov ax,irqm0tbl[eax*2]
  474.         mov irqm0,ax
  475.         mov edx,offset irq
  476.         call _setirqvect
  477.         xor al,al
  478.         call _setirqmask
  479.         mov edi,offset rmgusirqbuf
  480.         call _rmpmirqset
  481.         mov ormgusirqvect,edx
  482.  
  483.         pop ax
  484.         int 31h
  485.         popad
  486.         ret
  487.  
  488. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  489. ; Uninitialize GUS sound system
  490. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  491. _gs_uninit:
  492.         push ax bx edx
  493.         mov ax,900h
  494.         int 31h
  495.         push ax
  496.  
  497.         mov bl,_gusirq                  ; Kill GUS IRQ handler
  498.         cmp bl,2
  499.         jne short $+4
  500.         mov bl,9
  501.         mov edx,ormgusirqvect
  502.         call _rmpmirqfree
  503.         mov al,1
  504.         call _setirqmask
  505.  
  506.         mov dx,gusport103               ; Shut down GUS
  507.         @outb 4ch
  508.         add dl,2
  509.         @outb 0
  510.         sub dx,105h
  511.         @outb 0bh
  512.  
  513.         pop ax
  514.         int 31h
  515.         pop edx bx ax
  516.         ret
  517.  
  518. if EXTRACRAP ne 0
  519. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  520. ; EXTRA CRAP
  521. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  522.  
  523. include kb.inc
  524.  
  525. extrn   _putdosmsg:near
  526.  
  527. public  _gs_find, _gs_ask, _gs_test
  528.  
  529. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  530. ; EXTRA CRAP DATA
  531. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  532. pspultrastr     db      'ULTRASND'
  533.  
  534. askmsg0         db      'Where''s the Ultrasound bub...?',0dh,0ah
  535.                 db      '    0) I aint got one.',0dh,0ah
  536.                 db      '    1) 210h.',0dh,0ah
  537.                 db      '    2) 220h.',0dh,0ah
  538.                 db      '    3) 230h.',0dh,0ah
  539.                 db      '    4) 240h.',0dh,0ah
  540.                 db      '    5) 250h.',0dh,0ah
  541.                 db      '    6) 260h.',0dh,0ah
  542.                 db      'ENTER) 220h and 11 (default).',0dh,0ah,'$'
  543. askmsg1         db      0dh,0ah,'And what''s the magic IRQ number...?',0dh,0ah
  544.                 db      '    0) 2',0dh,0ah
  545.                 db      '    1) 3',0dh,0ah
  546.                 db      '    2) 5',0dh,0ah
  547.                 db      '    3) 7',0dh,0ah
  548.                 db      '    4) 11',0dh,0ah
  549.                 db      '    5) 12',0dh,0ah
  550.                 db      '    6) 15',0dh,0ah,'$'
  551.  
  552. irqtbl          db      2,3,5,7,11,12,15
  553.  
  554. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  555. ; EXTRA CRAP CODE
  556. ;▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
  557.  
  558. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  559. ; Find a GUS (environment variable)
  560. ; Out:
  561. ;   EAX,ECX,ESI,EDI - ?
  562. ;   CF=0 - found GUS
  563. ;   CF=1 - no GUS found
  564. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  565. _gs_find:
  566.         mov esi,_pspa
  567.         movzx esi,word ptr gs:[esi+2ch]
  568.         shl esi,4
  569. gsfindl3:
  570.         mov edi,offset pspultrastr
  571.         mov ecx,8
  572.         repe cmps byte ptr gs:[esi],byte ptr es:[edi]
  573.         jne short gsfindf0
  574.         mov edi,10h
  575.         call gsfindr0
  576.         mov _gusport,cx
  577.         call gsfindr0
  578.         call gsfindr0
  579.         mov edi,10
  580.         call gsfindr0
  581.         mov _gusirq,cl
  582.         clc
  583.         ret
  584. gsfindf0:
  585.         lea esi,[esi+ecx-8]
  586. gsfindl0:
  587.         inc esi
  588.         cmp byte ptr gs:[esi-1],0
  589.         jne gsfindl0
  590.         cmp byte ptr gs:[esi],0
  591.         jne gsfindl3
  592.         stc
  593.         ret
  594. ;-----------------------------------------------------------------------------
  595. gsfindr0:
  596.         movzx eax,byte ptr gs:[esi]
  597.         inc esi
  598.         sub al,'0'
  599.         jc gsfindr0
  600.         cmp al,9
  601.         ja gsfindr0
  602.         mov ecx,eax
  603. gsfindr0l0:
  604.         mov al,gs:[esi]
  605.         inc esi
  606.         sub al,'0'
  607.         jc gsfindr0d
  608.         cmp al,9
  609.         ja gsfindr0d
  610.         imul ecx,edi
  611.         add ecx,eax
  612.         jmp gsfindr0l0
  613. gsfindr0d:
  614.         ret
  615.  
  616. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  617. ; Ask if GUS present and for port and IRQ
  618. ; Out:
  619. ;   EAX,EDX - ?
  620. ;   CF=0 - no GUS
  621. ;   CF=1 - GUS be here
  622. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  623. _gs_ask:
  624.         mov byte ptr _gusport,20h
  625.         mov _gusirq,11
  626.         mov edx,offset askmsg0
  627.         call _putdosmsg
  628. gsaskl1:
  629.         call _getch
  630.         cmp al,13
  631.         je short gsaskd
  632.         sub al,'0'
  633.         jc gsaskl1
  634.         je short gsaska
  635.         cmp al,6
  636.         ja gsaskl1
  637.         shl al,4
  638.         mov byte ptr _gusport,al
  639.         mov edx,offset askmsg1
  640.         call _putdosmsg
  641. gsaskl0:
  642.         call _getch
  643.         sub al,'0'
  644.         jc gsaskl0
  645.         cmp al,6
  646.         ja gsaskl0
  647.         movzx eax,al
  648.         mov al,irqtbl[eax]
  649.         mov _gusirq,al
  650. gsaskd:
  651.         clc
  652.         ret
  653. gsaska:
  654.         stc
  655.         ret
  656.  
  657. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  658. ; Test _gusport
  659. ; Out:
  660. ;   AX,BL,DX - ?
  661. ;   CF=0 - GUS failed
  662. ;   CF=1 - GUS passed
  663. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  664. _gs_test:                       ; Temporarily out of service
  665.         clc
  666.         ret
  667. ;       mov ax,900h
  668. ;       int 31h
  669. ;       push ax
  670. ;       mov dx,_gusport
  671. ;       add dx,103h
  672. ;       @outb 44h
  673. ;       in al,dx
  674. ;       cmp al,44h
  675. ;       jne short gstesta
  676. ;       add dl,2
  677. ;       @outb 0
  678. ;       sub dl,2
  679. ;       @outb 43h
  680. ;       inc edx
  681. ;       @outw 0
  682. ;       add dl,3
  683. ;       in al,dx
  684. ;       mov bl,al
  685. ;       sub dl,3
  686. ;       @outw 1
  687. ;       add dl,3
  688. ;       not bl
  689. ;       @outb bl
  690. ;       sub dl,3
  691. ;       @outw 0
  692. ;       add dl,3
  693. ;       in al,dx
  694. ;       cmp al,bl
  695. ;       je short gstesta
  696. ;       sub dl,3
  697. ;       @outw 1
  698. ;       add dl,3
  699. ;       in al,dx
  700. ;       cmp al,bl
  701. ;       jne short gstesta
  702. ;       clc
  703. ;       pop ax
  704. ;       int 31h
  705. ;       ret
  706. gstesta:
  707. ;       stc
  708. ;       pop ax
  709. ;       int 31h
  710. ;       ret
  711. endif
  712.  
  713. code32  ends
  714.         end
  715.  
  716.