home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / s / scrd_asm.zip / ADLIBAPI.ASM < prev    next >
Assembly Source File  |  1992-06-17  |  7KB  |  246 lines

  1. comment *
  2.  
  3.         Purpose: API for producing sounds through AdLib
  4.  
  5.         Author: Yousuf J. Khan
  6.  
  7.         *
  8. include         adlib.inc       ;include macros
  9.  
  10. .model tiny
  11. .code
  12.  
  13. public  delay
  14. delay   proc    near
  15. comment *
  16.  
  17.         Purpose:
  18.         Produces a variable length delay on an AdLib or SoundBlaster
  19.         card, by reading the address port a number of times. Just the
  20.         act of calling a procedure, and doing a CX loop should add
  21.         delays of its own, so this is a very conservative procedure.
  22.         There should be more than enough delay here.
  23.  
  24.         Entry:
  25.         CX: # of loops to produce (six loops after writing to address
  26.         port, or thirty-five loops after writing to data port).
  27.  
  28.         Exit:
  29.         nothing.
  30.  
  31.         *
  32.         push    dx
  33.         mov     dx, 388h        ;AdLib address port at PC port 388h
  34.         call    sbdelay         ;call generalized delay procedure
  35.         pop     dx
  36.         ret
  37.         endp
  38.  
  39. public  sbdelay
  40. sbdelay proc    near
  41. comment *
  42.  
  43.         Purpose:
  44.         Same as the Delay procedure, except the port has to be set ahead
  45.         of time. More generalized procedure.
  46.  
  47.         Entry:
  48.         DX: status/address port i/o address
  49.         CX: # of loops to produce (six loops after writing to address
  50.         port, or thirty-five loops after writing to data port).
  51.  
  52.         Exit:
  53.         nothing.
  54.  
  55.         *
  56.         push    ax
  57. delayloop:
  58.         in      al, dx          ;read address port
  59.         loop    delayloop
  60.         pop     ax
  61.         ret
  62.         endp
  63.  
  64. public  adlibinit
  65. adlibinit       proc    near
  66. comment *
  67.  
  68.         Purpose:
  69.         Initializes AdLib registers to zero
  70.  
  71.         Entry:
  72.         nothing.
  73.  
  74.         Exit:
  75.         nothing.
  76.  
  77.         *
  78.         mov     al, 1
  79. zeroing_loop:
  80.         push    ax
  81.         mov     dx, 388h
  82.         out     dx, al          ;writing to address port
  83.         addrdelay
  84.         mov     al, 0           ;zero the data register
  85.         mov     dx, 389h
  86.         out     dx, al
  87.         datadelay
  88.         pop     ax
  89.         inc     al
  90.         ; there are only 245 AdLib registers (from 01h-F5h)
  91.         cmp     al, 0F5h                ;as long as AL is between
  92.         jbe     short zeroing_loop      ; 01-F5h, continue looping
  93.         ret
  94.         endp
  95.  
  96. public  detect_adlib
  97. detect_adlib    proc    near
  98. comment *
  99.  
  100.         Purpose:
  101.         To detect whether an AdLib-compatible is installed
  102.  
  103.         Entry:
  104.         nothing.
  105.  
  106.         Exit:
  107.         AX=0, if no AdLib
  108.         AX=1, if AdLib present
  109.  
  110.         *
  111.         push    dx              ;save DX before tests begin
  112.         setadlib        4,60h   ;reset both Adlib timers
  113.         setadlib        4,80h   ;enable Adlib interrupts
  114.         mov     dx, 388h        ;Status/Addr port
  115.         in      al, dx          ;gives state#1
  116.         test    al, 0E0h        ;AND state#1 with E0h
  117.         jne     short noAdLib   ;if 0 then goto next test
  118.         ;start 2nd state test
  119.         setadlib        2,0FFh  ;writing FFh to Adlib timer#1
  120.         setadlib        4,21h   ;start timer#1
  121.         mov     cx, 145         ;145 iteration loop,
  122.         call    delay           ; or approx. 80ms delay
  123.         mov     dx, 388h        ;Status/Addr port
  124.         in      al, dx          ;gives state#2
  125.         and     al, 0E0h        ;AND state#2 with E0h
  126.         cmp     al, 0C0h        ;is state#2 right? yes, AdLib here
  127.         mov     ax, 1           ;set return value of AX=1
  128.         jmp     short eop
  129. noAdLib:
  130.         mov     ax, 0           ;set return value of AX=0
  131. eop:
  132.         pop     dx              ;restore DX
  133.         ret
  134.         endp
  135.  
  136. public  detect_sb
  137. detect_sb       proc    near
  138. comment *
  139.  
  140.         Purpose:
  141.         To detect whether a SoundBlaster-compatible is installed
  142.  
  143.         Entry:
  144.         DS:DI-> pointer to word memory location to record SoundBlaster
  145.                 base port address to
  146.  
  147.         Exit:
  148.         AX=0, if no SoundBlaster
  149.         AX=1, if SoundBlaster present
  150.         DS:DI-> returns last possible SB port tested
  151.  
  152.         *
  153.  
  154.         comment *
  155.  
  156.                 Start scanning for a SoundBlaster base port on every PC
  157.                 port from 210h to 260h, in increments of 10h.
  158.  
  159.                 *
  160.         .data
  161.         sbflag  db      0       ;indicates how many port tests passed
  162.         sbport  dw      210h    ;i/o port where SB is located
  163.         .code
  164.         push    dx              ;save DX before tests begin
  165.         mov     dx, 210h        ;first port to check
  166.         mov     [di], dx        ;save to passed memory location
  167.         push    cx              ;save CX, we'll be using it to loop
  168.         mov     cx, 5           ;loop five times, test ports 210h-260h
  169. chkports:
  170.         push    cx
  171.         mov     cx, 200h
  172.         add     dx, 0Ch
  173. chkport1:
  174.         in      al, dx
  175.         and     al, 80h
  176.         cmp     al, 0
  177.         je      short foundport1
  178.         loop    chkport1
  179.         jmp     short test2
  180. foundport1:
  181.         inc     sbflag          ;first port in set found
  182. test2:
  183.         pop     cx
  184.         cmp     [sbflag], 0
  185.         je      short nextports ;no tests passed? go to next set
  186.         in      al, dx          ;small timing delay
  187.         mov     al, 0d3h
  188.         out     dx, al
  189.         push    cx
  190.         mov     cx, 1000h
  191. donothing:
  192.         loop    donothing       ;large timing delay
  193.         pop     cx
  194.         mov     dx, [di]
  195.         add     dx, 6
  196.         mov     al, 1
  197.         out     dx, al
  198.         rept    4
  199.         in      al, dx          ;timing delay
  200.         endm
  201.         mov     al, 0
  202.         out     dx, al
  203.         mov     dx, [di]
  204.         add     dx, 0Eh
  205.         push    cx
  206.         mov     cx, 200h
  207. chkport2:
  208.         in      al, dx
  209.         test    al, 80h
  210.         je      short foundport2
  211.         loop    chkport2
  212.         jmp     short noport2
  213. foundport2:
  214.         inc     sbflag          ;found second port in series
  215. noport2:
  216.         pop     cx
  217.         cmp     [sbflag], 2
  218.         jb      nextports       ;go to next set of ports
  219.         mov     dx, [di]
  220.         add     dx, 0Ah
  221.         in      al, dx
  222.         cmp     al, 0AAh
  223.         jne     nextports
  224.         inc     sbflag          ;found third port in series
  225.         mov     ax, 1           ;found SB, return AX=1
  226.         jmp     yes_sb
  227. nextports:
  228.         add     word ptr [di], 10h
  229.         mov     dx, [di]
  230. if ($-chkports) lt 128
  231.         loop    chkports
  232. else
  233.         dec     cx
  234.         cmp     cx, 0
  235.         je      @a
  236.         jmp     chkports
  237. @a:
  238. endif
  239.         mov     ax, 0           ;found no SB, return AX=0
  240. yes_sb:
  241.         pop     cx
  242.         pop     dx
  243.         ret
  244.         endp
  245.         END
  246.