home *** CD-ROM | disk | FTP | other *** search
/ Shareware Supreme Volume 6 #1 / swsii.zip / swsii / 355 / APDEVKIT.ZIP / AP / TEST.ASM < prev    next >
Assembly Source File  |  1992-05-11  |  12KB  |  568 lines

  1.  
  2.         Title   Find the Audio Port
  3.     page    63,131
  4.     .286
  5.  
  6. ;   /*\
  7. ;---|*|----====< TEST.ASM >====----
  8. ;---|*|
  9. ;---|*| This program searches for the Audio Port
  10. ;---|*| across the parallel port addresses.
  11. ;---|*|
  12. ;---|*| Media Vision Audio Port Demonstration Program.
  13. ;---|*| Copyright (c) 1992, All Rights Reserved. Media Vision, Inc.
  14. ;---|*|
  15. ;   \*/
  16.  
  17.     include model.inc
  18.  
  19.         .data
  20.  
  21.     include parr.inc
  22.  
  23. Idledly   equ   <out dx,al>
  24.  
  25.     extrn    PortAddress    :word    ; AP base address...
  26.     extrn    StartPCM    :byte
  27.     extrn    PCMLength    :word
  28.     extrn    RecPCMLength    :word
  29.  
  30. Copyright    db    0dh,0ah
  31.         db    'Media Vision Audio Port Demonstration Program.',0dh,0ah
  32.         db    'Copyright (c) 1992, All Rights Reserved. Media Vision, Inc.'
  33.         db    0dh,0ah,'$'
  34.  
  35. @nowhere        db      'Audio Port not detected!',0dh,0ah,'$'
  36. @378h        db    'Audio Port detected at 378h!',0dh,0ah,'$'
  37. @278h        db    'Audio Port detected at 278h!',0dh,0ah,'$'
  38. @3BCh        db    'Audio Port detected at 3BCh!',0dh,0ah,'$'
  39.  
  40. fmdemo        db    0dh,0ah,'FM demo...','$'
  41. pcmdemo     db    0dh,0ah,'PCM playback demo...','$'
  42. recpcmdemo    db    0dh,0ah,'PCM Record demo. Type a key to start...','$'
  43. recording    db    0dh,0ah,'Now recording...','$'
  44. version     db    'Audio Port, version ','$'
  45.  
  46. alldonemsg    db    0dh,0ah,'All done'
  47. cr_lf        db    0dh,0ah,'$'
  48.  
  49.  
  50.         .code
  51.  
  52.     extrn    AP_Reset      :near    ; Audio Port Reset
  53.     extrn    AP_MCW          :near    ; Micro Command Write
  54.     extrn    AP_MDW          :near    ; Micro Data Write
  55.     extrn    AP_FM_in      :near    ; read the FM status register
  56.     extrn    AP_FM_out     :near    ; output index/data to the FM chip
  57.     extrn    AP_MDR_wait   :near    ; wait for data to be available
  58.     extrn    AP_MDR          :near    ; read the micro data byte
  59.     extrn    AP_SRQ_stat   :near    ; wait for the service request
  60.     extrn    AP_ADC_input  :near    ; record 256 bytes
  61.     extrn    AP_DAC_output :near    ; play 256 bytes
  62.  
  63. main    proc    far
  64. ;
  65. ; setup for small model
  66. ;
  67.     mov    ax,@data        ; setup small model...
  68.     mov    ds,ax
  69.     mov    es,ax
  70. ;
  71. ; Give the opening logo.
  72. ;
  73.         lea     dx,Copyright
  74.     mov    ah,09
  75.     int    21h
  76. ;
  77. ; find the Audio Port
  78. ;
  79.     call    FindAudioPort
  80. ;
  81. ; get the Audio Port version #
  82. ;
  83.     call    PrintVersion
  84. ;
  85. ; Make some FM sounds
  86. ;
  87.     call    fmsounds
  88. ;
  89. ; Make some PCM sound...
  90. ;
  91.     call    playpcmsounds
  92. ;
  93. ; Record some PCM sound...
  94. ;
  95.     call    recordpcmsounds
  96. ;
  97. ; exit to DOS
  98. ;
  99.     mov    ah,9            ; give the all done message
  100.     lea    dx,alldonemsg
  101.         int     21h
  102.  
  103.     mov    ax,4c00h        ; exit to dos
  104.     int    21h
  105.  
  106. main    endp
  107.  
  108. ;
  109. ;
  110. ;=====================
  111. ;   Routine Section
  112. ;    level 1
  113. ;=====================
  114. ;
  115. ;
  116. ;   /*\
  117. ;---|*|----====< FindAudioPort >====----
  118. ;---|*|
  119. ;---|*| Find the Audio Port out on one of the parallel ports.
  120. ;---|*|
  121. ;   \*/
  122. ;
  123. FindAudioPort   proc    near
  124.  
  125.         mov     [PortAddress],378h      ; try the 1st port
  126.     call    AP_Reset        ; reset & return the reset value
  127.     lea    dx,@378h        ; get the text message
  128.     cmp    al,5Ah            ; is it here?
  129.     jz    found            ; yes, go report it...
  130.  
  131.     mov    [PortAddress],278h    ; try the 1st port
  132.     call    AP_Reset        ; reset & return the reset value
  133.     lea    dx,@278h        ; get the text message
  134.     cmp    al,5Ah            ; is it here?
  135.     jz    found            ; yes, go report it...
  136.  
  137.     mov    [PortAddress],3BCH    ; try the 1st port
  138.     call    AP_Reset        ; reset & return the reset value
  139.     lea    dx,@3BCh        ; get the text message
  140.     cmp    al,5Ah            ; is it here?
  141.     jz    found            ; yes, go report it...
  142.  
  143.     lea    dx,@nowhere        ; not found anywhere
  144.     mov    ah,9            ; give the message
  145.     int    21h
  146.     mov    ax,4c00h        ; and exit to DOS
  147.     int    21h
  148. ;
  149. found:
  150.     mov    ah,9            ; give the message
  151.     int    21h
  152.  
  153.         call    timewait
  154.  
  155.         ret
  156.  
  157. FindAudioPort    endp
  158.  
  159. ;
  160. ;   /*\
  161. ;---|*|----====< fmsounds >====----
  162. ;---|*|
  163. ;---|*| make some sound out on the FM chip.
  164. ;---|*|
  165. ;   \*/
  166. ;
  167. ;
  168. ; table of note frequencies and Octaves for the 3812
  169. ;
  170. ; each entry has the format of:    000bbbff:ffffffff
  171. ;                      ||||| ||||||||
  172. ;                      |||++-++++++++- 10 bit frequency
  173. ;                      |||
  174. ;                      +++------------ Octave
  175. ;
  176. OCTAVE_1    equ    (04h SHL 8)
  177. OCTAVE_2    equ    (08h SHL 8)
  178. OCTAVE_3    equ    (0ch SHL 8)
  179. OCTAVE_4    equ    (10h SHL 8)
  180. OCTAVE_5    equ    (14h SHL 8)
  181. OCTAVE_6    equ    (18h SHL 8)
  182. OCTAVE_7    equ    (1ch SHL 8)
  183.  
  184. noteC        equ    0342
  185. noteCSHARP    equ    0363
  186. noteD        equ    0384
  187. noteDSHARP    equ    0407
  188. noteE        equ    0432
  189. noteF        equ    0457
  190. noteFSHARP    equ    0484
  191. noteG        equ    0513
  192. noteGSHARP    equ    0544
  193. noteA        equ    0576
  194. noteASHARP    equ    0611
  195. noteB        equ    0647
  196.  
  197. fmsounds        proc    near
  198. ;
  199. ; give the FM demo message
  200. ;
  201.     lea    dx,fmdemo
  202.     mov    ah,9
  203.     int    21h
  204. ;
  205. ; just read the status for the fun of it. We do this to
  206. ; test the routine only...
  207. ;
  208.     call    AP_FM_in
  209. ;
  210. ; program one operator of the FM chip to do a simple tone
  211. ;
  212.     mov    ax,OCTAVE_3+noteC
  213.         call    loadfm
  214.  
  215.         mov     ax,OCTAVE_3+noteCSHARP
  216.         call    loadfm
  217.  
  218.         mov     ax,OCTAVE_3+noteD
  219.         call    loadfm
  220.  
  221.         mov     ax,OCTAVE_3+noteDSHARP
  222.         call    loadfm
  223.  
  224.         mov     ax,OCTAVE_3+noteE
  225.         call    loadfm
  226.  
  227.         mov     ax,OCTAVE_3+noteF
  228.         call    loadfm
  229.  
  230.         mov     ax,OCTAVE_3+noteFSHARP
  231.         call    loadfm
  232.  
  233.         mov     ax,OCTAVE_3+noteG
  234.         call    loadfm
  235.  
  236.         mov     ax,OCTAVE_3+noteGSHARP
  237.         call    loadfm
  238.  
  239.         mov     ax,OCTAVE_3+noteA
  240.         call    loadfm
  241.  
  242.         mov     ax,OCTAVE_3+noteASHARP
  243.     call    loadfm
  244.  
  245.         mov     ax,OCTAVE_3+noteB
  246.     call    loadfm
  247.  
  248.     ret
  249.  
  250. fmsounds        endp
  251.  
  252. ;
  253. ;   /*\
  254. ;---|*|----====< playpcmsounds >====----
  255. ;---|*|
  256. ;---|*| PCM output to the device.
  257. ;---|*|
  258. ;   \*/
  259. ;
  260. playpcmsounds    proc    near
  261. ;
  262. ; give the PCM demo message
  263. ;
  264.     lea    dx,pcmdemo
  265.     mov    ah,9
  266.     int    21h
  267. ;
  268. ; send the PCM commands
  269. ;
  270.     mov    al,042h         ; send play command w/sample rate
  271.     call    AP_MCW
  272.     mov    al,05Ah         ; send the sample rate for 11khz
  273.     call    AP_MCW
  274. ;
  275. ; Setup the source/destination for the transfer
  276. ;
  277.     push    es            ; save ES
  278.  
  279.     push    ds            ; ES:DI will point to the start
  280.     pop    es            ; of the PCM block.
  281.     lea    di,startpcm
  282.  
  283.     mov    si,[PCMLength]        ; si holds the length
  284. ;
  285. ; move all the data out to the FIFO in 256 byte blocks.
  286. ;
  287. pcm05:
  288.     mov    cx,256            ; get the 1/4 FIFO size
  289.     sub    si,cx            ; remove this from the block length
  290.     jnc    @F            ; jump if more data is available
  291.     add    cx,si            ; calc the true block length.
  292.     sub    si,si            ; says we are all done...
  293.     ;
  294.     @@:
  295.     call    AP_DAC_output        ; move 256 bytes out to the FIFO
  296. ;
  297. pcm15:
  298. ;
  299. ; wait till the service request line goes high, meaning, send another 256 bytes
  300. ;
  301.         call    AP_SRQ_stat             ; wait for the service request
  302.     jnc    pcm15            ; status to go high
  303. ;
  304. ; if the length wrapped, we're done...
  305. ;
  306.     cmp    cx,si            ; check to see if we're done
  307.     jnz    pcm05            ; not yet, continue till done
  308.  
  309.     pop    es
  310. ;
  311. ; we're done, tell the Audio Port to play the last of the queue, then stop
  312. ;
  313.     mov    al,010h         ; send the Idle command
  314.     call    AP_MCW
  315.  
  316.         ret
  317.  
  318. playpcmsounds    endp
  319.  
  320. ;
  321. ;   /*\
  322. ;---|*|----====< PrintVersion >====----
  323. ;---|*|
  324. ;---|*| Read the Audio Port's version #, then print it...
  325. ;---|*|
  326. ;   \*/
  327. ;
  328. PrintVersion    proc    near
  329. ;
  330. ; print the opening line
  331. ;
  332.     lea    dx,version
  333.     mov    ah,9
  334.     int    21h
  335. ;
  336. ; give the version command
  337. ;
  338.     mov    al,11H        ; get version
  339.     call    AP_MCW
  340.  
  341.     call    AP_MDR_wait    ; wait for data to become available
  342.     call    AP_MDR        ; print the MSB of the version
  343.     call    hexout
  344.  
  345.         call    AP_MDR_wait     ; wait for data to become available
  346.     call    AP_MDR        ; print the LSB of the version
  347.     call    hexout
  348.  
  349.         lea     dx,cr_lf
  350.     mov    ah,09h
  351.     int    21h
  352.  
  353.     ret
  354.  
  355. PrintVersion    endp
  356.  
  357. ;
  358. ;   /*\
  359. ;---|*|----====< recordpcmsounds >====----
  360. ;---|*|
  361. ;---|*| Record one buffer, then play it back.
  362. ;---|*|
  363. ;   \*/
  364. ;
  365. recordpcmsounds proc    near
  366. ;
  367. ; give the PCM demo message
  368. ;
  369.     lea    dx,recpcmdemo        ; print the "record demo" message
  370.     mov    ah,9
  371.     int    21h
  372.  
  373.     mov    ah,0            ; wait for a key...
  374.     int    16h
  375.  
  376.     lea    dx,recording        ; print the "now recording" message
  377.         mov     ah,9
  378.         int     21h
  379. ;
  380. ; send the Record PCM commands
  381. ;
  382.     mov    al,052h         ; send record command w/sample rate
  383.     call    AP_MCW
  384.     mov    al,05Ah         ; send the sample rate for 11khz
  385.     call    AP_MCW
  386. ;
  387. ; Setup the source/destination for the transfer
  388. ;
  389.     push    es            ; always save segments...
  390.  
  391.     push    ds            ; make ES:DI point to the start
  392.     pop    es
  393.     lea    di,startpcm        ; get the start of the PCM block
  394.  
  395.     mov    si,[RecPCMLength]    ; si holds the length
  396. ;
  397. rcd05:
  398. ;
  399. ; load the FIFO quarter size for use with the SRQ handshaking.
  400. ;
  401.     mov    cx,256            ; get the 1/4 FIFO size
  402.     sub    si,cx            ; remove this from the block length
  403.     jnc    rcd10            ; jump if more data is available
  404.     add    cx,si            ; calc the true block length.
  405.     sub    si,si            ; all done...
  406. ;
  407. rcd10:
  408. ;
  409. ; wait till the service request line goes high, meaning, read another 256 bytes
  410. ;
  411.         call    AP_SRQ_stat             ; wait for the service request
  412.     jnc    rcd10            ; status to go high
  413. ;
  414. ; record up to 256 bytes into our buffer
  415. ;
  416.     call    AP_ADC_input        ; does up to 256 bytes
  417. ;
  418. ; if the length wrapped, we're done...
  419. ;
  420.     cmp    cx,si            ; check to see if we're done
  421.     jnz    rcd05            ; not yet, continue till done
  422.  
  423.     pop    es
  424. ;
  425. ; we're done, tell the Audio Port to play the last of the queue, then stop
  426. ;
  427.     mov    al,010h         ; send the Idle command
  428.     call    AP_MCW
  429. ;
  430. ; play it back for the user...
  431. ;
  432.     mov    di,[RecPCMLength]    ; modify the length to be the whole
  433.     mov    [PCMLength],di        ; buffer.
  434.     call    playpcmsounds
  435. ;
  436. ; all done with the record demo
  437. ;
  438.         ret
  439.  
  440. recordpcmsounds   endp
  441.  
  442. ;
  443. ;
  444. ;=====================
  445. ;   Routine Section
  446. ;    Level 2
  447. ;=====================
  448. ;
  449. ;
  450. ;   /*\
  451. ;---|*|----====< hexout >====----
  452. ;---|*|
  453. ;---|*| Load the FM with a note, and pluck it...
  454. ;---|*|
  455. ;   \*/
  456. ;
  457.     public    hexout
  458. hexout    proc    near
  459.  
  460.     mov    cx,ax            ; save a copy of the byte
  461.     and    cl,00fh         ; cl = high nibble
  462.     and    al,0f0h
  463.     shr    al,4            ; al = low nibble
  464.  
  465.     add    al,90h            ; convert the low digit
  466.     daa
  467.     adc    al,0
  468.     add    al,40h
  469.     daa
  470.  
  471.         mov     ah,0Eh
  472.     sub    bx,bx
  473.         int     10h
  474.  
  475.     mov    al,cl            ; al = high nibble, bl = low nibble
  476.  
  477.     add    al,90h            ; convert the high digit
  478.     daa
  479.     adc    al,0
  480.     add    al,40h
  481.     daa
  482.  
  483.         mov     ah,0Eh
  484.     int    10h
  485.  
  486.     ret
  487.  
  488. hexout    endp
  489.  
  490.  
  491. ;
  492. ;   /*\
  493. ;---|*|----====< loadfm >====----
  494. ;---|*|
  495. ;---|*| Load the FM with a note, and pluck it...
  496. ;---|*|
  497. ;   \*/
  498. ;
  499.  
  500. loadfm  proc    near
  501.     push    bx
  502.     mov    bx,ax
  503.  
  504.     mov    ax,02F20h        ; index 20h
  505.     call    AP_FM_out
  506.  
  507.         mov     ax,00040h               ; index 40h
  508.         call    AP_FM_out
  509.  
  510.         mov     ax,0F060h               ; index 60h
  511.         call    AP_FM_out
  512.  
  513.     mov    ax,00680h        ; index 80h
  514.         call    AP_FM_out
  515.  
  516.     mov    ah,bl            ; place the data in ah
  517.     mov    al,0A0h         ; index A0h
  518.         call    AP_FM_out
  519.  
  520.         mov     ax,001C0h               ; index C0h
  521.         call    AP_FM_out
  522.  
  523.         mov     ax,000E0h               ; index E0h
  524.         call    AP_FM_out
  525.  
  526.     mov    ah,bh            ; place the data in ah
  527.     or    ah,20h            ; turn on the voice
  528.     mov    al,0B0h         ; index B0h
  529.         call    AP_FM_out
  530.  
  531.     mov    ah,bh            ; place the data in ah
  532.     mov    al,0B0h         ; index B0h
  533.         call    AP_FM_out
  534.  
  535.         call    timewait
  536.  
  537.         pop     bx
  538.     ret
  539.  
  540. loadfm    endp
  541.  
  542. ;
  543. ;   /*\
  544. ;---|*|----====< timewait >====----
  545. ;---|*|
  546. ;---|*| A slow loop. It can be sloppy in time, we
  547. ;---|*| just want to waist some time.
  548. ;---|*|
  549. ;   \*/
  550. ;
  551. timewait    proc    near
  552.     mov    dx,[PortAddress]
  553.     mov    ah,2
  554.     sub    cx,cx
  555. ;
  556. @@:
  557.     in    al,dx                ; 64k of SSLLOOWW in instructions
  558.     loop    @B
  559.     dec    ah
  560.     jnz    @B
  561.  
  562.     ret
  563.  
  564. timewait    endp
  565.  
  566.         end     main
  567.  
  568.