;****** thxplay.library/thxGetNumSongs ******************************************
;
;   NAME
;       thxGetNumSongs -- get number of subsongs.
;
;   SYNOPSIS
;       songs = thxGetNumSongs()
;       D0
;
;       UWORD thxGetNumSongs(void);
;
;       songs := thxGetNumSongs()
;
;   FUNCTION
;       Returns  the  number  of subsongs in the module, if any. You can use
;       the  thxSetSong()  function  to  play one of the subsongs, if that's
;       possible.
;
;   RESULT
;       songs - 0 if there are no subsongs (only the main song), otherwise
;               returns the number of subsongs.
;
;   SEE ALSO
;       thxSetSong()
;
;****************************************************************************
;
;
	cnop	0,4
	xdef	thxGetNumSongs
thxGetNumSongs
	move.l	THX+thxBSS_P(pc),d0
	beq.s	.exit
	move.l	d0,a0
	moveq	#0,d0
	move.b	thx_pSubsongs(a0),d0
.exit	rts




;****** thxplay.library/thxSetSong ******************************************
;
;   NAME
;       thxSetSong -- set song to be played.
;
;   SYNOPSIS
;       thxSetSong(song)
;                  D0
;
;       void thxSetSong(UWORD);
;
;       thxSetSong(song)
;
;   FUNCTION
;       Sets  which  song  to play, if a module contains more than one song.
;       Most  modules  only  contain  one  song,  but  some  modules contain
;       sub-songs  as  well  as  the  main one. You can use this function to
;       specify  which  one  should be played. If you call this function and
;       there is already a song playing, it will be stopped first.
;
;   INPUTS
;       song - 0 to set the main song to be played, any other number will
;              change to that subsong, if it exists. Otherwise, no change
;              will be made (other than the stoppage).
;
;   NOTE
;       It is up to you to start playing the module again.
;
;   SEE ALSO
;       thxGetNumSongs()
;
;****************************************************************************
;
;
	cnop	0,4
	xdef	thxSetSong__i
thxSetSong__i
	ifd	_LIBRARY_
	move.l	d0,-(sp)
	endc

	bsr	thxStop			; stop and get maximum no. of songs
	bsr.s	thxGetNumSongs

	ifd	_LIBRARY_
	move.l	(sp)+,d1
	else
	move.l	4(sp),d1
	endc

	cmp.l	d0,d1
	bhi.s	.exit			; exit if wanted (d1) > maximum (d0)
	move.l	d1,d0
	move.b	mod_OK(pc),d1
	beq.s	.exit
	lea	song(pc),a0
	move.w	d0,(a0)			; store this new subsong
	movem.l	d2-d7/a2-a6,-(sp)
	moveq	#1,d1
	bsr	THX+thxInitSubSong	; change to this subsong
	movem.l	(sp)+,d2-d7/a2-a6
.exit	rts




; VARIABLES
song	dc.w	0	; UWORD subsong currently playing
