home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 September / CHIP_CD_1997_09_PL.iso / software / news / wspecem / sources / tape2tap / sb.inc < prev    next >
Encoding:
Text File  |  1996-05-10  |  3.6 KB  |  176 lines

  1.  
  2.  ; Sb.inc : Primitives to deal with SoundBlaster.
  3.  ;
  4.  ; Copyright 1995 Rui Fernando Ferreira Ribeiro.
  5.  ;
  6.  ; This program is free software; you can redistribute it and/or modify
  7.  ; it under the terms of the GNU General Public License as published by
  8.  ; the Free Software Foundation; either version 2 of the License, or
  9.  ; (at your option) any later version.
  10.  ;
  11.  ; This program is distributed in the hope that it will be useful,
  12.  ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  ; GNU General Public License for more details.
  15.  ;
  16.  ; You should have received a copy of the GNU General Public License
  17.  ; along with this program; if not, write to the Free Software
  18.  ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  ;
  20.  
  21.  
  22.                     ; some equates
  23.                                         ; *************
  24.  
  25. ; the next equates are the displacement from the SB base address
  26. RESET        equ    6
  27. MIXER        equ    4
  28. WRITE        equ    0ch
  29. READ        equ    0ah
  30. DATA_AVAIL    equ    0eh
  31. READY        equ    0aah
  32.  
  33. FIRST_PORT    equ    0200h    ; first SB base port address to scan
  34.  
  35.  
  36. DSP_WRITE    MACRO    byte
  37. local        poll_wait
  38.  
  39.         add    dx,WRITE
  40. poll_wait:    in    al,dx
  41.         or    al,al
  42.         js    poll_wait
  43.         mov    al,byte
  44.         out    dx,al
  45.         sub    dx,WRITE
  46.         ENDM
  47.  
  48. DSP_READ    MACRO
  49. local        poll_wait
  50.  
  51.         add    dx,DATA_AVAIL
  52. poll_wait:    in    al,dx        ; poll until a byte is ready
  53.         or    al,al
  54.         jns    poll_wait
  55.         sub    dx,DATA_AVAIL-READ
  56.         in    al,dx
  57.         sub    dx,READ
  58.         ENDM
  59.  
  60. READ_SB        MACRO
  61.         local    val_ok
  62.  
  63.                 DSP_WRITE       020h    ; send read command
  64.         DSP_READ
  65.                 cmp     al,0e0h
  66.         ja    val_ok
  67.         xor    al,al
  68. val_ok:        test    al,080h
  69.         ENDM
  70.  
  71. READ_MIXER    MACRO    reg
  72.         add    dx,MIXER
  73.         mov    al,reg
  74.         out    dx,al
  75.         inc    dx
  76.         in    al,dx
  77.         sub    dx,MIXER+1
  78.         ENDM
  79.  
  80.  
  81. WRITE_MIXER    MACRO    reg, val
  82.         add    dx,MIXER
  83.         mov    al,reg
  84.         out    dx,al
  85.         inc    dx
  86.         mov    al,val
  87.         out    dx,al
  88.         sub    dx,MIXER+1
  89.         ENDM
  90.  
  91. INIT_MIXER    MACRO
  92.         ; Input Source
  93.         ; Line-in, filter HighPass (lowFilter)
  94.         WRITE_MIXER 00ch, 7
  95.                 ; Line-in volume
  96.         WRITE_MIXER 02Eh, 0eeh
  97.         ; CD volume
  98.         WRITE_MIXER 028h, 0
  99.         ; MIC volume
  100.         WRITE_MIXER 0ah, 0
  101.         ; MASTER volume
  102.         WRITE_MIXER 022h, 0FFh
  103.         ENDM
  104.  
  105. SAVE_MIXER    MACRO
  106.         READ_MIXER    00ch
  107.         mov    byte ptr ds:[input_s],al
  108.         READ_MIXER    02Eh
  109.         mov    byte ptr ds:[line_vol],al
  110.         READ_MIXER    028h
  111.         mov    byte ptr ds:[cd_vol],al
  112.         READ_MIXER    0ah
  113.         mov    byte ptr ds:[mic_vol],al
  114.         READ_MIXER    022h
  115.         mov    byte ptr ds:[master_vol],al
  116.         ENDM
  117.  
  118. RESTORE_MIXER    MACRO
  119.         mov    al,byte ptr ds:[input_s]
  120.         WRITE_MIXER    00ch,al
  121.         mov    al,byte ptr ds:[line_vol]
  122.         WRITE_MIXER    02Eh,al
  123.         mov    al,byte ptr ds:[cd_vol]
  124.         WRITE_MIXER    028h,al
  125.         mov    al,byte ptr ds:[mic_vol]
  126.         WRITE_MIXER    0ah,al
  127.         mov    al,byte ptr ds:[master_vol]
  128.         WRITE_MIXER    022h,al
  129.         ENDM
  130.  
  131. RESET_DSP    MACRO
  132.                 local   @@scanForDSP, @@wait, @@is_dsp, @@found_DSP, @@exit
  133.  
  134.         mov    dx,FIRST_PORT        ; first port to scan
  135.  
  136. @@scanForDSP:    add    dx,RESET        ; translate to RESET port
  137.         mov    al,1
  138.         out    dx,al
  139.         INIT_COUNT
  140. @@wait:        GIVE_COUNT
  141.         cmp    ax,30
  142.         jc    @@wait
  143.         xor    al,al
  144.         out    dx,al
  145.  
  146.         mov    cx,100
  147.         add    dx,READ-RESET        ; now port is read
  148. @@is_dsp:    in    al,dx
  149.         cmp    al,READY
  150.         jz    @@found_DSP
  151.         loop    @@is_dsp
  152.  
  153.         sub    dx,READ
  154.         add    dx,0010h        ; next base address
  155.                         ; to scan
  156.         cmp    dx,02A0h
  157.         jnz    @@scanForDSP
  158.         lea    dx,sb_not_found
  159.         jmp    short @@exit
  160.  
  161. @@found_DSP:    sub    dx,READ
  162.         mov    word ptr ds:[sb_base_addr],dx
  163.  
  164.         mov    ax,dx
  165.         and    ax,0f0h
  166.         shr    ax,4
  167.         add    al,'0'
  168.         mov    byte ptr ds:[port_sb],al
  169.  
  170.         lea    dx,sb_found
  171. @@exit:         PRINT_STRING
  172.         mov    dx,word ptr ds:[sb_base_addr]
  173.         ENDM
  174.  
  175. ; EOF: Sb.inc
  176.