*************************************************
*						*
*	       (C)opyright  1990-92		*
*						*
*		by  Tomi Blinnikka		*
*						*
*	Donīt try to understand the code	*
*						*
* Version 1.2	17/10/1991			*
*						*
* BUGS:						*
*						*
* Version 1.3	02/06/1992			*
*						*
* Updated and optimized.			*
*						*
* BUGS: Gave unknown command with no command	*
*						*
* Version 1.4	04/06/1992			*
*						*
*************************************************
	
OpenLibrary = -$0228
CloseLibrary = -$019E
OutPut = -$003C
Write = -$0030

RETURN_FAIL			  EQU	20  * Complete or severe failure

Begin:		movem.l	d2-d7/a2-a6,-(sp)
		move.l	a0,a4			;Pointer to the command.
		clr.b	-1(a0,d0.l)
		
		move.l	$4,a6			;Open the dos-library.
		clr.l	d0
		lea.l	DosName(pc),a1
		jsr	OpenLibrary(a6)
		tst.l	d0	
		bne.s	DosOpen
		move.l	#RETURN_FAIL,d0
		movem.l	(sp)+,d2-d7/a2-a6	;couldn't open dos, so
		rts				;it's back to CLI.

DosOpen:	move.l	d0,DosBase		;Get output file from
		move.l	d0,a6			;CLI.
		jsr	OutPut(a6)
		move.l	d0,OutPutFile		;Pointer to output file.

SelectCMD:	cmp.w	#'of',(a4)		;Find out the command. If the
		beq.s	FiltersOFF0		;command was 'off' turn off
		cmp.w	#'on',(a4)		;the filters.
		beq.s	FiltersON0

TstCMD:		tst.b	(a4)			;If it wasn't either, test if
		bne.s	UnCMD			;there was no command.If there
						;wasn't, print
NoCMD:		lea.l	NoCMDTxt(pc),a0		;some text. If there was
		bsr	Print			;a command which wasn't
		bra	ShutDown1		;'on' or 'off', print 

;Unknown Command Given!

UnCMD:		lea.l	UnknownCMDTxt(pc),a0	;the text for an unknown
		bsr	Print			;command.
ShutDown1:	lea.l	UsageTxt(pc),a0		;Print also the Usage and
		bsr	Print
EndTxt:		lea.l	AuthorTxt(pc),a0	;the author.
		bsr	Print

ShutDown2:	move.l	DosBase(pc),a1		;Close the dos-library.
		move.l	$4,a6
		jsr	CloseLibrary(a6)
		movem.l	(sp)+,d2-d7/a2-a6
		rts		

;Routines for changing the filters state.

FiltersON0:	clr.b	$bfe001			;Turn on the filters.
		clr.b	$bfe002
		lea.l	FiltersTxt(pc),a0
		bsr	Print
		lea.l	CMPFiltersONL(pc),a0
		bsr	Print			;Print that the filters
		bra	EndTxt			;are on and the author.
FiltersOFF0:	move.b	#$02,$bfe001		;Turn off the filters.
		move.b	#$02,$bfe002
		lea.l	FiltersTxt(pc),a0
		bsr	Print
		lea.l	CMPFiltersOFFL(pc),a0
		bsr	Print			;Print that the filters
		bra	EndTxt			;are off and the author.

Print:		move.l	a0,d2			;Printing subroutine.
Print1:		tst.b	(a0)+
		bne.s	Print1
		subq.l	#1,a0
		sub.l	d2,a0
		move.l	a0,d3
		move.l	OutPutFile(pc),d1	;Get the output file for
		move.l	DosBase(pc),a6		;the Write routine.
		jsr	Write(a6)
		rts				;Back to the main program

DosBase:	dc.l	0
OutPutFile:	dc.l	0

;Texts

CMPFiltersONL:	dc.b	"on",10,0
CMPFiltersOFFL:	dc.b	"off",10,0
NoCMDTxt:	dc.b	"No Command Given!",10,0
UnknownCMDTxt:	dc.b	"Unknown Command.",10,0
FiltersTxt:	dc.b	"Filters are ",0
VersionTxt:	dc.b	"$VER: "
AuthorTxt:	dc.b	"Filters 1.4 by Tomi Blinnikka",10,0
UsageTxt:	dc.b	"USAGE: Filters on/off. Use lower case only!",10,0
DosName:	dc.b	"dos.library",0
		ds.l	0

		END

