home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 106 / EnigmaAmiga106CD.iso / software / sviluppo / ahisrc / device / mixer_68k.s < prev    next >
Encoding:
Text File  |  1999-08-23  |  88.6 KB  |  5,232 lines

  1. ; $Id: mixer_68k.s,v 4.20 1999/08/23 21:34:50 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/exec.i
  22.     include    lvo/exec_lib.i
  23.     include    devices/ahi.i
  24.     include    utility/hooks.i
  25.     include    lvo/utility_lib.i
  26.     include    ahi_def.i
  27.     include    dsp.i
  28.  
  29.     XDEF    _InitMixroutine
  30.     XDEF    _CleanUpMixroutine
  31.  
  32.     XDEF    _calcMasterVolumeTable
  33.     XDEF    _initSignedTable
  34.     XDEF    _calcSignedTable
  35.     XDEF    _initUnsignedTable
  36.     XDEF    _calcUnsignedTable
  37.     XDEF    _SelectAddRoutine
  38.     XDEF    _Mix68k
  39.     XDEF    _CalcSamples
  40.  
  41.     XREF    _SysBase
  42.     XREF    _UtilityBase
  43.     XREF    _UDivMod64
  44.     XREF    _Fixed2Shift
  45.  
  46. TABLEMAXVOL    EQU    32
  47. TABLESHIFT    EQU    11    (TABLEMAXVOL<<TABLESHIFT == 0x10000)
  48.  
  49.     section    .text,code
  50.  
  51. ;-----------------------------------------
  52.  
  53. ;in:
  54. * a2    ptr to AHIAudioCtrl
  55. ;out:
  56. * d0    TRUE on success
  57. _InitMixroutine:
  58.     pushm    d1-a6
  59.     move.l    4.w,a6
  60.     move.w    ahiac_Channels(a2),d0
  61.     mulu.w    #AHIChannelData_SIZEOF,d0
  62.     move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1    ;may be accessed from interrupts!
  63.     call    AllocVec
  64.     move.l    d0,ahiac_ChannelDatas(a2)
  65.     beq    .error
  66.  
  67.     clr.l    ahiac_DryList(a2)
  68.     move.l    ahiac_ChannelDatas(a2),a0
  69.     move.l    a0,ahiac_WetList(a2)
  70.  
  71. *** Update the ChannelData structures (cd_ChannelNo and cd_Succ)
  72.     moveq    #0,d0
  73. .updateCDloop
  74.     move.w    d0,cd_ChannelNo(a0)
  75.     lea    AHIChannelData_SIZEOF(a0),a1
  76.     move.l    a1,cd_Succ(a0)
  77.     add.w    #AHIChannelData_SIZEOF,a0
  78.     addq.w    #1,d0
  79.     cmp.w    ahiac_Channels(a2),d0
  80.     blo    .updateCDloop
  81.     clr.l    -AHIChannelData_SIZEOF+cd_Succ(a0)
  82.  
  83.     move.w    ahiac_Sounds(a2),d0
  84.     mulu.w    #AHISoundData_SIZEOF,d0
  85.     move.l    #MEMF_PUBLIC!MEMF_CLEAR,d1    ;may be accessed from interrupts!
  86.     call    AllocVec
  87.     move.l    d0,ahiac_SoundDatas(a2)
  88.     beq    .error
  89.  
  90. *** Update the SoundData structure
  91.     move.l    d0,a0
  92.     move.w    ahiac_Sounds(a2),d0
  93.     subq.w    #1,d0
  94. .updateSDloop
  95.     move.l    #AHIST_NOTYPE,sd_Type(a0)
  96.     add.w    #AHISoundData_SIZEOF,a0
  97.     dbf    d0,.updateSDloop
  98.  
  99.     moveq    #TRUE,d0
  100. .exit    
  101.     popm    d1-a6
  102.     rts
  103. .error
  104.     moveq    #FALSE,d0
  105.     bra    .exit
  106.  
  107.  
  108. ;in:
  109. * a2    ptr to AHIAudioCtrl
  110. _CleanUpMixroutine:
  111.     rts
  112.  
  113. ;in:
  114. * a2    AHIAudioCtrl
  115. _calcMasterVolumeTable:
  116.     pushm    std
  117.     btst.b    #AHIACB_CLIPPING-24,ahiac_Flags(a2)
  118.     beq    .exit
  119.  
  120.     btst    #AHIACB_HIFI,ahiac_Flags+3(a2)
  121.     bne    .exit
  122.  
  123.  
  124.     move.l    _SysBase,a6
  125.     move.l    ahiac_MasterVolumeTable(a2),d0
  126.     bne    .gottable
  127.     move.l    #65536*2,d0
  128.     moveq    #MEMF_PUBLIC,d1
  129.     call    AllocVec
  130.     move.l    d0,ahiac_MasterVolumeTable(a2)
  131.     beq    .exit
  132.  
  133. .gottable
  134.     move.l    d0,a0
  135.     moveq    #0,d0
  136.     move.l    ahiac_SetMasterVolume(a2),d1
  137.     lsr.l    #8,d1
  138. .loop
  139.     move.w    d0,d2
  140.     muls.w    d1,d2
  141.     asr.l    #8,d2
  142.     cmp.l    #32767,d2
  143.     ble    .noposclip
  144.     move.w    #32767,d2
  145. .noposclip
  146.     cmp.l    #-32768,d2
  147.     bge    .nonegclip
  148.     move.w    #-32768,d2
  149. .nonegclip
  150.     move.w    d2,(a0)+
  151.     addq.w    #1,d0
  152.     bne    .loop
  153. .exit
  154.     popm    std
  155.     rts
  156.  
  157. ;in:
  158. * a2    ptr to AHIAudioCtrl
  159. ;out:
  160. * d0    TRUE on success
  161. _initSignedTable:
  162.     pushm    d1-a6
  163.     
  164.     move.l    ahiac_Flags(a2),d0
  165.     btst.l    #AHIACB_MULTTAB,d0
  166.     beq.b    .notable
  167.     tst.l    ahiac_MultTableS(a2)
  168.     bne.b    .notable            ;there is already a table!
  169.  
  170.     move.l    _SysBase,a6
  171.     move.l    #256*(TABLEMAXVOL+1)*4,d0    ;include highest volume, too!
  172.     moveq    #MEMF_PUBLIC,d1            ;may be accessed from interrupts
  173.     call    AllocVec
  174.     move.l    d0,ahiac_MultTableS(a2)
  175.     beq.b    .error
  176.     bsr.b    _calcSignedTable
  177. .notable
  178.     moveq    #TRUE,d0
  179. .exit
  180.     popm    d1-a6
  181.     rts
  182. .error
  183.     moveq    #FALSE,d0
  184.     bra    .exit
  185.  
  186. * Create multiplication table for use with signed bytes/words.
  187. *
  188. * WORD hints:
  189. * // 0<=v<=32 // (h*256+l)*(v*2048)>>16 = ((h*v)<<8+(l*v))>>5
  190. *s    =$fffffcf4
  191. *h    =s>>8        ;signed
  192. *l    =s&255        ;unsigned
  193. *v    =16
  194. *    PRINTV    h*v,l*v
  195. *    PRINTV    ((h*v)<<8+(l*v))>>5
  196. *
  197. * Usage: a0 points to correct line in table
  198. *
  199. *        d1 is signed byte with bits 8-15 cleared:
  200. *        move.w  0(a0,d1.w*4),d2        ;d2 is signed!
  201. *
  202. *        d1 is unsigned byte with bits 8-15 cleared:
  203. *        move.w  2(a0,d1.w*4),d2        ;d2 is unsigned!
  204. _calcSignedTable:
  205.     pushm    d0-d4/a0
  206.     move.l    ahiac_MultTableS(a2),d0
  207.     beq.b    .notable
  208.     move.l    d0,a0
  209.     add.l    #256*(TABLEMAXVOL+1)*4,a0
  210.     move.w    ahiac_Channels2(a2),d3
  211.     lsl.w    #8,d3
  212.     move.l    ahiac_MasterVolume(a2),d4    ; Range: (0 .. 1.0 .. ??) * 65536
  213.     lsr.l    #8,d4
  214.     moveq.l    #(TABLEMAXVOL+1)-1,d0
  215. .10
  216.     move.w    #255,d1
  217. .11
  218.     move.w    d1,d2                ; Unsigned
  219.     mulu.w    d0,d2
  220.     mulu.w    d4,d2                ; *((Mastervolume*65536)/256)
  221.     lsl.l    #TABLESHIFT-8,d2
  222.     divu.w    d3,d2                ; /(Channels*256)
  223.     move.w    d2,-(a0)
  224.  
  225.     move.b    d1,d2                 ; Signed
  226.     ext.w    d2
  227.     muls.w    d0,d2
  228.     muls.w    d4,d2                ; *((Mastervolume*65536)/256)
  229.     asl.l    #TABLESHIFT-8,d2
  230.     divs.w    d3,d2                ; /(Channels*256)
  231.     move.w    d2,-(a0)
  232.  
  233.     dbf    d1,.11
  234.     dbf    d0,.10
  235. .notable
  236.     popm    d0-d4/a0
  237.     rts
  238. ;in:
  239. * a2    ptr to AHIAudioCtrl
  240. ;out:
  241. * d0    TRUE on success
  242. _initUnsignedTable:
  243.     pushm    d1-a6
  244.     move.l    ahiac_Flags(a2),d0
  245.  
  246. ; Unsigned samples unconditionally uses tables!
  247. ;    btst.l    #AHIACB_MULTTAB,d0
  248. ;    beq.b    .notable
  249.  
  250.     tst.l    ahiac_MultTableU(a2)
  251.     bne.b    .notable            ;there is already a table!
  252.  
  253.     move.l    _SysBase,a6
  254.     move.l    #256*(TABLEMAXVOL+1)*4,d0    ;incude highest volume, too!
  255.                         ;*4 => Look like the signed table!
  256.     moveq    #MEMF_PUBLIC,d1            ;may be accessed from interrupts
  257.     call    AllocVec
  258.     move.l    d0,ahiac_MultTableU(a2)
  259.     beq.b    .error
  260.     bsr.b    _calcUnsignedTable
  261. .notable
  262.     moveq    #TRUE,d0
  263. .exit
  264.     popm    d1-a6
  265.     rts
  266. .error
  267.     moveq    #FALSE,d0
  268.     bra    .exit
  269.  
  270. * Create multiplication table for use with unsigned bytes
  271. * Note: The table has valid values in every other word. This is
  272. * done in order to be able to use the same mixing routines for
  273. * both signed and unsigned samples.
  274. * Usage: a0 points to correct line in table
  275. *
  276. *        d1 is unsigned byte with bits 8-15 cleared:
  277. *        move.w  0(a0,d1.w*4),d2        ;d2 is signed!
  278. _calcUnsignedTable:
  279.     pushm    d0-d4/a0
  280.     move.l    ahiac_MultTableU(a2),d0
  281.     beq.b    .notable
  282.     move.l    d0,a0
  283.     add.l    #256*(TABLEMAXVOL+1)*4,a0
  284.     move.w    ahiac_Channels2(a2),d3
  285.     lsl.w    #8,d3
  286.     move.l    ahiac_MasterVolume(a2),d4    ; Range: (0 .. 1.0 .. ??) * 65536
  287.     lsr.l    #8,d4
  288.     moveq.l    #(TABLEMAXVOL+1)-1,d0
  289. .10
  290.     move.w    #255,d1
  291. .11
  292.     move.b    d1,d2                ; Unsigned
  293.     sub.b    #$80,d2                ; -> Signed
  294.     ext.w    d2
  295.     muls.w    d0,d2
  296.     muls.w    d4,d2                ; *((Mastervolume*65536)/256)
  297.     asl.l    #TABLESHIFT-8,d2
  298.     divs.w    d3,d2                ; /(Channels*256)
  299.     clr.w    -(a0)                ; Insert dummy value
  300.     move.w    d2,-(a0)
  301.  
  302.     dbf    d1,.11
  303.     dbf    d0,.10
  304. .notable
  305.     popm    d0-d4/a0
  306.     rts
  307.  
  308.  
  309. ;in:
  310. * d0    VolumeLeft (Fixed)
  311. * d1    VolumeRight (Fixed)
  312. * d2    SampleType
  313. * a0    LONG *ScaleLeft
  314. * a1    LONG *ScaleRight
  315. * a2    AudioCtrl
  316. * a3    void *AddRoutine
  317.  
  318. RIGHTVOLUME    EQU    1
  319. LEFTVOLUME    EQU    2
  320. FASTMIX        EQU    4
  321. STEREO        EQU    8
  322. HIFI        EQU    16
  323.  
  324. EIGHTBIT    EQU    0
  325. EIGHT2BIT    EQU    32
  326. SIXTEENBIT    EQU    64
  327. SIXTEEN2BIT    EQU    96
  328.  
  329. typeconversion:
  330.     dc.l    EIGHTBIT    ;AHIST_M8S  (0)
  331.     dc.l    SIXTEENBIT    ;AHIST_M16S (1)
  332.     dc.l    EIGHT2BIT    ;AHIST_S8S  (2)
  333.     dc.l    SIXTEEN2BIT    ;AHIST_S16S (3)
  334.     dc.l    -1        ;AHIST_M8U  (4) << OBSOLETE >>
  335.     dc.l    -1
  336.     dc.l    -1
  337.     dc.l    -1
  338.     dc.l    -1        ;AHIST_M32S (8)
  339.     dc.l    -1
  340.     dc.l    -1        ;AHIST_S32S (10)
  341.     dc.l    -1
  342.     dc.l    -1
  343.     dc.l    -1
  344.     dc.l    -1
  345.     dc.l    -1
  346.  
  347. _SelectAddRoutine:
  348.     pushm    d2-a6
  349.  
  350. ;    PRINTF    0,"SelectAddRoutine(%ld, %ld, %08lx)",d0, d1, d2
  351.  
  352.     move.l    a0,a4
  353.     move.l    a1,a5
  354.     move.l    a3,a6
  355.  
  356.     move.l    d2,d3
  357.     move.l    ahiac_Flags(a2),d4
  358.  
  359.     and.l    #~AHIST_BW,d2
  360.  
  361. ;FIXIT  -- Unsigned samples are obosolete, and should be removed!
  362.     cmp.l    #AHIST_M8U,d2
  363.     beq    sar_unsigned
  364.  
  365.     lsl.l    #2,d2
  366.     move.l    (typeconversion,pc,d2.l),d2
  367.     bmi    .error
  368.  
  369.     btst.l    #AHIACB_STEREO,d4
  370.     beq    .not_stereo
  371.     or.l    #STEREO,d2
  372. .not_stereo
  373.  
  374.     btst.l    #AHIACB_HIFI,d4
  375.     beq    .not_hifi
  376.     or.l    #HIFI,d2
  377. .not_hifi
  378.  
  379.  
  380. ; Don't use tables for negative volume!
  381.  
  382.     tst.l    d0
  383.     bmi    .no_tables
  384.     tst.l    d1
  385.     bmi    .no_tables
  386.  
  387.     move.l    d2,d5
  388.     and.l    #HIFI,d5
  389.     bne    .no_tables        ;No tables in HiFi mode
  390.  
  391.     tst.l    ahiac_MultTableS(a2)
  392.     beq    .no_tables
  393.     or.l    #FASTMIX,d2
  394.  
  395. ; Scale volume for 16 bit /w "tables"
  396.     move.l    d2,d5
  397.     and.l    #SIXTEENBIT,d5        ;check for SIXTEENBIT or SIXTEEN2BIT
  398.     bne    .no_tables
  399.  
  400.     bra    .check_volume
  401. .no_tables
  402.  
  403. ; Scale volume according to the master volume
  404.  
  405.     push    d2
  406.     moveq    #0,d2
  407.     move.w    ahiac_Channels2(a2),d2
  408.     lsl.w    #8,d2
  409.     move.l    ahiac_MasterVolume(a2),d5
  410.     asr.l    #8,d5
  411.  
  412.  IFGE    __CPU-68020
  413.     muls.l    d5,d0
  414.     divs.l    d2,d0
  415.     muls.l    d5,d1
  416.     divs.l    d2,d1
  417.  ELSE
  418.     move.l    _UtilityBase,a0
  419.     
  420.     push    d1
  421.     move.l    d5,d1
  422.     jsr    _LVOSMult32(a0)
  423.     move.l    d2,d1
  424.     jsr    _LVOSDivMod32(a0)
  425.     pop    d1
  426.  
  427.     push    d0
  428.     move.l    d1,d0
  429.     move.l    d5,d1
  430.     jsr    _LVOSMult32(a0)
  431.     move.l    d2,d1
  432.     jsr    _LVOSDivMod32(a0)
  433.     move.l    d0,d1
  434.     pop    d0
  435.  ENDC
  436.     pop    d2
  437.  
  438. .check_volume
  439.     tst.l    ahiac_MasterVolume(a2)
  440.     beq    .not_volume
  441.  
  442.     tst.l    d0
  443.     beq    .not_left_volume
  444.     or.l    #LEFTVOLUME,d2
  445. .not_left_volume
  446.  
  447.     tst.l    d1
  448.     beq    .not_right_volume
  449.     or.l    #RIGHTVOLUME,d2
  450. .not_right_volume
  451.  
  452. .not_volume
  453.     lsl.l    #2,d2
  454.     move.l    (functionstable,pc,d2.l),a0
  455. ;    PRINTF    0,"Func: 0x%08lx", a0
  456.     jsr    (a0)        ;returns d0, d1 and a0
  457.  
  458.     and.l    #AHIST_BW,d3
  459.     beq    .fw
  460.     add.w    #OffsetBackward,a0
  461. .fw
  462.  
  463.     add.w    (a0),a0
  464. .exit:
  465.     move.l    d0,(a4)
  466.     move.l    d1,(a5)
  467.     move.l    a0,(a6)
  468. ;    PRINTF    0, "SAR: %ld, %ld, 0x%08lx",(a4), (a5), (a6)
  469.     popm    d2-a6
  470.     rts
  471. .error
  472.     lea    .dummy(pc),a0
  473.     bra    .exit
  474. .dummy
  475.     rts
  476.  
  477. ;FIXIT -- OBSOLETE!
  478.  
  479. sar_unsigned:
  480.     pea    .exit(pc)
  481.     tst.l    d0
  482.     bmi    FixVolSilence        ;Error
  483.     tst.l    d1
  484.     bmi    FixVolSilence        ;Error
  485.     tst.l    ahiac_MultTableU(a2)
  486.     beq    FixVolSilence        ;Error
  487.  
  488.     btst.l    #AHIACB_STEREO,d4
  489.     bne    .stereo
  490.     bra    FixVolUByteMVT
  491. .stereo
  492.     tst.l    d0
  493.     beq    FixVolUByteSVTr
  494.     tst.l    d1
  495.     beq    FixVolUByteSVTl
  496.     bra    FixVolUByteSVPT    
  497.  
  498. .exit:
  499.     and.l    #AHIST_BW,d3
  500.     beq    .fw
  501.     add.w    #OffsetBackward,a0
  502. .fw
  503.  
  504.     add.w    (a0),a0
  505.  
  506.     move.l    d0,(a4)
  507.     move.l    d1,(a5)
  508.     move.l    a0,(a6)
  509.     popm    d2-a6
  510.     rts
  511.  
  512. functionstable:
  513.                     ; Type    HiFi    Stereo    FastMix    Left    Right
  514.     dc.l    FixVolSilence        ; 8    -    -    -    -    -
  515.     dc.l    FixVolByteMV        ; 8    -    -    -    -    *
  516.     dc.l    FixVolByteMV        ; 8    -    -    -    *    -
  517.     dc.l    FixVolByteMV        ; 8    -    -    -    *    *
  518.     dc.l    FixVolSilence        ; 8    -    -    *    -    -
  519.     dc.l    FixVolByteMVT        ; 8    -    -    *    -    *
  520.     dc.l    FixVolByteMVT        ; 8    -    -    *    *    -
  521.     dc.l    FixVolByteMVT        ; 8    -    -    *    *    *
  522.     dc.l    FixVolSilence        ; 8    -    *    -    -    -
  523.     dc.l    FixVolByteSVr        ; 8    -    *    -    -    *
  524.     dc.l    FixVolByteSVl        ; 8    -    *    -    *    -
  525.     dc.l    FixVolByteSVP        ; 8    -    *    -    *    *
  526.     dc.l    FixVolSilence        ; 8    -    *    *    -    -
  527.     dc.l    FixVolByteSVTr        ; 8    -    *    *    -    *
  528.     dc.l    FixVolByteSVTl        ; 8    -    *    *    *    -
  529.     dc.l    FixVolByteSVPT        ; 8    -    *    *    *    *
  530.     dc.l    FixVolSilence        ; 8    *    -    -    -    -
  531.     dc.l    FixVolByteMVH        ; 8    *    -    -    -    *
  532.     dc.l    FixVolByteMVH        ; 8    *    -    -    *    -
  533.     dc.l    FixVolByteMVH        ; 8    *    -    -    *    *
  534.     dc.l    FixVolSilence        ; 8    *    -    *    -    -
  535.     dc.l    FixVolByteMVH        ; 8    *    -    *    -    *
  536.     dc.l    FixVolByteMVH        ; 8    *    -    *    *    -
  537.     dc.l    FixVolByteMVH        ; 8    *    -    *    *    *
  538.     dc.l    FixVolSilence        ; 8    *    *    -    -    -
  539.     dc.l    FixVolByteSVPH        ; 8    *    *    -    -    *
  540.     dc.l    FixVolByteSVPH        ; 8    *    *    -    *    -
  541.     dc.l    FixVolByteSVPH        ; 8    *    *    -    *    *
  542.     dc.l    FixVolSilence        ; 8    *    *    *    -    -
  543.     dc.l    FixVolByteSVPH        ; 8    *    *    *    -    *
  544.     dc.l    FixVolByteSVPH        ; 8    *    *    *    *    -
  545.     dc.l    FixVolByteSVPH        ; 8    *    *    *    *    *
  546.     dc.l    FixVolSilence        ; 8×2    -    -    -    -    -
  547.     dc.l    FixVolBytesMV        ; 8×2    -    -    -    -    *
  548.     dc.l    FixVolBytesMV        ; 8×2    -    -    -    *    -
  549.     dc.l    FixVolBytesMV        ; 8×2    -    -    -    *    *
  550.     dc.l    FixVolSilence        ; 8×2    -    -    *    -    -
  551.     dc.l    FixVolBytesMVT        ; 8×2    -    -    *    -    *
  552.     dc.l    FixVolBytesMVT        ; 8×2    -    -    *    *    -
  553.     dc.l    FixVolBytesMVT        ; 8×2    -    -    *    *    *
  554.     dc.l    FixVolSilence        ; 8×2    -    *    -    -    -
  555.     dc.l    FixVolBytesSVr        ; 8×2    -    *    -    -    *
  556.     dc.l    FixVolBytesSVl        ; 8×2    -    *    -    *    -
  557.     dc.l    FixVolBytesSVP        ; 8×2    -    *    -    *    *
  558.     dc.l    FixVolSilence        ; 8×2    -    *    *    -    -
  559.     dc.l    FixVolBytesSVTr        ; 8×2    -    *    *    -    *
  560.     dc.l    FixVolBytesSVTl        ; 8×2    -    *    *    *    -
  561.     dc.l    FixVolBytesSVPT        ; 8×2    -    *    *    *    *
  562.     dc.l    FixVolSilence        ; 8×2    *    -    -    -    -
  563.     dc.l    FixVolBytesMVH        ; 8×2    *    -    -    -    *
  564.     dc.l    FixVolBytesMVH        ; 8×2    *    -    -    *    -
  565.     dc.l    FixVolBytesMVH        ; 8×2    *    -    -    *    *
  566.     dc.l    FixVolSilence        ; 8×2    *    -    *    -    -
  567.     dc.l    FixVolBytesMVH        ; 8×2    *    -    *    -    *
  568.     dc.l    FixVolBytesMVH        ; 8×2    *    -    *    *    -
  569.     dc.l    FixVolBytesMVH        ; 8×2    *    -    *    *    *
  570.     dc.l    FixVolSilence        ; 8×2    *    *    -    -    -
  571.     dc.l    FixVolBytesSVPH        ; 8×2    *    *    -    -    *
  572.     dc.l    FixVolBytesSVPH        ; 8×2    *    *    -    *    -
  573.     dc.l    FixVolBytesSVPH        ; 8×2    *    *    -    *    *
  574.     dc.l    FixVolSilence        ; 8×2    *    *    *    -    -
  575.     dc.l    FixVolBytesSVPH        ; 8×2    *    *    *    -    *
  576.     dc.l    FixVolBytesSVPH        ; 8×2    *    *    *    *    -
  577.     dc.l    FixVolBytesSVPH        ; 8×2    *    *    *    *    *
  578.     dc.l    FixVolSilence        ; 16    -    -    -    -    -
  579.     dc.l    FixVolWordMV        ; 16    -    -    -    -    *
  580.     dc.l    FixVolWordMV        ; 16    -    -    -    *    -
  581.     dc.l    FixVolWordMV        ; 16    -    -    -    *    *
  582.     dc.l    FixVolSilence        ; 16    -    -    *    -    -
  583.     dc.l    FixVolWordMVT        ; 16    -    -    *    -    *
  584.     dc.l    FixVolWordMVT        ; 16    -    -    *    *    -
  585.     dc.l    FixVolWordMVT        ; 16    -    -    *    *    *
  586.     dc.l    FixVolSilence        ; 16    -    *    -    -    -
  587.     dc.l    FixVolWordSVr        ; 16    -    *    -    -    *
  588.     dc.l    FixVolWordSVl        ; 16    -    *    -    *    -
  589.     dc.l    FixVolWordSVP        ; 16    -    *    -    *    *
  590.     dc.l    FixVolSilence        ; 16    -    *    *    -    -
  591.     dc.l    FixVolWordSVTr        ; 16    -    *    *    -    *
  592.     dc.l    FixVolWordSVTl        ; 16    -    *    *    *    -
  593.     dc.l    FixVolWordSVPT        ; 16    -    *    *    *    *
  594.     dc.l    FixVolSilence        ; 16    *    -    -    -    -
  595.     dc.l    FixVolWordMVH        ; 16    *    -    -    -    *
  596.     dc.l    FixVolWordMVH        ; 16    *    -    -    *    -
  597.     dc.l    FixVolWordMVH        ; 16    *    -    -    *    *
  598.     dc.l    FixVolSilence        ; 16    *    -    *    -    -
  599.     dc.l    FixVolWordMVH        ; 16    *    -    *    -    *
  600.     dc.l    FixVolWordMVH        ; 16    *    -    *    *    -
  601.     dc.l    FixVolWordMVH        ; 16    *    -    *    *    *
  602.     dc.l    FixVolSilence        ; 16    *    *    -    -    -
  603.     dc.l    FixVolWordSVPH        ; 16    *    *    -    -    *
  604.     dc.l    FixVolWordSVPH        ; 16    *    *    -    *    -
  605.     dc.l    FixVolWordSVPH        ; 16    *    *    -    *    *
  606.     dc.l    FixVolSilence        ; 16    *    *    *    -    -
  607.     dc.l    FixVolWordSVPH        ; 16    *    *    *    -    *
  608.     dc.l    FixVolWordSVPH        ; 16    *    *    *    *    -
  609.     dc.l    FixVolWordSVPH        ; 16    *    *    *    *    *
  610.     dc.l    FixVolSilence        ; 16×2    -    -    -    -    -
  611.     dc.l    FixVolWordsMV        ; 16×2    -    -    -    -    *
  612.     dc.l    FixVolWordsMV        ; 16×2    -    -    -    *    -
  613.     dc.l    FixVolWordsMV        ; 16×2    -    -    -    *    *
  614.     dc.l    FixVolSilence        ; 16×2    -    -    *    -    -
  615.     dc.l    FixVolWordsMVT        ; 16×2    -    -    *    -    *
  616.     dc.l    FixVolWordsMVT        ; 16×2    -    -    *    *    -
  617.     dc.l    FixVolWordsMVT        ; 16×2    -    -    *    *    *
  618.     dc.l    FixVolSilence        ; 16×2    -    *    -    -    -
  619.     dc.l    FixVolWordsSVr        ; 16×2    -    *    -    -    *
  620.     dc.l    FixVolWordsSVl        ; 16×2    -    *    -    *    -
  621.     dc.l    FixVolWordsSVP        ; 16×2    -    *    -    *    *
  622.     dc.l    FixVolSilence        ; 16×2    -    *    *    -    -
  623.     dc.l    FixVolWordsSVTr        ; 16×2    -    *    *    -    *
  624.     dc.l    FixVolWordsSVTl        ; 16×2    -    *    *    *    -
  625.     dc.l    FixVolWordsSVPT        ; 16×2    -    *    *    *    *
  626.     dc.l    FixVolSilence        ; 16×2    *    -    -    -    -
  627.     dc.l    FixVolWordsMVH        ; 16×2    *    -    -    -    *
  628.     dc.l    FixVolWordsMVH        ; 16×2    *    -    -    *    -
  629.     dc.l    FixVolWordsMVH        ; 16×2    *    -    -    *    *
  630.     dc.l    FixVolSilence        ; 16×2    *    -    *    -    -
  631.     dc.l    FixVolWordsMVH        ; 16×2    *    -    *    -    *
  632.     dc.l    FixVolWordsMVH        ; 16×2    *    -    *    *    -
  633.     dc.l    FixVolWordsMVH        ; 16×2    *    -    *    *    *
  634.     dc.l    FixVolSilence        ; 16×2    *    *    -    -    -
  635.     dc.l    FixVolWordsSVPH        ; 16×2    *    *    -    -    *
  636.     dc.l    FixVolWordsSVPH        ; 16×2    *    *    -    *    -
  637.     dc.l    FixVolWordsSVPH        ; 16×2    *    *    -    *    *
  638.     dc.l    FixVolSilence        ; 16×2    *    *    *    -    -
  639.     dc.l    FixVolWordsSVPH        ; 16×2    *    *    *    -    *
  640.     dc.l    FixVolWordsSVPH        ; 16×2    *    *    *    *    -
  641.     dc.l    FixVolWordsSVPH        ; 16×2    *    *    *    *    *
  642.  
  643.  
  644.  
  645. *
  646. * The mixing routine mixes ahiac_BuffSamples each pass, fitting in
  647. * ahiac_BuffSizeNow bytes. ahiac_BuffSizeNow must be an even multiplier
  648. * of 8.
  649. *
  650.  
  651. ;in:
  652. * a0    Hook
  653. * a1    Mixing buffer (size is 8 byte aligned)
  654. * a2    AHIAudioCtrl
  655. _Mix68k:
  656.     pushm    d0-a6
  657.  
  658. ;    PRINTF    0,"Mix!"
  659. * Clear the buffer
  660.     move.l    ahiac_BuffSizeNow(a2),d0
  661.     lsr.l    #3,d0
  662.     subq.w    #1,d0
  663.     move.l    a1,a0
  664. .clearbuff
  665.     clr.l    (a0)+
  666.     clr.l    (a0)+
  667.     dbf    d0,.clearbuff
  668.  
  669. * Mix the samples
  670.     clr.b    ahiac_WetOrDry(a2)
  671.     move.l    ahiac_WetList(a2),d0
  672.     move.l    d0,a5
  673.     beq    .do_dry
  674.  
  675. .nextchannel
  676.     move.l    ahiac_BuffSamples(a2),d0
  677.     move.l    a1,a4            ;output buffer
  678.  
  679. .contchannel
  680.     tst.w    cd_EOS(a5)
  681.     beq    .notEOS
  682.  
  683. * Call Sound Hook
  684.     move.l    ahiac_SoundFunc(a2),d1
  685.     beq    .noSoundFunc
  686.     pushm    d0/a1
  687.     move.l    d1,a0
  688.     lea    cd_ChannelNo(a5),a1
  689.     move.l    h_Entry(a0),a3
  690.     jsr    (a3)            ;a2 ready
  691.     popm    d0/a1
  692. .noSoundFunc
  693.     clr.w    cd_EOS(a5)        ;clear EOS flag
  694. .notEOS
  695.  
  696.     movem.l    (a5),d1/d3/d4/d5/d6/a3    ;Flags,Offset,Add,DataStart
  697.     cmp.w    #TRUE<<8 | TRUE,d1    ;FreqOK and SoundOK must both be TRUE
  698.     bne    .channel_done        ;No sound or freq not set yet.
  699.  
  700.     cmp.l    cd_Samples(a5),d0
  701.     blo    .wont_reach_end
  702.  
  703. * How may samples left?
  704.     sub.l    cd_Samples(a5),d0
  705.  
  706.     push    d0
  707.     move.l    cd_Samples(a5),d0
  708.  
  709.     movem.l    cd_ScaleLeft(a5),d1/d2/a0
  710.     jsr    (a0)
  711.     move.l    cd_TempLastSampleL(a5),cd_LastSampleL(a5) ;linear interpol. stuff
  712.     move.l    cd_TempLastSampleR(a5),cd_LastSampleR(a5) ;linear interpol. stuff
  713.  
  714. ; d3:d4 always points OUTSIDE the sample after this call. Ie, if we read a
  715. ; sample at offset d3 now, it does not belong to the sample just played.
  716. ; This is true for both backward and forward mixing.
  717. ; Oh, btw... OffsetF is unsigned, so -0.5 is expressed as -1:$80000000.
  718.  
  719. ; What we do now is to calculate how much futher we have advanced.
  720.     sub.l    cd_LastOffset+F64_F(a5),d4
  721.     move.l    cd_LastOffset+F64_I(a5),d0
  722.     subx.l    d0,d3
  723.  
  724. ; d3:d4 should now be added to the NEXT OffsetI (and OffsetF which is 0 when
  725. ; every sample begin).
  726. ; d3:d4 is positive of the sample was mixed forwards, and negative if the sample
  727. ; was mixed backwards. There is one catch, however. If the direction is about
  728. ; to change now, d3:d4 should instead be SUBTRACTED. Let's check:
  729.     move.l    cd_Type(a5),d0
  730.     move.l    cd_NextType(a5),d1
  731.     eor.l    d0,d1
  732.     and.l    #AHIST_BW,d1            ;filter the BW bit
  733.     beq.b    .same_type
  734.     neg.l    d3
  735.     neg.l    d4
  736. .same_type
  737.  
  738. ; Ok, now we add.
  739.     add.l    cd_NextOffset+F64_F(a5),d4
  740.     move.l    cd_NextOffset+F64_I(a5),d0
  741.     addx.l    d0,d3
  742.     move.l    d3,cd_Offset+F64_I(a5)
  743.     move.l    d4,cd_Offset+F64_F(a5)
  744.     move.l    d3,cd_FirstOffsetI(a5)
  745.  
  746. ; But what if the next sample is so short that we just passed it!?
  747. ; Here is the nice part. CalcSamples checks this,
  748. ; and sets cd_Samples to 0 in that case. And the add routines doesn't
  749. ; do anything when asked to mix 0 samples.
  750. ; Assume we have passed a sample with 4 samples, and the next one
  751. ; is only 3. CalcSamples returns 0. The 'jsr (a0)' call above does
  752. ; not do anything at all, OffsetI is still 4. Now we subtract LastOffsetI,
  753. ; which is 3. Result: We have passed the sample with 1. And guess what?
  754. ; That's in range.
  755.  
  756. ; Now, let's copy the rest of the cd_Next#? stuff...
  757.     move.l    cd_NextFlags(a5),cd_Flags(a5)
  758.     movem.l    cd_NextAdd(a5),d0-d7/a0/a3/a6    ; Add,DataStart,LastOffset,ScaleLeft,ScaleRight,AddRoutine, VolumeLeft,VolumeRight,Type
  759.     movem.l    d0-d7/a0/a3/a6,cd_Add(a5)
  760.  
  761.                     ;Add,LastOffset ok
  762.     move.l    a6,d2            ;Type
  763.     movem.l    cd_Offset(a5),d5/d6    ;cd_Offset+F64_I/cd_Offset+F64_F
  764.     bsr    _CalcSamples
  765.     move.l    d0,cd_Samples(a5)
  766.  
  767.     pop    d0
  768.     move.w    #TRUE,cd_EOS(a5)    ;signal End-Of-Sample
  769.     bra.w    .contchannel        ;same channel, new sound
  770.  
  771. .wont_reach_end
  772.     sub.l    d0,cd_Samples(a5)
  773.     movem.l    cd_ScaleLeft(a5),d1/d2/a0
  774.     jsr    (a0)
  775.     movem.l    d3/d4,cd_Offset(a5)    ;update Offset
  776.  
  777. .channel_done
  778.     move.l    cd_Succ(a5),d0        ;next channel in list
  779.     move.l    d0,a5
  780.     bne    .nextchannel
  781.     tst.b    ahiac_WetOrDry(a2)
  782.     bne.b    .exit            ;Both wet and dry finished
  783.     addq.b    #1,ahiac_WetOrDry(a2)    ;Mark dry
  784.  
  785.     pushm    a0-a6
  786. *** AHIET_DSPECHO
  787.     move.l    ahiac_EffDSPEchoStruct(a2),d0
  788.     beq    .noEffDSPEcho
  789.     move.l    d0,a0
  790.     move.l    ahiecho_Code(a0),a3
  791.     jsr    (a3)
  792. .noEffDSPEcho
  793.     popm    a0-a6
  794.  
  795. .do_dry
  796.     move.l    ahiac_DryList(a2),d0
  797.     move.l    d0,a5
  798.     beq    .exit
  799.     btst.b    #AHIACB_POSTPROC-24,ahiac_Flags(a2)
  800.     beq    .nextchannel
  801.  
  802. *** AHIET_MASTERVOLUME
  803.     bsr    DoMasterVolume
  804.  
  805. ; BUG!! FIXIT! If there are no wet channels, and postprocessing is on,
  806. ; a4 will be uninitialized!!
  807.     move.l    a4,a1            ;New block
  808.     bra    .nextchannel
  809.  
  810. .exit
  811.  
  812. *** AHIET_MASTERVOLUME
  813.     bsr    DoMasterVolume
  814.  
  815. *** AHIET_OUTPUTBUFFER
  816.     move.l    ahiac_EffOutputBufferStruct(a2),d0
  817.     beq    .noEffOutputBuffer
  818.     move.l    a1,a4
  819.     move.l    d0,a1
  820.     move.l    ahieob_Func(a1),a0
  821.     move.l    a4,ahieob_Buffer(a1)
  822.     move.l    ahiac_BuffSamples(a2),ahieob_Length(a1)
  823.     move.l    ahiac_BuffType(a2),ahieob_Type(a1)
  824.     move.l    h_Entry(a0),a3
  825.     jsr    (a3)
  826. .noEffOutputBuffer
  827.  
  828. *** AHIET_CHANNELINFO
  829.     move.l    ahiac_EffChannelInfoStruct(a2),d0
  830.     beq    .noEffChannelInfo
  831.     move.l    d0,a1
  832.     move.l    ahieci_Func(a1),a0
  833.     move.w    ahieci_Channels(a1),d0
  834.     subq.w    #1,d0
  835.     lea    ahieci_Offset(a1),a3
  836.     move.l    ahiac_ChannelDatas(a2),a4
  837. .ci_loop
  838.     move.l    cd_Offset+F64_I(a4),(a3)+
  839.     add.w    #AHIChannelData_SIZEOF,a4
  840.     dbf    d0,.ci_loop
  841.     move.l    h_Entry(a0),a3
  842.     jsr    (a3)
  843. .noEffChannelInfo
  844.  
  845.  
  846.     popm    d0-a6
  847.     rts
  848.  
  849.  
  850. ;in:
  851. * a1    Buffer
  852. * a2    Audioctrl
  853. DoMasterVolume
  854.     pushm    d0-d2/a0-a1
  855.  
  856.     btst.b    #AHIACB_CLIPPING-24,ahiac_Flags(a2)
  857.     beq    .noclipping
  858.  
  859.     move.l    ahiac_BuffSamples(a2),d0
  860.     btst.b    #AHIACB_STEREO,ahiac_Flags+3(a2)
  861.     beq    .notstereo
  862.     lsl.l    #1,d0
  863. .notstereo
  864.  
  865.     btst.b    #AHIACB_HIFI,ahiac_Flags+3(a2)
  866.     bne    .32bit
  867.     move.l    ahiac_MasterVolumeTable(a2),d1
  868.     move.l    d1,a0
  869.     beq    .16bit
  870.  
  871. .16bittable
  872.     moveq    #0,d1
  873. .16bittable_loop
  874.  IFGE    __CPU-68020
  875.     move.w    (a1),d1
  876.     move.w    (a0,d1.l*2),(a1)+
  877.  ELSE
  878.     moveq    #0,d1
  879.     move.w    (a1),d1
  880.     add.w    d1,d1
  881.     move.w    (a0,d1.l),(a1)+
  882.  ENDC
  883.     subq.l    #1,d0
  884.     bne    .16bittable_loop
  885.     bra    .exit
  886.  
  887. .16bit
  888.     move.l    ahiac_SetMasterVolume(a2),d1
  889.     lsr.l    #8,d1
  890. .16bit_loop
  891.     move.w    (a1),d2
  892.     muls.w    d1,d2
  893.     asr.l    #8,d2
  894.     cmp.l    #32767,d2
  895.     ble    .16bit_noposclip
  896.     move.w    #32767,d2
  897. .16bit_noposclip
  898.     cmp.l    #-32768,d2
  899.     bge    .16bit_nonegclip
  900.     move.w    #-32768,d2
  901. .16bit_nonegclip
  902.     move.w    d2,(a1)+
  903.     subq.l    #1,d0
  904.     bne    .16bit_loop
  905.     bra    .exit
  906.  
  907. .32bit
  908.  IFGE    __CPU-68020
  909.     move.l    ahiac_SetMasterVolume(a2),d1
  910.     lsr.l    #8,d1
  911. .32bit_loop
  912.     move.l    (a1),d2
  913.     asr.l    #8,d2
  914.     muls.l    d1,d2
  915.     bvc    .32bit_store
  916.     bpl    .32bit_negclip
  917.     move.l    #$7fffffff,d2        ; MAXINT
  918.     bra    .32bit_store
  919. .32bit_negclip
  920.     move.l    #$80000000,d2        ; MININT
  921. .32bit_store
  922.     move.l    d2,(a1)+
  923.     subq.l    #1,d0
  924.     bne    .32bit_loop
  925.     bra    .exit
  926.  ENDIF
  927. .exit
  928.  
  929. .noclipping
  930.     popm    d0-d2/a0-a1
  931.     rts
  932.  
  933. ;in:
  934. * d0    AddI
  935. * d1    AddF
  936. * d2    Type
  937. * d3    LastOffsetI
  938. * d4    LastOffsetF
  939. * d5    OffsetI
  940. * d6    OffsetF
  941. ;ut:
  942. * d0    Samples
  943. _CalcSamples:
  944. * Calc how many loops the addroutines should run (Times=Length/Rate)
  945.  
  946. ; Quick fix when changed fraction to 32 bits...
  947.     swap.w    d1
  948.     swap.w    d4
  949.     swap.w    d6
  950.  
  951.     and.l    #AHIST_BW,d2
  952.     bne    .backwards
  953.     sub.w    d6,d4
  954.     subx.l    d5,d3
  955.     bra    .1
  956. .backwards
  957.     sub.w    d4,d6
  958.     subx.l    d3,d5
  959.     move.w    d6,d4
  960.     move.l    d5,d3
  961. .1
  962.     bmi    .error
  963.   IFLT    __CPU-68060
  964.     swap.w    d4
  965.     move.w    d3,d4
  966.     swap.w    d4
  967.     clr.w    d3
  968.     swap.w    d3
  969. ; d3:d4 is now (positive) length <<16
  970.  
  971.     swap    d0
  972.     move.w    d1,d0
  973.     tst.l    d0
  974.     beq    .error
  975. ; d0 is now rate<<16
  976.  
  977.   IFGE    __CPU-68020
  978.     divu.l    d0,d3:d4
  979.     move.l    d4,d0
  980.   ELSE
  981.     move.l    d3,d1
  982.     move.l    d4,d2
  983.     jsr    _UDivMod64        ;d0 = (d1:d2)/d0
  984.   ENDC * 68020
  985.     addq.l    #1,d0
  986.  
  987.  ELSE
  988.  
  989. *
  990. * BAHH! It doesn't work!
  991. *
  992. ;    fmove.l    d3,fp0
  993. ;    fmove.l    #65536,fp2
  994. ;    fmul    fp2,fp0
  995. ;    fmove.l    d0,fp1
  996. ;    fadd.w    d4,fp0
  997. ;    fmul    fp2,fp1
  998. ;    fadd.w    d1,fp1
  999. ;    fbeq    .error
  1000. ;    fdiv    fp1,fp0
  1001. ;    fmove.l    fp0,d0
  1002.  
  1003.     swap.w    d4
  1004.     move.w    d3,d4
  1005.     swap.w    d4
  1006.     clr.w    d3
  1007.     swap.w    d3
  1008.     swap    d0
  1009.     move.w    d1,d0
  1010.     tst.l    d0
  1011.     beq    .error
  1012.     move.l    d3,d1
  1013.     move.l    d4,d2
  1014.     jsr    _UDivMod64        ;d0 = (d1:d2)/d0
  1015.     addq.l    #1,d0
  1016.  ENDC * 68060
  1017.  
  1018.     rts
  1019. .error
  1020.     moveq    #0,d0
  1021.     rts
  1022.  
  1023.  
  1024. * ALL FIXVOL RUTINES:
  1025. ;in:
  1026. * d0    VolumeLeft (Fixed)
  1027. * d1    VolumeRight (Fixed)
  1028. * d3    Sample type (or:ed with AHIST_BW if backward play)
  1029. * a2    AudioCtrl
  1030. ;out:
  1031. * d0    ScaleLeft
  1032. * d1    ScaleRight (if needed)
  1033. * a0    Pointer to correct Offs#? label
  1034.  
  1035.  
  1036. ;******************************************************************************
  1037.  
  1038. ;FIXIT -- OBSOLETE!
  1039.  
  1040. FixVolUByteMVT:
  1041.     add.l    d1,d0
  1042.     move.l    ahiac_MultTableU(a2),a0
  1043.     lsr.l    #TABLESHIFT-(8+2),d0
  1044.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d0
  1045.     add.l    a0,d0
  1046.     lea    OffsByteMVT(pc),a0        ;Reuse!
  1047.     rts
  1048.  
  1049. FixVolUByteSVTl:
  1050.     move.l    ahiac_MultTableU(a2),a0
  1051.     lsr.l    #TABLESHIFT-(8+2),d0
  1052.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d0
  1053.     add.l    a0,d0
  1054.     lea    OffsByteSVTl(pc),a0        ;Reuse!
  1055.     rts
  1056.  
  1057. FixVolUByteSVTr:
  1058.     move.l    ahiac_MultTableU(a2),a0
  1059.     lsr.l    #TABLESHIFT-(8+2),d1
  1060.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d1
  1061.     add.l    a0,d1
  1062.     lea    OffsByteSVTr(pc),a0        ;Reuse!
  1063.     rts
  1064.  
  1065. FixVolUByteSVPT:
  1066.     move.l    ahiac_MultTableU(a2),a0
  1067.     lsr.l    #TABLESHIFT-(8+2),d0
  1068.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d0
  1069.     add.l    a0,d0
  1070.     lsr.l    #TABLESHIFT-(8+2),d1
  1071.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d1
  1072.     add.l    a0,d1
  1073.     lea    OffsByteSVPT(pc),a0        ;Reuse!
  1074.     rts
  1075.  
  1076.  
  1077. ;******************************************************************************
  1078.  
  1079. FixVolSilence:
  1080.     lea    OffsSilence(pc),a0
  1081.     rts
  1082.  
  1083. ;******************************************************************************
  1084.  
  1085. FixVolByteMV:
  1086.     add.l    d1,d0
  1087.     asr.l    #8,d0
  1088.     lea    OffsByteMV(pc),a0
  1089.     rts
  1090.  
  1091. FixVolByteMVT:
  1092.     add.l    d1,d0
  1093.     move.l    ahiac_MultTableS(a2),a0
  1094.     lsr.l    #TABLESHIFT-(8+2),d0
  1095.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d0
  1096.     add.l    a0,d0
  1097.     lea    OffsByteMVT(pc),a0
  1098.     rts
  1099.  
  1100. FixVolByteSVl:
  1101.     asr.l    #8,d0
  1102.     lea    OffsByteSVl(pc),a0
  1103.     rts
  1104.  
  1105. FixVolByteSVr:
  1106.     asr.l    #8,d1
  1107.     lea    OffsByteSVr(pc),a0
  1108.     rts
  1109.  
  1110. FixVolByteSVP:
  1111.     asr.l    #8,d0
  1112.     asr.l    #8,d1
  1113.     lea    OffsByteSVP(pc),a0
  1114.     rts
  1115.  
  1116. FixVolByteSVTl:
  1117.     move.l    ahiac_MultTableS(a2),a0
  1118.     lsr.l    #TABLESHIFT-(8+2),d0
  1119.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d0
  1120.     add.l    a0,d0
  1121.     lea    OffsByteSVTl(pc),a0
  1122.     rts
  1123.  
  1124. FixVolByteSVTr:
  1125.     move.l    ahiac_MultTableS(a2),a0
  1126.     lsr.l    #TABLESHIFT-(8+2),d1
  1127.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d1
  1128.     add.l    a0,d1
  1129.     lea    OffsByteSVTr(pc),a0
  1130.     rts
  1131.  
  1132. FixVolByteSVPT:
  1133.     move.l    ahiac_MultTableS(a2),a0
  1134.     lsr.l    #TABLESHIFT-(8+2),d0
  1135.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d0
  1136.     add.l    a0,d0
  1137.     lsr.l    #TABLESHIFT-(8+2),d1
  1138.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d1
  1139.     add.l    a0,d1
  1140.     lea    OffsByteSVPT(pc),a0
  1141.     rts
  1142.  
  1143. FixVolByteMVH:
  1144.     add.l    d1,d0
  1145.     lea    OffsByteMVH(pc),a0
  1146.     rts
  1147.  
  1148. FixVolByteSVPH:
  1149.     lea    OffsByteSVPH(pc),a0
  1150.     rts
  1151.  
  1152. ;******************************************************************************
  1153.  
  1154. FixVolBytesMV:
  1155.     asr.l    #8,d0
  1156.     asr.l    #8,d1
  1157.     lea    OffsBytesMV(pc),a0
  1158.     rts
  1159.  
  1160. FixVolBytesMVT:
  1161.     move.l    ahiac_MultTableS(a2),a0
  1162.     lsr.l    #TABLESHIFT-(8+2),d0
  1163.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d0
  1164.     add.l    a0,d0
  1165.     lsr.l    #TABLESHIFT-(8+2),d1
  1166.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d1
  1167.     add.l    a0,d1
  1168.     lea    OffsBytesMVT(pc),a0
  1169.     rts
  1170.  
  1171. FixVolBytesSVl:
  1172.     asr.l    #8,d0
  1173.     lea    OffsBytesSVl(pc),a0
  1174.     rts
  1175.  
  1176. FixVolBytesSVr:
  1177.     asr.l    #8,d1
  1178.     lea    OffsBytesSVr(pc),a0
  1179.     rts
  1180.  
  1181. FixVolBytesSVP:
  1182.     asr.l    #8,d0
  1183.     asr.l    #8,d1
  1184.     lea    OffsBytesSVP(pc),a0
  1185.     rts
  1186.  
  1187. FixVolBytesSVTl:
  1188.     move.l    ahiac_MultTableS(a2),a0
  1189.     lsr.l    #TABLESHIFT-(8+2),d0
  1190.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d0
  1191.     add.l    a0,d0
  1192.     lea    OffsBytesSVTl(pc),a0
  1193.     rts
  1194.  
  1195. FixVolBytesSVTr:
  1196.     move.l    ahiac_MultTableS(a2),a0
  1197.     lsr.l    #TABLESHIFT-(8+2),d1
  1198.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d1
  1199.     add.l    a0,d1
  1200.     lea    OffsBytesSVTr(pc),a0
  1201.     rts
  1202.  
  1203. FixVolBytesSVPT:
  1204.     move.l    ahiac_MultTableS(a2),a0
  1205.     lsr.l    #TABLESHIFT-(8+2),d0
  1206.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d0
  1207.     add.l    a0,d0
  1208.     lsr.l    #TABLESHIFT-(8+2),d1
  1209.     and.l    #(TABLEMAXVOL*2-1)<<(8+2),d1
  1210.     add.l    a0,d1
  1211.     lea    OffsBytesSVPT(pc),a0
  1212.     rts
  1213.  
  1214. FixVolBytesMVH:
  1215.     lea    OffsBytesMVH(pc),a0
  1216.     rts
  1217.  
  1218. FixVolBytesSVPH:
  1219.     lea    OffsBytesSVPH(pc),a0
  1220.     rts
  1221.  
  1222. ;******************************************************************************
  1223.  
  1224. FixVolWordMV:
  1225.     add.l    d1,d0
  1226.  IFGE    __CPU-68020
  1227.     cmp.l    #$10000,d0        ; Fix: 32768 doesn't fit a WORD!
  1228.     bne    .1
  1229.     move.l    #$ffff,d0
  1230. .1
  1231.     asr.l    #1,d0
  1232.  ELSE
  1233.     asr.l    #8,d0
  1234.  ENDC
  1235.     lea    OffsWordMV(pc),a0
  1236.     rts
  1237.  
  1238. FixVolWordMVT:
  1239.     add.l    d1,d0
  1240.     jsr    _Fixed2Shift
  1241.     lea    OffsWordMVT(pc),a0
  1242.     rts
  1243.  
  1244. FixVolWordSVl:
  1245.  IFGE    __CPU-68020
  1246.     cmp.l    #$10000,d0        ; Fix: 32768 doesn't fit a WORD!
  1247.     bne    .1
  1248.     move.l    #$ffff,d0
  1249. .1
  1250.     asr.l    #1,d0
  1251.  ELSE
  1252.     asr.l    #8,d0
  1253.  ENDC
  1254.     lea    OffsWordSVl(pc),a0
  1255.     rts
  1256.  
  1257. FixVolWordSVr:
  1258.  IFGE    __CPU-68020
  1259.     cmp.l    #$10000,d1        ; Fix: 32768 doesn't fit a WORD!
  1260.     bne    .1
  1261.     move.l    #$ffff,d1
  1262. .1
  1263.     asr.l    #1,d1
  1264.  ELSE
  1265.     asr.l    #8,d1
  1266.  ENDC
  1267.     lea    OffsWordSVr(pc),a0
  1268.     rts
  1269.  
  1270. FixVolWordSVP:
  1271.  IFGE    __CPU-68020
  1272.     cmp.l    #$10000,d0        ; Fix: 32768 doesn't fit a WORD!
  1273.     bne    .1
  1274.     move.l    #$ffff,d0
  1275. .1
  1276.     cmp.l    #$10000,d1        ; Fix: 32768 doesn't fit a WORD!
  1277.     bne    .2
  1278.     move.l    #$ffff,d1
  1279. .2
  1280.      asr.l    #1,d0
  1281.      asr.l    #1,d1
  1282.  ELSE
  1283.     asr.l    #8,d0
  1284.     asr.l    #8,d1
  1285.  ENDC
  1286.     lea    OffsWordSVP(pc),a0
  1287.     rts
  1288.  
  1289. FixVolWordSVTl:
  1290.     jsr    _Fixed2Shift
  1291.     lea    OffsWordSVTl(pc),a0
  1292.     rts
  1293.  
  1294. FixVolWordSVTr:
  1295.     move.l    d1,d0
  1296.     jsr    _Fixed2Shift
  1297.     move.l    d0,d1
  1298.     lea    OffsWordSVTr(pc),a0
  1299.     rts
  1300.  
  1301. FixVolWordSVPT:
  1302.     push    d1
  1303.     jsr    _Fixed2Shift
  1304.     pop    d1
  1305.     push    d0
  1306.     move.l    d1,d0
  1307.     jsr    _Fixed2Shift
  1308.     move.l    d0,d1
  1309.     pop    d0
  1310.     lea    OffsWordSVPT(pc),a0
  1311.     rts
  1312.  
  1313. FixVolWordMVH:
  1314.     add.l    d1,d0
  1315.     lea    OffsWordMVH(pc),a0
  1316.     rts
  1317.  
  1318. FixVolWordSVPH:
  1319.     lea    OffsWordSVPH(pc),a0
  1320.     rts
  1321.  
  1322. ;******************************************************************************
  1323.  
  1324. FixVolWordsMV:
  1325.     cmp.l    #$10000,d0        ; Fix: 32768 doesn't fit a WORD!
  1326.     bne    .1
  1327.     move.l    #$ffff,d0
  1328. .1
  1329.     cmp.l    #$10000,d1        ; Fix: 32768 doesn't fit a WORD!
  1330.     bne    .2
  1331.     move.l    #$ffff,d1
  1332. .2
  1333.     asr.l    #1,d0
  1334.     asr.l    #1,d1
  1335.     lea    OffsWordsMV(pc),a0
  1336.     rts
  1337.  
  1338. FixVolWordsMVT:
  1339.     push    d1
  1340.     jsr    _Fixed2Shift
  1341.     pop    d1
  1342.     push    d0
  1343.     move.l    d1,d0
  1344.     jsr    _Fixed2Shift
  1345.     move.l    d0,d1
  1346.     pop    d0
  1347.     lea    OffsWordsMVT(pc),a0
  1348.     rts
  1349.  
  1350. FixVolWordsSVl:
  1351.     cmp.l    #$10000,d0        ; Fix: 32768 doesn't fit a WORD!
  1352.     bne    .1
  1353.     move.l    #$ffff,d0
  1354. .1
  1355.     asr.l    #1,d0
  1356.     lea    OffsWordsSVl(pc),a0
  1357.     rts
  1358.  
  1359. FixVolWordsSVr:
  1360.     cmp.l    #$10000,d1        ; Fix: 32768 doesn't fit a WORD!
  1361.     bne    .1
  1362.     move.l    #$ffff,d1
  1363. .1
  1364.     asr.l    #1,d1
  1365.     lea    OffsWordsSVr(pc),a0
  1366.     rts
  1367.  
  1368. FixVolWordsSVP:
  1369.     cmp.l    #$10000,d0        ; Fix: 32768 doesn't fit a WORD!
  1370.     bne    .1
  1371.     move.l    #$ffff,d0
  1372. .1
  1373.     cmp.l    #$10000,d1        ; Fix: 32768 doesn't fit a WORD!
  1374.     bne    .2
  1375.     move.l    #$ffff,d1
  1376. .2
  1377.      asr.l    #1,d0
  1378.      asr.l    #1,d1
  1379.     lea    OffsWordsSVP(pc),a0
  1380.     rts
  1381.  
  1382. FixVolWordsSVTl:
  1383.     jsr    _Fixed2Shift
  1384.     lea    OffsWordsSVTl(pc),a0
  1385.     rts
  1386.  
  1387. FixVolWordsSVTr:
  1388.     move.l    d1,d0
  1389.     jsr    _Fixed2Shift
  1390.     move.l    d0,d1
  1391.     lea    OffsWordsSVTr(pc),a0
  1392.     rts
  1393.  
  1394. FixVolWordsSVPT:
  1395.     push    d1
  1396.     jsr    _Fixed2Shift
  1397.     pop    d1
  1398.     push    d0
  1399.     move.l    d1,d0
  1400.     jsr    _Fixed2Shift
  1401.     move.l    d0,d1
  1402.     pop    d0
  1403.     lea    OffsWordsSVPT(pc),a0
  1404.     rts
  1405.  
  1406. FixVolWordsMVH:
  1407.     lea    OffsWordsMVH(pc),a0
  1408.     rts
  1409.  
  1410. FixVolWordsSVPH:
  1411.     lea    OffsWordsSVPH(pc),a0
  1412.     rts
  1413.  
  1414. ;******************************************************************************
  1415.  
  1416.  
  1417.  
  1418. ;------------------------------------------------------------------------------
  1419. * Overview: - M=Mono S=Stereo V=Volume P=Panning T=Table H=HiFi
  1420. *             l=Left r=Right
  1421. *
  1422. * Routine    Speed¹    Memory    Volume    Panning
  1423. *
  1424. * AddSilence    0    None    =0    -
  1425. *
  1426. * AddByteMV    403    None    ±8 bit    -
  1427. * AddByteMVH        None    ±15 bit    -
  1428. * AddByteMVT    250    ²    5 bit ²    -
  1429. * AddByteSVl    455    None    ±8 bit    No (Left)
  1430. * AddByteSVr    474    None    ±8 bit    No (Right)
  1431. * AddByteSVP    704    None    ±8 bit    Yes
  1432. * AddByteSVPH        None    ±15 bit    Yes
  1433. * AddByteSVTl    327    ²    5 bit ²    No (Left)
  1434. * AddByteSVTr    324    ²    5 bit ²    No (Right)
  1435. * AddByteSVPT    384    ²    5 bit ²    Yes
  1436. *
  1437. * AddWordMV    438    None    ±15 bit    -
  1438. * AddWordMVH        None    ±16 bit    Yes
  1439. * AddWordMVT    374    ²    5 bit ²    -
  1440. * AddWordSVl    523    None    ±15 bit    No (Left)
  1441. * AddWordSVr    523    None    ±15 bit    No (Right)
  1442. * AddWordSVP    837    None    ±15 bit    Yes
  1443. * AddWordSVPH        None    ±16 bit    Yes
  1444. * AddWordSVTl    452    ²    5 bit ²    No (Left)
  1445. * AddWordSVTr    452    ²    5 bit ²    No (Right)
  1446. * AddWordSVPT    685    ²    5 bit ²    Yes
  1447. *
  1448. *
  1449. * ¹) Number of CIAA timer B ticks (PAL) it takes to process
  1450. *    10000 samples, divided by 16. Lower is faster. NOTE: The samples
  1451. *    are all the same, which makes the table routines look a little
  1452. *    better than they would in real life, where the cache cannot be
  1453. *    fully used.
  1454. *    System data:
  1455. *       A4000/040 25 Mhz, all caches on.
  1456. *       Code, samples and mixing buffer in Fast RAM.
  1457. *       All interrupts off - no multitasking.
  1458. * ²) Multiplication table, using 256*(TABLEMAXVOL+1)*4 bytes 
  1459. *    (includes 0 and TABLEMAXVOL itself!).
  1460. * ³) Multiplication table, using 256*(TABLEMAXVOL+1)*2 bytes 
  1461. *    (includes 0 and TABLEMAXVOL itself!).
  1462. *
  1463. ;------------------------------------------------------------------------------
  1464. * ALL ADD ROUTINES:
  1465. ;in:
  1466. * d0.l    Samples (scratch)
  1467. * d3    Offset Integer
  1468. * d4    Offset Fraction (upper word cleared!)
  1469. * d5    Add Integer (s)
  1470. * d6    Add Fraction (s) (upper word cleared!)
  1471. * d7    Scratch
  1472. * a0    Scratch
  1473. * a2    AHIAudioCtrl (only used by AddSilence routines)
  1474. * a3    Sample data (s)
  1475. * a4    Output buffer
  1476. * a5    ChannelDatas (only used by HiFi routines)
  1477. * a6    Scratch
  1478. ;out:
  1479. * d3    Updated Offset Integer
  1480. * d4    Updated Offset Fraction
  1481. * a4    Updated buffer pointer (where to store next sample)
  1482. ;------------------------------------------------------------------------------
  1483.  
  1484. OffsetTable:
  1485. OffsSilence:    dc.w    AddSilence-*
  1486.  
  1487. OffsByteMV:    dc.w    AddByteMV-*
  1488. OffsByteMVT:    dc.w    AddByteMVT-*
  1489. OffsByteSVl:    dc.w    AddByteSVl-*
  1490. OffsByteSVr:    dc.w    AddByteSVr-*
  1491. OffsByteSVP:    dc.w    AddByteSVP-*
  1492. OffsByteSVTl:    dc.w    AddByteSVTl-*
  1493. OffsByteSVTr:    dc.w    AddByteSVTr-*
  1494. OffsByteSVPT:    dc.w    AddByteSVPT-*
  1495. OffsByteMVH:    dc.w    AddByteMVH-*
  1496. OffsByteSVPH:    dc.w    AddByteSVPH-*
  1497.  
  1498. OffsBytesMV:    dc.w    AddBytesMV-*
  1499. OffsBytesMVT:    dc.w    AddBytesMVT-*
  1500. OffsBytesSVl:    dc.w    AddBytesSVl-*
  1501. OffsBytesSVr:    dc.w    AddBytesSVr-*
  1502. OffsBytesSVP:    dc.w    AddBytesSVP-*
  1503. OffsBytesSVTl:    dc.w    AddBytesSVTl-*
  1504. OffsBytesSVTr:    dc.w    AddBytesSVTr-*
  1505. OffsBytesSVPT:    dc.w    AddBytesSVPT-*
  1506. OffsBytesMVH:    dc.w    AddBytesMVH-*
  1507. OffsBytesSVPH:    dc.w    AddBytesSVPH-*
  1508.  
  1509. OffsWordMV:    dc.w    AddWordMV-*
  1510. OffsWordMVT:    dc.w    AddWordMVT-*
  1511. OffsWordSVl:    dc.w    AddWordSVl-*
  1512. OffsWordSVr:    dc.w    AddWordSVr-*
  1513. OffsWordSVP:    dc.w    AddWordSVP-*
  1514. OffsWordSVTl:    dc.w    AddWordSVTl-*
  1515. OffsWordSVTr:    dc.w    AddWordSVTr-*
  1516. OffsWordSVPT:    dc.w    AddWordSVPT-*
  1517. OffsWordMVH:    dc.w    AddWordMVH-*
  1518. OffsWordSVPH:    dc.w    AddWordSVPH-*
  1519.  
  1520. OffsWordsMV:    dc.w    AddWordsMV-*
  1521. OffsWordsMVT:    dc.w    AddWordsMVT-*
  1522. OffsWordsSVl:    dc.w    AddWordsSVl-*
  1523. OffsWordsSVr:    dc.w    AddWordsSVr-*
  1524. OffsWordsSVP:    dc.w    AddWordsSVP-*
  1525. OffsWordsSVTl:    dc.w    AddWordsSVTl-*
  1526. OffsWordsSVTr:    dc.w    AddWordsSVTr-*
  1527. OffsWordsSVPT:    dc.w    AddWordsSVPT-*
  1528. OffsWordsMVH:    dc.w    AddWordsMVH-*
  1529. OffsWordsSVPH:    dc.w    AddWordsSVPH-*
  1530.  
  1531. OffsetBackward    EQU    *-OffsetTable
  1532.  
  1533. OffsSilenceB:    dc.w    AddSilenceB-*
  1534.  
  1535. OffsByteMVB:    dc.w    AddByteMVB-*
  1536. OffsByteMVTB:    dc.w    AddByteMVTB-*
  1537. OffsByteSVlB:    dc.w    AddByteSVlB-*
  1538. OffsByteSVrB:    dc.w    AddByteSVrB-*
  1539. OffsByteSVPB:    dc.w    AddByteSVPB-*
  1540. OffsByteSVTlB:    dc.w    AddByteSVTlB-*
  1541. OffsByteSVTrB:    dc.w    AddByteSVTrB-*
  1542. OffsByteSVPTB:    dc.w    AddByteSVPTB-*
  1543. OffsByteMVHB:    dc.w    AddByteMVHB-*
  1544. OffsByteSVPHB:    dc.w    AddByteSVPHB-*
  1545.  
  1546. OffsBytesMVB:    dc.w    AddBytesMVB-*
  1547. OffsBytesMVTB:    dc.w    AddBytesMVTB-*
  1548. OffsBytesSVlB:    dc.w    AddBytesSVlB-*
  1549. OffsBytesSVrB:    dc.w    AddBytesSVrB-*
  1550. OffsBytesSVPB:    dc.w    AddBytesSVPB-*
  1551. OffsBytesSVTlB:    dc.w    AddBytesSVTlB-*
  1552. OffsBytesSVTrB:    dc.w    AddBytesSVTrB-*
  1553. OffsBytesSVPTB:    dc.w    AddBytesSVPTB-*
  1554. OffsBytesMVHB:    dc.w    AddBytesMVHB-*
  1555. OffsBytesSVPHB:    dc.w    AddBytesSVPHB-*
  1556.  
  1557. OffsWordMVB:    dc.w    AddWordMVB-*
  1558. OffsWordMVTB:    dc.w    AddWordMVTB-*
  1559. OffsWordSVlB:    dc.w    AddWordSVlB-*
  1560. OffsWordSVrB:    dc.w    AddWordSVrB-*
  1561. OffsWordSVPB:    dc.w    AddWordSVPB-*
  1562. OffsWordSVTlB:    dc.w    AddWordSVTlB-*
  1563. OffsWordSVTrB:    dc.w    AddWordSVTrB-*
  1564. OffsWordSVPTB:    dc.w    AddWordSVPTB-*
  1565. OffsWordMVHB:    dc.w    AddWordMVHB-*
  1566. OffsWordSVPHB:    dc.w    AddWordSVPHB-*
  1567.  
  1568. OffsWordsMVB:    dc.w    AddWordsMVB-*
  1569. OffsWordsMVTB:    dc.w    AddWordsMVTB-*
  1570. OffsWordsSVlB:    dc.w    AddWordsSVlB-*
  1571. OffsWordsSVrB:    dc.w    AddWordsSVrB-*
  1572. OffsWordsSVPB:    dc.w    AddWordsSVPB-*
  1573. OffsWordsSVTlB:    dc.w    AddWordsSVTlB-*
  1574. OffsWordsSVTrB:    dc.w    AddWordsSVTrB-*
  1575. OffsWordsSVPTB:    dc.w    AddWordsSVPTB-*
  1576. OffsWordsMVHB:    dc.w    AddWordsMVHB-*
  1577. OffsWordsSVPHB:    dc.w    AddWordsSVPHB-*
  1578.         dc.w    -1
  1579.  
  1580.  
  1581.  
  1582.     cnop    0,16
  1583.     ds.b    16
  1584.  
  1585. ; To make the backward-mixing routines, do this:
  1586. ; 1) Copy all mixing routines.
  1587. ; 2) Replace all occurences of ':' with 'B:' (all labels)
  1588. ; 3) Replace all occurences of 'add.l    d6,d4' with 'sub.l    d6,d4'
  1589. ; 4) Replace all occurences of 'addx.l    d5,d3' with 'subx.l    d5,d3'
  1590. ; 5) AddSilence uses different source registers for add/addx.
  1591. ; 6) The HiFi routines are different.
  1592.  
  1593.  
  1594. *******************************************************************************
  1595. ; HIFI routines (unoptimized, only 020+!)
  1596. ;------------------------------------------------------------------------------
  1597.     cnop    0,16
  1598.  
  1599. ;in
  1600. * d1.l    -65536..65536
  1601. AddByteMVH:
  1602.  IFGE    __CPU-68020
  1603.     clr.w    d4        ; 16 bit fraction
  1604.     clr.w    d6
  1605.     swap.w    d4
  1606.     swap.w    d6
  1607.     subq.w    #1,d0
  1608.     bmi.b    .exit
  1609. .nextsample
  1610.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  1611.     bne    .not_first
  1612.     move.l    cd_LastSampleL(a5),a0
  1613.     bra    .got_sample
  1614. .not_first
  1615.     move.b    -1(a3,d3.l),d7
  1616.     lsl.w    #8,d7
  1617. ;    ext.l    d7
  1618. ;    move.l    d7,a0
  1619.     move.w    d7,a0
  1620. .got_sample
  1621.     move.b    0(a3,d3.l),d7
  1622.     lsl.w    #8,d7
  1623.     ext.l    d7
  1624.     move.l    d7,cd_TempLastSampleL(a5)
  1625.     sub.l    a0,d7
  1626.     asr.l    #1,d7
  1627.     muls.l    d4,d7
  1628.     asr.l    #7,d7
  1629.     asr.l    #8,d7
  1630.     add.l    d7,a0
  1631.  
  1632.     move.l    a0,d7
  1633.     muls.l    d1,d7
  1634.     add.l    d7,(a4)+
  1635.  
  1636.     add.w    d6,d4
  1637.     addx.l    d5,d3
  1638.     dbf    d0,.nextsample
  1639. .exit
  1640.     swap.w    d4        ; 32 bit fraction
  1641.     swap.w    d6
  1642.  ENDC
  1643.     rts
  1644.  
  1645. ;in
  1646. * d1.l    -65536..65536
  1647. * d2.l    -65536..65536
  1648. AddByteSVPH:
  1649.  IFGE    __CPU-68020
  1650.     clr.w    d4        ; 16 bit fraction
  1651.     clr.w    d6
  1652.     swap.w    d4
  1653.     swap.w    d6
  1654.     subq.w    #1,d0
  1655.     bmi.b    .exit
  1656. .nextsample
  1657.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  1658.     bne    .not_first
  1659.     move.l    cd_LastSampleL(a5),a0
  1660.     bra    .got_sample
  1661. .not_first
  1662.     move.b    -1(a3,d3.l),d7
  1663.     lsl.w    #8,d7
  1664. ;    ext.l    d7
  1665. ;    move.l    d7,a0
  1666.     move.w    d7,a0
  1667. .got_sample
  1668.     move.b    0(a3,d3.l),d7
  1669.     lsl.w    #8,d7
  1670.     ext.l    d7
  1671.     move.l    d7,cd_TempLastSampleL(a5)
  1672.     sub.l    a0,d7
  1673.     asr.l    #1,d7
  1674.     muls.l    d4,d7
  1675.     asr.l    #7,d7
  1676.     asr.l    #8,d7
  1677.     add.l    d7,a0
  1678.  
  1679.     move.l    a0,d7
  1680.     muls.l    d1,d7
  1681.     add.l    d7,(a4)+
  1682.  
  1683.     move.l    a0,d7
  1684.     muls.l    d2,d7
  1685.     add.l    d7,(a4)+
  1686.  
  1687.     add.w    d6,d4
  1688.     addx.l    d5,d3
  1689.     dbf    d0,.nextsample
  1690. .exit
  1691.     swap.w    d4        ; 32 bit fraction
  1692.     swap.w    d6
  1693.  ENDC
  1694.     rts
  1695.  
  1696. ;in
  1697. * d1.l    -65536..65536
  1698. * d2.l    -65536..65536
  1699. AddBytesMVH:
  1700.  IFGE    __CPU-68020
  1701.     clr.w    d4        ; 16 bit fraction
  1702.     clr.w    d6
  1703.     swap.w    d4
  1704.     swap.w    d6
  1705.     subq.w    #1,d0
  1706.     bmi.b    .exit
  1707. .nextsample
  1708.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  1709.     bne    .not_firstL
  1710.     move.l    cd_LastSampleL(a5),a0
  1711.     bra    .got_sampleL
  1712. .not_firstL
  1713.     move.b    -2(a3,d3.l*2),d7
  1714.     lsl.w    #8,d7
  1715. ;    ext.l    d7
  1716. ;    move.l    d7,a0
  1717.     move.w    d7,a0
  1718. .got_sampleL
  1719.     move.b    0(a3,d3.l*2),d7
  1720.     lsl.w    #8,d7
  1721.     ext.l    d7
  1722.     move.l    d7,cd_TempLastSampleL(a5)
  1723.     sub.l    a0,d7
  1724.     asr.l    #1,d7
  1725.     muls.l    d4,d7
  1726.     asr.l    #7,d7
  1727.     asr.l    #8,d7
  1728.     add.l    d7,a0
  1729.  
  1730.     move.l    a0,d7
  1731.     muls.l    d1,d7
  1732.     add.l    d7,(a4)
  1733.  
  1734.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  1735.     bne    .not_firstR
  1736.     move.l    cd_LastSampleR(a5),a0
  1737.     bra    .got_sampleR
  1738. .not_firstR
  1739.     move.b    -1(a3,d3.l*2),d7
  1740.     lsl.w    #8,d7
  1741. ;    ext.l    d7
  1742. ;    move.l    d7,a0
  1743.     move.w    d7,a0
  1744. .got_sampleR
  1745.     move.b    1(a3,d3.l*2),d7
  1746.     lsl.w    #8,d7
  1747.     ext.l    d7
  1748.     move.l    d7,cd_TempLastSampleR(a5)
  1749.     sub.l    a0,d7
  1750.     asr.l    #1,d7
  1751.     muls.l    d4,d7
  1752.     asr.l    #7,d7
  1753.     asr.l    #8,d7
  1754.     add.l    d7,a0
  1755.  
  1756.     move.l    a0,d7
  1757.     muls.l    d2,d7
  1758.     add.l    d7,(a4)+
  1759.  
  1760.     add.w    d6,d4
  1761.     addx.l    d5,d3
  1762.     dbf    d0,.nextsample
  1763. .exit
  1764.     swap.w    d4        ; 32 bit fraction
  1765.     swap.w    d6
  1766.  ENDC
  1767.     rts
  1768.  
  1769. ;in
  1770. * d1.l    -65536..65536
  1771. * d2.l    -65536..65536
  1772. AddBytesSVPH:
  1773.  IFGE    __CPU-68020
  1774.     clr.w    d4        ; 16 bit fraction
  1775.     swap.w    d4
  1776.     clr.w    d6
  1777.     swap.w    d6
  1778.     subq.w    #1,d0
  1779.     bmi.b    .exit
  1780. .nextsample
  1781.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  1782.     bne    .not_firstL
  1783.     move.l    cd_LastSampleL(a5),a0
  1784.     bra    .got_sampleL
  1785. .not_firstL
  1786.     move.b    -2(a3,d3.l*2),d7
  1787.     lsl.w    #8,d7
  1788. ;    ext.l    d7
  1789. ;    move.l    d7,a0
  1790.     move.w    d7,a0
  1791. .got_sampleL
  1792.     move.b    0(a3,d3.l*2),d7
  1793.     lsl.w    #8,d7
  1794.     ext.l    d7
  1795.     move.l    d7,cd_TempLastSampleL(a5)
  1796.     sub.l    a0,d7
  1797.     asr.l    #1,d7
  1798.     muls.l    d4,d7
  1799.     asr.l    #7,d7
  1800.     asr.l    #8,d7
  1801.     add.l    d7,a0
  1802.  
  1803.     move.l    a0,d7
  1804.     muls.l    d1,d7
  1805.     add.l    d7,(a4)+
  1806.  
  1807.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  1808.     bne    .not_firstR
  1809.     move.l    cd_LastSampleR(a5),a0
  1810.     bra    .got_sampleR
  1811. .not_firstR
  1812.     move.b    -1(a3,d3.l*2),d7
  1813.     lsl.w    #8,d7
  1814. ;    ext.l    d7
  1815. ;    move.l    d7,a0
  1816.     move.w    d7,a0
  1817. .got_sampleR
  1818.     move.b    1(a3,d3.l*2),d7
  1819.     lsl.w    #8,d7
  1820.     ext.l    d7
  1821.     move.l    d7,cd_TempLastSampleR(a5)
  1822.     sub.l    a0,d7
  1823.     asr.l    #1,d7
  1824.     muls.l    d4,d7
  1825.     asr.l    #7,d7
  1826.     asr.l    #8,d7
  1827.     add.l    d7,a0
  1828.  
  1829.     move.l    a0,d7
  1830.     muls.l    d2,d7
  1831.     add.l    d7,(a4)+
  1832.  
  1833.     add.w    d6,d4
  1834.     addx.l    d5,d3
  1835.     dbf    d0,.nextsample
  1836. .exit
  1837.     swap.w    d4        ; 32 bit fraction
  1838.     swap.w    d6
  1839.  ENDC
  1840.     rts
  1841.  
  1842. ;in
  1843. * d1.l    -65536..65536
  1844. AddWordMVH:
  1845.  IFGE    __CPU-68020
  1846.     clr.w    d4        ; 16 bit fraction
  1847.     clr.w    d6
  1848.     swap.w    d4
  1849.     swap.w    d6
  1850.     subq.w    #1,d0
  1851.     bmi.b    .exit
  1852. .nextsample
  1853.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  1854.     bne    .not_first
  1855.     move.l    cd_LastSampleL(a5),a0
  1856.     bra    .got_sample
  1857. .not_first
  1858.     move.w    -2(a3,d3.l*2),a0
  1859. ;    ext.l    d7
  1860. ;    move.l    d7,a0
  1861. .got_sample
  1862.     move.w    0(a3,d3.l*2),d7
  1863.     ext.l    d7
  1864.     move.l    d7,cd_TempLastSampleL(a5)
  1865.     sub.l    a0,d7
  1866.     asr.l    #1,d7
  1867.     muls.l    d4,d7
  1868.     asr.l    #7,d7
  1869.     asr.l    #8,d7
  1870.     add.l    d7,a0
  1871.  
  1872.     move.l    a0,d7
  1873.     muls.l    d1,d7
  1874.     add.l    d7,(a4)+
  1875.  
  1876.     add.w    d6,d4
  1877.     addx.l    d5,d3
  1878.     dbf    d0,.nextsample
  1879. .exit
  1880.     swap.w    d4        ; 32 bit fraction
  1881.     swap.w    d6
  1882.  ENDC
  1883.     rts
  1884.  
  1885. ;in
  1886. * d1.l    -65536..65536
  1887. * d2.l    -65536..65536
  1888. AddWordSVPH:
  1889.  IFGE    __CPU-68020
  1890.     clr.w    d4        ; 16 bit fraction
  1891.     clr.w    d6
  1892.     swap.w    d4
  1893.     swap.w    d6
  1894.     subq.w    #1,d0
  1895.     bmi.b    .exit
  1896. .nextsample
  1897.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  1898.     bne    .not_first
  1899.     move.l    cd_LastSampleL(a5),a0
  1900.     bra    .got_sample
  1901. .not_first
  1902.     move.w    -2(a3,d3.l*2),a0
  1903. ;    ext.l    d7
  1904. ;    move.l    d7,a0
  1905. .got_sample
  1906.     move.w    0(a3,d3.l*2),d7
  1907.     ext.l    d7
  1908.     move.l    d7,cd_TempLastSampleL(a5)
  1909.     sub.l    a0,d7
  1910.     asr.l    #1,d7
  1911.     muls.l    d4,d7
  1912.     asr.l    #7,d7
  1913.     asr.l    #8,d7
  1914.     add.l    d7,a0
  1915.  
  1916.     move.l    a0,d7
  1917.     muls.l    d1,d7
  1918.     add.l    d7,(a4)+
  1919.  
  1920.     move.l    a0,d7
  1921.     muls.l    d2,d7
  1922.     add.l    d7,(a4)+
  1923.  
  1924.     add.w    d6,d4
  1925.     addx.l    d5,d3
  1926.     dbf    d0,.nextsample
  1927. .exit
  1928.     swap.w    d4        ; 32 bit fraction
  1929.     swap.w    d6
  1930.  ENDC
  1931.     rts
  1932.  
  1933. ;in
  1934. * d1.l    -65536..65536
  1935. * d2.l    -65536..65536
  1936. AddWordsMVH:
  1937.  IFGE    __CPU-68020
  1938.     clr.w    d4        ; 16 bit fraction
  1939.     clr.w    d6
  1940.     swap.w    d4
  1941.     swap.w    d6
  1942.     subq.w    #1,d0
  1943.     bmi.b    .exit
  1944. .nextsample
  1945.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  1946.     bne    .not_firstL
  1947.     move.l    cd_LastSampleL(a5),a0
  1948.     bra    .got_sampleL
  1949. .not_firstL
  1950.     move.w    -4(a3,d3.l*4),a0
  1951. ;    ext.l    d7
  1952. ;    move.l    d7,a0
  1953. .got_sampleL
  1954.     move.w    0(a3,d3.l*4),d7
  1955.     ext.l    d7
  1956.     move.l    d7,cd_TempLastSampleL(a5)
  1957.     sub.l    a0,d7
  1958.     asr.l    #1,d7
  1959.     muls.l    d4,d7
  1960.     asr.l    #7,d7
  1961.     asr.l    #8,d7
  1962.     add.l    d7,a0
  1963.  
  1964.     move.l    a0,d7
  1965.     muls.l    d1,d7
  1966.     add.l    d7,(a4)
  1967.  
  1968.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  1969.     bne    .not_firstR
  1970.     move.l    cd_LastSampleR(a5),a0
  1971.     bra    .got_sampleR
  1972. .not_firstR
  1973.     move.w    -2(a3,d3.l*4),a0
  1974. ;    ext.l    d7
  1975. ;    move.l    d7,a0
  1976. .got_sampleR
  1977.     move.w    2(a3,d3.l*4),d7
  1978.     ext.l    d7
  1979.     move.l    d7,cd_TempLastSampleR(a5)
  1980.     sub.l    a0,d7
  1981.     asr.l    #1,d7
  1982.     muls.l    d4,d7
  1983.     asr.l    #7,d7
  1984.     asr.l    #8,d7
  1985.     add.l    d7,a0
  1986.  
  1987.     move.l    a0,d7
  1988.     muls.l    d2,d7
  1989.     add.l    d7,(a4)+
  1990.  
  1991.     add.w    d6,d4
  1992.     addx.l    d5,d3
  1993.     dbf    d0,.nextsample
  1994. .exit
  1995.     swap.w    d4        ; 32 bit fraction
  1996.     swap.w    d6
  1997.  ENDC
  1998.     rts
  1999.  
  2000. ;in
  2001. * d1.l    -65536..65536
  2002. * d2.l    -65536..65536
  2003. AddWordsSVPH:
  2004.  IFGE    __CPU-68020
  2005.     clr.w    d4        ; 16 bit fraction
  2006.     clr.w    d6
  2007.     swap.w    d4
  2008.     swap.w    d6
  2009.     subq.w    #1,d0
  2010.     bmi.b    .exit
  2011. .nextsample
  2012.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2013.     bne    .not_firstL
  2014.     move.l    cd_LastSampleL(a5),a0
  2015.     bra    .got_sampleL
  2016. .not_firstL
  2017.     move.w    -4(a3,d3.l*4),a0
  2018. ;    ext.l    d7
  2019. ;    move.l    d7,a0
  2020. .got_sampleL
  2021.     move.w    0(a3,d3.l*4),d7
  2022.     ext.l    d7
  2023.     move.l    d7,cd_TempLastSampleL(a5)
  2024.     sub.l    a0,d7
  2025.     asr.l    #1,d7
  2026.     muls.l    d4,d7
  2027.     asr.l    #7,d7
  2028.     asr.l    #8,d7
  2029.     add.l    d7,a0
  2030.  
  2031.     move.l    a0,d7
  2032.     muls.l    d1,d7
  2033.     add.l    d7,(a4)+
  2034.  
  2035.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2036.     bne    .not_firstR
  2037.     move.l    cd_LastSampleR(a5),a0
  2038.     bra    .got_sampleR
  2039. .not_firstR
  2040.     move.w    -2(a3,d3.l*4),a0
  2041. ;    ext.l    d7
  2042. ;    move.l    d7,a0
  2043. .got_sampleR
  2044.     move.w    2(a3,d3.l*4),d7
  2045.     ext.l    d7
  2046.     move.l    d7,cd_TempLastSampleR(a5)
  2047.     sub.l    a0,d7
  2048.     asr.l    #1,d7
  2049.     muls.l    d4,d7
  2050.     asr.l    #7,d7
  2051.     asr.l    #8,d7
  2052.     add.l    d7,a0
  2053.  
  2054.     move.l    a0,d7
  2055.     muls.l    d2,d7
  2056.     add.l    d7,(a4)+
  2057.  
  2058.     add.w    d6,d4
  2059.     addx.l    d5,d3
  2060.     dbf    d0,.nextsample
  2061. .exit
  2062.     swap.w    d4        ; 32 bit fraction
  2063.     swap.w    d6
  2064.  ENDC
  2065.     rts
  2066.  
  2067.  
  2068. ;------------------------------------------------------------------------------
  2069.  
  2070. AddByteMVHB:
  2071.  IFGE    __CPU-68020
  2072.     clr.w    d4        ; 16 bit fraction
  2073.     clr.w    d6
  2074.     swap.w    d4
  2075.     swap.w    d6
  2076.     neg.w    d4
  2077.     subq.w    #1,d0
  2078.     bmi.b    .exit
  2079. .nextsample
  2080.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2081.     bne    .not_first
  2082.     move.l    cd_LastSampleL(a5),a0
  2083.     bra    .got_sample
  2084. .not_first
  2085.     move.b    1(a3,d3.l),d7
  2086.     lsl.w    #8,d7
  2087. ;    ext.l    d7
  2088. ;    move.l    d7,a0
  2089.     move.w    d7,a0
  2090. .got_sample
  2091.     move.b    0(a3,d3.l),d7
  2092.     lsl.w    #8,d7
  2093.     ext.l    d7
  2094.     move.l    d7,cd_TempLastSampleL(a5)
  2095.     sub.l    a0,d7
  2096.     asr.l    #1,d7
  2097.     muls.l    d4,d7
  2098.     asr.l    #7,d7
  2099.     asr.l    #8,d7
  2100.     add.l    d7,a0
  2101.  
  2102.     move.l    a0,d7
  2103.     muls.l    d1,d7
  2104.     add.l    d7,(a4)+
  2105.  
  2106.     add.w    d6,d4
  2107.     subx.l    d5,d3
  2108.     dbf    d0,.nextsample
  2109. .exit
  2110.     neg.w    d4
  2111.     swap.w    d4        ; 32 bit fraction
  2112.     swap.w    d6
  2113.  ENDC
  2114.     rts
  2115.  
  2116. AddByteSVPHB:
  2117.  IFGE    __CPU-68020
  2118.     clr.w    d4        ; 16 bit fraction
  2119.     clr.w    d6
  2120.     swap.w    d4
  2121.     swap.w    d6
  2122.     neg.w    d4
  2123.     subq.w    #1,d0
  2124.     bmi.b    .exit
  2125. .nextsample
  2126.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2127.     bne    .not_first
  2128.     move.l    cd_LastSampleL(a5),a0
  2129.     bra    .got_sample
  2130. .not_first
  2131.     move.b    1(a3,d3.l),d7
  2132.     lsl.w    #8,d7
  2133. ;    ext.l    d7
  2134. ;    move.l    d7,a0
  2135.     move.w    d7,a0
  2136. .got_sample
  2137.     move.b    0(a3,d3.l),d7
  2138.     lsl.w    #8,d7
  2139.     ext.l    d7
  2140.     move.l    d7,cd_TempLastSampleL(a5)
  2141.     sub.l    a0,d7
  2142.     asr.l    #1,d7
  2143.     muls.l    d4,d7
  2144.     asr.l    #7,d7
  2145.     asr.l    #8,d7
  2146.     add.l    d7,a0
  2147.  
  2148.     move.l    a0,d7
  2149.     muls.l    d1,d7
  2150.     add.l    d7,(a4)+
  2151.  
  2152.     move.l    a0,d7
  2153.     muls.l    d2,d7
  2154.     add.l    d7,(a4)+
  2155.  
  2156.     add.w    d6,d4
  2157.     subx.l    d5,d3
  2158.     dbf    d0,.nextsample
  2159. .exit
  2160.     neg.w    d4
  2161.     swap.w    d4        ; 32 bit fraction
  2162.     swap.w    d6
  2163.  ENDC
  2164.     rts
  2165.  
  2166. AddBytesMVHB:
  2167.  IFGE    __CPU-68020
  2168.     clr.w    d4        ; 16 bit fraction
  2169.     clr.w    d6
  2170.     swap.w    d4
  2171.     swap.w    d6
  2172.     neg.w    d4
  2173.     subq.w    #1,d0
  2174.     bmi.b    .exit
  2175. .nextsample
  2176.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2177.     bne    .not_firstL
  2178.     move.l    cd_LastSampleL(a5),a0
  2179.     bra    .got_sampleL
  2180. .not_firstL
  2181.     move.b    2(a3,d3.l*2),d7
  2182.     lsl.w    #8,d7
  2183. ;    ext.l    d7
  2184. ;    move.l    d7,a0
  2185.     move.w    d7,a0
  2186. .got_sampleL
  2187.     move.b    0(a3,d3.l*2),d7
  2188.     lsl.w    #8,d7
  2189.     ext.l    d7
  2190.     move.l    d7,cd_TempLastSampleL(a5)
  2191.     sub.l    a0,d7
  2192.     asr.l    #1,d7
  2193.     muls.l    d4,d7
  2194.     asr.l    #7,d7
  2195.     asr.l    #8,d7
  2196.     add.l    d7,a0
  2197.  
  2198.     move.l    a0,d7
  2199.     muls.l    d1,d7
  2200.     add.l    d7,(a4)
  2201.  
  2202.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2203.     bne    .not_firstR
  2204.     move.l    cd_LastSampleR(a5),a0
  2205.     bra    .got_sampleR
  2206. .not_firstR
  2207.     move.b    3(a3,d3.l*2),d7
  2208.     lsl.w    #8,d7
  2209. ;    ext.l    d7
  2210. ;    move.l    d7,a0
  2211.     move.w    d7,a0
  2212. .got_sampleR
  2213.     move.b    1(a3,d3.l*2),d7
  2214.     lsl.w    #8,d7
  2215.     ext.l    d7
  2216.     move.l    d7,cd_TempLastSampleR(a5)
  2217.     sub.l    a0,d7
  2218.     asr.l    #1,d7
  2219.     muls.l    d4,d7
  2220.     asr.l    #7,d7
  2221.     asr.l    #8,d7
  2222.     add.l    d7,a0
  2223.  
  2224.     move.l    a0,d7
  2225.     muls.l    d2,d7
  2226.     add.l    d7,(a4)+
  2227.  
  2228.     add.w    d6,d4
  2229.     subx.l    d5,d3
  2230.     dbf    d0,.nextsample
  2231. .exit
  2232.     neg.w    d4
  2233.     swap.w    d4        ; 32 bit fraction
  2234.     swap.w    d6
  2235.  ENDC
  2236.     rts
  2237.  
  2238. AddBytesSVPHB:
  2239.  IFGE    __CPU-68020
  2240.     clr.w    d4        ; 16 bit fraction
  2241.     clr.w    d6
  2242.     swap.w    d4
  2243.     swap.w    d6
  2244.     neg.w    d4
  2245.     subq.w    #1,d0
  2246.     bmi.b    .exit
  2247. .nextsample
  2248.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2249.     bne    .not_firstL
  2250.     move.l    cd_LastSampleL(a5),a0
  2251.     bra    .got_sampleL
  2252. .not_firstL
  2253.     move.b    2(a3,d3.l*2),d7
  2254.     lsl.w    #8,d7
  2255. ;    ext.l    d7
  2256. ;    move.l    d7,a0
  2257.     move.w    d7,a0
  2258. .got_sampleL
  2259.     move.b    0(a3,d3.l*2),d7
  2260.     lsl.w    #8,d7
  2261.     ext.l    d7
  2262.     move.l    d7,cd_TempLastSampleL(a5)
  2263.     sub.l    a0,d7
  2264.     asr.l    #1,d7
  2265.     muls.l    d4,d7
  2266.     asr.l    #7,d7
  2267.     asr.l    #8,d7
  2268.     add.l    d7,a0
  2269.  
  2270.     move.l    a0,d7
  2271.     muls.l    d1,d7
  2272.     add.l    d7,(a4)+
  2273.  
  2274.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2275.     bne    .not_firstR
  2276.     move.l    cd_LastSampleR(a5),a0
  2277.     bra    .got_sampleR
  2278. .not_firstR
  2279.     move.b    3(a3,d3.l*2),d7
  2280.     lsl.w    #8,d7
  2281. ;    ext.l    d7
  2282. ;    move.l    d7,a0
  2283.     move.w    d7,a0
  2284. .got_sampleR
  2285.     move.b    1(a3,d3.l*2),d7
  2286.     lsl.w    #8,d7
  2287.     ext.l    d7
  2288.     move.l    d7,cd_TempLastSampleR(a5)
  2289.     sub.l    a0,d7
  2290.     asr.l    #1,d7
  2291.     muls.l    d4,d7
  2292.     asr.l    #7,d7
  2293.     asr.l    #8,d7
  2294.     add.l    d7,a0
  2295.  
  2296.     move.l    a0,d7
  2297.     muls.l    d2,d7
  2298.     add.l    d7,(a4)+
  2299.  
  2300.     add.w    d6,d4
  2301.     subx.l    d5,d3
  2302.     dbf    d0,.nextsample
  2303. .exit
  2304.     neg.w    d4
  2305.     swap.w    d4        ; 32 bit fraction
  2306.     swap.w    d6
  2307.  ENDC
  2308.     rts
  2309.  
  2310. AddWordMVHB:
  2311.  IFGE    __CPU-68020
  2312.     clr.w    d4        ; 16 bit fraction
  2313.     clr.w    d6
  2314.     swap.w    d4
  2315.     swap.w    d6
  2316.     neg.w    d4
  2317.     subq.w    #1,d0
  2318.     bmi.b    .exit
  2319. .nextsample
  2320.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2321.     bne    .not_first
  2322.     move.l    cd_LastSampleL(a5),a0
  2323.     bra    .got_sample
  2324. .not_first
  2325.     move.w    2(a3,d3.l*2),a0
  2326. ;    ext.l    d7
  2327. ;    move.l    d7,a0
  2328. .got_sample
  2329.     move.w    0(a3,d3.l*2),d7
  2330.     ext.l    d7
  2331.     move.l    d7,cd_TempLastSampleL(a5)
  2332.     sub.l    a0,d7
  2333.     asr.l    #1,d7
  2334.     muls.l    d4,d7
  2335.     asr.l    #7,d7
  2336.     asr.l    #8,d7
  2337.     add.l    d7,a0
  2338.  
  2339.     move.l    a0,d7
  2340.     muls.l    d1,d7
  2341.     add.l    d7,(a4)+
  2342.  
  2343.     add.w    d6,d4
  2344.     subx.l    d5,d3
  2345.     dbf    d0,.nextsample
  2346. .exit
  2347.     neg.w    d4
  2348.     swap.w    d4        ; 32 bit fraction
  2349.     swap.w    d6
  2350.  ENDC
  2351.     rts
  2352.  
  2353. AddWordSVPHB:
  2354.  IFGE    __CPU-68020
  2355.     clr.w    d4        ; 16 bit fraction
  2356.     clr.w    d6
  2357.     swap.w    d4
  2358.     swap.w    d6
  2359.     neg.w    d4
  2360.     subq.w    #1,d0
  2361.     bmi.b    .exit
  2362. .nextsample
  2363.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2364.     bne    .not_first
  2365.     move.l    cd_LastSampleL(a5),a0
  2366.     bra    .got_sample
  2367. .not_first
  2368.     move.w    2(a3,d3.l*2),a0
  2369. ;    ext.l    d7
  2370. ;    move.l    d7,a0
  2371. .got_sample
  2372.     move.w    0(a3,d3.l*2),d7
  2373.     ext.l    d7
  2374.     move.l    d7,cd_TempLastSampleL(a5)
  2375.     sub.l    a0,d7
  2376.     asr.l    #1,d7
  2377.     muls.l    d4,d7
  2378.     asr.l    #7,d7
  2379.     asr.l    #8,d7
  2380.     add.l    d7,a0
  2381.  
  2382.     move.l    a0,d7
  2383.     muls.l    d1,d7
  2384.     add.l    d7,(a4)+
  2385.  
  2386.     move.l    a0,d7
  2387.     muls.l    d2,d7
  2388.     add.l    d7,(a4)+
  2389.  
  2390.     add.w    d6,d4
  2391.     subx.l    d5,d3
  2392.     dbf    d0,.nextsample
  2393. .exit
  2394.     neg.w    d4
  2395.     swap.w    d4        ; 32 bit fraction
  2396.     swap.w    d6
  2397.  ENDC
  2398.     rts
  2399.  
  2400.  
  2401. AddWordsMVHB:
  2402.  IFGE    __CPU-68020
  2403.     clr.w    d4        ; 16 bit fraction
  2404.     clr.w    d6
  2405.     swap.w    d4
  2406.     swap.w    d6
  2407.     neg.w    d4
  2408.     subq.w    #1,d0
  2409.     bmi.b    .exit
  2410. .nextsample
  2411.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2412.     bne    .not_firstL
  2413.     move.l    cd_LastSampleL(a5),a0
  2414.     bra    .got_sampleL
  2415. .not_firstL
  2416.     move.w    4(a3,d3.l*4),a0
  2417. ;    ext.l    d7
  2418. ;    move.l    d7,a0
  2419. .got_sampleL
  2420.     move.w    0(a3,d3.l*4),d7
  2421.     ext.l    d7
  2422.     move.l    d7,cd_TempLastSampleL(a5)
  2423.     sub.l    a0,d7
  2424.     asr.l    #1,d7
  2425.     muls.l    d4,d7
  2426.     asr.l    #7,d7
  2427.     asr.l    #8,d7
  2428.     add.l    d7,a0
  2429.  
  2430.     move.l    a0,d7
  2431.     muls.l    d1,d7
  2432.     add.l    d7,(a4)
  2433.  
  2434.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2435.     bne    .not_firstR
  2436.     move.l    cd_LastSampleR(a5),a0
  2437.     bra    .got_sampleR
  2438. .not_firstR
  2439.     move.w    6(a3,d3.l*4),a0
  2440. ;    ext.l    d7
  2441. ;    move.l    d7,a0
  2442. .got_sampleR
  2443.     move.w    2(a3,d3.l*4),d7
  2444.     ext.l    d7
  2445.     move.l    d7,cd_TempLastSampleR(a5)
  2446.     sub.l    a0,d7
  2447.     asr.l    #1,d7
  2448.     muls.l    d4,d7
  2449.     asr.l    #7,d7
  2450.     asr.l    #8,d7
  2451.     add.l    d7,a0
  2452.  
  2453.     move.l    a0,d7
  2454.     muls.l    d2,d7
  2455.     add.l    d7,(a4)+
  2456.  
  2457.     add.w    d6,d4
  2458.     subx.l    d5,d3
  2459.     dbf    d0,.nextsample
  2460. .exit
  2461.     neg.w    d4
  2462.     swap.w    d4        ; 32 bit fraction
  2463.     swap.w    d6
  2464.  ENDC
  2465.     rts
  2466.  
  2467. AddWordsSVPHB:
  2468.  IFGE    __CPU-68020
  2469.     clr.w    d4        ; 16 bit fraction
  2470.     clr.w    d6
  2471.     swap.w    d4
  2472.     swap.w    d6
  2473.     neg.w    d4
  2474.     subq.w    #1,d0
  2475.     bmi.b    .exit
  2476. .nextsample
  2477.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2478.     bne    .not_firstL
  2479.     move.l    cd_LastSampleL(a5),a0
  2480.     bra    .got_sampleL
  2481. .not_firstL
  2482.     move.w    4(a3,d3.l*4),a0
  2483. ;    ext.l    d7
  2484. ;    move.l    d7,a0
  2485. .got_sampleL
  2486.     move.w    0(a3,d3.l*4),d7
  2487.     ext.l    d7
  2488.     move.l    d7,cd_TempLastSampleL(a5)
  2489.     sub.l    a0,d7
  2490.     asr.l    #1,d7
  2491.     muls.l    d4,d7
  2492.     asr.l    #7,d7
  2493.     asr.l    #8,d7
  2494.     add.l    d7,a0
  2495.  
  2496.     move.l    a0,d7
  2497.     muls.l    d1,d7
  2498.     add.l    d7,(a4)+
  2499.  
  2500.     cmp.l    cd_FirstOffsetI(a5),d3    ;Is this the first sample?
  2501.     bne    .not_firstR
  2502.     move.l    cd_LastSampleR(a5),a0
  2503.     bra    .got_sampleR
  2504. .not_firstR
  2505.     move.w    6(a3,d3.l*4),a0
  2506. ;    ext.l    d7
  2507. ;    move.l    d7,a0
  2508. .got_sampleR
  2509.     move.w    2(a3,d3.l*4),d7
  2510.     ext.l    d7
  2511.     move.l    d7,cd_TempLastSampleR(a5)
  2512.     sub.l    a0,d7
  2513.     asr.l    #1,d7
  2514.     muls.l    d4,d7
  2515.     asr.l    #7,d7
  2516.     asr.l    #8,d7
  2517.     add.l    d7,a0
  2518.  
  2519.     move.l    a0,d7
  2520.     muls.l    d2,d7
  2521.     add.l    d7,(a4)+
  2522.  
  2523.     add.w    d6,d4
  2524.     subx.l    d5,d3
  2525.     dbf    d0,.nextsample
  2526. .exit
  2527.     neg.w    d4
  2528.     swap.w    d4        ; 32 bit fraction
  2529.     swap.w    d6
  2530.  ENDC
  2531.     rts
  2532.  
  2533. ;******************************************************************************
  2534.     cnop    0,16
  2535.  
  2536. AddSilence:
  2537.     clr.w    d4            ; 16 bit fraction
  2538.     clr.w    d6
  2539.     swap.w    d4
  2540.     swap.w    d6
  2541.  IFGE    __CPU-68020
  2542.   IFLT    __CPU-68060
  2543.     move.l    d5,d1            ;AddI<65535
  2544.     swap.w    d1
  2545.     move.w    d6,d1            ;d1=Add<<16
  2546.     mulu.l    d0,d2:d1
  2547.     add.w    d0,d4            ;New OffsetF (X)
  2548.     move.w    d1,d0
  2549.     move.w    d2,d1
  2550.     swap.w    d1            ;d1=d2:d1>>16
  2551.     addx.l    d1,d3            ;New OffsetI
  2552.   ELSE
  2553.     move.l    d5,d1
  2554.     mulu.w    d0,d1            ;OffsI*BuffSamples
  2555.     move.l    d6,d2
  2556.     add.l    d1,d3            ;New OffsetI (1)
  2557.     mulu.w    d0,d2            ;OffsF*BuffSamples...
  2558.     add.w    d2,d4            ;New OffsetF (X)
  2559.     clr.w    d2
  2560.     swap.w    d2            ;...>>16
  2561.     addx.l    d2,d3            ;New OffsetI (2)
  2562.   ENDC
  2563.  ELSE
  2564.     move.l    d5,d1
  2565.     mulu.w    d0,d1            ;OffsI*BuffSamples
  2566.     move.l    d6,d2
  2567.     add.l    d1,d3            ;New OffsetI (1)
  2568.     mulu.w    d0,d2            ;OffsF*BuffSamples...
  2569.     add.w    d2,d4            ;New OffsetF (X)
  2570.     clr.w    d2
  2571.     swap.w    d2            ;...>>16
  2572.     addx.l    d2,d3            ;New OffsetI (2)
  2573.  ENDC
  2574.     btst.b    #AHIACB_STEREO,ahiac_Flags+3(a2)
  2575.     beq.b    .nostereo
  2576.     lsl.l    #1,d0
  2577. .nostereo
  2578.     btst.b    #AHIACB_HIFI,ahiac_Flags+3(a2)
  2579.     beq.b    .nohifi
  2580.     lsl.l    #1,d0
  2581. .nohifi
  2582.     lsl.l    #1,d0
  2583.     add.l    d0,a4            ;New buffer pointer
  2584.     swap.w    d4            ; 32 bit fraction
  2585.     swap.w    d6
  2586.     rts
  2587.  
  2588. ;------------------------------------------------------------------------------
  2589.     cnop    0,16
  2590.  
  2591. AddSilenceB:
  2592.     clr.w    d4            ; 16 bit fraction
  2593.     clr.w    d6
  2594.     swap.w    d4
  2595.     swap.w    d6
  2596.  IFGE    __CPU-68020
  2597.   IFLT    __CPU-68060
  2598.     move.l    d5,d1            ;AddI<65535
  2599.     swap.w    d1
  2600.     move.w    d6,d1            ;d1=Add<<16
  2601.     mulu.l    d0,d2:d1
  2602.     sub.w    d0,d4            ;New OffsetF (X)
  2603.     move.w    d1,d0
  2604.     move.w    d2,d1
  2605.     swap.w    d1            ;d1=d2:d1>>16
  2606.     subx.l    d1,d3            ;New OffsetI
  2607.   ELSE
  2608.     move.l    d5,d1
  2609.     mulu.w    d0,d1            ;OffsI*BuffSamples
  2610.     move.l    d6,d2
  2611.     add.l    d1,d3            ;New OffsetI (1)
  2612.     mulu.w    d0,d2            ;OffsF*BuffSamples...
  2613.     sub.w    d2,d4            ;New OffsetF (X)
  2614.     clr.w    d2
  2615.     swap.w    d2            ;...>>16
  2616.     subx.l    d2,d3            ;New OffsetI (2)
  2617.   ENDC
  2618.  ELSE
  2619.     move.l    d5,d1
  2620.     mulu.w    d0,d1            ;OffsI*BuffSamples
  2621.     move.l    d6,d2
  2622.     add.l    d1,d3            ;New OffsetI (1)
  2623.     mulu.w    d0,d2            ;OffsF*BuffSamples...
  2624.     sub.w    d2,d4            ;New OffsetF (X)
  2625.     clr.w    d2
  2626.     swap.w    d2            ;...>>16
  2627.     subx.l    d2,d3            ;New OffsetI (2)
  2628.  ENDC
  2629.     btst.b    #AHIACB_STEREO,ahiac_Flags+3(a2)
  2630.     beq.b    .nostereo
  2631.     lsl.l    #1,d0
  2632. .nostereo
  2633.     btst.b    #AHIACB_HIFI,ahiac_Flags+3(a2)
  2634.     beq.b    .nohifi
  2635.     lsl.l    #1,d0
  2636. .nohifi
  2637.     lsl.l    #1,d0
  2638.     add.l    d0,a4            ;New buffer pointer
  2639.     swap.w    d4            ; 32 bit fraction
  2640.     swap.w    d6
  2641.     rts
  2642.  
  2643. ;******************************************************************************
  2644.     cnop    0,16
  2645.  
  2646. ;in
  2647. * d1.w    -256..256
  2648. AddByteMV:
  2649.     lsr.w    #1,d0
  2650.     bcs.b    .1
  2651.     subq.w    #1,d0
  2652.     bmi.b    .exit
  2653. .nextsample
  2654.     move.b    (a3,d3.l),d7
  2655.     ext.w    d7
  2656.     muls.w    d1,d7
  2657.     add.w    d7,(a4)+
  2658.     add.l    d6,d4
  2659.     addx.l    d5,d3
  2660. .1
  2661.     move.b    (a3,d3.l),d7
  2662.     ext.w    d7
  2663.     muls.w    d1,d7
  2664.     add.w    d7,(a4)+
  2665.     add.l    d6,d4
  2666.     addx.l    d5,d3
  2667.     dbf    d0,.nextsample
  2668. .exit
  2669.     rts
  2670.  
  2671. ;------------------------------------------------------------------------------
  2672.     cnop    0,16
  2673.  
  2674. ;in
  2675. * d1.l    Pointer in multiplication table
  2676. AddByteMVT:
  2677.     move.l    d1,a0
  2678.     moveq    #0,d1
  2679.     lsr.w    #1,d0
  2680.     bcs.b    .1
  2681.     subq.w    #1,d0
  2682.     bmi.b    .exit
  2683. .nextsample
  2684.     move.b    (a3,d3.l),d1
  2685.  IFGE    __CPU-68020
  2686.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  2687.  ELSE
  2688.     add.w    d1,d1
  2689.     add.w    d1,d1
  2690.     move.w    0(a0,d1.w),d2        ;signed multiplication
  2691.     moveq    #0,d1
  2692.  ENDC
  2693.     add.w    d2,(a4)+
  2694.     add.l    d6,d4
  2695.     addx.l    d5,d3
  2696. .1
  2697.     move.b    (a3,d3.l),d1
  2698.  IFGE    __CPU-68020
  2699.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  2700.  ELSE
  2701.     add.w    d1,d1
  2702.     add.w    d1,d1
  2703.     move.w    0(a0,d1.w),d2        ;signed multiplication
  2704.     moveq    #0,d1
  2705.  ENDC
  2706.     add.w    d2,(a4)+
  2707.     add.l    d6,d4
  2708.     addx.l    d5,d3
  2709.  
  2710.     dbf    d0,.nextsample
  2711. .exit
  2712.     rts
  2713.  
  2714. ;------------------------------------------------------------------------------
  2715.     cnop    0,16
  2716.  
  2717. ;in
  2718. * d1.w    -256..256
  2719. AddByteSVl:
  2720.     lsr.w    #1,d0
  2721.     bcs.b    .1
  2722.     subq.w    #1,d0
  2723.     bmi.b    .exit
  2724. .nextsample
  2725.     move.b    (a3,d3.l),d7
  2726.     ext.w    d7
  2727.     muls.w    d1,d7
  2728.     add.w    d7,(a4)+
  2729.     add.l    d6,d4
  2730.     addx.l    d5,d3
  2731.     addq.l    #2,a4
  2732. .1
  2733.     move.b    (a3,d3.l),d7
  2734.     ext.w    d7
  2735.     muls.w    d1,d7
  2736.     add.w    d7,(a4)+
  2737.     add.l    d6,d4
  2738.     addx.l    d5,d3
  2739.     addq.l    #2,a4
  2740.     dbf    d0,.nextsample
  2741. .exit
  2742.     rts
  2743.  
  2744. ;------------------------------------------------------------------------------
  2745.     cnop    0,16
  2746.  
  2747. ;in
  2748. * d2.w    -256..256
  2749. AddByteSVr:
  2750.     moveq    #0,d7
  2751.     lsr.w    #1,d0
  2752.     bcs.b    .1
  2753.     subq.w    #1,d0
  2754.     bmi.b    .exit
  2755. .nextsample
  2756.     move.b    (a3,d3.l),d7
  2757.     addq.l    #2,a4
  2758.     ext.w    d7
  2759.     muls.w    d2,d7
  2760.     add.w    d7,(a4)+
  2761.     add.l    d6,d4
  2762.     addx.l    d5,d3
  2763. .1
  2764.     move.b    (a3,d3.l),d7
  2765.     addq.l    #2,a4
  2766.     ext.w    d7
  2767.     muls.w    d2,d7
  2768.     add.w    d7,(a4)+
  2769.     add.l    d6,d4
  2770.     addx.l    d5,d3
  2771.     dbf    d0,.nextsample
  2772. .exit
  2773.     rts
  2774.  
  2775. ;------------------------------------------------------------------------------
  2776.     cnop    0,16
  2777.  
  2778. ;in
  2779. * d1.w    -256..256
  2780. * d2.w    -256..256
  2781. AddByteSVP:
  2782.     lsr.w    #1,d0
  2783.     bcs.b    .1
  2784.     subq.w    #1,d0
  2785.     bmi.b    .exit
  2786. .nextsample
  2787.     move.b    (a3,d3.l),d7
  2788.     ext.w    d7
  2789.     move.w    d7,a0
  2790.     muls.w    d1,d7
  2791.     add.w    d7,(a4)+
  2792.     move.w    a0,d7
  2793.     muls.w    d2,d7
  2794.     add.w    d7,(a4)+
  2795.     add.l    d6,d4
  2796.     addx.l    d5,d3
  2797. .1
  2798.     move.b    (a3,d3.l),d7
  2799.     ext.w    d7
  2800.     move.w    d7,a0
  2801.     muls.w    d1,d7
  2802.     add.w    d7,(a4)+
  2803.     move.w    a0,d7
  2804.     muls.w    d2,d7
  2805.     add.w    d7,(a4)+
  2806.     add.l    d6,d4
  2807.     addx.l    d5,d3
  2808.     dbf    d0,.nextsample
  2809. .exit
  2810.     rts
  2811.  
  2812. ;------------------------------------------------------------------------------
  2813.     cnop    0,16
  2814.  
  2815. ;in
  2816. * d1.l    Pointer in multiplication table
  2817. AddByteSVTl:
  2818.     move.l    d1,a0
  2819.     moveq    #0,d1
  2820.     lsr.w    #1,d0
  2821.     bcs.b    .1
  2822.     subq.w    #1,d0
  2823.     bmi.b    .exit
  2824. .nextsample
  2825.     move.b    (a3,d3.l),d1
  2826.  IFGE    __CPU-68020
  2827.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  2828.  ELSE
  2829.     add.w    d1,d1
  2830.     add.w    d1,d1
  2831.     move.w    0(a0,d1.w),d2        ;signed multiplication
  2832.     moveq    #0,d1
  2833.  ENDC
  2834.     add.w    d2,(a4)+
  2835.     add.l    d6,d4
  2836.     addx.l    d5,d3
  2837.     addq.l    #2,a4
  2838. .1
  2839.     move.b    (a3,d3.l),d1
  2840.  IFGE    __CPU-68020
  2841.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  2842.  ELSE
  2843.     add.w    d1,d1
  2844.     add.w    d1,d1
  2845.     move.w    0(a0,d1.w),d2        ;signed multiplication
  2846.     moveq    #0,d1
  2847.  ENDC
  2848.     add.w    d2,(a4)+
  2849.     add.l    d6,d4
  2850.     addx.l    d5,d3
  2851.     addq.l    #2,a4
  2852.     dbf    d0,.nextsample
  2853. .exit
  2854.     rts
  2855. ;------------------------------------------------------------------------------
  2856.     cnop    0,16
  2857.  
  2858. ;in
  2859. * d2.l    Pointer in multiplication table
  2860. AddByteSVTr:
  2861.     move.l    d2,a0
  2862.     moveq    #0,d1
  2863.     moveq    #0,d2
  2864.     lsr.w    #1,d0
  2865.     bcs.b    .1
  2866.     subq.w    #1,d0
  2867.     bmi.b    .exit
  2868. .nextsample
  2869.     move.b    (a3,d3.l),d1
  2870.  IFGE    __CPU-68020
  2871.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  2872.  ELSE
  2873.     add.w    d1,d1
  2874.     add.w    d1,d1
  2875.     move.w    0(a0,d1.w),d2        ;signed multiplication
  2876.     moveq    #0,d1
  2877.  ENDC
  2878.     addq.l    #2,a4
  2879.     add.w    d2,(a4)+
  2880.     add.l    d6,d4
  2881.     addx.l    d5,d3
  2882. .1
  2883.     move.b    (a3,d3.l),d1
  2884.  IFGE    __CPU-68020
  2885.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  2886.  ELSE
  2887.     add.w    d1,d1
  2888.     add.w    d1,d1
  2889.     move.w    0(a0,d1.w),d2        ;signed multiplication
  2890.     moveq    #0,d1
  2891.  ENDC
  2892.     addq.l    #2,a4
  2893.     add.w    d2,(a4)+
  2894.     add.l    d6,d4
  2895.     addx.l    d5,d3
  2896.     dbf    d0,.nextsample
  2897. .exit
  2898.     rts
  2899.  
  2900. ;------------------------------------------------------------------------------
  2901.     cnop    0,16
  2902.  
  2903. ;in
  2904. * d1.l    Pointer in multiplication table
  2905. * d2.l    Pointer in multiplication table
  2906. AddByteSVPT:
  2907.     move.l    a1,d7            ;save a1
  2908.     move.l    d1,a0
  2909.     move.l    d2,a1
  2910.     moveq    #0,d1
  2911.     lsr.w    #1,d0
  2912.     bcs.b    .1
  2913.     subq.w    #1,d0
  2914.     bmi.b    .exit
  2915. .nextsample
  2916.     move.b    (a3,d3.l),d1
  2917.  IFGE    __CPU-68020
  2918.     move.w    0(a0,d1.w*4),d2
  2919.  ELSE
  2920.     add.w    d1,d1
  2921.     add.w    d1,d1
  2922.     move.w    0(a0,d1.w),d2
  2923.  ENDC
  2924.     add.w    d2,(a4)+
  2925.  
  2926.  IFGE    __CPU-68020
  2927.     move.w    0(a1,d1.w*4),d2
  2928.  ELSE
  2929.     move.w    0(a1,d1.w),d2
  2930.     moveq    #0,d1
  2931.  ENDC
  2932.     add.w    d2,(a4)+
  2933.     add.l    d6,d4
  2934.     addx.l    d5,d3
  2935. .1
  2936.     move.b    (a3,d3.l),d1
  2937.  IFGE    __CPU-68020
  2938.     move.w    0(a0,d1.w*4),d2
  2939.  ELSE
  2940.     add.w    d1,d1
  2941.     add.w    d1,d1
  2942.     move.w    0(a0,d1.w),d2
  2943.  ENDC
  2944.     add.w    d2,(a4)+
  2945.  
  2946.  IFGE    __CPU-68020
  2947.     move.w    0(a1,d1.w*4),d2
  2948.  ELSE
  2949.     move.w    0(a1,d1.w),d2
  2950.     moveq    #0,d1
  2951.  ENDC
  2952.     add.w    d2,(a4)+
  2953.     add.l    d6,d4
  2954.     addx.l    d5,d3
  2955.     dbf    d0,.nextsample
  2956. .exit
  2957.     move.l    d7,a1            ;restore a1
  2958.     rts
  2959.  
  2960. ;******************************************************************************
  2961.     cnop    0,16
  2962.  
  2963. ;in
  2964. * d1.w    -256..256
  2965. * d2.w    -256..256
  2966. AddBytesMV:
  2967.  IFGE    __CPU-68020
  2968.     lsr.w    #1,d0
  2969.     bcs.b    .1
  2970.     subq.w    #1,d0
  2971.     bmi.b    .exit
  2972. .nextsample
  2973.     move.b    0(a3,d3.l*2),d7
  2974.     ext.w    d7
  2975.     muls.w    d1,d7
  2976.     add.w    d7,(a4)
  2977.     move.b    1(a3,d3.l*2),d7
  2978.     ext.w    d7
  2979.     muls.w    d2,d7
  2980.     add.w    d7,(a4)+
  2981.     add.l    d6,d4
  2982.     addx.l    d5,d3
  2983. .1
  2984.     move.b    0(a3,d3.l*2),d7
  2985.     ext.w    d7
  2986.     muls.w    d1,d7
  2987.     add.w    d7,(a4)
  2988.     move.b    1(a3,d3.l*2),d7
  2989.     ext.w    d7
  2990.     muls.w    d2,d7
  2991.     add.w    d7,(a4)+
  2992.     add.l    d6,d4
  2993.     addx.l    d5,d3
  2994.     dbf    d0,.nextsample
  2995. .exit
  2996.  ENDC
  2997.     rts
  2998.  
  2999. ;------------------------------------------------------------------------------
  3000.     cnop    0,16
  3001.  
  3002. ;in
  3003. * d1.l    Pointer in multiplication table
  3004. * d2.l    Pointer in multiplication table
  3005. AddBytesMVT:
  3006.  IFGE    __CPU-68020
  3007.     push    a1
  3008.     move.l    d1,a0
  3009.     move.l    d2,a1
  3010.     moveq    #0,d1
  3011.     lsr.w    #1,d0
  3012.     bcs.b    .1
  3013.     subq.w    #1,d0
  3014.     bmi.b    .exit
  3015. .nextsample
  3016.     move.b    0(a3,d3.l*2),d1
  3017.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  3018.     move.b    1(a3,d3.l*2),d1
  3019.     add.w    0(a1,d1.w*4),d2        ;signed multiplication
  3020.     add.w    d2,(a4)+
  3021.     add.l    d6,d4
  3022.     addx.l    d5,d3
  3023. .1
  3024.     move.b    0(a3,d3.l*2),d1
  3025.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  3026.     move.b    1(a3,d3.l*2),d1
  3027.     add.w    0(a1,d1.w*4),d2        ;signed multiplication
  3028.     add.w    d2,(a4)+
  3029.     add.l    d6,d4
  3030.     addx.l    d5,d3
  3031.  
  3032.     dbf    d0,.nextsample
  3033. .exit
  3034.     pop    a1
  3035.  ENDC
  3036.     rts
  3037.  
  3038. ;------------------------------------------------------------------------------
  3039.     cnop    0,16
  3040.  
  3041. ;in
  3042. * d1.w    -256..256
  3043. AddBytesSVl:
  3044.  IFGE    __CPU-68020
  3045.     lsr.w    #1,d0
  3046.     bcs.b    .1
  3047.     subq.w    #1,d0
  3048.     bmi.b    .exit
  3049. .nextsample
  3050.     move.b    0(a3,d3.l*2),d7
  3051.     ext.w    d7
  3052.     muls.w    d1,d7
  3053.     add.w    d7,(a4)+
  3054.     add.l    d6,d4
  3055.     addx.l    d5,d3
  3056.     addq.l    #2,a4
  3057. .1
  3058.     move.b    0(a3,d3.l*2),d7
  3059.     ext.w    d7
  3060.     muls.w    d1,d7
  3061.     add.w    d7,(a4)+
  3062.     add.l    d6,d4
  3063.     addx.l    d5,d3
  3064.     addq.l    #2,a4
  3065.     dbf    d0,.nextsample
  3066. .exit
  3067.  ENDC
  3068.     rts
  3069.  
  3070. ;------------------------------------------------------------------------------
  3071.     cnop    0,16
  3072.  
  3073. ;in
  3074. * d2.w    -256..256
  3075. AddBytesSVr:
  3076.  IFGE    __CPU-68020
  3077.     moveq    #0,d7
  3078.     lsr.w    #1,d0
  3079.     bcs.b    .1
  3080.     subq.w    #1,d0
  3081.     bmi.b    .exit
  3082. .nextsample
  3083.     move.b    1(a3,d3.l*2),d7
  3084.     addq.l    #2,a4
  3085.     ext.w    d7
  3086.     muls.w    d2,d7
  3087.     add.w    d7,(a4)+
  3088.     add.l    d6,d4
  3089.     addx.l    d5,d3
  3090. .1
  3091.     move.b    1(a3,d3.l*2),d7
  3092.     addq.l    #2,a4
  3093.     ext.w    d7
  3094.     muls.w    d2,d7
  3095.     add.w    d7,(a4)+
  3096.     add.l    d6,d4
  3097.     addx.l    d5,d3
  3098.     dbf    d0,.nextsample
  3099. .exit
  3100.  ENDC
  3101.     rts
  3102.  
  3103. ;------------------------------------------------------------------------------
  3104.     cnop    0,16
  3105.  
  3106. ;in
  3107. * d1.w    -256..256
  3108. * d2.w    -256..256
  3109. AddBytesSVP:
  3110.  IFGE    __CPU-68020
  3111.     lsr.w    #1,d0
  3112.     bcs.b    .1
  3113.     subq.w    #1,d0
  3114.     bmi.b    .exit
  3115. .nextsample
  3116.     move.b    0(a3,d3.l*2),d7
  3117.     ext.w    d7
  3118.     muls.w    d1,d7
  3119.     add.w    d7,(a4)+
  3120.     move.b    1(a3,d3.l*2),d7
  3121.     ext.w    d7
  3122.     muls.w    d2,d7
  3123.     add.w    d7,(a4)+
  3124.     add.l    d6,d4
  3125.     addx.l    d5,d3
  3126. .1
  3127.     move.b    0(a3,d3.l*2),d7
  3128.     ext.w    d7
  3129.     muls.w    d1,d7
  3130.     add.w    d7,(a4)+
  3131.     move.b    1(a3,d3.l*2),d7
  3132.     ext.w    d7
  3133.     muls.w    d2,d7
  3134.     add.w    d7,(a4)+
  3135.     add.l    d6,d4
  3136.     addx.l    d5,d3
  3137.     dbf    d0,.nextsample
  3138. .exit
  3139.  ENDC
  3140.     rts
  3141.  
  3142. ;------------------------------------------------------------------------------
  3143.     cnop    0,16
  3144.  
  3145. ;in
  3146. * d1.l    Pointer in multiplication table
  3147. AddBytesSVTl:
  3148.  IFGE    __CPU-68020
  3149.     move.l    d1,a0
  3150.     moveq    #0,d1
  3151.     lsr.w    #1,d0
  3152.     bcs.b    .1
  3153.     subq.w    #1,d0
  3154.     bmi.b    .exit
  3155. .nextsample
  3156.     move.b    0(a3,d3.l*2),d1
  3157.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  3158.     add.w    d2,(a4)+
  3159.     add.l    d6,d4
  3160.     addx.l    d5,d3
  3161.     addq.l    #2,a4
  3162. .1
  3163.     move.b    0(a3,d3.l*2),d1
  3164.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  3165.     add.w    d2,(a4)+
  3166.     add.l    d6,d4
  3167.     addx.l    d5,d3
  3168.     addq.l    #2,a4
  3169.     dbf    d0,.nextsample
  3170. .exit
  3171.  ENDC
  3172.     rts
  3173. ;------------------------------------------------------------------------------
  3174.     cnop    0,16
  3175.  
  3176. ;in
  3177. * d2.l    Pointer in multiplication table
  3178. AddBytesSVTr:
  3179.  IFGE    __CPU-68020
  3180.     move.l    d2,a0
  3181.     moveq    #0,d1
  3182.     moveq    #0,d2
  3183.     lsr.w    #1,d0
  3184.     bcs.b    .1
  3185.     subq.w    #1,d0
  3186.     bmi.b    .exit
  3187. .nextsample
  3188.     move.b    1(a3,d3.l*2),d1
  3189.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  3190.     addq.l    #2,a4
  3191.     add.w    d2,(a4)+
  3192.     add.l    d6,d4
  3193.     addx.l    d5,d3
  3194. .1
  3195.     move.b    1(a3,d3.l*2),d1
  3196.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  3197.     addq.l    #2,a4
  3198.     add.w    d2,(a4)+
  3199.     add.l    d6,d4
  3200.     addx.l    d5,d3
  3201.     dbf    d0,.nextsample
  3202. .exit
  3203.  ENDC
  3204.     rts
  3205.  
  3206. ;------------------------------------------------------------------------------
  3207.     cnop    0,16
  3208.  
  3209. ;in
  3210. * d1.l    Pointer in multiplication table
  3211. * d2.l    Pointer in multiplication table
  3212. AddBytesSVPT:
  3213.  IFGE    __CPU-68020
  3214.     move.l    a1,d7            ;save a1
  3215.     move.l    d1,a0
  3216.     move.l    d2,a1
  3217.     moveq    #0,d1
  3218.     lsr.w    #1,d0
  3219.     bcs.b    .1
  3220.     subq.w    #1,d0
  3221.     bmi.b    .exit
  3222. .nextsample
  3223.     move.b    0(a3,d3.l*2),d1
  3224.     move.w    0(a0,d1.w*4),d2
  3225.     add.w    d2,(a4)+
  3226.     move.b    1(a3,d3.l*2),d1
  3227.     move.w    0(a1,d1.w*4),d2
  3228.     add.w    d2,(a4)+
  3229.     add.l    d6,d4
  3230.     addx.l    d5,d3
  3231. .1
  3232.     move.b    0(a3,d3.l*2),d1
  3233.     move.w    0(a0,d1.w*4),d2
  3234.     add.w    d2,(a4)+
  3235.     move.b    1(a3,d3.l*2),d1
  3236.     move.w    0(a1,d1.w*4),d2
  3237.     add.w    d2,(a4)+
  3238.     add.l    d6,d4
  3239.     addx.l    d5,d3
  3240.     dbf    d0,.nextsample
  3241. .exit
  3242.     move.l    d7,a1            ;restore a1
  3243.  ENDC
  3244.     rts
  3245.  
  3246. ;******************************************************************************
  3247.     cnop    0,16
  3248.  
  3249. ;in
  3250. * d1.l    -32768..32767/-256..256
  3251. AddWordMV:
  3252. * 16/8 bit signed input (8 for '000 version)
  3253.     moveq    #15,d2
  3254.  
  3255.     lsr.w    #1,d0
  3256.     bcs.b    .1
  3257.     subq.w    #1,d0
  3258.     bmi.b    .exit
  3259. .nextsample
  3260.  IFGE    __CPU-68020
  3261.     move.w    (a3,d3.l*2),d7
  3262.     muls.w    d1,d7
  3263.     asr.l    d2,d7
  3264.  ELSE
  3265.     move.l    d3,d7
  3266.     add.l    d7,d7
  3267.     move.b    0(a3,d7.l),d7        ;high byte
  3268.     ext.w    d7
  3269.     muls.w    d1,d7
  3270.  ENDC
  3271.     add.w    d7,(a4)+
  3272.     add.l    d6,d4
  3273.     addx.l    d5,d3
  3274. .1
  3275.  IFGE    __CPU-68020
  3276.     move.w    (a3,d3.l*2),d7
  3277.     muls.w    d1,d7
  3278.     asr.l    d2,d7
  3279.  ELSE
  3280.     move.l    d3,d7
  3281.     add.l    d7,d7
  3282.     move.b    0(a3,d7.l),d7        ;high byte
  3283.     ext.w    d7
  3284.     muls.w    d1,d7
  3285.  ENDC
  3286.     add.w    d7,(a4)+
  3287.     add.l    d6,d4
  3288.     addx.l    d5,d3
  3289.     dbf    d0,.nextsample
  3290. .exit
  3291.     rts
  3292.  
  3293. ;------------------------------------------------------------------------------
  3294.     cnop    0,16
  3295.  
  3296. ;in
  3297. * d1.l    Shift count
  3298. AddWordMVT:
  3299.     lsr.w    #1,d0
  3300.     bcs.b    .1
  3301.     subq.w    #1,d0
  3302.     bmi.b    .exit
  3303. .nextsample
  3304.  IFGE    __CPU-68020
  3305.     move.w    (a3,d3.l*2),d7
  3306.  ELSE
  3307.     move.l    d3,d7
  3308.      add.l    d7,d7
  3309.     move.w    (a3,d7.l),d7
  3310.  ENDC
  3311.     asr.w    d1,d7
  3312.     add.w    d7,(a4)+
  3313.     add.l    d6,d4
  3314.     addx.l    d5,d3
  3315. .1
  3316.  IFGE    __CPU-68020
  3317.     move.w    (a3,d3.l*2),d7
  3318.  ELSE
  3319.     move.l    d3,d7
  3320.      add.l    d7,d7
  3321.     move.w    (a3,d7.l),d7
  3322.  ENDC
  3323.     asr.w    d1,d7
  3324.     add.w    d7,(a4)+
  3325.     add.l    d6,d4
  3326.     addx.l    d5,d3
  3327.     dbf    d0,.nextsample
  3328. .exit
  3329.     rts
  3330.  
  3331. ;------------------------------------------------------------------------------
  3332.     cnop    0,16
  3333.  
  3334. ;in
  3335. * d1.l    -32768..32767/-256..256
  3336. AddWordSVl:
  3337. * 16/8 bit signed input (8 for '000 version)
  3338.     moveq    #15,d2
  3339.     lsr.w    #1,d0
  3340.     bcs.b    .1
  3341.     subq.w    #1,d0
  3342.     bmi.b    .exit
  3343. .nextsample
  3344.  IFGE    __CPU-68020
  3345.     move.w    (a3,d3.l*2),d7
  3346.     muls.w    d1,d7
  3347.     asr.l    d2,d7
  3348.  ELSE
  3349.     move.l    d3,d7
  3350.     add.l    d7,d7
  3351.     move.b    0(a3,d7.l),d7        ;high byte
  3352.     ext.w    d7
  3353.     muls.w    d1,d7
  3354.  ENDC
  3355.     add.w    d7,(a4)+
  3356.     add.l    d6,d4
  3357.     addx.l    d5,d3
  3358.     addq.l    #2,a4
  3359. .1
  3360.  IFGE    __CPU-68020
  3361.     move.w    (a3,d3.l*2),d7
  3362.     muls.w    d1,d7
  3363.     asr.l    d2,d7
  3364.  ELSE
  3365.     move.l    d3,d7
  3366.     add.l    d7,d7
  3367.     move.b    0(a3,d7.l),d7        ;high byte
  3368.     ext.w    d7
  3369.     muls.w    d1,d7
  3370.  ENDC
  3371.     add.w    d7,(a4)+
  3372.     add.l    d6,d4
  3373.     addx.l    d5,d3
  3374.     addq.l    #2,a4
  3375.     dbf    d0,.nextsample
  3376. .exit
  3377.     rts
  3378.  
  3379. ;------------------------------------------------------------------------------
  3380.     cnop    0,16
  3381.  
  3382. ;in
  3383. * d2.l    -32768..32767/-256..256
  3384. AddWordSVr:
  3385. * 16/8 bit signed input (8 for '000 version)
  3386.     moveq    #15,d1
  3387.  
  3388.     lsr.w    #1,d0
  3389.     bcs.b    .1
  3390.     subq.w    #1,d0
  3391.     bmi.b    .exit
  3392. .nextsample
  3393.  IFGE    __CPU-68020
  3394.     move.w    (a3,d3.l*2),d7
  3395.     muls.w    d2,d7
  3396.     asr.l    d1,d7
  3397.  ELSE
  3398.     move.l    d3,d7
  3399.     add.l    d7,d7
  3400.     move.b    0(a3,d7.l),d7        ;high byte
  3401.     ext.w    d7
  3402.     muls.w    d2,d7
  3403.  ENDC
  3404.     addq.l    #2,a4
  3405.     add.w    d7,(a4)+
  3406.     add.l    d6,d4
  3407.     addx.l    d5,d3
  3408. .1
  3409.  IFGE    __CPU-68020
  3410.     move.w    (a3,d3.l*2),d7
  3411.     muls.w    d2,d7
  3412.     asr.l    d1,d7
  3413.  ELSE
  3414.     move.l    d3,d7
  3415.     add.l    d7,d7
  3416.     move.b    0(a3,d7.l),d7        ;high byte
  3417.     ext.w    d7
  3418.     muls.w    d2,d7
  3419.  ENDC
  3420.     addq.l    #2,a4
  3421.     add.w    d7,(a4)+
  3422.     add.l    d6,d4
  3423.     addx.l    d5,d3
  3424.     dbf    d0,.nextsample
  3425. .exit
  3426.     rts
  3427.  
  3428. ;------------------------------------------------------------------------------
  3429.     cnop    0,16
  3430.  
  3431. ;in
  3432. * d1.l    -32768..32767/-256..256
  3433. * d2.l    -32768..32767/-256..256
  3434. AddWordSVP:
  3435. * 16/8 bit signed input (8 for '000 version)
  3436.     lsr.w    #1,d0
  3437.     bcs.b    .1
  3438.     subq.w    #1,d0
  3439.     bmi.b    .exit
  3440. .nextsample
  3441.  IFGE    __CPU-68020
  3442.     move.w    (a3,d3.l*2),d7
  3443.     move.l    d7,a0
  3444.     muls.w    d1,d7
  3445.     asr.l    #8,d7
  3446.     asr.l    #7,d7
  3447.     add.w    d7,(a4)+
  3448.  
  3449.     move.l    a0,d7
  3450.     muls.w    d2,d7
  3451.     asr.l    #8,d7
  3452.     asr.l    #7,d7
  3453.     add.w    d7,(a4)+
  3454.  ELSE
  3455.     move.l    d3,d7
  3456.     add.l    d7,d7
  3457.     move.b    0(a3,d7.l),d7        ;high byte
  3458.     ext.w    d7
  3459.     move.l    d7,a0
  3460.     muls.w    d1,d7
  3461.     add.w    d7,(a4)+
  3462.  
  3463.     move.l    a0,d7
  3464.     muls.w    d2,d7
  3465.     add.w    d7,(a4)+
  3466.  ENDC
  3467.     add.l    d6,d4
  3468.     addx.l    d5,d3
  3469. .1
  3470.  IFGE    __CPU-68020
  3471.     move.w    (a3,d3.l*2),d7
  3472.     move.l    d7,a0
  3473.     muls.w    d1,d7
  3474.     asr.l    #8,d7
  3475.     asr.l    #7,d7
  3476.     add.w    d7,(a4)+
  3477.  
  3478.     move.l    a0,d7
  3479.     muls.w    d2,d7
  3480.     asr.l    #8,d7
  3481.     asr.l    #7,d7
  3482.     add.w    d7,(a4)+
  3483.  ELSE
  3484.     move.l    d3,d7
  3485.     add.l    d7,d7
  3486.     move.b    0(a3,d7.l),d7        ;high byte
  3487.     ext.w    d7
  3488.     move.l    d7,a0
  3489.     muls.w    d1,d7
  3490.     add.w    d7,(a4)+
  3491.  
  3492.     move.l    a0,d7
  3493.     muls.w    d2,d7
  3494.     add.w    d7,(a4)+
  3495.  ENDC
  3496.     add.l    d6,d4
  3497.     addx.l    d5,d3
  3498.     dbf    d0,.nextsample
  3499. .exit
  3500.     rts
  3501.  
  3502. ;------------------------------------------------------------------------------
  3503.     cnop    0,16
  3504.  
  3505. ;in
  3506. * d1.l    Shift count
  3507. AddWordSVTl:
  3508.     lsr.w    #1,d0
  3509.     bcs.b    .1
  3510.     subq.w    #1,d0
  3511.     bmi.b    .exit
  3512. .nextsample
  3513.  IFGE    __CPU-68020
  3514.     move.w    (a3,d3.l*2),d7
  3515.  ELSE
  3516.     move.l    d3,d7
  3517.     add.l    d7,d7
  3518.     move.w    (a3,d7.l),d7
  3519.  ENDC
  3520.     asr.w    d1,d7
  3521.     add.w    d7,(a4)+
  3522.     add.l    d6,d4
  3523.     addx.l    d5,d3
  3524.     addq.l    #2,a4
  3525. .1
  3526.  IFGE    __CPU-68020
  3527.     move.w    (a3,d3.l*2),d7
  3528.  ELSE
  3529.     move.l    d3,d7
  3530.     add.l    d7,d7
  3531.     move.w    (a3,d7.l),d7
  3532.  ENDC
  3533.     asr.w    d1,d7
  3534.     add.w    d7,(a4)+
  3535.     add.l    d6,d4
  3536.     addx.l    d5,d3
  3537.     addq.l    #2,a4
  3538.  
  3539.     dbf    d0,.nextsample
  3540. .exit
  3541.     rts
  3542.  
  3543. ;------------------------------------------------------------------------------
  3544.     cnop    0,16
  3545.  
  3546. ;in
  3547. * d2.l    Shift count
  3548. AddWordSVTr:
  3549.     lsr.w    #1,d0
  3550.     bcs.b    .1
  3551.     subq.w    #1,d0
  3552.     bmi.b    .exit
  3553. .nextsample
  3554.  IFGE    __CPU-68020
  3555.     move.w    (a3,d3.l*2),d7
  3556.  ELSE
  3557.     move.l    d3,d7
  3558.     add.l    d7,d7
  3559.     move.w    (a3,d7.l),d7
  3560.  ENDC
  3561.     asr.w    d2,d7
  3562.     addq.l    #2,a4
  3563.     add.w    d7,(a4)+
  3564.     add.l    d6,d4
  3565.     addx.l    d5,d3
  3566. .1
  3567.  IFGE    __CPU-68020
  3568.     move.w    (a3,d3.l*2),d7
  3569.  ELSE
  3570.     move.l    d3,d7
  3571.     add.l    d7,d7
  3572.     move.w    (a3,d7.l),d7
  3573.  ENDC
  3574.     asr.w    d2,d7
  3575.     addq.l    #2,a4
  3576.     add.w    d7,(a4)+
  3577.     add.l    d6,d4
  3578.     addx.l    d5,d3
  3579.     dbf    d0,.nextsample
  3580. .exit
  3581.     rts
  3582.  
  3583. ;------------------------------------------------------------------------------
  3584.     cnop    0,16
  3585.  
  3586. ;in
  3587. * d1.l    Shift count
  3588. * d2.l    Shift count
  3589. AddWordSVPT:
  3590.     lsr.w    #1,d0
  3591.     bcs.b    .1
  3592.     subq.w    #1,d0
  3593.     bmi.b    .exit
  3594. .nextsample
  3595.  IFGE    __CPU-68020
  3596.     move.w    (a3,d3.l*2),d7
  3597.     asr.w    d1,d7
  3598.     add.w    d7,(a4)+
  3599.     move.w    (a3,d3.l*2),d7
  3600.     asr.w    d2,d7
  3601.     add.w    d7,(a4)+
  3602.  ELSE
  3603.     move.l    d3,d7
  3604.     add.l    d7,d7
  3605.     move.w    (a3,d7.l),d7
  3606.     move.l    d7,a0
  3607.     asr.w    d1,d7
  3608.     add.w    d7,(a4)+
  3609.     move.l    a0,d7
  3610.     asr.w    d2,d7
  3611.     add.w    d7,(a4)+
  3612.  ENDC
  3613.     add.l    d6,d4
  3614.     addx.l    d5,d3
  3615. .1
  3616.  IFGE    __CPU-68020
  3617.     move.w    (a3,d3.l*2),d7
  3618.     asr.w    d1,d7
  3619.     add.w    d7,(a4)+
  3620.     move.w    (a3,d3.l*2),d7
  3621.     asr.w    d2,d7
  3622.     add.w    d7,(a4)+
  3623.  ELSE
  3624.     move.l    d3,d7
  3625.     add.l    d7,d7
  3626.     move.w    (a3,d7.l),d7
  3627.     move.l    d7,a0
  3628.     asr.w    d1,d7
  3629.     add.w    d7,(a4)+
  3630.     move.l    a0,d7
  3631.     asr.w    d2,d7
  3632.     add.w    d7,(a4)+
  3633.  ENDC
  3634.     add.l    d6,d4
  3635.     addx.l    d5,d3
  3636.  
  3637.     dbf    d0,.nextsample
  3638. .exit
  3639.     rts
  3640.  
  3641.  
  3642. ;******************************************************************************
  3643.     cnop    0,16
  3644.  
  3645. ;in
  3646. * d1.l    -32768..32767
  3647. * d2.l    -32768..32767
  3648. AddWordsMV:
  3649. * 16 bit signed input
  3650.  IFGE    __CPU-68020
  3651.     lsr.w    #1,d0
  3652.     bcs.b    .1
  3653.     subq.w    #1,d0
  3654.     bmi.b    .exit
  3655. .nextsample
  3656.     move.w    0(a3,d3.l*4),d7
  3657.     muls.w    d1,d7
  3658.     asr.l    #8,d7
  3659.     asr.l    #7,d7
  3660.     add.w    d7,(a4)
  3661.     move.w    2(a3,d3.l*4),d7
  3662.     muls.w    d2,d7
  3663.     asr.l    #8,d7
  3664.     asr.l    #7,d7
  3665.     add.w    d7,(a4)+
  3666.     add.l    d6,d4
  3667.     addx.l    d5,d3
  3668. .1
  3669.     move.w    0(a3,d3.l*4),d7
  3670.     muls.w    d1,d7
  3671.     asr.l    #8,d7
  3672.     asr.l    #7,d7
  3673.     add.w    d7,(a4)
  3674.     move.w    2(a3,d3.l*4),d7
  3675.     muls.w    d2,d7
  3676.     asr.l    #8,d7
  3677.     asr.l    #7,d7
  3678.     add.w    d7,(a4)+
  3679.     add.l    d6,d4
  3680.     addx.l    d5,d3
  3681.     dbf    d0,.nextsample
  3682. .exit
  3683.  ENDC
  3684.     rts
  3685.  
  3686. ;------------------------------------------------------------------------------
  3687.     cnop    0,16
  3688.  
  3689. ;in
  3690. * d1.l    Shift Count
  3691. * d2.l    Shift Count
  3692. AddWordsMVT:
  3693.  IFGE    __CPU-68020
  3694.     lsr.w    #1,d0
  3695.     bcs.b    .1
  3696.     subq.w    #1,d0
  3697.     bmi.b    .exit
  3698. .nextsample
  3699.     move.w    (a3,d3.l*4),d7
  3700.     asr.w    d1,d7
  3701.     add.w    d7,(a4)
  3702.     move.w    2(a3,d3.l*4),d7
  3703.     asr.w    d2,d7
  3704.     add.w    d7,(a4)+
  3705.     add.l    d6,d4
  3706.     addx.l    d5,d3
  3707. .1
  3708.     move.w    (a3,d3.l*4),d7
  3709.     asr.w    d1,d7
  3710.     add.w    d7,(a4)
  3711.     move.w    2(a3,d3.l*4),d7
  3712.     asr.w    d2,d7
  3713.     add.w    d7,(a4)+
  3714.     add.l    d6,d4
  3715.     addx.l    d5,d3
  3716.  
  3717.     dbf    d0,.nextsample
  3718. .exit
  3719.  ENDC
  3720.     rts
  3721.  
  3722. ;------------------------------------------------------------------------------
  3723.     cnop    0,16
  3724.  
  3725. ;in
  3726. * d1.l    -32768..32767
  3727. AddWordsSVl:
  3728. * 16 bit signed input
  3729.  IFGE    __CPU-68020
  3730.     moveq    #15,d2
  3731.     lsr.w    #1,d0
  3732.     bcs.b    .1
  3733.     subq.w    #1,d0
  3734.     bmi.b    .exit
  3735. .nextsample
  3736.     move.w    0(a3,d3.l*4),d7
  3737.     muls.w    d1,d7
  3738.     asr.l    d2,d7
  3739.     add.w    d7,(a4)+
  3740.     add.l    d6,d4
  3741.     addx.l    d5,d3
  3742.     addq.l    #2,a4
  3743. .1
  3744.     move.w    0(a3,d3.l*4),d7
  3745.     muls.w    d1,d7
  3746.     asr.l    d2,d7
  3747.     add.w    d7,(a4)+
  3748.     add.l    d6,d4
  3749.     addx.l    d5,d3
  3750.     addq.l    #2,a4
  3751.     dbf    d0,.nextsample
  3752. .exit
  3753.  ENDC
  3754.     rts
  3755.  
  3756. ;------------------------------------------------------------------------------
  3757.     cnop    0,16
  3758.  
  3759. ;in
  3760. * d2.l    -32768..32767/
  3761. AddWordsSVr:
  3762. * 16 bit signed input
  3763.  IFGE    __CPU-68020
  3764.     moveq    #15,d1
  3765.  
  3766.     lsr.w    #1,d0
  3767.     bcs.b    .1
  3768.     subq.w    #1,d0
  3769.     bmi.b    .exit
  3770. .nextsample
  3771.     move.w    2(a3,d3.l*4),d7
  3772.     muls.w    d2,d7
  3773.     asr.l    d1,d7
  3774.     addq.l    #2,a4
  3775.     add.w    d7,(a4)+
  3776.     add.l    d6,d4
  3777.     addx.l    d5,d3
  3778. .1
  3779.     move.w    2(a3,d3.l*4),d7
  3780.     muls.w    d2,d7
  3781.     asr.l    d1,d7
  3782.     addq.l    #2,a4
  3783.     add.w    d7,(a4)+
  3784.     add.l    d6,d4
  3785.     addx.l    d5,d3
  3786.     dbf    d0,.nextsample
  3787. .exit
  3788.  ENDC
  3789.     rts
  3790.  
  3791. ;------------------------------------------------------------------------------
  3792.     cnop    0,16
  3793.  
  3794. ;in
  3795. * d1.l    -32768..32767/-256..256
  3796. * d2.l    -32768..32767/-256..256
  3797. AddWordsSVP:
  3798. * 16/8 bit signed input (8 for '000 version)
  3799.  IFGE    __CPU-68020
  3800.     lsr.w    #1,d0
  3801.     bcs.b    .1
  3802.     subq.w    #1,d0
  3803.     bmi.b    .exit
  3804. .nextsample
  3805.     move.w    0(a3,d3.l*4),d7
  3806.     muls.w    d1,d7
  3807.     asr.l    #8,d7
  3808.     asr.l    #7,d7
  3809.     add.w    d7,(a4)+
  3810.  
  3811.     move.w    2(a3,d3.l*4),d7
  3812.     muls.w    d2,d7
  3813.     asr.l    #8,d7
  3814.     asr.l    #7,d7
  3815.     add.w    d7,(a4)+
  3816.     add.l    d6,d4
  3817.     addx.l    d5,d3
  3818. .1
  3819.     move.w    0(a3,d3.l*4),d7
  3820.     muls.w    d1,d7
  3821.     asr.l    #8,d7
  3822.     asr.l    #7,d7
  3823.     add.w    d7,(a4)+
  3824.  
  3825.     move.w    2(a3,d3.l*4),d7
  3826.     muls.w    d2,d7
  3827.     asr.l    #8,d7
  3828.     asr.l    #7,d7
  3829.     add.w    d7,(a4)+
  3830.     add.l    d6,d4
  3831.     addx.l    d5,d3
  3832.     dbf    d0,.nextsample
  3833. .exit
  3834.  ENDC
  3835.     rts
  3836.  
  3837. ;------------------------------------------------------------------------------
  3838.     cnop    0,16
  3839.  
  3840. ;in
  3841. * d1.l    Shift count
  3842. AddWordsSVTl:
  3843.  IFGE    __CPU-68020
  3844.     lsr.w    #1,d0
  3845.     bcs.b    .1
  3846.     subq.w    #1,d0
  3847.     bmi.b    .exit
  3848. .nextsample
  3849.     move.w    (a3,d3.l*4),d7
  3850.     asr.w    d1,d7
  3851.     add.w    d7,(a4)+
  3852.     add.l    d6,d4
  3853.     addx.l    d5,d3
  3854.     addq.l    #2,a4
  3855. .1
  3856.     move.w    (a3,d3.l*4),d7
  3857.     asr.w    d1,d7
  3858.     add.w    d7,(a4)+
  3859.     add.l    d6,d4
  3860.     addx.l    d5,d3
  3861.     addq.l    #2,a4
  3862.  
  3863.     dbf    d0,.nextsample
  3864. .exit
  3865.  ENDC
  3866.     rts
  3867.  
  3868. ;------------------------------------------------------------------------------
  3869.     cnop    0,16
  3870.  
  3871. ;in
  3872. * d2.l    Shift count
  3873. AddWordsSVTr:
  3874.  IFGE    __CPU-68020
  3875.     lsr.w    #1,d0
  3876.     bcs.b    .1
  3877.     subq.w    #1,d0
  3878.     bmi.b    .exit
  3879. .nextsample
  3880.     move.w    2(a3,d3.l*4),d7
  3881.     asr.w    d2,d7
  3882.     addq.l    #2,a4
  3883.     add.w    d7,(a4)+
  3884.     add.l    d6,d4
  3885.     addx.l    d5,d3
  3886. .1
  3887.     move.w    2(a3,d3.l*4),d7
  3888.     asr.w    d2,d7
  3889.     addq.l    #2,a4
  3890.     add.w    d7,(a4)+
  3891.     add.l    d6,d4
  3892.     addx.l    d5,d3
  3893.  
  3894.     dbf    d0,.nextsample
  3895. .exit
  3896.  ENDC
  3897.     rts
  3898.  
  3899. ;------------------------------------------------------------------------------
  3900.     cnop    0,16
  3901.  
  3902. ;in
  3903. * d1.l    Shift count
  3904. * d2.l    Shift count
  3905. AddWordsSVPT:
  3906.  IFGE    __CPU-68020
  3907.     lsr.w    #1,d0
  3908.     bcs.b    .1
  3909.     subq.w    #1,d0
  3910.     bmi.b    .exit
  3911. .nextsample
  3912.     move.w    (a3,d3.l*4),d7
  3913.     asr.w    d1,d7
  3914.     add.w    d7,(a4)+
  3915.     move.w    2(a3,d3.l*4),d7
  3916.     asr.w    d2,d7
  3917.     add.w    d7,(a4)+
  3918.     add.l    d6,d4
  3919.     addx.l    d5,d3
  3920. .1
  3921.     move.w    (a3,d3.l*4),d7
  3922.     asr.w    d1,d7
  3923.     add.w    d7,(a4)+
  3924.     move.w    2(a3,d3.l*4),d7
  3925.     asr.w    d2,d7
  3926.     add.w    d7,(a4)+
  3927.     add.l    d6,d4
  3928.     addx.l    d5,d3
  3929.  
  3930.     dbf    d0,.nextsample
  3931. .exit
  3932.  ENDC
  3933.     rts
  3934.  
  3935. ;******************************************************************************
  3936. ;**** Backwards ***************************************************************
  3937. ;******************************************************************************
  3938.  
  3939.     cnop    0,16
  3940.  
  3941. ;in
  3942. * d1.w    -256..256
  3943. AddByteMVB:
  3944.     lsr.w    #1,d0
  3945.     bcs.b    .1
  3946.     subq.w    #1,d0
  3947.     bmi.b    .exit
  3948. .nextsample
  3949.     move.b    (a3,d3.l),d7
  3950.     ext.w    d7
  3951.     muls.w    d1,d7
  3952.     add.w    d7,(a4)+
  3953.     sub.l    d6,d4
  3954.     subx.l    d5,d3
  3955. .1
  3956.     move.b    (a3,d3.l),d7
  3957.     ext.w    d7
  3958.     muls.w    d1,d7
  3959.     add.w    d7,(a4)+
  3960.     sub.l    d6,d4
  3961.     subx.l    d5,d3
  3962.     dbf    d0,.nextsample
  3963. .exit
  3964.     rts
  3965.  
  3966. ;------------------------------------------------------------------------------
  3967.     cnop    0,16
  3968.  
  3969. ;in
  3970. * d1.l    Pointer in multiplication table
  3971. AddByteMVTB:
  3972.     move.l    d1,a0
  3973.     moveq    #0,d1
  3974.     lsr.w    #1,d0
  3975.     bcs.b    .1
  3976.     subq.w    #1,d0
  3977.     bmi.b    .exit
  3978. .nextsample
  3979.     move.b    (a3,d3.l),d1
  3980.  IFGE    __CPU-68020
  3981.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  3982.  ELSE
  3983.     add.w    d1,d1
  3984.     add.w    d1,d1
  3985.     move.w    0(a0,d1.w),d2        ;signed multiplication
  3986.     moveq    #0,d1
  3987.  ENDC
  3988.     add.w    d2,(a4)+
  3989.     sub.l    d6,d4
  3990.     subx.l    d5,d3
  3991. .1
  3992.     move.b    (a3,d3.l),d1
  3993.  IFGE    __CPU-68020
  3994.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  3995.  ELSE
  3996.     add.w    d1,d1
  3997.     add.w    d1,d1
  3998.     move.w    0(a0,d1.w),d2        ;signed multiplication
  3999.     moveq    #0,d1
  4000.  ENDC
  4001.     add.w    d2,(a4)+
  4002.     sub.l    d6,d4
  4003.     subx.l    d5,d3
  4004.  
  4005.     dbf    d0,.nextsample
  4006. .exit
  4007.     rts
  4008.  
  4009. ;------------------------------------------------------------------------------
  4010.     cnop    0,16
  4011.  
  4012. ;in
  4013. * d1.w    -256..256
  4014. AddByteSVlB:
  4015.     lsr.w    #1,d0
  4016.     bcs.b    .1
  4017.     subq.w    #1,d0
  4018.     bmi.b    .exit
  4019. .nextsample
  4020.     move.b    (a3,d3.l),d7
  4021.     ext.w    d7
  4022.     muls.w    d1,d7
  4023.     add.w    d7,(a4)+
  4024.     sub.l    d6,d4
  4025.     subx.l    d5,d3
  4026.     addq.l    #2,a4
  4027. .1
  4028.     move.b    (a3,d3.l),d7
  4029.     ext.w    d7
  4030.     muls.w    d1,d7
  4031.     add.w    d7,(a4)+
  4032.     sub.l    d6,d4
  4033.     subx.l    d5,d3
  4034.     addq.l    #2,a4
  4035.     dbf    d0,.nextsample
  4036. .exit
  4037.     rts
  4038.  
  4039. ;------------------------------------------------------------------------------
  4040.     cnop    0,16
  4041.  
  4042. ;in
  4043. * d2.w    -256..256
  4044. AddByteSVrB:
  4045.     moveq    #0,d7
  4046.     lsr.w    #1,d0
  4047.     bcs.b    .1
  4048.     subq.w    #1,d0
  4049.     bmi.b    .exit
  4050. .nextsample
  4051.     move.b    (a3,d3.l),d7
  4052.     addq.l    #2,a4
  4053.     ext.w    d7
  4054.     muls.w    d2,d7
  4055.     add.w    d7,(a4)+
  4056.     sub.l    d6,d4
  4057.     subx.l    d5,d3
  4058. .1
  4059.     move.b    (a3,d3.l),d7
  4060.     addq.l    #2,a4
  4061.     ext.w    d7
  4062.     muls.w    d2,d7
  4063.     add.w    d7,(a4)+
  4064.     sub.l    d6,d4
  4065.     subx.l    d5,d3
  4066.     dbf    d0,.nextsample
  4067. .exit
  4068.     rts
  4069.  
  4070. ;------------------------------------------------------------------------------
  4071.     cnop    0,16
  4072.  
  4073. ;in
  4074. * d1.w    -256..256
  4075. * d2.w    -256..256
  4076. AddByteSVPB:
  4077.     lsr.w    #1,d0
  4078.     bcs.b    .1
  4079.     subq.w    #1,d0
  4080.     bmi.b    .exit
  4081. .nextsample
  4082.     move.b    (a3,d3.l),d7
  4083.     ext.w    d7
  4084.     move.w    d7,a0
  4085.     muls.w    d1,d7
  4086.     add.w    d7,(a4)+
  4087.     move.w    a0,d7
  4088.     muls.w    d2,d7
  4089.     add.w    d7,(a4)+
  4090.     sub.l    d6,d4
  4091.     subx.l    d5,d3
  4092. .1
  4093.     move.b    (a3,d3.l),d7
  4094.     ext.w    d7
  4095.     move.w    d7,a0
  4096.     muls.w    d1,d7
  4097.     add.w    d7,(a4)+
  4098.     move.w    a0,d7
  4099.     muls.w    d2,d7
  4100.     add.w    d7,(a4)+
  4101.     sub.l    d6,d4
  4102.     subx.l    d5,d3
  4103.     dbf    d0,.nextsample
  4104. .exit
  4105.     rts
  4106.  
  4107. ;------------------------------------------------------------------------------
  4108.     cnop    0,16
  4109.  
  4110. ;in
  4111. * d1.l    Pointer in multiplication table
  4112. AddByteSVTlB:
  4113.     move.l    d1,a0
  4114.     moveq    #0,d1
  4115.     lsr.w    #1,d0
  4116.     bcs.b    .1
  4117.     subq.w    #1,d0
  4118.     bmi.b    .exit
  4119. .nextsample
  4120.     move.b    (a3,d3.l),d1
  4121.  IFGE    __CPU-68020
  4122.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  4123.  ELSE
  4124.     add.w    d1,d1
  4125.     add.w    d1,d1
  4126.     move.w    0(a0,d1.w),d2        ;signed multiplication
  4127.     moveq    #0,d1
  4128.  ENDC
  4129.     add.w    d2,(a4)+
  4130.     sub.l    d6,d4
  4131.     subx.l    d5,d3
  4132.     addq.l    #2,a4
  4133. .1
  4134.     move.b    (a3,d3.l),d1
  4135.  IFGE    __CPU-68020
  4136.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  4137.  ELSE
  4138.     add.w    d1,d1
  4139.     add.w    d1,d1
  4140.     move.w    0(a0,d1.w),d2        ;signed multiplication
  4141.     moveq    #0,d1
  4142.  ENDC
  4143.     add.w    d2,(a4)+
  4144.     sub.l    d6,d4
  4145.     subx.l    d5,d3
  4146.     addq.l    #2,a4
  4147.     dbf    d0,.nextsample
  4148. .exit
  4149.     rts
  4150. ;------------------------------------------------------------------------------
  4151.     cnop    0,16
  4152.  
  4153. ;in
  4154. * d2.l    Pointer in multiplication table
  4155. AddByteSVTrB:
  4156.     move.l    d2,a0
  4157.     moveq    #0,d1
  4158.     moveq    #0,d2
  4159.     lsr.w    #1,d0
  4160.     bcs.b    .1
  4161.     subq.w    #1,d0
  4162.     bmi.b    .exit
  4163. .nextsample
  4164.     move.b    (a3,d3.l),d1
  4165.  IFGE    __CPU-68020
  4166.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  4167.  ELSE
  4168.     add.w    d1,d1
  4169.     add.w    d1,d1
  4170.     move.w    0(a0,d1.w),d2        ;signed multiplication
  4171.     moveq    #0,d1
  4172.  ENDC
  4173.     addq.l    #2,a4
  4174.     add.w    d2,(a4)+
  4175.     sub.l    d6,d4
  4176.     subx.l    d5,d3
  4177. .1
  4178.     move.b    (a3,d3.l),d1
  4179.  IFGE    __CPU-68020
  4180.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  4181.  ELSE
  4182.     add.w    d1,d1
  4183.     add.w    d1,d1
  4184.     move.w    0(a0,d1.w),d2        ;signed multiplication
  4185.     moveq    #0,d1
  4186.  ENDC
  4187.     addq.l    #2,a4
  4188.     add.w    d2,(a4)+
  4189.     sub.l    d6,d4
  4190.     subx.l    d5,d3
  4191.     dbf    d0,.nextsample
  4192. .exit
  4193.     rts
  4194.  
  4195. ;------------------------------------------------------------------------------
  4196.     cnop    0,16
  4197.  
  4198. ;in
  4199. * d1.l    Pointer in multiplication table
  4200. * d2.l    Pointer in multiplication table
  4201. AddByteSVPTB:
  4202.     move.l    a1,d7            ;save a1
  4203.     move.l    d1,a0
  4204.     move.l    d2,a1
  4205.     moveq    #0,d1
  4206.     lsr.w    #1,d0
  4207.     bcs.b    .1
  4208.     subq.w    #1,d0
  4209.     bmi.b    .exit
  4210. .nextsample
  4211.     move.b    (a3,d3.l),d1
  4212.  IFGE    __CPU-68020
  4213.     move.w    0(a0,d1.w*4),d2
  4214.  ELSE
  4215.     add.w    d1,d1
  4216.     add.w    d1,d1
  4217.     move.w    0(a0,d1.w),d2
  4218.  ENDC
  4219.     add.w    d2,(a4)+
  4220.  
  4221.  IFGE    __CPU-68020
  4222.     move.w    0(a1,d1.w*4),d2
  4223.  ELSE
  4224.     move.w    0(a1,d1.w),d2
  4225.     moveq    #0,d1
  4226.  ENDC
  4227.     add.w    d2,(a4)+
  4228.     sub.l    d6,d4
  4229.     subx.l    d5,d3
  4230. .1
  4231.     move.b    (a3,d3.l),d1
  4232.  IFGE    __CPU-68020
  4233.     move.w    0(a0,d1.w*4),d2
  4234.  ELSE
  4235.     add.w    d1,d1
  4236.     add.w    d1,d1
  4237.     move.w    0(a0,d1.w),d2
  4238.  ENDC
  4239.     add.w    d2,(a4)+
  4240.  
  4241.  IFGE    __CPU-68020
  4242.     move.w    0(a1,d1.w*4),d2
  4243.  ELSE
  4244.     move.w    0(a1,d1.w),d2
  4245.     moveq    #0,d1
  4246.  ENDC
  4247.     add.w    d2,(a4)+
  4248.     sub.l    d6,d4
  4249.     subx.l    d5,d3
  4250.     dbf    d0,.nextsample
  4251. .exit
  4252.     move.l    d7,a1            ;restore a1
  4253.     rts
  4254.  
  4255. ;******************************************************************************
  4256.     cnop    0,16
  4257.  
  4258. ;in
  4259. * d1.w    -256..256
  4260. * d2.w    -256..256
  4261. AddBytesMVB:
  4262.  IFGE    __CPU-68020
  4263.     lsr.w    #1,d0
  4264.     bcs.b    .1
  4265.     subq.w    #1,d0
  4266.     bmi.b    .exit
  4267. .nextsample
  4268.     move.b    0(a3,d3.l*2),d7
  4269.     ext.w    d7
  4270.     muls.w    d1,d7
  4271.     add.w    d7,(a4)
  4272.     move.b    1(a3,d3.l*2),d7
  4273.     ext.w    d7
  4274.     muls.w    d2,d7
  4275.     add.w    d7,(a4)+
  4276.     sub.l    d6,d4
  4277.     subx.l    d5,d3
  4278. .1
  4279.     move.b    0(a3,d3.l*2),d7
  4280.     ext.w    d7
  4281.     muls.w    d1,d7
  4282.     add.w    d7,(a4)
  4283.     move.b    1(a3,d3.l*2),d7
  4284.     ext.w    d7
  4285.     muls.w    d2,d7
  4286.     add.w    d7,(a4)+
  4287.     sub.l    d6,d4
  4288.     subx.l    d5,d3
  4289.     dbf    d0,.nextsample
  4290. .exit
  4291.  ENDC
  4292.     rts
  4293.  
  4294. ;------------------------------------------------------------------------------
  4295.     cnop    0,16
  4296.  
  4297. ;in
  4298. * d1.l    Pointer in multiplication table
  4299. * d2.l    Pointer in multiplication table
  4300. AddBytesMVTB:
  4301.  IFGE    __CPU-68020
  4302.     push    a1
  4303.     move.l    d1,a0
  4304.     move.l    d2,a1
  4305.     moveq    #0,d1
  4306.     lsr.w    #1,d0
  4307.     bcs.b    .1
  4308.     subq.w    #1,d0
  4309.     bmi.b    .exit
  4310. .nextsample
  4311.     move.b    0(a3,d3.l*2),d1
  4312.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  4313.     move.b    1(a3,d3.l*2),d1
  4314.     add.w    0(a1,d1.w*4),d2        ;signed multiplication
  4315.     add.w    d2,(a4)+
  4316.     sub.l    d6,d4
  4317.     subx.l    d5,d3
  4318. .1
  4319.     move.b    0(a3,d3.l*2),d1
  4320.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  4321.     move.b    1(a3,d3.l*2),d1
  4322.     add.w    0(a1,d1.w*4),d2        ;signed multiplication
  4323.     add.w    d2,(a4)+
  4324.     sub.l    d6,d4
  4325.     subx.l    d5,d3
  4326.  
  4327.     dbf    d0,.nextsample
  4328. .exit
  4329.     pop    a1
  4330.  ENDC
  4331.     rts
  4332.  
  4333. ;------------------------------------------------------------------------------
  4334.     cnop    0,16
  4335.  
  4336. ;in
  4337. * d1.w    -256..256
  4338. AddBytesSVlB:
  4339.  IFGE    __CPU-68020
  4340.     lsr.w    #1,d0
  4341.     bcs.b    .1
  4342.     subq.w    #1,d0
  4343.     bmi.b    .exit
  4344. .nextsample
  4345.     move.b    0(a3,d3.l*2),d7
  4346.     ext.w    d7
  4347.     muls.w    d1,d7
  4348.     add.w    d7,(a4)+
  4349.     sub.l    d6,d4
  4350.     subx.l    d5,d3
  4351.     addq.l    #2,a4
  4352. .1
  4353.     move.b    0(a3,d3.l*2),d7
  4354.     ext.w    d7
  4355.     muls.w    d1,d7
  4356.     add.w    d7,(a4)+
  4357.     sub.l    d6,d4
  4358.     subx.l    d5,d3
  4359.     addq.l    #2,a4
  4360.     dbf    d0,.nextsample
  4361. .exit
  4362.  ENDC
  4363.     rts
  4364.  
  4365. ;------------------------------------------------------------------------------
  4366.     cnop    0,16
  4367.  
  4368. ;in
  4369. * d2.w    -256..256
  4370. AddBytesSVrB:
  4371.  IFGE    __CPU-68020
  4372.     moveq    #0,d7
  4373.     lsr.w    #1,d0
  4374.     bcs.b    .1
  4375.     subq.w    #1,d0
  4376.     bmi.b    .exit
  4377. .nextsample
  4378.     move.b    1(a3,d3.l*2),d7
  4379.     addq.l    #2,a4
  4380.     ext.w    d7
  4381.     muls.w    d2,d7
  4382.     add.w    d7,(a4)+
  4383.     sub.l    d6,d4
  4384.     subx.l    d5,d3
  4385. .1
  4386.     move.b    1(a3,d3.l*2),d7
  4387.     addq.l    #2,a4
  4388.     ext.w    d7
  4389.     muls.w    d2,d7
  4390.     add.w    d7,(a4)+
  4391.     sub.l    d6,d4
  4392.     subx.l    d5,d3
  4393.     dbf    d0,.nextsample
  4394. .exit
  4395.  ENDC
  4396.     rts
  4397.  
  4398. ;------------------------------------------------------------------------------
  4399.     cnop    0,16
  4400.  
  4401. ;in
  4402. * d1.w    -256..256
  4403. * d2.w    -256..256
  4404. AddBytesSVPB:
  4405.  IFGE    __CPU-68020
  4406.     lsr.w    #1,d0
  4407.     bcs.b    .1
  4408.     subq.w    #1,d0
  4409.     bmi.b    .exit
  4410. .nextsample
  4411.     move.b    0(a3,d3.l*2),d7
  4412.     ext.w    d7
  4413.     muls.w    d1,d7
  4414.     add.w    d7,(a4)+
  4415.     move.b    1(a3,d3.l*2),d7
  4416.     ext.w    d7
  4417.     muls.w    d2,d7
  4418.     add.w    d7,(a4)+
  4419.     sub.l    d6,d4
  4420.     subx.l    d5,d3
  4421. .1
  4422.     move.b    0(a3,d3.l*2),d7
  4423.     ext.w    d7
  4424.     muls.w    d1,d7
  4425.     add.w    d7,(a4)+
  4426.     move.b    1(a3,d3.l*2),d7
  4427.     ext.w    d7
  4428.     muls.w    d2,d7
  4429.     add.w    d7,(a4)+
  4430.     sub.l    d6,d4
  4431.     subx.l    d5,d3
  4432.     dbf    d0,.nextsample
  4433. .exit
  4434.  ENDC
  4435.     rts
  4436.  
  4437. ;------------------------------------------------------------------------------
  4438.     cnop    0,16
  4439.  
  4440. ;in
  4441. * d1.l    Pointer in multiplication table
  4442. AddBytesSVTlB:
  4443.  IFGE    __CPU-68020
  4444.     move.l    d1,a0
  4445.     moveq    #0,d1
  4446.     lsr.w    #1,d0
  4447.     bcs.b    .1
  4448.     subq.w    #1,d0
  4449.     bmi.b    .exit
  4450. .nextsample
  4451.     move.b    0(a3,d3.l*2),d1
  4452.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  4453.     add.w    d2,(a4)+
  4454.     sub.l    d6,d4
  4455.     subx.l    d5,d3
  4456.     addq.l    #2,a4
  4457. .1
  4458.     move.b    0(a3,d3.l*2),d1
  4459.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  4460.     add.w    d2,(a4)+
  4461.     sub.l    d6,d4
  4462.     subx.l    d5,d3
  4463.     addq.l    #2,a4
  4464.     dbf    d0,.nextsample
  4465. .exit
  4466.  ENDC
  4467.     rts
  4468. ;------------------------------------------------------------------------------
  4469.     cnop    0,16
  4470.  
  4471. ;in
  4472. * d2.l    Pointer in multiplication table
  4473. AddBytesSVTrB:
  4474.  IFGE    __CPU-68020
  4475.     move.l    d2,a0
  4476.     moveq    #0,d1
  4477.     moveq    #0,d2
  4478.     lsr.w    #1,d0
  4479.     bcs.b    .1
  4480.     subq.w    #1,d0
  4481.     bmi.b    .exit
  4482. .nextsample
  4483.     move.b    1(a3,d3.l*2),d1
  4484.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  4485.     addq.l    #2,a4
  4486.     add.w    d2,(a4)+
  4487.     sub.l    d6,d4
  4488.     subx.l    d5,d3
  4489. .1
  4490.     move.b    1(a3,d3.l*2),d1
  4491.     move.w    0(a0,d1.w*4),d2        ;signed multiplication
  4492.     addq.l    #2,a4
  4493.     add.w    d2,(a4)+
  4494.     sub.l    d6,d4
  4495.     subx.l    d5,d3
  4496.     dbf    d0,.nextsample
  4497. .exit
  4498.  ENDC
  4499.     rts
  4500.  
  4501. ;------------------------------------------------------------------------------
  4502.     cnop    0,16
  4503.  
  4504. ;in
  4505. * d1.l    Pointer in multiplication table
  4506. * d2.l    Pointer in multiplication table
  4507. AddBytesSVPTB:
  4508.  IFGE    __CPU-68020
  4509.     move.l    a1,d7            ;save a1
  4510.     move.l    d1,a0
  4511.     move.l    d2,a1
  4512.     moveq    #0,d1
  4513.     lsr.w    #1,d0
  4514.     bcs.b    .1
  4515.     subq.w    #1,d0
  4516.     bmi.b    .exit
  4517. .nextsample
  4518.     move.b    0(a3,d3.l*2),d1
  4519.     move.w    0(a0,d1.w*4),d2
  4520.     add.w    d2,(a4)+
  4521.     move.b    1(a3,d3.l*2),d1
  4522.     move.w    0(a1,d1.w*4),d2
  4523.     add.w    d2,(a4)+
  4524.     sub.l    d6,d4
  4525.     subx.l    d5,d3
  4526. .1
  4527.     move.b    0(a3,d3.l*2),d1
  4528.     move.w    0(a0,d1.w*4),d2
  4529.     add.w    d2,(a4)+
  4530.     move.b    1(a3,d3.l*2),d1
  4531.     move.w    0(a1,d1.w*4),d2
  4532.     add.w    d2,(a4)+
  4533.     sub.l    d6,d4
  4534.     subx.l    d5,d3
  4535.     dbf    d0,.nextsample
  4536. .exit
  4537.     move.l    d7,a1            ;restore a1
  4538.  ENDC
  4539.     rts
  4540.  
  4541. ;******************************************************************************
  4542.     cnop    0,16
  4543.  
  4544. ;in
  4545. * d1.l    -32768..32767/-256..256
  4546. AddWordMVB:
  4547. * 16/8 bit signed input (8 for '000 version)
  4548.     moveq    #15,d2
  4549.  
  4550.     lsr.w    #1,d0
  4551.     bcs.b    .1
  4552.     subq.w    #1,d0
  4553.     bmi.b    .exit
  4554. .nextsample
  4555.  IFGE    __CPU-68020
  4556.     move.w    (a3,d3.l*2),d7
  4557.     muls.w    d1,d7
  4558.     asr.l    d2,d7
  4559.  ELSE
  4560.     move.l    d3,d7
  4561.     add.l    d7,d7
  4562.     move.b    0(a3,d7.l),d7        ;high byte
  4563.     ext.w    d7
  4564.     muls.w    d1,d7
  4565.  ENDC
  4566.     add.w    d7,(a4)+
  4567.     sub.l    d6,d4
  4568.     subx.l    d5,d3
  4569. .1
  4570.  IFGE    __CPU-68020
  4571.     move.w    (a3,d3.l*2),d7
  4572.     muls.w    d1,d7
  4573.     asr.l    d2,d7
  4574.  ELSE
  4575.     move.l    d3,d7
  4576.     add.l    d7,d7
  4577.     move.b    0(a3,d7.l),d7        ;high byte
  4578.     ext.w    d7
  4579.     muls.w    d1,d7
  4580.  ENDC
  4581.     add.w    d7,(a4)+
  4582.     sub.l    d6,d4
  4583.     subx.l    d5,d3
  4584.     dbf    d0,.nextsample
  4585. .exit
  4586.     rts
  4587.  
  4588. ;------------------------------------------------------------------------------
  4589.     cnop    0,16
  4590.  
  4591. ;in
  4592. * d1.l    Shift count
  4593. AddWordMVTB:
  4594.     lsr.w    #1,d0
  4595.     bcs.b    .1
  4596.     subq.w    #1,d0
  4597.     bmi.b    .exit
  4598. .nextsample
  4599.  IFGE    __CPU-68020
  4600.     move.w    (a3,d3.l*2),d7
  4601.  ELSE
  4602.     move.l    d3,d7
  4603.      add.l    d7,d7
  4604.     move.w    (a3,d7.l),d7
  4605.  ENDC
  4606.     asr.w    d1,d7
  4607.     add.w    d7,(a4)+
  4608.     sub.l    d6,d4
  4609.     subx.l    d5,d3
  4610. .1
  4611.  IFGE    __CPU-68020
  4612.     move.w    (a3,d3.l*2),d7
  4613.  ELSE
  4614.     move.l    d3,d7
  4615.      add.l    d7,d7
  4616.     move.w    (a3,d7.l),d7
  4617.  ENDC
  4618.     asr.w    d1,d7
  4619.     add.w    d7,(a4)+
  4620.     sub.l    d6,d4
  4621.     subx.l    d5,d3
  4622.     dbf    d0,.nextsample
  4623. .exit
  4624.     rts
  4625.  
  4626. ;------------------------------------------------------------------------------
  4627.     cnop    0,16
  4628.  
  4629. ;in
  4630. * d1.l    -32768..32767/-256..256
  4631. AddWordSVlB:
  4632. * 16/8 bit signed input (8 for '000 version)
  4633.     moveq    #15,d2
  4634.     lsr.w    #1,d0
  4635.     bcs.b    .1
  4636.     subq.w    #1,d0
  4637.     bmi.b    .exit
  4638. .nextsample
  4639.  IFGE    __CPU-68020
  4640.     move.w    (a3,d3.l*2),d7
  4641.     muls.w    d1,d7
  4642.     asr.l    d2,d7
  4643.  ELSE
  4644.     move.l    d3,d7
  4645.     add.l    d7,d7
  4646.     move.b    0(a3,d7.l),d7        ;high byte
  4647.     ext.w    d7
  4648.     muls.w    d1,d7
  4649.  ENDC
  4650.     add.w    d7,(a4)+
  4651.     sub.l    d6,d4
  4652.     subx.l    d5,d3
  4653.     addq.l    #2,a4
  4654. .1
  4655.  IFGE    __CPU-68020
  4656.     move.w    (a3,d3.l*2),d7
  4657.     muls.w    d1,d7
  4658.     asr.l    d2,d7
  4659.  ELSE
  4660.     move.l    d3,d7
  4661.     add.l    d7,d7
  4662.     move.b    0(a3,d7.l),d7        ;high byte
  4663.     ext.w    d7
  4664.     muls.w    d1,d7
  4665.  ENDC
  4666.     add.w    d7,(a4)+
  4667.     sub.l    d6,d4
  4668.     subx.l    d5,d3
  4669.     addq.l    #2,a4
  4670.     dbf    d0,.nextsample
  4671. .exit
  4672.     rts
  4673.  
  4674. ;------------------------------------------------------------------------------
  4675.     cnop    0,16
  4676.  
  4677. ;in
  4678. * d2.l    -32768..32767/-256..256
  4679. AddWordSVrB:
  4680. * 16/8 bit signed input (8 for '000 version)
  4681.     moveq    #15,d1
  4682.  
  4683.     lsr.w    #1,d0
  4684.     bcs.b    .1
  4685.     subq.w    #1,d0
  4686.     bmi.b    .exit
  4687. .nextsample
  4688.  IFGE    __CPU-68020
  4689.     move.w    (a3,d3.l*2),d7
  4690.     muls.w    d2,d7
  4691.     asr.l    d1,d7
  4692.  ELSE
  4693.     move.l    d3,d7
  4694.     add.l    d7,d7
  4695.     move.b    0(a3,d7.l),d7        ;high byte
  4696.     ext.w    d7
  4697.     muls.w    d2,d7
  4698.  ENDC
  4699.     addq.l    #2,a4
  4700.     add.w    d7,(a4)+
  4701.     sub.l    d6,d4
  4702.     subx.l    d5,d3
  4703. .1
  4704.  IFGE    __CPU-68020
  4705.     move.w    (a3,d3.l*2),d7
  4706.     muls.w    d2,d7
  4707.     asr.l    d1,d7
  4708.  ELSE
  4709.     move.l    d3,d7
  4710.     add.l    d7,d7
  4711.     move.b    0(a3,d7.l),d7        ;high byte
  4712.     ext.w    d7
  4713.     muls.w    d2,d7
  4714.  ENDC
  4715.     addq.l    #2,a4
  4716.     add.w    d7,(a4)+
  4717.     sub.l    d6,d4
  4718.     subx.l    d5,d3
  4719.     dbf    d0,.nextsample
  4720. .exit
  4721.     rts
  4722.  
  4723. ;------------------------------------------------------------------------------
  4724.     cnop    0,16
  4725.  
  4726. ;in
  4727. * d1.l    -32768..32767/-256..256
  4728. * d2.l    -32768..32767/-256..256
  4729. AddWordSVPB:
  4730. * 16/8 bit signed input (8 for '000 version)
  4731.     lsr.w    #1,d0
  4732.     bcs.b    .1
  4733.     subq.w    #1,d0
  4734.     bmi.b    .exit
  4735. .nextsample
  4736.  IFGE    __CPU-68020
  4737.     move.w    (a3,d3.l*2),d7
  4738.     move.l    d7,a0
  4739.     muls.w    d1,d7
  4740.     asr.l    #8,d7
  4741.     asr.l    #7,d7
  4742.     add.w    d7,(a4)+
  4743.  
  4744.     move.l    a0,d7
  4745.     muls.w    d2,d7
  4746.     asr.l    #8,d7
  4747.     asr.l    #7,d7
  4748.     add.w    d7,(a4)+
  4749.  ELSE
  4750.     move.l    d3,d7
  4751.     add.l    d7,d7
  4752.     move.b    0(a3,d7.l),d7        ;high byte
  4753.     ext.w    d7
  4754.     move.l    d7,a0
  4755.     muls.w    d1,d7
  4756.     add.w    d7,(a4)+
  4757.  
  4758.     move.l    a0,d7
  4759.     muls.w    d2,d7
  4760.     add.w    d7,(a4)+
  4761.  ENDC
  4762.     sub.l    d6,d4
  4763.     subx.l    d5,d3
  4764. .1
  4765.  IFGE    __CPU-68020
  4766.     move.w    (a3,d3.l*2),d7
  4767.     move.l    d7,a0
  4768.     muls.w    d1,d7
  4769.     asr.l    #8,d7
  4770.     asr.l    #7,d7
  4771.     add.w    d7,(a4)+
  4772.  
  4773.     move.l    a0,d7
  4774.     muls.w    d2,d7
  4775.     asr.l    #8,d7
  4776.     asr.l    #7,d7
  4777.     add.w    d7,(a4)+
  4778.  ELSE
  4779.     move.l    d3,d7
  4780.     add.l    d7,d7
  4781.     move.b    0(a3,d7.l),d7        ;high byte
  4782.     ext.w    d7
  4783.     move.l    d7,a0
  4784.     muls.w    d1,d7
  4785.     add.w    d7,(a4)+
  4786.  
  4787.     move.l    a0,d7
  4788.     muls.w    d2,d7
  4789.     add.w    d7,(a4)+
  4790.  ENDC
  4791.     sub.l    d6,d4
  4792.     subx.l    d5,d3
  4793.     dbf    d0,.nextsample
  4794. .exit
  4795.     rts
  4796.  
  4797. ;------------------------------------------------------------------------------
  4798.     cnop    0,16
  4799.  
  4800. ;in
  4801. * d1.l    Shift count
  4802. AddWordSVTlB:
  4803.     lsr.w    #1,d0
  4804.     bcs.b    .1
  4805.     subq.w    #1,d0
  4806.     bmi.b    .exit
  4807. .nextsample
  4808.  IFGE    __CPU-68020
  4809.     move.w    (a3,d3.l*2),d7
  4810.  ELSE
  4811.     move.l    d3,d7
  4812.     add.l    d7,d7
  4813.     move.w    (a3,d7.l),d7
  4814.  ENDC
  4815.     asr.w    d1,d7
  4816.     add.w    d7,(a4)+
  4817.     sub.l    d6,d4
  4818.     subx.l    d5,d3
  4819.     addq.l    #2,a4
  4820. .1
  4821.  IFGE    __CPU-68020
  4822.     move.w    (a3,d3.l*2),d7
  4823.  ELSE
  4824.     move.l    d3,d7
  4825.     add.l    d7,d7
  4826.     move.w    (a3,d7.l),d7
  4827.  ENDC
  4828.     asr.w    d1,d7
  4829.     add.w    d7,(a4)+
  4830.     sub.l    d6,d4
  4831.     subx.l    d5,d3
  4832.     addq.l    #2,a4
  4833.  
  4834.     dbf    d0,.nextsample
  4835. .exit
  4836.     rts
  4837.  
  4838. ;------------------------------------------------------------------------------
  4839.     cnop    0,16
  4840.  
  4841. ;in
  4842. * d2.l    Shift count
  4843. AddWordSVTrB:
  4844.     moveq    #0,d1
  4845.     lsr.w    #1,d0
  4846.     bcs.b    .1
  4847.     subq.w    #1,d0
  4848.     bmi.b    .exit
  4849. .nextsample
  4850.  IFGE    __CPU-68020
  4851.     move.w    (a3,d3.l*2),d7
  4852.  ELSE
  4853.     move.l    d3,d7
  4854.     add.l    d7,d7
  4855.     move.w    (a3,d7.l),d7
  4856.  ENDC
  4857.     asr.w    d2,d7
  4858.     addq.l    #2,a4
  4859.     add.w    d7,(a4)+
  4860.     sub.l    d6,d4
  4861.     subx.l    d5,d3
  4862. .1
  4863.  IFGE    __CPU-68020
  4864.     move.w    (a3,d3.l*2),d7
  4865.  ELSE
  4866.     move.l    d3,d7
  4867.     add.l    d7,d7
  4868.     move.w    (a3,d7.l),d7
  4869.  ENDC
  4870.     asr.w    d2,d7
  4871.     addq.l    #2,a4
  4872.     add.w    d7,(a4)+
  4873.     sub.l    d6,d4
  4874.     subx.l    d5,d3
  4875.     dbf    d0,.nextsample
  4876. .exit
  4877.     rts
  4878.  
  4879. ;------------------------------------------------------------------------------
  4880.     cnop    0,16
  4881.  
  4882. ;in
  4883. * d1.l    Shift count
  4884. * d2.l    Shift count
  4885. AddWordSVPTB:
  4886.     lsr.w    #1,d0
  4887.     bcs.b    .1
  4888.     subq.w    #1,d0
  4889.     bmi.b    .exit
  4890. .nextsample
  4891.  IFGE    __CPU-68020
  4892.     move.w    (a3,d3.l*2),d7
  4893.     asr.w    d1,d7
  4894.     add.w    d7,(a4)+
  4895.     move.w    (a3,d3.l*2),d7
  4896.     asr.w    d2,d7
  4897.     add.w    d7,(a4)+
  4898.  ELSE
  4899.     move.l    d3,d7
  4900.     add.l    d7,d7
  4901.     move.w    (a3,d7.l),d7
  4902.     move.l    d7,a0
  4903.     asr.w    d1,d7
  4904.     add.w    d7,(a4)+
  4905.     move.l    a0,d7
  4906.     asr.w    d2,d7
  4907.     add.w    d7,(a4)+
  4908.  ENDC
  4909.     sub.l    d6,d4
  4910.     subx.l    d5,d3
  4911. .1
  4912.  IFGE    __CPU-68020
  4913.     move.w    (a3,d3.l*2),d7
  4914.     asr.w    d1,d7
  4915.     add.w    d7,(a4)+
  4916.     move.w    (a3,d3.l*2),d7
  4917.     asr.w    d2,d7
  4918.     add.w    d7,(a4)+
  4919.  ELSE
  4920.     move.l    d3,d7
  4921.     add.l    d7,d7
  4922.     move.w    (a3,d7.l),d7
  4923.     move.l    d7,a0
  4924.     asr.w    d1,d7
  4925.     add.w    d7,(a4)+
  4926.     move.l    a0,d7
  4927.     asr.w    d2,d7
  4928.     add.w    d7,(a4)+
  4929.  ENDC
  4930.     sub.l    d6,d4
  4931.     subx.l    d5,d3
  4932.  
  4933.     dbf    d0,.nextsample
  4934. .exit
  4935.     rts
  4936.  
  4937.  
  4938. ;******************************************************************************
  4939.     cnop    0,16
  4940.  
  4941. ;in
  4942. * d1.l    -32768..32767
  4943. * d2.l    -32768..32767
  4944. AddWordsMVB:
  4945. * 16 bit signed input
  4946.  IFGE    __CPU-68020
  4947.     lsr.w    #1,d0
  4948.     bcs.b    .1
  4949.     subq.w    #1,d0
  4950.     bmi.b    .exit
  4951. .nextsample
  4952.     move.w    0(a3,d3.l*4),d7
  4953.     muls.w    d1,d7
  4954.     asr.l    #8,d7
  4955.     asr.l    #7,d7
  4956.     add.w    d7,(a4)
  4957.     move.w    2(a3,d3.l*4),d7
  4958.     muls.w    d2,d7
  4959.     asr.l    #8,d7
  4960.     asr.l    #7,d7
  4961.     add.w    d7,(a4)+
  4962.     sub.l    d6,d4
  4963.     subx.l    d5,d3
  4964. .1
  4965.     move.w    0(a3,d3.l*4),d7
  4966.     muls.w    d1,d7
  4967.     asr.l    #8,d7
  4968.     asr.l    #7,d7
  4969.     add.w    d7,(a4)
  4970.     move.w    2(a3,d3.l*4),d7
  4971.     muls.w    d2,d7
  4972.     asr.l    #8,d7
  4973.     asr.l    #7,d7
  4974.     add.w    d7,(a4)+
  4975.     sub.l    d6,d4
  4976.     subx.l    d5,d3
  4977.     dbf    d0,.nextsample
  4978. .exit
  4979.  ENDC
  4980.     rts
  4981.  
  4982. ;------------------------------------------------------------------------------
  4983.     cnop    0,16
  4984.  
  4985. ;in
  4986. * d1.l    Shift Count
  4987. * d2.l    Shift Count
  4988. AddWordsMVTB:
  4989.  IFGE    __CPU-68020
  4990.     lsr.w    #1,d0
  4991.     bcs.b    .1
  4992.     subq.w    #1,d0
  4993.     bmi.b    .exit
  4994. .nextsample
  4995.     move.w    (a3,d3.l*4),d7
  4996.     asr.w    d1,d7
  4997.     add.w    d7,(a4)
  4998.     move.w    2(a3,d3.l*4),d7
  4999.     asr.w    d2,d7
  5000.     add.w    d7,(a4)+
  5001.     sub.l    d6,d4
  5002.     subx.l    d5,d3
  5003. .1
  5004.     move.w    (a3,d3.l*4),d7
  5005.     asr.w    d1,d7
  5006.     add.w    d7,(a4)
  5007.     move.w    2(a3,d3.l*4),d7
  5008.     asr.w    d2,d7
  5009.     add.w    d7,(a4)+
  5010.     sub.l    d6,d4
  5011.     subx.l    d5,d3
  5012.  
  5013.     dbf    d0,.nextsample
  5014. .exit
  5015.  ENDC
  5016.     rts
  5017.  
  5018. ;------------------------------------------------------------------------------
  5019.     cnop    0,16
  5020.  
  5021. ;in
  5022. * d1.l    -32768..32767
  5023. AddWordsSVlB:
  5024. * 16 bit signed input
  5025.  IFGE    __CPU-68020
  5026.     moveq    #15,d2
  5027.     lsr.w    #1,d0
  5028.     bcs.b    .1
  5029.     subq.w    #1,d0
  5030.     bmi.b    .exit
  5031. .nextsample
  5032.     move.w    0(a3,d3.l*4),d7
  5033.     muls.w    d1,d7
  5034.     asr.l    d2,d7
  5035.     add.w    d7,(a4)+
  5036.     sub.l    d6,d4
  5037.     subx.l    d5,d3
  5038.     addq.l    #2,a4
  5039. .1
  5040.     move.w    0(a3,d3.l*4),d7
  5041.     muls.w    d1,d7
  5042.     asr.l    d2,d7
  5043.     add.w    d7,(a4)+
  5044.     sub.l    d6,d4
  5045.     subx.l    d5,d3
  5046.     addq.l    #2,a4
  5047.     dbf    d0,.nextsample
  5048. .exit
  5049.  ENDC
  5050.     rts
  5051.  
  5052. ;------------------------------------------------------------------------------
  5053.     cnop    0,16
  5054.  
  5055. ;in
  5056. * d2.l    -32768..32767/
  5057. AddWordsSVrB:
  5058. * 16 bit signed input
  5059.  IFGE    __CPU-68020
  5060.     moveq    #15,d1
  5061.  
  5062.     lsr.w    #1,d0
  5063.     bcs.b    .1
  5064.     subq.w    #1,d0
  5065.     bmi.b    .exit
  5066. .nextsample
  5067.     move.w    2(a3,d3.l*4),d7
  5068.     muls.w    d2,d7
  5069.     asr.l    d1,d7
  5070.     addq.l    #2,a4
  5071.     add.w    d7,(a4)+
  5072.     sub.l    d6,d4
  5073.     subx.l    d5,d3
  5074. .1
  5075.     move.w    2(a3,d3.l*4),d7
  5076.     muls.w    d2,d7
  5077.     asr.l    d1,d7
  5078.     addq.l    #2,a4
  5079.     add.w    d7,(a4)+
  5080.     sub.l    d6,d4
  5081.     subx.l    d5,d3
  5082.     dbf    d0,.nextsample
  5083. .exit
  5084.  ENDC
  5085.     rts
  5086.  
  5087. ;------------------------------------------------------------------------------
  5088.     cnop    0,16
  5089.  
  5090. ;in
  5091. * d1.l    -32768..32767/-256..256
  5092. * d2.l    -32768..32767/-256..256
  5093. AddWordsSVPB:
  5094. * 16/8 bit signed input (8 for '000 version)
  5095.  IFGE    __CPU-68020
  5096.     lsr.w    #1,d0
  5097.     bcs.b    .1
  5098.     subq.w    #1,d0
  5099.     bmi.b    .exit
  5100. .nextsample
  5101.     move.w    0(a3,d3.l*4),d7
  5102.     muls.w    d1,d7
  5103.     asr.l    #8,d7
  5104.     asr.l    #7,d7
  5105.     add.w    d7,(a4)+
  5106.  
  5107.     move.w    2(a3,d3.l*4),d7
  5108.     muls.w    d2,d7
  5109.     asr.l    #8,d7
  5110.     asr.l    #7,d7
  5111.     add.w    d7,(a4)+
  5112.     sub.l    d6,d4
  5113.     subx.l    d5,d3
  5114. .1
  5115.     move.w    0(a3,d3.l*4),d7
  5116.     muls.w    d1,d7
  5117.     asr.l    #8,d7
  5118.     asr.l    #7,d7
  5119.     add.w    d7,(a4)+
  5120.  
  5121.     move.w    2(a3,d3.l*4),d7
  5122.     muls.w    d2,d7
  5123.     asr.l    #8,d7
  5124.     asr.l    #7,d7
  5125.     add.w    d7,(a4)+
  5126.     sub.l    d6,d4
  5127.     subx.l    d5,d3
  5128.     dbf    d0,.nextsample
  5129. .exit
  5130.  ENDC
  5131.     rts
  5132.  
  5133. ;------------------------------------------------------------------------------
  5134.     cnop    0,16
  5135.  
  5136. ;in
  5137. * d1.l    Shift count
  5138. AddWordsSVTlB:
  5139.  IFGE    __CPU-68020
  5140.     lsr.w    #1,d0
  5141.     bcs.b    .1
  5142.     subq.w    #1,d0
  5143.     bmi.b    .exit
  5144. .nextsample
  5145.     move.w    (a3,d3.l*4),d7
  5146.     asr.w    d1,d7
  5147.     add.w    d7,(a4)+
  5148.     sub.l    d6,d4
  5149.     subx.l    d5,d3
  5150.     addq.l    #2,a4
  5151. .1
  5152.     move.w    (a3,d3.l*4),d7
  5153.     asr.w    d1,d7
  5154.     add.w    d7,(a4)+
  5155.     sub.l    d6,d4
  5156.     subx.l    d5,d3
  5157.     addq.l    #2,a4
  5158.  
  5159.     dbf    d0,.nextsample
  5160. .exit
  5161.  ENDC
  5162.     rts
  5163.  
  5164. ;------------------------------------------------------------------------------
  5165.     cnop    0,16
  5166.  
  5167. ;in
  5168. * d2.l    Shift count
  5169. AddWordsSVTrB:
  5170.  IFGE    __CPU-68020
  5171.     lsr.w    #1,d0
  5172.     bcs.b    .1
  5173.     subq.w    #1,d0
  5174.     bmi.b    .exit
  5175. .nextsample
  5176.     move.w    2(a3,d3.l*4),d7
  5177.     asr.w    d2,d7
  5178.     addq.l    #2,a4
  5179.     add.w    d7,(a4)+
  5180.     sub.l    d6,d4
  5181.     subx.l    d5,d3
  5182. .1
  5183.     move.w    2(a3,d3.l*4),d7
  5184.     asr.w    d2,d7
  5185.     addq.l    #2,a4
  5186.     add.w    d7,(a4)+
  5187.     sub.l    d6,d4
  5188.     subx.l    d5,d3
  5189.  
  5190.     dbf    d0,.nextsample
  5191. .exit
  5192.  ENDC
  5193.     rts
  5194.  
  5195. ;------------------------------------------------------------------------------
  5196.     cnop    0,16
  5197.  
  5198. ;in
  5199. * d1.l    Shift count
  5200. * d2.l    Shift count
  5201. AddWordsSVPTB:
  5202.  IFGE    __CPU-68020
  5203.     lsr.w    #1,d0
  5204.     bcs.b    .1
  5205.     subq.w    #1,d0
  5206.     bmi.b    .exit
  5207. .nextsample
  5208.     move.w    (a3,d3.l*4),d7
  5209.     asr.w    d1,d7
  5210.     add.w    d7,(a4)+
  5211.     move.w    2(a3,d3.l*4),d7
  5212.     asr.w    d2,d7
  5213.     add.w    d7,(a4)+
  5214.     sub.l    d6,d4
  5215.     subx.l    d5,d3
  5216. .1
  5217.     move.w    (a3,d3.l*4),d7
  5218.     asr.w    d1,d7
  5219.     add.w    d7,(a4)+
  5220.     move.w    2(a3,d3.l*4),d7
  5221.     asr.w    d2,d7
  5222.     add.w    d7,(a4)+
  5223.     sub.l    d6,d4
  5224.     subx.l    d5,d3
  5225.  
  5226.     dbf    d0,.nextsample
  5227. .exit
  5228.  ENDC
  5229.     rts
  5230.  
  5231. ;------------------------------------------------------------------------------
  5232.