home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / software / sviluppo / ahisrc / device / devsupp.s < prev    next >
Encoding:
Text File  |  1999-04-22  |  10.1 KB  |  474 lines

  1. ; $Id: devsupp.s,v 4.8 1999/04/22 19:42:03 lcs Exp $
  2.  
  3. ;    AHI - Hardware independent audio subsystem
  4. ;    Copyright (C) 1996-1999 Martin Blom <martin@blom.org>
  5. ;     
  6. ;    This library is free software; you can redistribute it and/or
  7. ;    modify it under the terms of the GNU Library General Public
  8. ;    License as published by the Free Software Foundation; either
  9. ;    version 2 of the License, or (at your option) any later version.
  10. ;     
  11. ;    This library 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 GNU
  14. ;    Library General Public License for more details.
  15. ;     
  16. ;    You should have received a copy of the GNU Library General Public
  17. ;    License along with this library; if not, write to the
  18. ;    Free Software Foundation, Inc., 59 Temple Place - Suite 330, Cambridge,
  19. ;    MA 02139, USA.
  20.  
  21.     include exec/types.i
  22.     include    macros.i
  23.  
  24.     XDEF    _RecM8S
  25.     XDEF    _RecS8S
  26.     XDEF    _RecM16S
  27.     XDEF    _RecS16S
  28.     XDEF    _RecM32S
  29.     XDEF    _RecS32S
  30.  
  31.     XDEF    _MultFixed
  32.     XDEF    _asmRecordFunc
  33.  
  34.     section    .text,code
  35.  
  36. * Not the best routines (fraction does not get saved between calls,
  37. * loads of byte writes, no interpolation etc), but who cares? 
  38.  
  39. ;in:
  40. * d0    Number of SAMPLES to fill. (Max 131071)
  41. * d1    Add interger.fraction in samples (2×16 bit)
  42. * a0    Source (AHIST_S16S)
  43. * a2    Pointer to Source Offset in bytes (will be updated)
  44. * a3    Pointer to Destination (will be updated)
  45. ;out
  46.  
  47. Cnt    EQUR    d0
  48. Tmp    EQUR    d1
  49. OffsI    EQUR    d2
  50. OffsF    EQUR    d3
  51. AddI    EQUR    d4
  52. AddF    EQUR    d5
  53. Src    EQUR    a0
  54. Dst    EQUR    a1
  55.  
  56. *******************************************************************************
  57. ** RecM8S *********************************************************************
  58. *******************************************************************************
  59.  
  60. _RecM8S:
  61.     pushm    d2-d5,-(sp)
  62.     move.w    d1,AddF
  63.     moveq    #0,AddI
  64.     swap.w    d1
  65.     move.w    d1,AddI
  66.     moveq    #0,OffsI
  67.     moveq    #0,OffsF
  68.     add.l    (a2),Src        ;Get Source
  69.     move.l    (a3),Dst        ;Get Dest
  70.     lsr.l    #1,Cnt            ;Unroll one time
  71.     bcs    .1
  72.     subq.w    #1,Cnt
  73.     bmi.b    .exit
  74. .nextsample
  75.  IFGE    __CPU-68020
  76.     move.b    (Src,OffsI.l*4),(Dst)+
  77.  ELSE
  78.     move.l    OffsI,Tmp
  79.     add.l    Tmp,Tmp
  80.     add.l    Tmp,Tmp
  81.     move.b    (Src,Tmp.l),(Dst)+
  82.  ENDC
  83.     add.w    AddF,OffsF
  84.     addx.l    AddI,OffsI
  85. .1
  86.  IFGE    __CPU-68020
  87.     move.b    (Src,OffsI.l*4),(Dst)+
  88.  ELSE
  89.     move.l    OffsI,Tmp
  90.     add.l    Tmp,Tmp
  91.     add.l    Tmp,Tmp
  92.     move.b    (Src,Tmp.l),(Dst)+
  93.  ENDC
  94.     add.w    AddF,OffsF
  95.     addx.l    AddI,OffsI
  96.     dbf    Cnt,.nextsample
  97.     lsl.l    #2,OffsI
  98.     add.l    OffsI,(a2)        ;Update Offset
  99.     move.l    Dst,(a3)        ;Update Dest
  100. .exit
  101.     popm    d2-d5,-(sp)
  102.     rts
  103.  
  104. *******************************************************************************
  105. ** RecS8S *********************************************************************
  106. *******************************************************************************
  107.  
  108. _RecS8S:
  109.     pushm    d2-d5,-(sp)
  110.     move.w    d1,AddF
  111.     moveq    #0,AddI
  112.     swap.w    d1
  113.     move.w    d1,AddI
  114.     moveq    #0,OffsI
  115.     moveq    #0,OffsF
  116.     add.l    (a2),Src        ;Get Source
  117.     move.l    (a3),Dst        ;Get Dest
  118.     lsr.l    #1,Cnt            ;Unroll one time
  119.     bcs    .1
  120.     subq.w    #1,Cnt
  121.     bmi.b    .exit
  122. .nextsample
  123.  IFGE    __CPU-68020
  124.     move.b    (Src,OffsI.l*4),(Dst)+
  125.     move.b    2(Src,OffsI.l*4),(Dst)+
  126.  ELSE
  127.     move.l    OffsI,Tmp
  128.     add.l    Tmp,Tmp
  129.     add.l    Tmp,Tmp
  130.     move.b    (Src,Tmp.l),(Dst)+
  131.     move.b    2(Src,Tmp.l),(Dst)+
  132.  ENDC
  133.     add.w    AddF,OffsF
  134.     addx.l    AddI,OffsI
  135. .1
  136.  IFGE    __CPU-68020
  137.     move.b    (Src,OffsI.l*4),(Dst)+
  138.     move.b    2(Src,OffsI.l*4),(Dst)+
  139.  ELSE
  140.     move.l    OffsI,Tmp
  141.     add.l    Tmp,Tmp
  142.     add.l    Tmp,Tmp
  143.     move.b    (Src,Tmp.l),(Dst)+
  144.     move.b    2(Src,Tmp.l),(Dst)+
  145.  ENDC
  146.     add.w    AddF,OffsF
  147.     addx.l    AddI,OffsI
  148.     dbf    Cnt,.nextsample
  149.     lsl.l    #2,OffsI
  150.     add.l    OffsI,(a2)        ;Update Offset
  151.     move.l    Dst,(a3)        ;Update Dest
  152. .exit
  153.     popm    d2-d5,-(sp)
  154.     rts
  155.  
  156. *******************************************************************************
  157. ** RecM16S ********************************************************************
  158. *******************************************************************************
  159.  
  160. _RecM16S:
  161.     pushm    d2-d5,-(sp)
  162.     move.w    d1,AddF
  163.     moveq    #0,AddI
  164.     swap.w    d1
  165.     move.w    d1,AddI
  166.     moveq    #0,OffsI
  167.     moveq    #0,OffsF
  168.     add.l    (a2),Src        ;Get Source
  169.     move.l    (a3),Dst        ;Get Dest
  170.     lsr.l    #1,Cnt            ;Unroll one time
  171.     bcs    .1
  172.     subq.w    #1,Cnt
  173.     bmi.b    .exit
  174. .nextsample
  175.  IFGE    __CPU-68020
  176.     move.w    (Src,OffsI.l*4),(Dst)+
  177.  ELSE
  178.     move.l    OffsI,Tmp
  179.     add.l    Tmp,Tmp
  180.     add.l    Tmp,Tmp
  181.     move.w    (Src,Tmp.l),(Dst)+
  182.  ENDC
  183.     add.w    AddF,OffsF
  184.     addx.l    AddI,OffsI
  185. .1
  186.  IFGE    __CPU-68020
  187.     move.w    (Src,OffsI.l*4),(Dst)+
  188.  ELSE
  189.     move.l    OffsI,Tmp
  190.     add.l    Tmp,Tmp
  191.     add.l    Tmp,Tmp
  192.     move.w    (Src,Tmp.l),(Dst)+
  193.  ENDC
  194.     add.w    AddF,OffsF
  195.     addx.l    AddI,OffsI
  196.     dbf    Cnt,.nextsample
  197.     lsl.l    #2,OffsI
  198.     add.l    OffsI,(a2)        ;Update Offset
  199.     move.l    Dst,(a3)        ;Update Dest
  200. .exit
  201.     popm    d2-d5,-(sp)
  202.     rts
  203.  
  204. *******************************************************************************
  205. ** RecS16S ********************************************************************
  206. *******************************************************************************
  207.  
  208. _RecS16S:
  209.     pushm    d2-d5,-(sp)
  210.     move.w    d1,AddF
  211.     moveq    #0,AddI
  212.     swap.w    d1
  213.     move.w    d1,AddI
  214.     moveq    #0,OffsI
  215.     moveq    #0,OffsF
  216.     add.l    (a2),Src        ;Get Source
  217.     move.l    (a3),Dst        ;Get Dest
  218.     lsr.l    #1,Cnt            ;Unroll one time
  219.     bcs    .1
  220.     subq.w    #1,Cnt
  221.     bmi.b    .exit
  222. .nextsample
  223.  IFGE    __CPU-68020
  224.     move.l    (Src,OffsI.l*4),(Dst)+
  225.  ELSE
  226.     move.l    OffsI,Tmp
  227.     add.l    Tmp,Tmp
  228.     add.l    Tmp,Tmp
  229.     move.l    (Src,Tmp.l),(Dst)+
  230.  ENDC
  231.     add.w    AddF,OffsF
  232.     addx.l    AddI,OffsI
  233. .1
  234.  IFGE    __CPU-68020
  235.     move.l    (Src,OffsI.l*4),(Dst)+
  236.  ELSE
  237.     move.l    OffsI,Tmp
  238.     add.l    Tmp,Tmp
  239.     add.l    Tmp,Tmp
  240.     move.l    (Src,Tmp.l),(Dst)+
  241.  ENDC
  242.     add.w    AddF,OffsF
  243.     addx.l    AddI,OffsI
  244.     dbf    Cnt,.nextsample
  245.     lsl.l    #2,OffsI
  246.     add.l    OffsI,(a2)        ;Update Offset
  247.     move.l    Dst,(a3)        ;Update Dest
  248. .exit
  249.     popm    d2-d5,-(sp)
  250.     rts
  251.  
  252. *******************************************************************************
  253. ** RecM32S ********************************************************************
  254. *******************************************************************************
  255.  
  256. _RecM32S:
  257.     pushm    d2-d5,-(sp)
  258.     move.w    d1,AddF
  259.     moveq    #0,AddI
  260.     swap.w    d1
  261.     move.w    d1,AddI
  262.     moveq    #0,OffsI
  263.     moveq    #0,OffsF
  264.     add.l    (a2),Src        ;Get Source
  265.     move.l    (a3),Dst        ;Get Dest
  266.     lsr.l    #1,Cnt            ;Unroll one time
  267.     bcs    .1
  268.     subq.w    #1,Cnt
  269.     bmi.b    .exit
  270. .nextsample
  271.  IFGE    __CPU-68020
  272.     move.w    (Src,OffsI.l*4),(Dst)+
  273.  ELSE
  274.     move.l    OffsI,Tmp
  275.     add.l    Tmp,Tmp
  276.     add.l    Tmp,Tmp
  277.     move.w    (Src,Tmp.l),(Dst)+
  278.  ENDC
  279.     clr.w    (Dst)+
  280.     add.w    AddF,OffsF
  281.     addx.l    AddI,OffsI
  282. .1
  283.  IFGE    __CPU-68020
  284.     move.w    (Src,OffsI.l*4),(Dst)+
  285.  ELSE
  286.     move.l    OffsI,Tmp
  287.     add.l    Tmp,Tmp
  288.     add.l    Tmp,Tmp
  289.     move.w    (Src,Tmp.l),(Dst)+
  290.  ENDC
  291.     clr.w    (Dst)+
  292.     add.w    AddF,OffsF
  293.     addx.l    AddI,OffsI
  294.     dbf    Cnt,.nextsample
  295.     lsl.l    #2,OffsI
  296.     add.l    OffsI,(a2)        ;Update Offset
  297.     move.l    Dst,(a3)        ;Update Dest
  298. .exit
  299.     popm    d2-d5,-(sp)
  300.     rts
  301.  
  302. *******************************************************************************
  303. ** RecS32S ********************************************************************
  304. *******************************************************************************
  305.  
  306. _RecS32S:
  307.     pushm    d2-d5,-(sp)
  308.     move.w    d1,AddF
  309.     moveq    #0,AddI
  310.     swap.w    d1
  311.     move.w    d1,AddI
  312.     moveq    #0,OffsI
  313.     moveq    #0,OffsF
  314.     add.l    (a2),Src        ;Get Source
  315.     move.l    (a3),Dst        ;Get Dest
  316.     lsr.l    #1,Cnt            ;Unroll one time
  317.     bcs    .1
  318.     subq.w    #1,Cnt
  319.     bmi.b    .exit
  320. .nextsample
  321.  IFGE    __CPU-68020
  322.     move.w    (Src,OffsI.l*4),(Dst)+
  323.     clr.w    (Dst)+
  324.     move.w    2(Src,OffsI.l*4),(Dst)+
  325.     clr.w    (Dst)+
  326.  ELSE
  327.     move.l    OffsI,Tmp
  328.     add.l    Tmp,Tmp
  329.     add.l    Tmp,Tmp
  330.     move.w    (Src,Tmp.l),(Dst)+
  331.     clr.w    (Dst)+
  332.     move.w    2(Src,Tmp.l),(Dst)+
  333.     clr.w    (Dst)+
  334.  ENDC
  335.     add.w    AddF,OffsF
  336.     addx.l    AddI,OffsI
  337. .1
  338.  IFGE    __CPU-68020
  339.     move.w    (Src,OffsI.l*4),(Dst)+
  340.     clr.w    (Dst)+
  341.     move.w    2(Src,OffsI.l*4),(Dst)+
  342.     clr.w    (Dst)+
  343.  ELSE
  344.     move.l    OffsI,Tmp
  345.     add.l    Tmp,Tmp
  346.     add.l    Tmp,Tmp
  347.     move.w    (Src,Tmp.l),(Dst)+
  348.     clr.w    (Dst)+
  349.     move.w    2(Src,Tmp.l),(Dst)+
  350.     clr.w    (Dst)+
  351.  ENDC
  352.     add.w    AddF,OffsF
  353.     addx.l    AddI,OffsI
  354.     dbf    Cnt,.nextsample
  355.     lsl.l    #2,OffsI
  356.     add.l    OffsI,(a2)        ;Update Offset
  357.     move.l    Dst,(a3)        ;Update Dest
  358. .exit
  359.     popm    d2-d5,-(sp)
  360.     rts
  361.  
  362. *******************************************************************************
  363. ** MultFixed ******************************************************************
  364. *******************************************************************************
  365.  
  366. ;in:
  367. * d0    unsigned long
  368. * d1    Fixed
  369. ;out:
  370. * d0    d0*d1
  371. _MultFixed:
  372.     push    d2
  373.     move.l    d0,d2
  374.     move.l    d1,d0
  375.     beq    .exit            ;Sanity check
  376.     swap.w    d2
  377.     moveq    #0,d1
  378.     move.w    d2,d1
  379.     clr.w    d2
  380. * d2:d0 is now d0<<16
  381.  IFGE    __CPU-68020
  382.     divu.l    d0,d1:d2
  383.     move.l    d2,d0
  384.  ELSE
  385.     XREF    _UDivMod64
  386.     jsr    _UDivMod64        ;d0 = (d1:d2)/d0
  387.  ENDC
  388. ;    addq.l    #1,d0
  389. .exit
  390.     pop    d2
  391.     rts
  392.  
  393. *******************************************************************************
  394. ** RecordFunc *****************************************************************
  395. *******************************************************************************
  396.  
  397. * This function is not used, but can be used to fill a large record buffer
  398.  
  399. ;in:
  400. * d0    Sample frames in buffer
  401. * a0    Pointer to struct RD
  402. * a1    The samples themselves
  403.  
  404.     STRUCTURE RD,0
  405.     APTR    buffer1                ;Address of first buffer
  406.     APTR    buffer2                ;Address of second buffer
  407.     ULONG    bufferlen            ;Length in samples
  408.     APTR    task                ;Task to signal when buffer is full
  409.     ULONG    signalmask            ;Signal mask
  410.     ULONG    offs                ;My variable
  411.     ULONG    count                ;My variable
  412.  
  413. ;    struct {
  414. ;     APTR             buffer1;
  415. ;     APTR             buffer2;
  416. ;     ULONG             bufferlen;
  417. ;     APTR             task;
  418. ;     ULONG             signalmask;
  419. ;     ULONG             offs;
  420. ;     ULONG             count;
  421. ;    }             ahidu_RecordData;
  422.  
  423. _asmRecordFunc:
  424.  
  425.     IF    0
  426.  
  427.     move.l    a2,-(sp)
  428.  
  429.     move.l    buffer1(a0),a2            ; Our own buffer
  430.     add.l    offs(a0),a2
  431.  
  432.     cmp.l    count(a0),d0            ; Will all samples fit in our buffer?
  433.     bls.b    3$                ; Branch if yes.
  434.  
  435. ; Fill buffer until it's full
  436.     move.l    count(a0),d1            ; Number of samples left
  437.     beq.b    2$                ; Buffer already full? Skip 1st pass.
  438.     sub.l    d1,d0                ; d0 = # of samples in second pass.
  439. 1$
  440.     move.l    (a1)+,(a2)+            ; Move both left & right word
  441.     subq.l    #1,d1                ; We can't use dbf/dbra here.
  442.     bne.b    1$
  443. 2$
  444.     move.l    buffer2(a0),a2            ; Swap pointers to 1st and 2nd buffer
  445.     move.l    buffer1(a0),buffer2(a0)
  446.     move.l    a2,buffer1(a0)
  447.     move.l    bufferlen(a0),count(a0)        ; Init count
  448.     clr.l    offs(a0)
  449.     movem.l    d0/a0-a1/a6,-(sp)
  450.     move.l    4.w,a6
  451.     move.l    task(a0),a1
  452.     move.l    signalflag(a0),d0
  453.     jsr    _LVOSignal(a6)            ; Tell main task buffer is ready
  454.     movem.l    (sp)+,d0/a0-a1/a6
  455.  
  456. * Now fill the rest of the new buffer and exit.
  457.  
  458. 3$
  459.     sub.l    d0,count(a0)            ; Update count
  460.     move.l    d0,d1
  461.     lsl.l    #2,d1
  462.     add.l    d1,offs(a0)
  463. 4$
  464.     move.l    (a1)+,(a2)+            ; Move both left & right word
  465.     subq.l    #1,d0
  466.     bne.b    4$
  467.  
  468.     move.l    (sp)+,a2
  469.  
  470.     ENDC
  471.  
  472.     rts
  473.  
  474.