        CASE ON

        IMPORT R0056_TOS_CallXBIOS
        IMPORT R0057_TOS_CallGEMDOS

F0061_SOUND_SetChannelAmplitudes        PROC EXPORT
        EXPORT E0061_SOUND_Exception77Handler_TimerA_SoundPlayer
        ENTRY loc_172A
        ENTRY loc_1730
        ENTRY loc_1736
        ENTRY loc_173E
        ENTRY loc_174A
        
        link    a6,#0
        movem.l d6-d7,-(sp)
        move.w  8(a6),d7
        clr.l   -(sp)
        move.w  #$20,-(sp)
        jsr     R0057_TOS_CallGEMDOS(a5)
        addq.l  #6,sp
        move.l  d0,d6
        andi.w  #$F,d7
        add.b   d7,d7
        add.b   d7,d7
        movea.w #$8800,a1
        lea     V0061004_ChannelsAmplitudeTableLoud,a0
        move.l  -$40(a0,d7.w),(a1)
        move.l  (a0,d7.w),(a1)
        move.l  $40(a0,d7.w),(a1)
        bra.w   loc_1756
E0061_SOUND_Exception77Handler_TimerA_SoundPlayer
        movem.l d7/a0-a1,-(sp)
        lea     V0061000_RemainingSoundSampleCount,a0
        tst.w   (a0)
        beq.s   loc_1542
        subq.w  #1,(a0)+
        tst.w   (a0)+
        beq.s   loc_14E4
        subq.w  #1,-(a0)
        bra.s   loc_150A
loc_14E4
        move.l  (a0),d7
        addq.l  #1,(a0)+
        lsr.l   #1,d7
        bcs.s   loc_1516
        movea.l d7,a1
        move.b  (a1),d7
        lsr.b   #2,d7
        andi.w  #$3C,d7
        beq.s   loc_1554
        movea.w #$8800,a1
        movea.l (a0),a0
        move.l  -$40(a0,d7.w),(a1)
        move.l  (a0,d7.w),(a1)
        move.l  $40(a0,d7.w),(a1)
loc_150A
        bclr    #5,($FFFFFA0F).w
        movem.l (sp)+,d7/a0-a1
        rte
loc_1516
        movea.l d7,a1
        move.b  (a1),d7
        andi.w  #$F,d7
        beq.s   loc_1554
        add.b   d7,d7
        add.b   d7,d7
        movea.w #$8800,a1
        movea.l (a0),a0
        move.l  -$40(a0,d7.w),(a1)
        move.l  (a0,d7.w),(a1)
        move.l  $40(a0,d7.w),(a1)
        bclr    #5,($FFFFFA0F).w
        movem.l (sp)+,d7/a0-a1
        rte
loc_1542
        bclr    #5,($FFFFFA07).w
        bclr    #5,($FFFFFA0F).w
        movem.l (sp)+,d7/a0-a1
        rte
loc_1554
        move.l  d6,-(sp)
        clr.w   d6
loc_1558
        lea     V0061002_NextSoundSample,a0
        move.l  (a0),d7
        addq.l  #1,(a0)
        lsr.l   #1,d7
        bcs.s   loc_156C
        movea.l d7,a1
        move.b  (a1),d7
        lsr.b   #4,d7
        bra.s   loc_1570
loc_156C
        movea.l d7,a1
        move.b  (a1),d7
loc_1570
        btst    #3,d7
        beq.s   loc_1580
        andi.w  #7,d7
        lsl.w   #3,d6
        add.w   d7,d6
        bra.s   loc_1558
loc_1580
        lsl.w   #3,d6
        andi.w  #7,d7
        add.w   d7,d6
        addq.w  #2,d6
        lea     V0061001_SoundSampleRepeatCount,a0
        move.w  d6,(a0)
        bclr    #5,($FFFFFA0F).w
        move.l  (sp)+,d6
        movem.l (sp)+,d7/a0-a1
        rte
V0061000_RemainingSoundSampleCount
        dc.w 0
V0061001_SoundSampleRepeatCount
        dc.w 0
V0061002_NextSoundSample
        dc.l 0
V0061003_CurrentChannelsAmplitudeTable
        dc.l 0
        dc.l $8000000
        dc.l $8000800
        dc.l $8000A00
        dc.l $8000B00
        dc.l $8000C00
        dc.l $8000D00
        dc.l $8000D00
        dc.l $8000D00
        dc.l $8000E00
        dc.l $8000E00
        dc.l $8000E00
        dc.l $8000E00
        dc.l $8000F00
        dc.l $8000E00
        dc.l $8000E00
        dc.l $8000E00
V0061004_ChannelsAmplitudeTableLoud
        dc.l $9000000
        dc.l $9000500
        dc.l $9000700
        dc.l $9000900
        dc.l $9000900
        dc.l $9000500
        dc.l $9000A00
        dc.l $9000C00
        dc.l $9000800
        dc.l $9000A00
        dc.l $9000C00
        dc.l $9000D00
        dc.l $9000B00
        dc.l $9000E00
        dc.l $9000E00
        dc.l $9000E00
        dc.l $A000000
        dc.l $A000000
        dc.l $A000000
        dc.l $A000000
        dc.l $A000000
        dc.l $A000000
        dc.l $A000600
        dc.l $A000000
        dc.l $A000000
        dc.l $A000A00
        dc.l $A000A00
        dc.l $A000A00
        dc.l $A000000
        dc.l $A000B00
        dc.l $A000D00
        dc.l $A000E00
        dc.l $8000000
        dc.l $8000500
        dc.l $8000700
        dc.l $8000800
        dc.l $8000900
        dc.l $8000900
        dc.l $8000A00
        dc.l $8000A00
        dc.l $8000B00
        dc.l $8000B00
        dc.l $8000B00
        dc.l $8000B00
        dc.l $8000C00
        dc.l $8000C00
        dc.l $8000C00
        dc.l $8000C00
V0061005_ChannelsAmplitudeTableSoft
        dc.l $9000000
        dc.l $9000000
        dc.l $9000100
        dc.l $9000200
        dc.l $9000200
        dc.l $9000500
        dc.l $9000200
        dc.l $9000600
        dc.l $9000300
        dc.l $9000600
        dc.l $9000700
        dc.l $9000800
        dc.l $9000400
        dc.l $9000600
        dc.l $9000800
        dc.l $9000900
        dc.l $A000000
        dc.l $A000000
        dc.l $A000000
        dc.l $A000000
        dc.l $A000000
        dc.l $A000200
        dc.l $A000200
        dc.l $A000100
        dc.l $A000100
        dc.l $A000200
        dc.l $A000400
        dc.l $A000500
        dc.l $A000100
        dc.l $A000200
        dc.l $A000000
        dc.l $A000000
loc_172A
        lea     V0061002_NextSoundSample,a0
        rts
loc_1730
        lea     V0061000_RemainingSoundSampleCount,a0
        rts
loc_1736
        lea     V0061001_SoundSampleRepeatCount,a0
        clr.w   (a0)
        rts
loc_173E
        lea     V0061004_ChannelsAmplitudeTableLoud,a0
        lea     V0061003_CurrentChannelsAmplitudeTable,a1
        move.l  a0,(a1)
        rts
loc_174A
        lea     V0061005_ChannelsAmplitudeTableSoft,a0
        lea     V0061003_CurrentChannelsAmplitudeTable,a1
        move.l  a0,(a1)
        rts
loc_1756
        move.l  d6,-(sp)
        move.w  #$20,-(sp)
        jsr     R0057_TOS_CallGEMDOS(a5)
        addq.l  #6,sp
        movem.l (sp)+,d6-d7
        unlk    a6
        rts
        ENDPROC
F0060_SOUND_Play_CPSX   PROC EXPORT
        link    a6,#-$E
        clr.w   -$A(a6)
        move.l  8(a6),-4(a6)
        move.l  -4(a6),d0
        addq.l  #2,d0
        add.l   d0,d0
        move.l  d0,-4(a6)
        movea.l 8(a6),a0
        moveq   #0,d0
        move.b  (a0),d0
        andi.w  #$FF,d0
        lsl.w   #8,d0
        movea.l 8(a6),a0
        moveq   #0,d1
        move.b  1(a0),d1
        andi.w  #$FF,d1
        or.w    d1,d0
        move.w  d0,-6(a6)
        move.w  #$8B,-(sp)
        clr.w   -(sp)
        move.w  #$1C,-(sp)
        jsr     R0056_TOS_CallXBIOS(a5)
        addq.l  #6,sp
        move.w  #$8C,-(sp)
        clr.w   -(sp)
        move.w  #$1C,-(sp)
        jsr     R0056_TOS_CallXBIOS(a5)
        addq.l  #6,sp
        move.w  #7,-(sp)
        clr.w   -(sp)
        move.w  #$1C,-(sp)
        jsr     R0056_TOS_CallXBIOS(a5)
        addq.l  #6,sp
        ext.w   d0
        move.w  d0,-8(a6)
        moveq   #$3F,d0
        or.w    -8(a6),d0
        move.w  #$87,-(sp)
        move.w  d0,-(sp)
        move.w  #$1C,-(sp)
        jsr     R0056_TOS_CallXBIOS(a5)
        addq.l  #6,sp
        moveq   #0,d0
        move.b  $D(a6),d0
        cmpi.w  #$A,d0
        bls.s   loc_1824
        clr.l   -(sp)
        move.w  #$20,-(sp)
        jsr     R0057_TOS_CallGEMDOS(a5)
        addq.l  #6,sp
        move.l  d0,-$E(a6)
        lea     ($FFFFFA1F).w,a0
        move.b  $D(a6),(a0)
        move.l  -$E(a6),-(sp)
        move.w  #$20,-(sp)
        jsr     R0057_TOS_CallGEMDOS(a5)
        addq.l  #6,sp
loc_1824
        jsr     loc_172A
        move.l  -4(a6),(a0)
        jsr     loc_1730
        move.w  -6(a6),(a0)
        jsr     loc_1736
        tst.w   $E(a6)
        bne.s   loc_1844
        jsr     loc_174A
        bra.s   loc_1848
loc_1844
        jsr     loc_173E
loc_1848
        move.w  #$D,-(sp)
        move.w  #$1B,-(sp)
        jsr     R0056_TOS_CallXBIOS(a5)
        addq.l  #4,sp
        unlk    a6
        rts
        ENDPROC
        END
