*****************************************************************
*								*
*	maestix.library-Demo:	CSBchanger			*
*								*
*****************************************************************
*
*	Programmed by		Richard Körber
*	Date			1995-02-01
*
*****************************************************************
*  This  demonstration  shows the  basic encoder  functions of  *
*  the  maestix library.  It allocates the  Maestro soundcard,  *
*  decodes the incoming signal  and encodes it again using new	*
*  channel status bits.  In this example,  the copy protection	*
*  will be removed.						*
*****************************************************************

		INCDIR	"include:"
		INCLUDE	exec.i			; Library call macros
		INCLUDE	intuition.i
		INCLUDE	graphics.i
		INCLUDE	dos.i
		INCLUDE	maestix.i
		INCLUDE	libraries/maestix.i	;Reference includes
		INCLUDE	intuition/intuition.i
		INCLUDE	dos/dostags.i
		INCLUDE	exec/ports.i

		SECTION text,CODE

*---------------------------------------------------------------*
*	== START OF PROGRAM ==					*
*								*
start	;-- Open all libraries -----------------;
		lea	maestname(PC),a1	;maestix
		moveq	#35,d0			; V35+
		exec	OpenLibrary		; open
		move.l	d0,maestbase		; store base
		beq	error1			; not found!
		lea	intuiname(PC),a1	;intuition
		moveq	#36,d0			; V36+
		exec	OpenLibrary		; open
		move.l	d0,intuibase		; store base
		beq	error2
	;-- Allocate Maestro -------------------;
		sub.l	a0,a0			;no tags
		maest	AllocMaestro
		move.l	d0,maestro		;^Maestro base
		beq	error3
	;-- Set Modus --------------------------;
		move.l	maestro(PC),a0		;^Maestro base
		lea	modustags(PC),a1	;^Modus tags
		maest	SetMaestro		;set it now
	;-- Open a window ----------------------;
		sub.l	a0,a0			;no newwindow struct
		lea	windowtags(PC),a1	; but loads of tags
		intui	OpenWindowTagList
		move.l	d0,window
		beq	error4
	;-- Wait for reply (main loop) ---------;
.mainloop	move.l	window(PC),a0		;window message?
		move.l	wd_UserPort(a0),a0	; ^message port
		exec	WaitPort
.nextmsg	move.l	window(PC),a0		;window message?
		move.l	wd_UserPort(a0),a0	; ^message port
		exec	GetMsg			; try to get it...
		tst.l	d0			; got one?
		beq.b	.mainloop		; nope: wait for next msg
	;---- got a window event ---------------;
		move.l	d0,a0			;^IDCMP-message -> a0
		cmp.l	#IDCMP_CLOSEWINDOW,im_Class(a0) ;close window?
		bne.b	.nextmsg		; no -> look for next msg
	;-- Exit program -----------------------;
exit		move.l	window(PC),a0		;Close output window
		intui	CloseWindow
error4		move.l	maestro(PC),a0		;Set maestro free
		maest	FreeMaestro
error3		move.l	intuibase(PC),a1	;close intuition library
		exec	CloseLibrary
error2		move.l	maestbase(PC),a1	;close maestix library
		exec	CloseLibrary
error1		moveq	#0,d0			;Reply 0
		rts				;back to CLI

*---------------------------------------------------------------*
*	== DATA SECTION ==					*
*								*
maestbase	dc.l	0			;^Maestix Lib Base
intuibase	dc.l	0			;^Intuition Lib Base
maestro		dc.l	0			;^Maestro Base
window		dc.l	0			;^Window structure

modustags	dc.l	MTAG_Output,OUTPUT_INPUT ;Input -> Output
		dc.l	MTAG_Input,INPUT_STD	 ;Custom input
		dc.l	MTAG_CopyProh,CPROH_OFF  ;No copy protection
		dc.l	MTAG_Emphasis,EMPH_INPUT ;Emphasis see input
		dc.l	MTAG_Source,SRC_INPUT	 ;Source see input
		dc.l	MTAG_Rate,RATE_INPUT	 ;Rate see input
		dc.l	TAG_DONE

windowtags	dc.l	WA_IDCMP,IDCMP_CLOSEWINDOW ;<- New window's tags
		dc.l	WA_Title,.title
		dc.l	WA_InnerWidth,150
		dc.l	WA_InnerHeight,0
		dc.l	WA_DragBar,-1
		dc.l	WA_DepthGadget,-1
		dc.l	WA_CloseGadget,-1
		dc.l	WA_Activate,-1
		dc.l	WA_RMBTrap,-1
		dc.l	TAG_DONE
.title		dc.b	"CSBchanger",0
		even

maestname	dc.b	"maestix.library",0	;Maestix name
intuiname	dc.b	"intuition.library",0	;Intuition name
		even

*---------------------------------------------------------------*
*	== END ==						*
*								*
		END
