   DMA mode

   Under  the  DMA-mode,  the  Channel  I  of the DMAC on   the   CPU   is   programmed
   to transfer the data between the memory and die DSP.  'Ibis frees the application
   program for other tasks.

   Besides the 8-bit  data  format,  DSP  supports  3  additional  compressed  data
   format for voice output.  The digitized voice can be compressed  by  software  to
   save disk and memory space.  'Me DSP compresses  the  data  during  voice  output.
   This has a clear advantage in that the CPU need  not  spend  time  decompressing
   the data and memory wasted to store the decompressed data.

   The compression schemes used are:
      a.  4-bit DAC     (2 to 1 compression)
      b. 2.6-bit DAC (3 to 1 compression)
      c. 2-bit DAC      (4 to 1 compression)


Under DMA Mode, the sampling rate is controlled by the DSP. The DSP uses a 
one-byte variable, called TIEM_CONSTANT, to generate the DMA request for
the DMA-controller on the system to transfer the data.

The TIME_CONSTANT variable is set by the DSP command's 40H. It only
requires to be set once, unless the sampling rate needs to be changed.



   The formula for the TIME-CONSTANT is as follow:

       TIME-CONSTANT=256-1000000/sampling rate

       Eg.
                 For a 80OOHz sampling rate,

                 TIME-CONSTANT =256-1000000/8000
                                     =131


    Due to the difference in complexity of each scheme, the maximum sampling rate

       Input (ADC)            8-bit only,        4 KHz to  12  KHz
       Output (DAC)           8-bit,             4 KHz to  23  KHz

                              4-bit ADPCM,       4  KHz  to  12KHz

                              2.6-bit ADPCM,     4 KHz to  13  KHz

                              2-bit ADPCM,       4 KHz to 11  KHz

Note: setting to  a sampling rate that is beyond the capability of that mode
      will result in no increase in actual samplinh rate.



    Voice Data Size

    Theoretically, for the Direct and DMA mode, the  size  of  voice  data  can  be
    transferred is limited by the size of memory buffer available on the system  for
    the voice data.

    For Direct mode, since the data is  output/input  directly  by  the  application
    program through the DSP, the size of data to be transferred is  handled  by  the
    application program.

    Under the DMA  mode,  the  DATA  LENGTH  is  used  as  a  2-byte  parameter  for
    any of the voice input/output command.  The LSB (less significant  byte)  of  the
    DATA-LENGTH is written to  the  DSP  after  the  command  and  followed  by  the
    MSB.

    The DATA-LENGTH is defined as:

        DATA-LENGTH=actual number of data - 1.

    For example, to transfer I  byte  of  data,  DATA-LENGTH  =  0.  To  transfer  a
    full 64KB of data, DATA-LENGTH = 65535 (FFFFH).

    Note:  1.  Due to the characteristic of the DMAC, the actual  size  of  data  to
               transfer at a time is limited by  the  physical  page  boundary,  which
               is 64KB at maximum.

           2.  The details on how to transfer data beyond 64KB is left  to  a  later
               section.



 Programming the DMAC

 The discussion here only provides brief instructions on programming the DMAC
 (8237) for transferring the data between the memory and the DSP.

 To have a better understanding of programming the DMAC (DMA Controller),
 refer to its Data Sheet.

 Two unique characteristics of the DMAC have to be discussed.
    a. The DMAC can only transfer data within a physical memory page.
       The system memory is divided into physical page of 64KB each.  For a
   1 MB memory, it is divided into 16 pages as follows:
       Page    Segment:Offset Address
       0       0000:0000-0000:FFFF
       I       1000:0000-1000:FFFF
       2       2000:0000-2000:FFFF

       :           "
       :           "
       :           "

       E       E00O:OOOO-E0OO:FFFF
       F       FOOO:OOOO-FOOO:FFFF

           The  DMAC  (DMA  controller)  cannot  be  programmed  to  transfer  this  set
           ofd ata in one go as they are not within the same physical page.It must
           be handled as  2  blocks.

           Therefore, a set of voice data has to  be  divided  into  sub-blocks  at  the
           physical pageboundary.  This limits the maximum number of data that
           can be transferred each time to 64KB.

       b.  The DAC's  data  counter  is  always  1  byte  less  the  the  actual  number
           of bytes to transfer.

           This  is  how  the  DATA-LENGTH  for  the  DSP,  discussed  in  the  previous
           section, is being defined.


     The parameters for programming the DMAC are:

        a.    Page    Number       The physical page address of the data for DMA.

        b.   Base    Address       A 2-byte value for the offset address of the data  in
                                   the physical page.  The  LSB  comes  first,  then  the
                                   MSB.

        c.   Data    Counter       A  2-byte  value  for  the  DATA-LENGTH  as   defined
                                   in the previous section.  LSB comes first also.

        d.   Transfer   Mode       A byte that indicates the direction of transfer (read
                                   from  or  write  to  memory),  direction  of   memory
                                   address change and other parameters.

                                   The value to use are:

                                   For voice input, (DAC)      - 49H
                                   For voice output (ADC)      - 45H



 The DMAC is programmed through a few I/O ports.  The procedure is listed
   below:

     a.  out OAH with 5;mask off channel  1

     b.  out OCH with O;clear byte pointer F/F to lower byte

     c.  out OBH with 49H;set transfer mode to DAC, for ADC, it is 45H

     d.  out 02H with LSB of  Base  Address

     e.  out 02H with MSB of  Base  Address

     f.  out 83H with Page Number

     g.  out 03H with LSB of  Data  Counter

     h.  out 03H with MSB of  Data  Counter

     i.  out OAH with I;enable channel I

Note:  The DMAC must be programmed before the DSP is programmed 
        for the DMS transfer.




End of DMA Interrupt

The DSP is designed to  provide  a  hardware  interrupt  at  the  end  of  each  DMA
transfer.  The actual interrupt number is selectable from 2, 3, 5 and 7 on the  card.
(Refer to the Installation Note for detail).

For voice data that resides in more than one  physical  page,  it  must  be  divided
into sub-blocks at the page boundary for transfer.

When the intenrrupt occurs after transferring each sub-blocks,the interrupt            service
routine programs the DMAC  and  the  DSP  to  transfer  next  sub-block,  until  all
the blocks are transferred.  This solves the problem of  a  voice  data  that  crosses
the physical page boundary, be it more than 64K or not.

  The actions of the interrupt service routine are as follows:
      a.  Preserve machine status
      b.  Acknowledge the DSP interrupt
      c.  Goto (f), if no more blocks to transfer
      d.  Program the DMAC for next block
      e.  Program the DSP for next block
      f.  Output EOI (End of Interrupt) to  Interrupt  Controller  at  I/O  port  20H
      g.  Restore machine status
      h.  Execute an IRET
   Note:  
   1.  The hardware interrupt  is also enabled/disabled by  the Interrupt 
       Register of the DMAC at I/O Port (21h).
   2.  Application program has to clear/set the corresponding bit on the port
       for the interrupt number used. MSB (bit 7) is for interrupt 7 and LSB
       (bit 0) is for interrupt 0.       

   

    Use of Reference Byte

    The  compression  scheme  used  by  DSP  is  known  as  ADPCM  (Adaptive  Delta
    Pulse Code Modulation).  This scheme stores the difference between  data  values
    instead of the actual data.

    The first byte of the compressed data is always a REFERENCE byte  which  is  not
    the ADPCM code but the actual data byte value.  This byte is used by the DSP  as
    a reference during the decompression of the data.

    A   separate   set of ADPCM DAC commands   are   used to identify   the    REFERENCE
    byte in a data block.  As the compressed data may be sent to the DSP in a few sub-
    blocks,due to page crossing problem discussed earlier,and only the first block
    contains the REFERENCE byte.

    The different ADPCM  DAC  commands  for  each  compression  scheme  are  shown
    below: (Refer to each command's specification for more detail).


-------------------------------------------------------------------------
|    Compression   |     with REFERENCE   |     without REFERENCE       |
|      Scheme      |          byte        |           byte              |
-------------------------------------------------------------------------
|      4 bit       |          75H         |            74H              |
|                  |                      |                             |
|     2.6-bit      |          77H         |            76H              |
|                  |                      |                             |
|      2-bit       |          7BH         |            7AH              |
-------------------------------------------------------------------------




  
Summary
-------

  Procedure to output voice (DAC) is listed below:


  a.  Program the TIME-CONSTANT for the DSP, if necessary

  b.  Setup the intenupt service routine to handle the End of DMA interrupt

  c.  Program the DMAC for the voice output, with 49H as the mode register
    value

  d.  Unmask the Interrupt Mask Register at I/O port 21 H

  e.  Program the DSP to output the first sub-block with a REFERENCE byte,
    if the compressed data is used

  f.  At each interrupt service, output subsequent block until all blocks are
    output

  g.  When all blocks are output, mask the Interrupt Mask Register

  h.  Restore the original interrupt service routine.




  The Procedure to input (ADC) is listed below:

  a. Proogram the TIME_CONSTANT for the DSP, if nessesary
  
  b. Setup the interrupt serivce routine to handle the End of DMA interrupt

  c. Program the DMAC for the voice input, with 45H as the mode register value

  d. Unmask the Interrupt Mask Register at I/O Port 21H

  e. Program the DSP to input the first sub-block

  f. At each interrupt service, input next sub-block until memory buffer full.
 
  g. Mask the Interrupt Mask Register

  h. Restore the original interrupt service routine



okay, now you're ready to defeat the SB(pro) DMA .. ;-)

bye
chris
