;****** thxplay.library/thxPlay ******************************************
;
;   NAME
;       thxPlay -- start playing the song.
;
;   SYNOPSIS
;       void thxPlay()
;
;       void thxPlay(void);
;
;       thxPlay()
;
;   FUNCTION
;       Starts  playing  the module. If the module has just been initialised
;       or  stopped,  or  the  subsong has just been changed, then play will
;       start  at  the  beginning  of  the  song/subsong. Otherwise, it will
;       continue from where it was paused.
;
;   SEE ALSO
;       thxStop(), thxPause()
;
;****************************************************************************
;
;
	xdef	thxPlay
thxPlay
	move.l	THX+thxBSS_P(pc),d0
	beq.s	.exit
	move.l	d0,a0
	st.b	thx_pPlaying(a0)
.exit	rts




;****** thxplay.library/thxPause ******************************************
;
;   NAME
;       thxPause -- pause play of a song.
;
;   SYNOPSIS
;       void thxPause()
;
;       void thxPause(void);
;
;       thxPause()
;
;   FUNCTION
;       Pauses the playing module. Call thxPlay() to continue play again.
;
;   SEE ALSO
;       thxPlay()
;
;****************************************************************************
;
;
	cnop	0,4
	xdef	thxPause
thxPause
	move.l	THX+thxBSS_P(pc),d0
	beq.s	.exit
	move.l	d0,a0
	clr.b	thx_pPlaying(a0)
.exit	rts




;****** thxplay.library/thxStop ******************************************
;
;   NAME
;       thxStop -- stop playing a song/module.
;
;   SYNOPSIS
;       void thxStop()
;
;       void thxStop(void);
;
;       thxStop()
;
;   FUNCTION
;       Stops  the  module.  Can  be restarted from the beginning again with
;       thxPlay().
;
;   SEE ALSO
;       thxPlay(), thxFree()
;
;****************************************************************************
;
;
	cnop	0,4
	xdef	thxStop
thxStop
	movem.l	d2-d7/a2-a6,-(sp)
	move.b	mod_OK(pc),d0
	beq.s	.nosong

	lea	dosig(pc),a0
	clr.w	(a0)			; reset Signal() trigger

	lea	_notes(pc),a0
	moveq	#(bn_SIZEOF*4)-1,d0	; clear bangnote structures
.clr	clr.b	(a0)+
	dbra	d0,.clr

	bsr	THX+thxStopSong		; stop song in thx player

	move.l	mod(pc),d0
	beq.s	.nosong
	move.l	d0,a0
	bsr	THX+thxInitModule	; reinit module
	moveq	#0,d0
	lea	song(pc),a0
	move.w	(a0),d0			; select current subsong
	moveq	#1,d1			; don't play immediately
	bsr	THX+thxInitSubSong
.nosong	movem.l	(sp)+,d2-d7/a2-a6
	rts




;****** thxplay.library/thxWind ******************************************
;
;   NAME
;       thxWind -- wind the song forward or back.
;
;   SYNOPSIS
;       void thxWind(direction)
;                    D0
;
;       void thxWind(UBYTE);
;
;       thxWind(direction)
;
;   FUNCTION
;       Advances forward or backwards through the song by a specified number
;       of  positions. Please use the value 1 to skip forward and -1 to skip
;       back, for future compatibility.
;
;   INPUTS
;       direction - if  1, winds on to the next position.
;                   if -1, winds back to the previous position,
;                   if  0, ignored.
;
;   NOTE
;       Be  wary  of  stepping  beyond  the  end  of  a song. Also note this
;       function only takes effect only once a frame.
;
;****************************************************************************
;
;
	cnop	0,4
	xdef	thxWind__i
thxWind__i
	ifnd	_LIBRARY_
	move.l	4(sp),d0
	endc
	movem.l	d2-d7/a2-a6,-(sp)
	move.b	mod_OK(pc),d1
	beq.s	.exit
	tst.l	d0
	beq.s	.exit			; exit if direction=0
	bmi.s	.neg			; skip back if direction<0
	bsr	THX+thxNextPattern	; otherwise skip fwd (direction >0)
	bra.s	.exit
.neg	bsr	THX+thxPrevPattern
.exit	movem.l	(sp)+,d2-d7/a2-a6
	rts
