;*********************************
;* Jungle Jag - JagCode 500 Game *
;*********************************
;
; by Cedric Bourse, (a.k.a Orion_) [2007]
;
; http://onorisoft.info/
;
; This Source Code is licensed under the term of the following Creative Commons License:
; http://creativecommons.org/licenses/by-nc/3.0/
;
; You are free:
;  * to Share : to copy, distribute and transmit the work
;  * to Remix : to adapt the work
;
; Under the following conditions:
;  * Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
;  * Noncommercial. You may not use this work for commercial purposes.
;  * For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.
;  * Any of the above conditions can be waived if you get permission from the copyright holder.
;  * Nothing in this license impairs or restricts the author's moral rights.
;

	.text

;---------------------------------
; 68k Part of the sound manager (see dsp.s)
;
; Looping supported in the sound manager, but not in this function (don't need it in this game)
;
; This is a very basic addsound function (no advanced features .. no time to do more..)
;

AddSound:	; a0 = Sound Data, a1 = Sound Data End
	lea	Channel1_ptr,a2
	suba.l	a0,a1	; Sound Length

	tst.l	(a2)			; Channel 1
	beq.s	.addtothischannel
	lea	4*4(a2),a2
	tst.l	(a2)			; Channel 2
	beq.s	.addtothischannel
	lea	4*4(a2),a2
	tst.l	(a2)			; Channel 3
	beq.s	.addtothischannel
	lea	4*4(a2),a2
	tst.l	(a2)			; Channel 4
	beq.s	.addtothischannel
	rts				; No more channel free :/

.addtothischannel:
	tst.l	ChannelAccess		; Don't modify channel if DSP ChannelManager Running !
	bne.s	.addtothischannel

	move.l	a0,(a2)+	; Data
	move.l	a1,(a2)		; Len
	rts
