


;*--------------T-----------T-------------------------------T------------T-----
;* RexxCompile 1.3 (100% PC-Relativ)
;* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;*
;* Copyright © 1997 by Sunbeam/Shelter.
;*
;* Date: 27.05.97
;*
;* Assembler: SNMA 2.04, PhxAss 4.35, OMA 2.1, Devpac 3.14, Barfly 1.131
;*            AsmOne 1.29
;* Includes: 40.13
;*-----------------------------------------------------------------------------


ASMONE	SET	0	;false,true
	IFNE	ASMONE
	MC68020
	ENDC
	INCLUDE	"RC:rcincludes/rc12.i"


;*---------------------------------------------------------------------------
;* Workbench / Shell Startup
;*---------------------------------------------------------------------------



Main	lea	VBase(pc),a5
	IFNE	ASMONE
	move.l	SysBase,a6
	ELSE
	move.l	SysBase.w,a6
	ENDC
	move.l	a6,_SysBase-VBase(a5)
	move.l	ThisTask(a6),a4
	tst.l	pr_CLI(a4)
	bne.s	ShellStart

	lea	pr_MsgPort(a4),a0
	CALL	WaitPort
	lea	pr_MsgPort(a4),a0
	CALL	GetMsg
	move.l	d0,_WBStartup-VBase(a5)

ShellStart	btst	#AFB_68020,AttnFlags+1(a6)
	beq	OSErrorExit

	lea	DOSName-VBase(a5),a1
	moveq	#OS204,d0
	CALL	OpenLibrary
	move.l	d0,_DOSBase-VBase(a5)
	beq	OSError

	move.l	d0,a4
	move.l	dl_IntuitionBase(a4),_IntuitionBase-VBase(a5)

	lea	MUIMasterName-VBase(a5),a1
	moveq	#19,d0
	CALL	OpenLibrary
	move.l	d0,_MUIMasterBase-VBase(a5)
	beq	MUIMasterError

	move.l	a4,a6
	move.l	_WBStartup-VBase(a5),d1
	bne	ChangeDir



;*---------------------------------------------------------------------------
;* Shell Handler
;*---------------------------------------------------------------------------



	pea	ShellStr-VBase(a5)
	bsr	Print

	lea	ArgsTemplate-VBase(a5),a0
	move.l	a0,d1
	lea	SourceName-VBase(a5),a0
	move.l	a0,d2
	moveq	#0,d3
	CALL	ReadArgs
	move.l	d0,RDArgs-VBase(a5)
	bne.s	shLoadPrefs

	pea	MUITagMemError-VBase(a5)
	bra	PrintError

	dc.b	"i love ilka and i hate you!"
	cnop	0,4

shLoadPrefs	lea	PrefsName-VBase(a5),a3
	bsr	LoadPrefs
	bne.s	ExaminePrefs
	lea	Prefs2Name-VBase(a5),a3
	bsr	LoadPrefs
	bne.s	ExaminePrefs

	pea	HandleExit-VBase(a5)
	pea	PrefsLoadStr-VBase(a5)
	bra	Print

	dc.b	"$VER: rexxcompile 1.3 (27.5.97)",13,10,0
	cnop	0,4

ExaminePrefs	move.l	#500,d0	;set def_std. id (ID_CRYPT)
	tst.l	ShellDecrypt-VBase(a5)
	beq.s	.CheckStrip
	addq.l	#ID_DECRYPT-500,d0
	move.l	d0,d7
	bra	GetSourceName
.CheckStrip	tst.l	ShellStrip-VBase(a5)
	beq.s	.NoStrip
	addq.l	#ID_STRIP-500,d0
	move.l	d0,d7
	bra	GetSourceName
.NoStrip	move.l	d0,d7
	bra	GetSourceName



;*---------------------------------------------------------------------------
;* Allocate MUI Buffer / Init MUI / Load Prefs / Get DiskObject
;*---------------------------------------------------------------------------



ChangeDir	move.l	d1,a0
	move.l	sm_ArgList(a0),a1
	move.l	(a1),d1
;	move.l	wa_Lock(a1),d1
	CALL	DupLock
	move.l	d0,DirLock-VBase(a5)
	move.l	d0,d1
	CALL	CurrentDir
	move.l	_SysBase-VBase(a5),a6

	lea	IconName-VBase(a5),a1
	CALL	OldOpenLibrary
	move.l	d0,_IconBase-VBase(a5)
	beq.s	.1

	move.l	_WBStartup-VBase(a5),a0
	move.l	sm_ArgList(a0),a0
	move.l	wa_Name(a0),a0
	move.l	d0,a6
	CALL	GetDiskObject
	move.l	d0,DiskObject-VBase(a5)
	move.l	_SysBase-VBase(a5),a6

.1	move.l	#MUI_TAG_SPACE,d0
	moveq	#MEMF_CLEAR>>16,d1
	swap	d1
	CALL	AllocVec
	tst.l	d0
	beq	MUITagMemError

	move.l	d0,MR
	lea	PrefsName-VBase(a5),a3
	bsr	LoadPrefs
	bne.s	.2
	lea	Prefs2Name-VBase(a5),a3
	bsr	LoadPrefs
.2	bsr	AbsReloc	;relocate relocs
	bsr	MakePortTable	;create new portlist
	bsr	InitMUI	;create application

	move.l	MR,-(sp)	;we need a4
	tst.l	App-VBase(a5)
	beq	AppError



;*---------------------------------------------------------------------------
;* MainLoop
;*---------------------------------------------------------------------------



MainLoop	tst.l	_WBStartup-VBase(a5)	;quit if shell-mode
	beq	Quit
	bsr	SetActualPort	;set port if one selected
	clr.l	-(sp)
	clr.l	-(sp)
	pea	MUIA_Application_Sleep
	move.l	App-VBase(a5),a0
	move.l	sp,a1
	move.l	_IntuitionBase-VBase(a5),a6
	CALL	SetAttrsA	;remove busy pointer
	clr.l	-(sp)
	pea	Signal-VBase(a5)	;get return id's
	pea	MUIM_Application_Input
	move.l	App-VBase(a5),-(sp)
	bsr	_DoMethod
	lea	7*4(sp),sp

	move.l	d0,d7	;save return id
	moveq	#GUI_CALL,d6	;set gui call for getattr()
	moveq	#MUIV_Application_ReturnID_Quit,d1
	cmp.l	d1,d0
	beq	Quit

	sub.l	#ID_CRYPT,d0
	beq	GetSourceName
	subq.l	#1,d0	;ID_ABOUT
	beq	About
	subq.l	#1,d0	;ID_DECRYPT
	beq	GetSourceName
	subq.l	#1,d0	;ID_ICONIFY
	beq	Iconify
	subq.l	#1,d0	;ID_ABOUTMUI
	beq	AboutMUI
	subq.l	#1,d0	;ID_SSAVE
	beq	ToggleStripSave
	subq.l	#1,d0	;ID_STRIP
	beq	GetSourceName
	subq.l	#1,d0	;ID_SEM
	beq	ToggleSemFlg
	subq.l	#1,d0	;ID_PREFS
	beq	SavePrefs
	subq.l	#1,d0	;ID_SETTINGS
	beq.s	MUISettings
	subq.l	#1,d0	;ID_QUIT
	beq.s	SaveQuit
	subq.l	#1,d0	;ID_CHECK
	beq	GetSourceName
	subq.l	#1,d0	;ID_EQUAL
	beq	ToggleEqualFlg

CheckWait	move.l	Signal-VBase(a5),d0
	beq	MainLoop
	pea	MainLoop-VBase(a5)
	move.l	_SysBase-VBase(a5),a6
	JUMP	Wait

CheckWaitOk	pea	_OkStr-VBase(a5)
	bsr	SetAction
	bra.s	CheckWait



;*---------------------------------------------------------------------------
;* Some Sub Routines
;*---------------------------------------------------------------------------



SaveQuit	pea	QuitTitle-VBase(a5)	;safely quit
	bsr	SetAction
	move.l	App-VBase(a5),d0
	move.l	MainWindow-VBase(a5),d1
	moveq	#0,d2
	lea	MessageTitle-VBase(a5),a0
	lea	SaveQuitGad-VBase(a5),a1
	lea	SaveQuitStr-VBase(a5),a2
	sub.l	a3,a3
	move.l	_MUIMasterBase-VBase(a5),a6
	CALL	MUI_RequestA
	tst.l	d0
	beq.s	CheckWaitOk
	subq.l	#1,d0
	bne.s	Iconify
	bra	Quit


MUISettings	pea	MSettingsTitle-VBase(a5)	;mui settings window
	bsr	SetAction
	clr.l	-(sp)
	pea	MUIM_Application_OpenConfigWindow
	move.l	App-VBase(a5),-(sp)
	bsr	_DoMethod
	lea	3*4(sp),sp
	bra.s	CheckWaitOk


About	pea	AboutTitle-VBase(a5)	;about requester
	bsr.s	SetAction
	move.l	App-VBase(a5),d0
	move.l	MainWindow-VBase(a5),d1
	moveq	#0,d2
	lea	AboutTitle-VBase(a5),a0
	lea	OkGad-VBase(a5),a1
	lea	AboutStr-VBase(a5),a2
	sub.l	a3,a3
	move.l	_MUIMasterBase-VBase(a5),a6
	CALL	MUI_RequestA
	bra	CheckWaitOk


Iconify	clr.l	-(sp)
	moveq	#TRUE,d0	;iconify the program
	move.l	d0,-(sp)
	pea	MUIA_Application_Iconified
	move.l	App-VBase(a5),a0
	move.l	sp,a1
	move.l	_IntuitionBase-VBase(a5),a6
	CALL	SetAttrsA
	lea	3*4(sp),sp
	bra	CheckWait


AboutMUI	pea	AboutMUITitle-VBase(a5)	;open the 'aboutmui' window
	bsr.s	SetAction
	move.l	MainWindow-VBase(a5),-(sp)
	pea	MUIM_Application_AboutMUI
	move.l	App-VBase(a5),-(sp)
	bsr	_DoMethod
	lea	3*4(sp),sp
	bra	CheckWaitOk


SetAction	movem.l	d0-d7/a0-a6,-(sp)	;set status in bar
	move.l	16*4(sp),a0	;get string
	tst.l	_WBStartup-VBase(a5)
	beq.s	ActionShell
	clr.l	-(sp)
	move.l	a0,-(sp)
	pea	MUIA_Text_Contents
	move.l	ActionGad-VBase(a5),a0
	move.l	sp,a1
	move.l	_IntuitionBase-VBase(a5),a6
	CALL	SetAttrsA
	lea	3*4(sp),sp
ActionDone	movem.l	(sp)+,d0-d7/a0-a6
	rtd	#4
ActionShell	move.l	a0,-(sp)
	bsr	Print
	pea	Linefeed-VBase(a5)
	bsr	Print
	bra.s	ActionDone


ErrorRequest	movem.l	d0-d7/a0-a6,-(sp)	;display error requester
	tst.l	_WBStartup-VBase(a5)
	beq.s	ErrorShell
	pea	_ErrorStr-VBase(a5)
	bsr.s	SetAction
	move.l	App-VBase(a5),d0
	move.l	MainWindow-VBase(a5),d1
	moveq	#0,d2
	lea	ErrorTitle-VBase(a5),a0
	lea	OkGad-VBase(a5),a1
	lea	Array-VBase(a5),a3
	move.l	_MUIMasterBase-VBase(a5),a6
	CALL	MUI_RequestA
	pea	_OkStr-VBase(a5)
	bsr.s	SetAction
ErrorDone	movem.l	(sp)+,d0-d7/a0-a6
	rts
ErrorShell	move.l	Array-VBase(a5),-(sp)
	move.l	a2,-(sp)
	bsr	Print
	addq.w	#4,sp
	pea	Linefeed-VBase(a5)
	bsr	Print
	bra.s	ErrorDone


ToggleStripSave	bchg	#0,StripSaveFlg+3-VBase(a5)	;menu flags check
	bra	CheckWait

ToggleSemFlg	bchg	#0,SemFlg+3-VBase(a5)
	bra	CheckWait

ToggleEqualFlg	bchg	#0,EqualFlg+3-VBase(a5)
	bra	CheckWait



;*---------------------------------------------------------------------------
;* Prefs Saver/Loader
;*---------------------------------------------------------------------------



SavePrefs	movem.l	d0-d7/a0-a6,-(sp)
	move.l	_IntuitionBase-VBase(a5),a6
	move.l	#MUIA_Cycle_Active,d6
	move.l	d6,d0
	move.l	StripCYGad-VBase(a5),a0
	lea	StripFlag-VBase(a5),a1
	CALL	GetAttr
	move.l	d6,d0
	move.l	CryptModeGad-VBase(a5),a0
	lea	CryptMode-VBase(a5),a1
	CALL	GetAttr
	move.l	d6,d0
	move.l	CrunchGad-VBase(a5),a0
	lea	CrunchMode-VBase(a5),a1
	CALL	GetAttr

	pea	_PrefsStr-VBase(a5)
	bsr	SetAction
	move.l	_DOSBase-VBase(a5),a6
	lea	PrefsName-VBase(a5),a4
	bsr.s	WritePrefs
	lea	Prefs2Name-VBase(a5),a4
	bsr.s	WritePrefs
	movem.l	(sp)+,d0-d7/a0-a6
	bra	CheckWaitOk

WritePrefs	move.l	a4,d1
	move.l	#MODE_NEWFILE,d2
	CALL	Open
	move.l	d0,d4
	bne.s	SavePrefHeader

	move.l	a4,Array-VBase(a5)
	lea	SaveStr-VBase(a5),a2
	bra	ErrorRequest

SavePrefHeader	move.l	d0,d1
	lea	PrefsHeader-VBase(a5),a0
	move.l	a0,d2
	moveq	#4,d3
	CALL	Write
	move.l	d4,d1
	lea	StripFlag-VBase(a5),a0
	move.l	a0,d2
	moveq	#4,d3
	CALL	Write
	lea	CryptMode-VBase(a5),a0
	move.l	a0,d2
	move.l	d4,d1
	moveq	#4,d3
	CALL	Write
	lea	CrunchMode-VBase(a5),a0
	move.l	a0,d2
	moveq	#4,d3
	move.l	d4,d1
	CALL	Write
	lea	SemFlg-VBase(a5),a0
	move.l	a0,d2
	moveq	#4,d3
	move.l	d4,d1
	CALL	Write
	lea	StripSaveFlg-VBase(a5),a0
	move.l	a0,d2
	moveq	#4,d3
	move.l	d4,d1
	CALL	Write
	lea	EqualFlg-VBase(a5),a0
	move.l	a0,d2
	moveq	#4,d3
	move.l	d4,d1
	CALL	Write
	move.l	d4,d1
	JUMP	Close



LoadPrefs	movem.l	d1-d7/a0-a6,-(sp)
	moveq	#0,d7
	move.l	_DOSBase-VBase(a5),a6
	move.l	a3,d1
	move.l	#MODE_OLDFILE,d2
	CALL	Open
	move.l	d0,d4
	bne.s	lPrefs
PrefsFail	move.l	d7,d0
	movem.l	(sp)+,d1-d7/a0-a6
	rts

lPrefs	lea	-28(sp),sp
	move.l	sp,d2
	moveq	#28,d3
	move.l	d0,d1
	CALL	Read
	move.l	d4,d1
	CALL	Close
	move.l	sp,a0
	cmp.l	#"RC13",(a0)+
	beq.s	GetPrefs
PrefsDone	lea	28(sp),sp
	bra.s	PrefsFail

GetPrefs	move.l	(a0)+,StripFlag-VBase(a5)
	move.l	(a0)+,CryptMode-VBase(a5)
	move.l	(a0)+,CrunchMode-VBase(a5)
	move.l	(a0)+,SemFlg-VBase(a5)
	move.l	(a0)+,StripSaveFlg-VBase(a5)
	move.l	(a0),EqualFlg-VBase(a5)
	moveq	#-1,d7
	bra.s	PrefsDone



;*---------------------------------------------------------------------------
;* Get FileNames / Load Source File / Handle ARexx Hooks
;*---------------------------------------------------------------------------



StripRX	movem.l	d1-d7/a0-a6,-(sp)	;a1=arg array
	move.l	#ID_STRIP,d7
RXCall	lea	VBase(pc),a5
	move.l	(a1)+,SourceName-VBase(a5)
	move.l	(a1),DestName-VBase(a5)
	moveq	#REXX_CALL,d6	;set rx call
	bsr.s	GetSourceName
	movem.l	(sp)+,d1-d7/a0-a6
	moveq	#0,d0
	rts

CompileRX	movem.l	d1-d7/a0-a6,-(sp)
	move.l	#ID_CRYPT,d7
	bra.s	RXCall

DecompileRX	movem.l	d1-d7/a0-a6,-(sp)
	move.l	#ID_DECRYPT,d7
	bra.s	RXCall




GetSourceName	tst.l	_WBStartup-VBase(a5)
	beq	.ShellCall

	move.l	_IntuitionBase-VBase(a5),a6
	clr.l	-(sp)
	moveq	#TRUE,d0
	move.l	d0,-(sp)
	pea	MUIA_Application_Sleep
	move.l	sp,a1
	move.l	App-VBase(a5),a0
	CALL	SetAttrsA	;set busy pointer
	lea	3*4(sp),sp

	move.l	#MUIA_String_Contents,d5
	tst.l	d6	;gui or rexx call?
	bne.s	.RexxCall
	move.l	d5,d0
	move.l	SourceGad-VBase(a5),a0
	lea	SourceName-VBase(a5),a1
	CALL	GetAttr
	move.l	d5,d0
	move.l	DestGad-VBase(a5),a0
	lea	DestName-VBase(a5),a1
	CALL	GetAttr
.RexxCall	move.l	d5,d0
	move.l	PasswordGad-VBase(a5),a0
	lea	Password-VBase(a5),a1
	CALL	GetAttr
	move.l	d5,d0
	move.l	VerGad-VBase(a5),a0
	lea	_Version-VBase(a5),a1
	CALL	GetAttr
	move.l	d5,d0
	move.l	DestRexxGad-VBase(a5),a0
	lea	DestRexx-VBase(a5),a1
	CALL	GetAttr
	move.l	#MUIA_Cycle_Active,d5
	move.l	d5,d0
	move.l	StripCYGad-VBase(a5),a0
	lea	StripFlag-VBase(a5),a1
	CALL	GetAttr
	move.l	d5,d0
	move.l	CryptModeGad-VBase(a5),a0
	lea	CryptMode-VBase(a5),a1
	CALL	GetAttr
	move.l	d5,d0
	move.l	CrunchGad-VBase(a5),a0
	lea	CrunchMode-VBase(a5),a1
	CALL	GetAttr

.ShellCall	move.l	SourceName-VBase(a5),a0	;filenames selected?
	move.l	DestName-VBase(a5),a1
	tst.b	(a0)
	bne.s	CheckDestName
	lea	NoSourceStr-VBase(a5),a2
GetNameError	bsr	ErrorRequest
	bra	CheckWait


CheckDestName	cmp.l	#ID_CHECK,d7	;check don't need dest
	beq.s	OpenFile
	tst.b	(a1)
	bne.s	CheckDestPort
	lea	NoDestStr-VBase(a5),a2
	bra.s	GetNameError

CheckDestPort	cmp.l	#ID_STRIP,d7	;strip don't needs a dest port
	beq.s	OpenFile
	move.l	DestRexx-VBase(a5),a2
	tst.b	(a2)
	bne.s	OpenFile
	lea	DestRexxStr-VBase(a5),a2
	bra.s	GetNameError


OpenFile	move.l	a0,d1
	pea	_LoadStr-VBase(a5)
	bsr	SetAction
	move.l	_DOSBase-VBase(a5),a6
	move.l	#MODE_OLDFILE,d2
	CALL	Open
	move.l	d0,d4
	bne.s	ExamineFile

	move.l	SourceName-VBase(a5),Array-VBase(a5)
	lea	OpenStr-VBase(a5),a2
	bra.s	GetNameError

ExamineFile	move.l	d0,d1
	lea	-fib_SIZEOF(sp),sp
	move.l	sp,d2
	CALL	ExamineFH
	move.l	fib_Size(sp),d0
	lea	fib_SIZEOF(sp),sp
	move.l	d0,d5
	addq.l	#8,d0	;for even check
	move.l	_SysBase-VBase(a5),a6
	moveq	#MEMF_CLEAR>>16,d1
	swap	d1	;alloc cleared memory
	CALL	AllocVec
	move.l	_DOSBase-VBase(a5),a6
	move.l	d0,d6
	bne.s	LoadFile

	lea	Array-VBase(a5),a0
	move.l	SourceName-VBase(a5),(a0)+
	move.l	d5,(a0)
	lea	MemoryStr-VBase(a5),a2
	bsr	ErrorRequest
	move.l	d4,d1
	CALL	Close
	bra	CheckWait

LoadFile	move.l	d4,d1
	move.l	d0,d2
	move.l	d5,d3
	CALL	Read
	move.l	d4,d1
	CALL	Close


	cmp.l	#ID_DECRYPT,d7	;decrypt file?
	beq	DecryptFile
	cmp.l	#ID_CHECK,d7
	beq	CheckScript



;*---------------------------------------------------------------------------
;* Check Script / Init Strip alorythm
;*---------------------------------------------------------------------------



	move.l	d5,FileLength-VBase(a5)
	move.l	d2,a0
	move.w	#"/*",d0
	cmp.w	(a0),d0	;is arexx file?
	beq.s	StripFile
	cmp.w	1(a0),d0
	beq.s	StripFile

	move.l	SourceName-VBase(a5),Array-VBase(a5)
	lea	NoARexxStr-VBase(a5),a2
	bsr	ErrorRequest
FreeFileMem	move.l	d6,a1
	move.l	_SysBase-VBase(a5),a6
	CALL	FreeVec
	bra	CheckWait


StripFile	cmp.l	#ID_STRIP,d7	;only strip? (gadget)
	beq.s	StripIt
	tst.l	StripFlag-VBase(a5)	;strip file? (cyclegad)
	bne	CryptInit

StripIt	move.l	d7,-(sp)	;save returnid
	pea	_StripStr-VBase(a5)
	bsr	SetAction
	lea	LineCounter-VBase(a5),a2
	moveq	#1,d0
	move.l	d0,(a2)	;reset line counter
	move.l	d6,a0
	move.l	a0,a4
	move.l	a0,a1	;a1=dest
	move.l	d5,d0
	moveq	#$0A,d4	;=lf
	moveq	#$09,d7	;=tab



;*---------------------------------------------------------------------------
;* Stripper
;*---------------------------------------------------------------------------



StripLoop	move.b	(a0)+,d1	;get orig byte
	cmp.b	d4,d1
	bne.s	.1
	addq.l	#1,(a2)
	bra	WriteByte

.1	moveq	#"/",d2
	cmp.b	d2,d1
	bne.s	CheckQuote
	moveq	#"*",d3
	cmp.b	(a0),d3
	bne.s	CheckQuote


StripComment	subq.l	#1,d0
	beq	CommentError
	cmp.b	(a0),d4
	bne.s	.2
	addq.l	#1,(a2)
.2	cmp.b	(a0)+,d3
	bne.s	StripComment
	cmp.b	(a0),d2
	bne.s	StripComment

	addq.w	#1,a0
	subq.l	#1,d0
	beq	StripDone
	bra	StripSubLoop


CheckQuote	moveq	#'"',d2	;skip quoted block
	cmp.b	d2,d1
	beq.s	.3
	moveq	#"'",d2
	cmp.b	d2,d1
	bne.s	CheckLF

.3	move.b	d2,(a1)+	;copy quote char
SkipQuote	subq.l	#1,d0
	beq	QuoteError
	move.b	(a0)+,d1
	cmp.b	d4,d1	;lf received?
	beq	QuoteError
	move.b	d1,(a1)+
	cmp.b	d2,d1	;next quote char found?
	bne.s	SkipQuote
	bra	StripSubLoop



CheckLF	moveq	#" ",d3	;strip front lf/tab/spaces.
	cmp.b	d4,d1
	bne.s	SingleStrip

.4	cmp.l	a1,a4	;first byte?
	beq.s	StripLF
	cmp.b	-(a1),d3	;find next char.
	bge.s	.4
	addq.w	#1,a1
StripLF	subq.l	#1,d0
	beq	StripDone
	cmp.b	(a0),d4
	bne.s	.5
	addq.l	#1,(a2)
.5	cmp.b	(a0)+,d3	;lf/tab or space?
	bgt.s	StripLF
Done	subq.w	#1,a0
	move.b	d4,(a1)+	;copy lf
	bra	StripLoop



SingleStrip	moveq	#"=",d2	;front/end - space/tab stripper
	cmp.b	d2,d1	;of any char. (d2)
	beq.s	StripEqual
	moveq	#"~",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#";",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#"(",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#")",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#",",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#"<",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#"+",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#"-",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#"*",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#"/",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#"%",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#"^",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#"&",d2
	cmp.b	d2,d1
	beq.s	StripFront
	moveq	#">",d2
	cmp.b	d2,d1
	bne.s	FuncStrip
	bra.s	StripFront

StripEqual	btst	#0,EqualFlg+3-VBase(a5)
	beq.s	StripFront
	cmp.b	(a0),d2
	bne.s	StripFront
	move.b	d3,(a0)
StripFront	cmp.l	a1,a4
	beq.s	.6
	cmp.b	-(a1),d3	;go back to an char
	bge.s	StripFront
	addq.w	#1,a1
.6	move.b	d1,(a1)+

StripEnd	subq.l	#1,d0
	beq	SingleError
	move.b	(a0)+,d1
	cmp.b	d4,d1	;lf received?
	beq.s	FrontDone
	cmp.b	d3,d1	;space or tab?
	ble.s	StripEnd
FrontDone	subq.w	#1,a0
	bra	StripLoop



FuncStrip	moveq	#":",d2	;:<char>
	cmp.b	d2,d1
	bne.s	Optimize
.7	subq.l	#1,d0
	beq	FuncArgError
	cmp.b	(a0),d4
	bne.s	.8
	addq.l	#1,(a2)
.8	cmp.b	(a0)+,d3
	bge.s	.7
	subq.w	#1,a0
	addq.l	#1,d0
	bra.s	WriteByte



Optimize	moveq	#"|",d2	;optimize || (only strings)
	cmp.b	d2,d1
;	bne.s	StyleText
	bne.s	WriteByte
	cmp.b	(a0),d2
;	bne.s	StyleText
	bne.s	WriteByte
	moveq	#"'",d2
	cmp.b	-2(a0),d2
	beq.s	.9
	moveq	#'"',d2
	cmp.b	-2(a0),d2
	beq.s	.9
	cmp.b	1(a0),d2
	beq.s	.9
	moveq	#"'",d2
	cmp.b	1(a0),d2
;	bne.s	StyleText
	bne.s	WriteByte
.9	addq.w	#1,a0
	subq.l	#1,d0
	beq.s	StripDone
	bra.s	StripSubLoop



;StyleText	bra.s	WriteByte
;	cmp.b	d3,d1	;format text to <char><space><char>
;	beq.s	.10
;	cmp.b	d7,d1
;	bne.s	WriteByte
;
;.10	cmp.b	-(a1),d3
;	bge.s	.10
;	addq.w	#1,a1
;	move.b	d3,(a1)+
;	bra.s	StripSubLoop
;

WriteByte	move.b	d1,(a1)+	;do nothing only char copy
StripSubLoop	subq.l	#1,d0
	bne	StripLoop



;*---------------------------------------------------------------------------
;* Master LF/TAB/SPACE Stripper
;*---------------------------------------------------------------------------



StripDone	sub.l	d6,a1	;get new script length
	move.l	a1,d5
	beq.s	EmptyScript

	move.l	d6,a0
	move.l	a0,a1
	moveq	#" ",d2
	move.l	d4,d7	;=LF
	move.l	d5,d0
	btst	#0,SemFlg+3-VBase(a5)	;LF->;?
	beq.s	.0
	moveq	#";",d7

.0	subq.l	#1,d5
	beq.s	EmptyScript
	move.b	(a0)+,d1
	cmp.b	d4,d1
	beq.s	.0
	bra.s	.2

.1	move.b	(a0)+,d1
	cmp.b	d4,d1	;wait for lf
	bne.s	.2

.5	cmp.b	-(a1),d2
	bge.s	.5
	addq.w	#1,a1
.4	subq.l	#1,d5
	beq.s	CalcLength
	cmp.b	(a0)+,d2
	bge.s	.4
	subq.w	#1,a0
	move.b	d7,(a1)+	;copy lf or ;
	bra.s	.1
.2	move.b	d1,(a1)+
.3	subq.l	#1,d5
	bne.s	.1

CalcLength	sub.l	d6,a1
	move.l	a1,d5
	move.l	d5,FileLengthStrip-VBase(a5)
	bne.s	_save

EmptyScript	lea	EmptyStr-VBase(a5),a2
	bsr	ErrorRequest
	addq.w	#4,sp
	bra	FreeFileMem


;*---------------------------------------------------------------------------
;* Check Strip Save or Strip Gadget
;*---------------------------------------------------------------------------



_save	move.l	(sp)+,d7	;only strip?
	cmp.l	#ID_STRIP,d7	;yes->save and leave routine
	beq.s	.5
	btst	#0,StripSaveFlg+3-VBase(a5)	;save .strip?
	beq	CryptInit

.5	pea	_SaveStr-VBase(a5)
	bsr	SetAction

	move.l	DestName-VBase(a5),a1
	lea	-256(sp),sp
	move.l	sp,a0
.6	move.b	(a1)+,(a0)+
	bne.s	.6
	subq.w	#1,a0
	cmp.l	#ID_STRIP,d7	;strip or compile mode?
	beq.s	.7
	move.l	#".str",(a0)+
	move.w	#"ip",(a0)+
.7	sf	(a0)
	move.l	sp,d1
	move.l	_DOSBase-VBase(a5),a6
	move.l	#MODE_NEWFILE,d2
	CALL	Open
	move.l	d0,d4
	bne.s	SaveStripScript

	move.l	sp,Array-VBase(a5)
	lea	SaveStr-VBase(a5),a2
	bsr	ErrorRequest
	bra.s	SSaveErr

SaveStripScript	lea	StripHeader-VBase(a5),a0
	move.l	a0,d2
	moveq	#StripHeadLen,d3
	move.l	d0,d1
	CALL	Write
	move.l	d6,d2
	move.l	d5,d3
	move.l	d4,d1
	CALL	Write
	move.l	d4,d1
	CALL	Close

	move.l	sp,d1	;protect script (S)
	moveq	#FIBF_SCRIPT,d2
	CALL	SetProtection

SSaveErr	lea	256(sp),sp
	cmp.l	#ID_STRIP,d7
	bne.s	CryptInit

	pea	_OkStr-VBase(a5)
	bsr	SetAction

	lea	Array-VBase(a5),a3
	move.l	SourceName-VBase(a5),d1
	CALL	FilePart
	move.l	d0,(a3)
	lea	Done3Str-VBase(a5),a2
	bra	DisplaySave



;*---------------------------------------------------------------------------
;* Master Crypt(s) Init
;*---------------------------------------------------------------------------



CryptInit	tst.l	CrunchMode-VBase(a5)	;check for crunch
	bne	CrunchS404

CalcHunkLen	move.l	d6,a0
	move.l	d6,d4
	add.l	d5,d4	;goto end of script
	addq.w	#3,d4
	moveq	#-4,d7
	and.l	d7,d4	;long align
	sub.l	d6,d4	;get new aligned length
	move.l	d4,d1
	sub.l	d5,d1	;already long aligned?
	beq.s	CalcHunk
	move.l	d6,a1	;remove alignlong chars -> null
	add.l	d5,a1
.1	sf	(a1)+	;clear align data
	subq.l	#1,d1
	bne.s	.1


CalcHunk	move.l	d4,d5
	lsr.l	#2,d4	;d4=hunklength
	lea	CodeLength-VBase(a5),a1
	clr.l	(a1)
	clr.l	8(a1)
	tst.l	CrunchMode-VBase(a5)
	beq.s	.2
	move.l	FileLength-VBase(a5),d0
	lsr.l	#2,d0
	move.l	d0,(a1)	;set decrunch buffer

.2	pea	_CryptStr-VBase(a5)
	bsr	SetAction

	move.l	CryptMode-VBase(a5),d0	;get crypt mode
	beq.s	RandomCrypt
	subq.l	#1,d0	;CY_PASSWORD
	beq	PasswordCrypt
	subq.l	#1,d0	;CY_JN25
	beq	PWShellCrypt

	;save uncrypted

	add.l	#uHUNKLENGTH,d4	;save uncrypted executable
	add.l	d4,(a1)+
	move.l	d4,4(a1)

	bsr	SaveHeader
	move.l	d4,d1
	lea	uARexxPortName-VBase(a5),a0
	bsr	CopyPort
	lea	UncryHeader-VBase(a5),a0
	move.l	a0,d2
	move.l	#uhl,d3
	CALL	Write
	bra	SaveScriptPart



;*---------------------------------------------------------------------------
;* #Random-Crypter
;*---------------------------------------------------------------------------



RandomCrypt	add.l	#HUNKLENGTH,d4	;set hunk header data
	add.l	d4,(a1)+
	move.l	d4,4(a1)

	move.l	d5,d0
	move.l	d0,LoopLength+2-VBase(a5)
	move.l	d0,LoopLength2+2-VBase(a5)
	move.b	custom+vhposr,d2
	move.b	d2,RandomKey+3-VBase(a5)

	movem.l	d0/a0,-(sp)	;generate checksum (32bit)
	moveq	#0,d1
	lsr.l	#2,d0
GenChecksum	add.l	(a0)+,d1
	subq.l	#1,d0
	bne.s	GenChecksum
	move.l	d1,Checksum+2-VBase(a5)
	movem.l	(sp),d0/a0


CryptLoop	move.b	(a0),d1	;main crypt
	not.b	d1
	rol.b	#2,d1
	bchg	#1,d1
	moveq	#"S",d3
	add.b	d3,d1
	moveq	#"L",d3
	add.b	d3,d1
	moveq	#"T",d3
	add.b	d3,d1
	not.b	d1
	moveq	#$66,d3
	eor.b	d3,d1
	add.b	d2,d1
	move.b	d1,(a0)+
	subq.b	#1,d2
	subq.l	#1,d0
	bne.s	CryptLoop


	movem.l	(sp)+,d0/a0	;reverse bits
	lsr.l	#2,d0
CryptPass2	moveq	#0,d2	;dest bits
	moveq	#32-1,d3	;num bits
	move.l	(a0),d4
	swap	d4
	bra.s	.2
.1	rol.l	#1,d4
.2	move.l	d4,d1
	and.l	#%00000000000000000000000000000001,d1
	or.l	d1,d2
	ror.l	#1,d2
	dbra	d3,.1
	move.l	d2,(a0)+
	subq.l	#1,d0
	bne.s	CryptPass2

	bsr	SaveHeader
	move.l	d4,d1
	lea	ARexxPortName-VBase(a5),a0
	bsr	CopyPort
	lea	dmain-VBase(a5),a0
	move.l	a0,d2
	move.l	#dhl,d3
	CALL	Write
	bra	SaveScriptPart



;*---------------------------------------------------------------------------
;* #Password Crypter
;*---------------------------------------------------------------------------



PasswordCrypt	move.l	Password-VBase(a5),a2
	moveq	#-1,d0
.1	addq.l	#1,d0
	tst.b	(a2)+
	bne.s	.1
	moveq	#3,d1
	cmp.l	d1,d0
	bge.s	CheckMax

PWLowErr	lea	LowPasswordStr-VBase(a5),a2
PWerr	move.l	d1,Array-VBase(a5)
	bsr	ErrorRequest
	bra	FreeFileMem

CheckMax	moveq	#8,d1
	cmp.l	d1,d0
	ble.s	PWOk

PWHighErr	lea	HighPasswordStr-VBase(a5),a2
	bra.s	PWerr

PWOk	add.l	#pHUNKLENGTH,d4	;set hunk size
	add.l	d4,(a1)+
	move.l	d4,4(a1)

	move.l	d5,d0
	move.l	d0,pLoopLength+2-VBase(a5)
	move.l	d0,pLoopLength2+2-VBase(a5)
	lsr.l	#2,d0	;make 32bit checksum
	movem.l	d0/a0,-(sp)
	moveq	#0,d1
GenPWChecksum	add.l	(a0)+,d1
	subq.l	#1,d0
	bne.s	GenPWChecksum

	move.l	d1,pChecksum+2-VBase(a5)
	movem.l	(sp)+,d0/a0


	move.l	Password-VBase(a5),a1	;crypt password (8 chars)
	movem.l	(a1),d1-d2
	subq.b	#4,d1
	swap	d1
	not.l	d1
	add.l	#$10101010,d1
	addq.b	#5,d2
	rol.l	#6,d2
	swap	d2
	subq.b	#4,d2
	ror.l	#4,d2
	move.l	d1,pmain+2-VBase(a5)
	move.l	d2,pPassword+2-VBase(a5)

PWCryptLoop	move.l	(a0),d3	;main crypter
	add.l	d2,d3
	bchg	#1,d3
	not.l	d3
	bchg	#4,d3
	subq.b	#3,d3
	rol.l	#4,d3
	sub.l	d2,d3
	sub.l	d1,d3
	move.l	d3,(a0)+
	sub.l	d2,d1
	subq.l	#1,d0
	bne.s	PWCryptLoop


	bsr	SaveHeader
	lea	pARexxPortName-VBase(a5),a0
	bsr	CopyPort
	lea	pmain-VBase(a5),a0
	move.l	a0,d2
	move.l	d4,d1
	move.l	#phl,d3
	CALL	Write
	bra	SaveScriptPart



;*---------------------------------------------------------------------------
;* #PWShell Crypter
;*---------------------------------------------------------------------------



PWShellCrypt	move.l	Password-VBase(a5),a2
	moveq	#-1,d2
.1	addq.l	#1,d2
	tst.b	(a2)+
	bne.s	.1
	moveq	#3,d1
	cmp.l	d1,d2
	blt	PWLowErr
	moveq	#100,d1
	cmp.l	d1,d2
	bgt	PWHighErr

	add.l	#sHUNKLENGTH+5+3,d4	;set hunk size
	add.l	d4,(a1)+
	move.l	d4,4(a1)

	move.l	d5,sLoopLength+2-VBase(a5)

	move.l	Password-VBase(a5),a2
	move.l	a2,a3
	move.l	a2,a4
	add.l	d2,a3	;eop
	move.l	d5,d1	;file length
sCryptLoop	move.b	(a0),d4
	move.b	(a2)+,d3
	eor.b	d3,d4
	ror.b	#1,d4
	moveq	#$23,d0
	eor.b	d0,d4
	not.b	d4
	move.b	-1(a4,d2.w),d3
	eor.b	d3,d4
	move.b	d4,(a0)+
	cmp.l	a3,a2
	bne.s	.2
	move.l	Password-VBase(a5),a2
.2	subq.l	#1,d1
	bne.s	sCryptLoop

	move.l	Password-VBase(a5),a1
	move.b	(a1),d0
	move.b	1(a1),d1
	lea	sCryptJSR-VBase(a5),a0
	move.w	(a0),d7
	eor.b	d0,(a0)
	eor.b	d0,1(a0)
	eor.b	d1,d0
	eor.b	d0,(a0)

	bsr.s	SaveHeader
	move.l	d4,d1
	lea	sARexxPortName-VBase(a5),a0
	bsr	CopyPort
	lea	ShellHeader-VBase(a5),a0
	move.l	a0,d2
	move.l	#shl,d3
	CALL	Write
	lea	sCryptJSR-VBase(a5),a0
	move.w	d7,(a0)	;restore header JSR
	bra.s	SaveScriptPart



;*---------------------------------------------------------------------------
;* Save Executable File-Parts
;*---------------------------------------------------------------------------



SaveHeader	pea	_SaveStr-VBase(a5)
	bsr	SetAction
	bsr	MakeVersion
	beq.s	.1
	lea	CodeLength-VBase(a5),a0
	addq.l	#8-1,d7	;+ver_int len,-null byte
	lsr.l	#2,d7
	add.l	d7,(a0)
	add.l	d7,8(a0)
.1	move.l	_DOSBase-VBase(a5),a6
	move.l	DestName-VBase(a5),d1
	move.l	#MODE_NEWFILE,d2
	CALL	Open
	move.l	d0,d4
	beq.s	.2
	move.l	d0,d1
	lea	HunkHeader-VBase(a5),a0
	move.l	a0,d2
	moveq	#HeaderLen,d3
	JUMP	Write

.2	addq.w	#4,sp	;break BSR
OpenError	move.l	DestName-VBase(a5),Array-VBase(a5)
	lea	SaveStr-VBase(a5),a2
	bsr	ErrorRequest
	bra	FreeFileMem



SaveScriptPart	move.l	d6,d2
	move.l	d5,d3
	move.l	d4,d1
	CALL	Write
	moveq	#8,d3	;hunk end length
	lea	HunkEnd-VBase(a5),a0
	bsr	MakeVersion
	beq.s	.1
	lea	VerID-VBase(a5),a0
	move.l	a0,d2
	move.l	d4,d1
	moveq	#8,d3
	CALL	Write
	move.l	d7,d3
	move.l	_Version-VBase(a5),d2
	move.l	d4,d1
	CALL	Write
	lea	HunkEnd+4-VBase(a5),a0
	moveq	#4,d3

.1	move.l	a0,d2	;save hunk_end
	move.l	d4,d1
	CALL	Write
	move.l	d4,d1
	CALL	Close

	pea	_OkStr-VBase(a5)
	bsr	SetAction

	move.l	SourceName-VBase(a5),d1
	CALL	FilePart
	lea	Array-VBase(a5),a3
	move.l	d0,(a3)
	lea	DoneStr-VBase(a5),a2
	tst.l	StripFlag-VBase(a5)
	bne.s	MDR

	lea	Done2Str-VBase(a5),a2
DisplaySave	move.l	FileLength-VBase(a5),d1
	sub.l	FileLengthStrip-VBase(a5),d1
	move.l	d1,4(a3)
	mulu.l	#100,d1	;calc %
	divu.l	FileLength-VBase(a5),d1
	move.l	d1,8(a3)


MDR	tst.l	_WBStartup-VBase(a5)
	beq	FreeFileMem
	move.l	App-VBase(a5),d0	;display saved requester
	move.l	MainWindow-VBase(a5),d1
	moveq	#0,d2
	lea	MessageTitle-VBase(a5),a0
	lea	OkGad-VBase(a5),a1
	move.l	_MUIMasterBase-VBase(a5),a6
	CALL	MUI_RequestA
	bra	FreeFileMem


MakeVersion	moveq	#0,d7	;make $VER: string longalign
	move.l	_Version-VBase(a5),a1	;d7=length or NULL
	tst.b	(a1)
	beq.s	.2
.1	tst.b	(a1)+
	bne.s	.1
	subq.w	#1,a1
	sub.l	_Version-VBase(a5),a1
	move.l	a1,d7
	addq.w	#3,d7
	moveq	#-4,d0
	and.l	d0,d7
.2	rts


CopyPort	move.l	DestRexx-VBase(a5),a2	;copy arexxport string
	moveq	#20-1,d0	;max len.
.1	move.b	(a2)+,(a0)+
	beq.s	.2
	dbra	d0,.1
	rts
.2	sf	(a0)+	;remove old cryp
	dbra	d0,.2
	rts


;*---------------------------------------------------------------------------
;* S404 Cruncher
;*---------------------------------------------------------------------------



CrunchS404	movem.l	d0-d7/a0-a6,-(sp)	;open 'stc.library' V3+
	clr.l	CrunchMode-VBase(a5)	;for errors. (Don't Crunch)
	pea	_CrunchStr-VBase(a5)
	bsr	SetAction
	cmp.l	#1000,d5
	bgt.s	CrunchIt

	lea	SmallStr-VBase(a5),a2
	bsr	ErrorRequest
	bra	StcQuit

CrunchIt	move.l	_SysBase-VBase(a5),a6
	lea	Stc020Name-VBase(a5),a1
	moveq	#STCVERSION,d0
	CALL	OpenLibrary
	move.l	d0,_StcBase-VBase(a5)
	bne.s	.1

	lea	StcName-VBase(a5),a1
	moveq	#STCVERSION,d0
	CALL	OpenLibrary
	move.l	d0,_StcBase-VBase(a5)
	bne.s	.1
	lea	NoStcLibStr-VBase(a5),a2	;requester if no library found.
	bsr	ErrorRequest
	bra	StcQuit


.1	move.l	_DOSBase-VBase(a5),a6
	lea	StcTempFile-VBase(a5),a0	;save actual script to tmp
	move.l	a0,d1
	move.l	#MODE_NEWFILE,d2
	CALL	Open
	move.l	d0,d4
	bne.s	.2

	lea	Array-VBase(a5),a0	;display save error
	move.l	StcTempFile-VBase(a5),(a0)
	lea	SaveStr-VBase(a5),a2
	bsr	ErrorRequest
	bra	TempQuit

.2	move.l	d5,d3	;save script to temp
	move.l	d0,d1
	move.l	d6,d2
	CALL	Write
	move.l	d4,d1
	CALL	Close

	move.l	_StcBase-VBase(a5),a6	;alloc crunch buffer
	moveq	#stcSecurityLen,d0
	lea	StcTempFile-VBase(a5),a0
	CALL	stcNewAllocFileBuffer
	move.l	d0,stcFileBuffer-VBase(a5)
	bne.s	.3

	lea	CrunchMemStr-VBase(a5),a2
	bsr	ErrorRequest
	bra.s	NoFMem

.3	move.l	d0,a0	;load script.
	CALL	stcLoadFileBuffer
	move.l	d0,stcFileLength-VBase(a5)

	moveq	#S404,d0	;alloc security header (S404)
	CALL	stcAllocBuffer
	move.l	d0,stcBuffer-VBase(a5)

	lea	stcCrunchTags-VBase(a5),a0	;crunch arexx script
	CALL	stcCrunchDataTags
	move.l	d0,stcCrunchedLen-VBase(a5)
	bne.s	.4

	lea	CrunchFailStr-VBase(a5),a2	;display if failed.
	bsr	ErrorRequest
	bra.s	CrunchFailQuit


.4	move.l	d6,a0
	move.l	stcFileBuffer-VBase(a5),a1
	addq.w	#4,a1	;skip id
	subq.l	#4,d0
	move.l	#"CRU!",(a1)	;overwrite security length
.5	move.b	(a1)+,(a0)+	;copy new data to old buffer
	subq.l	#1,d0
	bne.s	.5

	moveq	#CY_PACK,d0
	move.l	d0,CrunchMode-VBase(a5)	;set again crunch mode
	bsr.s	FreeS404Mem
	bsr.s	DelTmp
	bsr.s	CloseStcLib
	movem.l	(sp)+,d0-d7/a0-a6
	move.l	stcCrunchedLen-VBase(a5),d5	;set new filelength
	bra	CalcHunkLen	;back to crypt routine.

CrunchFailQuit	bsr.s	FreeS404Mem
NoFMem	bsr.s	DelTmp
TempQuit	bsr.s	CloseStcLib
StcQuit	movem.l	(sp)+,d0-d7/a0-a6
	bra	CalcHunkLen


DelTmp	lea	StcTempFile-VBase(a5),a0	;delete temp file
	move.l	a0,d1
	move.l	_DOSBase-VBase(a5),a6
	JUMP	DeleteFile

FreeS404Mem	move.l	_StcBase-VBase(a5),a6	;free crunch buffers.
	move.l	stcBuffer-VBase(a5),a1
	CALL	stcFreeBuffer
	move.l	stcFileBuffer-VBase(a5),a1
	JUMP	stcFreeFileBuffer

CloseStcLib	move.l	_StcBase-VBase(a5),a1	;close stc.library
	move.l	_SysBase-VBase(a5),a6
	JUMP	CloseLibrary



;*---------------------------------------------------------------------------
;* Decrypter (Random/Password/None/PWShell)
;*---------------------------------------------------------------------------



DecryptFile	move.l	d2,a0
	move.l	#"CRU!",d0
	move.l	#"FedQ",d1
	move.l	#"HFUC",d2

	cmp.l	$64(a0),d0
	bne.s	.1
	cmp.l	$167(a0),d1
	bne.s	.1
	cmp.l	$234(a0),d2
	beq.s	.None

.1	cmp.l	$a6(a0),d0
	bne.s	.2
	cmp.l	$1af(a0),d1
	bne.s	.2
	cmp.l	$27c(a0),d2
	beq.s	.Password

.2	cmp.l	$fc(a0),d0
	bne.s	.3
	cmp.l	$1fb(a0),d1
	bne.s	.3
	cmp.l	$2c8(a0),d2
	beq	.PWShell

.3	cmp.l	$cc(a0),d0
	bne.s	.4
	cmp.l	$1d7(a0),d1
	bne.s	.4
	cmp.l	$2a4(a0),d2
	beq	.Random

.4	move.l	SourceName-VBase(a5),Array-VBase(a5)
	lea	NoRCStr-VBase(a5),a2
	bsr	ErrorRequest
	bra	FreeFileMem

;*---------------------------------------------------------------------------

.None	lea	uData-UncryHeader+4+$20(a0),a1
	cmp.l	#"CRU!",(a1)
	bne.s	.55
	bsr	DepackScript
	move.l	a0,-(sp)
	bra	SaveDecrypted

.55	move.l	a1,-(sp)
	moveq	#-1,d5	;calc script length
.5	addq.l	#1,d5
	tst.b	(a1)+
	bne.s	.5
	bra	SaveDecrypted

;*---------------------------------------------------------------------------

.Password	move.l	Password-VBase(a5),a2
	tst.b	(a2)	;password entered?
	bne.s	.6
.NoPassword	lea	PasswordStr-VBase(a5),a2
	bsr	ErrorRequest
	bra	FreeFileMem

.6	pea	_DecryptStr-VBase(a5)
	bsr	SetAction
	move.l	d6,a0
	move.l	pmain-pmain+2+$20(a0),d1
	move.l	pPassword-pmain+2+$20(a0),d2
	move.l	pLoopLength-pmain+2+$20(a0),d0
	lea	pData-pmain+$20(a0),a1
	move.l	d0,d5
	move.l	a1,-(sp)
	movem.l	d1-d2,-(sp)
	sub.l	#$10101010,d1	;password->ori ascii string
	not.l	d1
	swap	d1
	addq.b	#4,d1
	rol.l	#4,d2
	addq.b	#4,d2
	swap	d2
	ror.l	#6,d2
	subq.b	#5,d2

	cmp.l	(a2)+,d1
	bne	WrongPassword
	cmp.l	(a2),d2
	bne	WrongPassword

	movem.l	(sp)+,d1-d2
	lsr.l	#2,d0
	move.l	d0,d4

.7	move.l	(a1),d3
	add.l	d1,d3
	add.l	d2,d3
	ror.l	#4,d3
	addq.b	#3,d3
	bchg	#4,d3
	not.l	d3
	bchg	#1,d3
	sub.l	d2,d3
	move.l	d3,(a1)+
	sub.l	d2,d1
	subq.l	#1,d0
	bne.s	.7

.8	add.l	-(a1),d0
	subq.l	#1,d4
	bne.s	.8

	cmp.l	pChecksum+2-pmain+$20(a0),d0
	bne	ChecksumError
	bra	SaveDecrypted

;*---------------------------------------------------------------------------

.PWShell	move.l	Password-VBase(a5),a3
	tst.b	(a3)
	beq	.NoPassword
	move.l	a3,a4
	move.l	sLoopLength-ShellHeader+2+$20(a0),d1
	move.l	d1,d5
	lea	sData-ShellHeader+5+$20(a0),a1
	move.l	a1,-(sp)

	moveq	#-1,d0
.GetLength	addq.l	#1,d0
	tst.b	(a3)+
	bne.s	.GetLength
	move.l	a4,a3

.9	move.b	(a1),d2
	move.b	(a3)+,d3
	move.b	-1(a4,d0.w),d4
	eor.b	d4,d2
	not.b	d2
	eor.b	#$23,d2
	rol.b	#1,d2
	eor.b	d3,d2
	move.b	d2,(a1)+
	cmp.l	a3,a4
	bne.s	.10
	move.l	a4,a3
.10	subq.l	#1,d1
	bne.s	.9
	bra	SaveDecrypted

;*---------------------------------------------------------------------------

.Random	move.l	LoopLength-dmain+2+$20(a0),d2
	move.l	d2,d5
	lea	Data-dmain+$20(a0),a1
	move.l	a1,-(sp)
	lsr.l	#2,d2
.11	moveq	#0,d4
	moveq	#32-1,d3
	move.l	(a1),d0
	swap	d0
	bra.s	.13
.12	rol.l	#1,d0
.13	move.l	d0,d1
	and.l	#%00000000000000000000000000000001,d1
	or.l	d1,d4
	ror.l	#1,d4
	dbra	d3,.12
	move.l	d4,(a1)+
	subq.l	#1,d2
	bne.s	.11

	move.b	RandomKey-dmain+3+$20(a0),d3
	move.l	LoopLength-dmain+2+$20(a0),d4
	move.l	(sp),a1
.14	move.b	(a1),d1
	sub.b	d3,d1
	eor.b	#$66,d1
	not.b	d1
	moveq	#"T",d0
	sub.b	d0,d1
	moveq	#"L",d0
	sub.b	d0,d1
	moveq	#"S",d0
	sub.b	d0,d1
	bchg	#1,d1
	ror.b	#2,d1
	not.b	d1
	move.b	d1,(a1)+
	subq.b	#1,d3
	subq.l	#1,d4
	bne.s	.14

	move.l	LoopLength-dmain+2+$20(a0),d3
	lsr.l	#2,d3
.15	add.l	-(a1),d4
	subq.l	#1,d3
	bne.s	.15

	cmp.l	Checksum-dmain+2+$20(a0),d4
	bne.s	ChecksumError
	bra	SaveDecrypted

;*---------------------------------------------------------------------------

WrongPassword	lea	3*4(sp),sp	;pw and script on stack
	lea	WrongPWStr-VBase(a5),a2
	bsr	ErrorRequest
	bra	FreeFileMem

ChecksumError	lea	Array-VBase(a5),a3
	move.l	SourceName-VBase(a5),(a3)
	lea	ChecksumStr-VBase(a5),a2
	lea	ErrorTitle-VBase(a5),a0
	lea	ChecksumGad-VBase(a5),a1
	move.l	App-VBase(a5),d0
	move.l	MainWindow-VBase(a5),d1
	moveq	#0,d2
	move.l	_MUIMasterBase-VBase(a5),a6
	CALL	MUI_RequestA
	tst.l	d0
	bne.s	SaveDecrypted
	addq.w	#4,sp	;script on stack
	pea	_OkStr-VBase(a5)
	bsr	SetAction
	bra	FreeFileMem

DepackScript	cmp.l	#"CRU!",(a1)
	bne.s	.DepackDone
	addq.w	#4,a1
	move.l	(a1),d0
	move.l	d0,d5
	move.l	a1,-(sp)
	move.l	_SysBase-VBase(a5),a6
	moveq	#MEMF_CLEAR>>16,d1
	swap	d1
	CALL	AllocVec
	move.l	(sp)+,a1
	move.l	d0,d7
	bne.s	.DepackIt
	lea	DecrunchMemStr-VBase(a5),a2
	bsr	ErrorRequest
	addq.w	#4,sp	;break BSR
	bra	FreeFileMem
.DepackIt	move.l	d0,a0
	bsr	_DecrunchS404
	move.l	d6,a1	;old memory free!
	CALL	FreeVec
	move.l	d7,d6
	move.l	d7,a1
.DepackDone	move.l	a1,a0
	rts



;*---------------------------------------------------------------------------
;* Save Decrypted file
;*---------------------------------------------------------------------------


SaveDecrypted	pea	_SaveStr-VBase(a5)
	bsr	SetAction
	move.l	(sp)+,a1
	bsr.s	DepackScript
	move.l	a0,a4
	move.l	_DOSBase-VBase(a5),a6
	move.l	DestName-VBase(a5),d1
	move.l	#MODE_NEWFILE,d2
	CALL	Open
	move.l	d0,d4
	beq	OpenError

	move.w	#"/*",d1
	cmp.w	(a4),d1
	beq.s	.1
	cmp.w	1(a4),d1
	beq.s	.1

	lea	RexxHeader-VBase(a5),a0
	move.l	a0,d2
	move.l	d0,d1
	moveq	#RexxHeaderLen,d3
	CALL	Write

.1	move.l	d4,d1
	move.l	a4,d2
	move.l	d5,d3
	CALL	Write
	move.l	d4,d1
	CALL	Close

	move.l	DestName-VBase(a5),d1	;protect file with >S<
	moveq	#FIBF_SCRIPT,d2
	CALL	SetProtection

	pea	_OkStr-VBase(a5)
	bsr	SetAction

	lea	Array-VBase(a5),a3
	move.l	SourceName-VBase(a5),(a3)
	move.l	MainWindow-VBase(a5),d1
	moveq	#0,d2
	lea	MessageTitle-VBase(a5),a0
	lea	OkGad-VBase(a5),a1
	lea	DecryptStr-VBase(a5),a2
	tst.l	_WBStartup-VBase(a5)
	beq.s	.2
	move.l	App-VBase(a5),d0
	move.l	_MUIMasterBase-VBase(a5),a6
	CALL	MUI_RequestA
	bra	FreeFileMem

.2	move.l	a3,-(sp)
	move.l	a2,-(sp)
	bsr	Print
	addq.w	#4,sp
	pea	Linefeed-VBase(a5)
	bsr	Print
	bra	FreeFileMem



;*-------------------------------------------------------------------------------
;* Strip Errors
;*-------------------------------------------------------------------------------



SingleError	lea	SingleStr-VBase(a5),a0
	bra.s	MakeStripError
QuoteError	lea	QuoteStr-VBase(a5),a0
	bra.s	MakeStripError
CommentError	lea	CommentStr-VBase(a5),a0
	bra.s	MakeStripError
FuncArgError	lea	FuncArgStr-VBase(a5),a0
MakeStripError	addq.w	#4,sp	;returnid on stack!
	lea	Array-VBase(a5),a3
	move.l	a0,(a3)+
	move.l	(a2),(a3)	;line counter
	lea	StripStr-VBase(a5),a2
	bsr	ErrorRequest
	bra	FreeFileMem



;*-------------------------------------------------------------------------------
;* Executable Script Headers
;*-------------------------------------------------------------------------------



	cnop	0,4
	INCLUDE	"RC:rcincludes/header_random.asm"
	cnop	0,4
	INCLUDE	"RC:rcincludes/header_uncryp.asm"
	cnop	0,4
	INCLUDE	"RC:rcincludes/header_passwo.asm"
	cnop	0,4
	INCLUDE	"RC:rcincludes/header_pwshel.asm"
	cnop	0,4



;*---------------------------------------------------------------------------
;* Quit
;*---------------------------------------------------------------------------



Quit	tst.l	_WBStartup-VBase(a5)
	beq.s	HandleExit
	move.l	App-VBase(a5),a0
	move.l	_MUIMasterBase-VBase(a5),a6
	CALL	MUI_DisposeObject
AppExit	move.l	_SysBase-VBase(a5),a6
	move.l	(sp)+,a1	;MR is on stack stored
	CALL	FreeVec
	move.l	_PortList-VBase(a5),d0
	beq.s	HandleExit
	move.l	d0,a1
	CALL	FreeVec
HandleExit	move.l	_DOSBase-VBase(a5),a6
	move.l	RDArgs-VBase(a5),d1
	beq.s	MUITagMemError
	CALL	FreeArgs
MUITagMemError	move.l	DiskObject-VBase(a5),a0
	move.l	a0,d0
	beq.s	.1
	move.l	_IconBase-VBase(a5),a6
	CALL	FreeDiskObject
	move.l	a6,a1
	move.l	_SysBase-VBase(a5),a6
	CALL	CloseLibrary
.1	move.l	_DOSBase-VBase(a5),a6
	move.l	DirLock-VBase(a5),d1
	beq.s	.2
	CALL	UnLock
.2	move.l	_SysBase-VBase(a5),a6
	move.l	_MUIMasterBase-VBase(a5),a1
	CALL	CloseLibrary
MUIMasterExit	move.l	_DOSBase-VBase(a5),a1
	CALL	CloseLibrary
OSErrorExit	move.l	_WBStartup-VBase(a5),d0
	beq.s	.3
	move.l	d0,a1
	addq.b	#1,IDNestCnt(a6)
	CALL	ReplyMsg
.3	moveq	#0,d0
	rts



;*---------------------------------------------------------------------------
;* muimaster.library/Application Error Requester & OS Error
;*---------------------------------------------------------------------------



MUIMasterError	lea	MUIMasterStr-VBase(a5),a0
	bsr.s	EasyRequest
	move.l	_SysBase-VBase(a5),a6
	bra.s	MUIMasterExit

AppError	lea	AppStr-VBase(a5),a0
	bsr.s	EasyRequest
	bra	AppExit


EasyRequest	move.l	_IntuitionBase-VBase(a5),a6
	pea	QuitGad-VBase(a5)
	move.l	a0,-(sp)
	pea	ErrorTitle-VBase(a5)
	sub.l	a0,a0
	sub.l	a2,a2
	sub.l	a3,a3
	clr.l	-(sp)
	moveq	#20,d0
	move.l	d0,-(sp)
	move.l	sp,a1
	CALL	EasyRequestArgs
	lea	5*4(sp),sp
	rts


OSError	lea	DOSName-VBase(a5),a1
	CALL	OldOpenLibrary
	tst.l	d0
	beq.s	OSErrorExit
	move.l	d0,a6
	move.l	pr_COS(a4),d1
	lea	OSErrorStr-VBase(a5),a0
	move.l	a0,d2
	moveq	#OSErrorLen,d3
	CALL	Write
	move.l	a6,a1
	move.l	_SysBase-VBase(a5),a6
	CALL	CloseLibrary
	bra.s	OSErrorExit



;*---------------------------------------------------------------------------
;* amiga.lib
;*---------------------------------------------------------------------------



_DoMethod	move.l	a2,-(sp)
	move.l	2*4(sp),a2
	move.l	a2,d0
	beq.s	.1

	lea	3*4(sp),a1
	move.l	-4(a2),a0
	move.l	8(a0),a6
	jsr	(a6)
.1	move.l	(sp)+,a2
	rts



;*---------------------------------------------------------------------------
;* Shell Routines
;*---------------------------------------------------------------------------



PrintError	CALL	IoErr
	move.l	d0,d1
	moveq	#0,d2
	JUMP	PrintFault


Print	movem.l	d0-d2/a0/a6,-(sp)
	move.l	_DOSBase-VBase(a5),a6
	move.l	6*4(sp),d1
	lea	7*4(sp),a0
	move.l	a0,d2
	CALL	VPrintf
	movem.l	(sp)+,d0-d2/a0/a6
	rtd	#4



;*---------------------------------------------------------------------------
;* S404 Decruncher
;*---------------------------------------------------------------------------



	cnop	0,4
	INCLUDE	"RC:rcincludes/s404_main.asm"
	cnop	0,4



;*---------------------------------------------------------------------------
;* Generate Actual PortList
;*---------------------------------------------------------------------------



MakePortTable	move.l	_SysBase-VBase(a5),a6
	lea	PortList(a6),a0
	move.l	(a0),d1
	beq.s	.noports
	moveq	#-1,d0

.loop	addq.l	#1,d0	;add port entry
	move.l	d1,a0
;	move.l	LN_SUCC(a0),d1
	move.l	(a0),d1
	bne.s	.loop

	addq.l	#1,d0	;+TAG_DONE
	lsl.l	#2,d0
	moveq	#MEMF_CLEAR>>16,d1
	swap	d1
	CALL	AllocVec
	lea	_PortList-VBase(a5),a1
	move.l	d0,(a1)
	beq.s	.noports

	move.l	(a1),a1
	lea	PortList(a6),a0
	move.l	(a0),d0
.nameloop	move.l	d0,a0
	move.l	LN_NAME(a0),a2
	tst.b	(a2)
	beq.s	.skip
	move.l	a2,(a1)+	;copy name ptr.
.skip	;move.l	LN_SUCC(a0),d0
	move.l	(a0),d0
	bne.s	.nameloop
	clr.l	(a1)	;TAG_DONE
.noports	rts


SetActualPort	move.l	a6,-(sp)
	move.l	_IntuitionBase-VBase(a5),a6
	move.l	#MUIA_List_Active,d0
	move.l	DestRexxList-VBase(a5),a0
	lea	ActiList-VBase(a5),a1
	CALL	GetAttr
	move.l	ActiList-VBase(a5),d0
	moveq	#-1,d1
	cmp.l	d1,d0
	beq.s	.1
	clr.l	-(sp)
	move.l	_PortList-VBase(a5),a0
	move.l	(a0,d0.l*4),-(sp)
	pea	MUIA_String_Contents
	move.l	sp,a1
	move.l	DestRexxGad-VBase(a5),a0
	CALL	SetAttrsA
	lea	3*4(sp),sp
.1	move.l	(sp)+,a6
	rts


;*---------------------------------------------------------------------------
;* Relocate Relocs / Build Arrays
;*---------------------------------------------------------------------------


AbsReloc	lea	CrunchList-VBase(a5),a1	;create cycle crunch
	lea	UncrunchedStr-VBase(a5),a0
	move.l	a0,(a1)+
	lea	StoneCrackerStr-VBase(a5),a0
	move.l	a0,(a1)

	lea	CryptModeList-VBase(a5),a1	;create cycle crypt
	lea	CryptRndStr-VBase(a5),a0
	move.l	a0,(a1)+
	lea	CryptPwStr-VBase(a5),a0
	move.l	a0,(a1)+
	lea	CryptJn25Str-VBase(a5),a0
	move.l	a0,(a1)+
	lea	CryptNoStr-VBase(a5),a0
	move.l	a0,(a1)

	lea	StripList-VBase(a5),a1	;create cycle strip
	lea	StripYesStr-VBase(a5),a0
	move.l	a0,(a1)+
	lea	StripNoStr-VBase(a5),a0
	move.l	a0,(a1)

	lea	Commands-VBase(a5),a1	;create mui_command
	lea	Comm1-VBase(a5),a0
	moveq	#8-1,d0 ;num commands
MakeCommList	move.l	a0,(a1)+
	lea	9*4(a0),a0
	dbra	d0,MakeCommList

	lea	Comm1-VBase(a5),a0
	bsr.s	Reloc
	lea	Comm2-VBase(a5),a0
	bsr.s	Reloc
	lea	Comm3-VBase(a5),a0
	bsr.s	Reloc
	lea	Comm4-VBase(a5),a0
	bsr.s	Reloc
	lea	Comm5-VBase(a5),a0
	bsr.s	RelocCommHook
	lea	Comm6-VBase(a5),a0
	bsr.s	RelocCommHook
	lea	Comm7-VBase(a5),a0
	bsr.s	RelocCommHook
	lea	Comm5Hook-VBase(a5),a0
	moveq	#3-1,d1
	move.l	a0,d0
	addq.w	#8,a0
.1	add.l	d0,(a0)+
	lea	8+8(a0),a0
	dbra	d1,.1

	lea	Bitmap-VBase(a5),a0	;init bitmap
	move.l	Main-4-VBase(a5),a1
	add.l	a1,a1
	add.l	a1,a1
	addq.w	#4,a1
	move.l	a1,bm_Planes(a0)
	lea	WIDTH*HEIGHT/8(a1),a1
	move.l	a1,bm_Planes+4(a0)
	rts

Reloc	move.l	a0,d0
	add.l	d0,(a0)
	rts

RelocCommHook	move.l	a0,d0
	add.l	d0,(a0)+
	add.l	d0,(a0)+
	addq.w	#4,a0
	add.l	d0,(a0)
	rts



;*---------------------------------------------------------------------------
;* Check ARexx-Script
;*---------------------------------------------------------------------------



CheckScript	pea	_CheckStr-VBase(a5)
	bsr	SetAction
	move.l	_MUIMasterBase-VBase(a5),a6	;for error reqs
	lea	LineCounter-VBase(a5),a1
	moveq	#1,d0
	move.l	d0,(a1)	;reset line counter
	move.l	d6,a0
	moveq	#$0A,d4
	moveq	#0,d0	;error cnt

.checkloop	subq.l	#1,d5
	beq	.checkdone
	move.b	(a0)+,d1
	cmp.b	d4,d1
	bne.s	.checkcomment
	addq.l	#1,(a1)
	bra.s	.checkloop

;*---------------------------------------------------------------------------

.checkcomment	moveq	#"/",d2
	cmp.b	d1,d2
	bne.s	.checkquote
	moveq	#"*",d3
	cmp.b	(a0),d3
	bne.s	.checkquote
	moveq	#0,d7	;lf cnt for comment
.commentloop	subq.l	#1,d5
	beq.s	.commenterr
	move.b	(a0)+,d1
	cmp.b	d4,d1
	bne.s	.commnolf
	addq.l	#1,d7
	bra.s	.commentloop
.commnolf	cmp.b	d1,d3
	bne.s	.commentloop
	cmp.b	(a0),d2
	bne.s	.commentloop
	add.l	d7,(a1)
	addq.w	#1,a0
	subq.l	#1,d5
	beq	.checkdone
	bra.s	.checkloop

.commenterr	lea	CommentStr-VBase(a5),a4
	bsr	.checkerr	;bsr need for stack fixup

;*---------------------------------------------------------------------------

.checkquote	moveq	#"'",d2
	cmp.b	d1,d2
	beq.s	.quoteloop
	moveq	#'"',d2
	cmp.b	d1,d2
	bne.s	.checkpart
	moveq	#0,d7
.quoteloop	subq.l	#1,d5
	beq.s	.quoteerr
	move.b	(a0)+,d1
	cmp.b	d1,d4
	beq.s	.quoteerr
	addq.l	#1,d7
	cmp.l	#65535,d7
	beq.s	.quotebig
	cmp.b	d1,d2
	bne.s	.quoteloop
	bra.s	.checkloop

.quotebig	lea	BigStr-VBase(a5),a4
	moveq	#0,d7
	bra.s	.suberr
.quoteerr	moveq	#0,d7
	lea	QuoteStr-VBase(a5),a4
.suberr	bsr	.checkerr
	tst.l	d5	;file end?
	bne	.checkloop
.eof	lea	EofStr-VBase(a5),a2
	pea	.checkdone-VBase(a5)
	bra	ErrorRequest

;*---------------------------------------------------------------------------

.checkpart	moveq	#"(",d2
	moveq	#")",d3
	cmp.b	d3,d1
	beq.s	.parterr
	cmp.b	d2,d1
	bne.s	.checkexpr
	moveq	#0,d7	;parenthese cnt
.partloop	subq.l	#1,d5
	beq.s	.parterr
	move.b	(a0)+,d1
	cmp.b	d4,d1
	beq.s	.parterr
	moveq	#'"',d2
	cmp.b	d2,d1
	beq.s	.partquote
	moveq	#"'",d2
	cmp.b	d2,d1
	beq.s	.partquote
	moveq	#"(",d2
	cmp.b	d2,d1
	bne.s	.nonextpart
	addq.l	#1,d7
.nonextpart	cmp.b	d1,d3
	bne.s	.partloop
	dbra	d7,.partloop
	bra	.checkloop

.partquote	subq.l	#1,d5
	beq.s	.quoteerr
	move.b	(a0)+,d1
	cmp.b	d1,d4
	beq.s	.quoteerr
	cmp.b	d1,d2
	bne.s	.partquote
	bra.s	.partloop

.parterr	moveq	#0,d7
	lea	PartStr-VBase(a5),a4
	bra.s	.suberr

;*---------------------------------------------------------------------------

.checkexpr	moveq	#">",d2
	cmp.b	d2,d1
	beq.s	.checkexprinit
	moveq	#"|",d2
	cmp.b	d2,d1
	beq.s	.checkexprinit
	moveq	#"&",d2
	cmp.b	d2,d1
	beq.s	.checkexprinit
	moveq	#"^",d2
	cmp.b	d2,d1
	beq.s	.checkexprinit
	moveq	#"%",d2
	cmp.b	d2,d1
	beq.s	.checkexprinit
	moveq	#"/",d2
	cmp.b	d2,d1
	beq.s	.checkexprinit
	moveq	#"*",d2
	cmp.b	d2,d1
	beq.s	.checkexprinit
	moveq	#"-",d2
	cmp.b	d2,d1
	beq.s	.checkexprinit
	moveq	#"+",d2
	cmp.b	d2,d1
	beq.s	.checkexprinit
	moveq	#"<",d2
	cmp.b	d2,d1
	beq.s	.checkexprinit
	moveq	#0,d7
	moveq	#"=",d2
	cmp.b	d2,d1
	bne.s	.checkbool

.checkexprinit	lea	ExpressStr-VBase(a5),a4
.checkexprloop	subq.l	#1,d5
	beq	.suberr
	move.b	(a0)+,d1
	cmp.b	d4,d1
	beq	.suberr
	moveq	#$09,d3
	cmp.b	d3,d1
	beq.s	.checkexprloop
	moveq	#$0A,d3
	cmp.b	d3,d1
	beq.s	.checkexprloop
	subq.w	#1,a0
	addq.l	#1,d5
	bra	.checkloop

;*---------------------------------------------------------------------------

.checkbool	moveq	#"~",d2
	cmp.b	d2,d1
	bne	.checkloop
	lea	BoolStr-VBase(a5),a4
	bra.s	.checkexprloop

;*---------------------------------------------------------------------------

.checkdone	pea	_OkStr-VBase(a5)
	bsr	SetAction
	lea	Array-VBase(a5),a3
	move.l	d0,(a3)
	lea	CheckOkStr-VBase(a5),a2
	move.l	App-VBase(a5),d0
	move.l	MainWindow-VBase(a5),d1
	moveq	#0,d2
	lea	MessageTitle-VBase(a5),a0
	lea	OkGad-VBase(a5),a1
	lea	CheckOkStr-VBase(a5),a2
	CALL	MUI_RequestA
	bra	FreeFileMem

.checkerr	addq.l	#1,d0	;add error
	movem.l	d0-d7/a0-a6,-(sp)
	lea	Array-VBase(a5),a3
	move.l	a4,(a3)
	move.l	(a1),4(a3)
	pea	_ErrorStr-VBase(a5)
	bsr	SetAction
	move.l	App-VBase(a5),d0
	move.l	MainWindow-VBase(a5),d1
	moveq	#0,d2
	lea	ErrorTitle-VBase(a5),a0
	tst.l	d7
	beq.s	.contreq
	lea	CheckAbGadStr-VBase(a5),a1
	bra.s	.req
.contreq	lea	CheckErrGadStr-VBase(a5),a1
.req	lea	StripStr-VBase(a5),a2
	CALL	MUI_RequestA
	tst.l	d0
	movem.l	(sp)+,d0-d7/a0-a6	;no CCR activity!
	beq.s	.aborted
	pea	_CheckStr-VBase(a5)
	bsr	SetAction
	rts
.aborted	pea	_OkStr-VBase(a5)
	bsr	SetAction
	addq.w	#4,sp
	bra	FreeFileMem



;*---------------------------------------------------------------------------
;* Create MUI Application
;*---------------------------------------------------------------------------



InitMUI	move.l	sp,StackSave-VBase(a5)
	move.l	_MUIMasterBase-VBase(a5),a6


;title text

HEIGHT	EQU	43
WIDTH	EQU	90
DEPTH	EQU	2

	BitmapObject
	MUIT3	MUIA_Bitmap_Bitmap,Bitmap
	MUIT3	MUIA_Bitmap_SourceColors,Colors
	MUITQ	MUIA_FixHeight,HEIGHT
	MUITQ	MUIA_Bitmap_Width,WIDTH
	MUIT	MUIA_Bitmap_Height,HEIGHT
	MUITQ	MUIA_Bitmap_Transparent,FALSE
	Endi
	isLab	Picture

;	TextObject
;	MUITQ	MUIA_InputMode,MUIV_InputMode_RelVerify
;	MUIT	MUIA_Background,MUII_BACKGROUND
;	MUITQ	MUIA_Frame,MUIV_Frame_Text
;	MUIT3	MUIA_Text_Contents,TitleTextStr
;	MUIT3	MUIA_ShortHelp,AboutHelp
;	MUITQ	MUIA_ControlChar,"a"
;	Endi
;	isLab	TitleText


;bevel line


	RectangleObject
	MUITQ	MUIA_Rectangle_HBar,TRUE
	MUITQ	MUIA_FixHeight,8
	Endi
	isLab	RectangleOne


;source popasl


	StrLabel	SourceGadStr
	isLab	SourceText
	StringObject
	MUITQ	MUIA_Frame,MUIV_Frame_String
	MUITQ	MUIA_ControlChar,"s"
	Endi
	isLab	STR_SourceGad
	PopaslObject
	MUITQ	MUIA_CycleChain,TRUE
	MUIT3	MUIA_ShortHelp,SourceHelp
	MUITQ	MUIA_Popasl_Type,ASL_FileRequest
	MUIT	MUIA_Popstring_String
	MUIT2	STR_SourceGad-VBase(a5)
	MUIT	MUIA_Popstring_Button
	MakeImage	MUII_PopFile
	MUIT2	d0
	Endi
	isLab	SourceGad


;dest popfileasl


	StrLabel	DestGadStr
	isLab	DestText
	StringObject
	MUITQ	MUIA_Frame,MUIV_Frame_String
	MUITQ	MUIA_ControlChar,"e"
	Endi
	isLab	STR_DestGad
	PopaslObject
	MUITQ	MUIA_CycleChain,TRUE
	MUIT3	MUIA_ShortHelp,DestHelp
	MUITQ	MUIA_Popasl_Type,ASL_FileRequest
	MUIT	MUIA_Popstring_String
	MUIT2	STR_DestGad-VBase(a5)
	MUIT	MUIA_Popstring_Button
	MakeImage	MUII_PopFile
	MUIT2	d0
	Endi
	isLab	DestGad


;crunchmode cycle


	StrLabel	CrunchGadStr
	isLab	CrunchText
	CycleObject
	MUITQ	MUIA_CycleChain,TRUE
	MUIT3	MUIA_ShortHelp,CrunchHelp
	MUIT3	MUIA_Cycle_Entries,CrunchList
	MUITQ	MUIA_ControlChar,"u"
	MUIT	MUIA_Cycle_Active
	MUIT2	CrunchMode-VBase(a5)
	Endi
	isLab	CrunchGad


;cryptmode cycle


	StrLabel	CryptModeStr
	isLab	CryptModeText
	CycleObject
	MUITQ	MUIA_CycleChain,TRUE
	MUIT3	MUIA_ShortHelp,CryptModeHelp
	MUIT3	MUIA_Cycle_Entries,CryptModeList
	MUITQ	MUIA_ControlChar,"m"
	MUIT	MUIA_Cycle_Active
	MUIT2	CryptMode-VBase(a5)
	Endi
	isLab	CryptModeGad


;strip cycle


	StrLabel	StripCYGadStr
	isLab	StripText
	CycleObject
	MUITQ	MUIA_CycleChain,TRUE
	MUIT3	MUIA_ShortHelp,StripCYHelp
	MUIT3	MUIA_Cycle_Entries,StripList
	MUITQ	MUIA_ControlChar,"i"
	MUIT	MUIA_Cycle_Active
	MUIT2	StripFlag-VBase(a5)
	Endi
	isLab	StripCYGad


;password string


	StrLabel	PasswordGadStr
	isLab	PasswordText
	StringObject
	MUITQ	MUIA_CycleChain,TRUE
	MUIT3	MUIA_ShortHelp,PasswordHelp
	MUITQ	MUIA_String_MaxLen,100+1
	MUITQ	MUIA_String_Secret,TRUE
	MUITQ	MUIA_Frame,MUIV_Frame_String
	MUITQ	MUIA_ControlChar,"p"
	Endi
	isLab	PasswordGad


;$ver string

	StrLabel	VerGadStr
	isLab	VerText
	StringObject
	MUITQ	MUIA_CycleChain,TRUE
	MUIT3	MUIA_ShortHelp,VerHelp
	MUITQ	MUIA_String_MaxLen,80+1
	MUITQ	MUIA_Frame,MUIV_Frame_String
	MUITQ	MUIA_ControlChar,"v"
	Endi
	isLab	VerGad


;dest rexx string

;*** listview


	ListObject
	MUITQ	MUIA_Frame,MUIV_Frame_InputList
	MUITQ	MUIA_List_AutoVisible,TRUE
	MUIT	MUIA_List_SourceArray
	MUIT2	_PortList-VBase(a5)
	MUIT3	MUIA_List_Title,ListTitle
	Endi
	isLab	DestRexxList
	ListviewObject
	MUITQ	MUIA_Listview_Input,TRUE
	MUIT	MUIA_Listview_List
	MUIT2	DestRexxList-VBase(a5)
	Endi
	isLab	DestRexxList


;*** popobject


	StrLabel	DestRexxGadStr
	isLab	DestRexxText
	StringObject
	MUITQ	MUIA_CycleChain,TRUE
	MUIT3	MUIA_ShortHelp,DestRexxHelp
	MUITQ	MUIA_String_MaxLen,19+1
	MUITQ	MUIA_Frame,MUIV_Frame_String
	MUITQ	MUIA_ControlChar,"x"
	MUIT3	MUIA_String_Contents,DestRexxDef
	MUIT	MUIA_ObjectID,"DRGD"
	Endi
	isLab	STR_DestRexxGad

	PopobjectObject
	MUITQ	MUIA_CycleChain,TRUE
	MUIT3	MUIA_ShortHelp,DestRexxHelp
	MUITQ	MUIA_Popobject_Follow,TRUE
	MUITQ	MUIA_Popobject_Light,TRUE
	MUITQ	MUIA_Popobject_Volatile,TRUE
	MUIT	MUIA_Popobject_Object
	MUIT2	DestRexxList-VBase(a5)
	MUIT	MUIA_Popstring_String
	MUIT2	STR_DestRexxGad-VBase(a5)
	MUIT	MUIA_Popstring_Button
	MakeImage	MUII_PopUp
	MUIT2	d0
	Endi
	isLab	DestRexxGad


;setup group


	GroupObject
	MUITQ	MUIA_Frame,MUIV_Frame_Group
	MUIT3	MUIA_FrameTitle,grpTWOStr
	MUITQ	MUIA_Group_Columns,2
	MUITQ	MUIA_Background,MUII_GroupBack
	MUIT	MUIA_Group_Child
	MUIT2	SourceText-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	SourceGad-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	DestText-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	DestGad-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	CrunchText-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	CrunchGad-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	CryptModeText-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	CryptModeGad-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	StripText-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	StripCYGad-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	PasswordText-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	PasswordGad-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	VerText-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	VerGad-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	DestRexxText-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	DestRexxGad-VBase(a5)
	Endi
	isLab	GROUP_TWO


;crypt gadget


	TextObject
	MUITQ	MUIA_CycleChain,TRUE
	MUITQ	MUIA_Frame,MUIV_Frame_Button
	MUITQ	MUIA_InputMode,MUIV_InputMode_RelVerify
	MUIT3	MUIA_Text_Contents,CryptGadStr
	MUIT3	MUIA_ShortHelp,CryptHelp
	MUIT	MUIA_Background,MUII_BACKGROUND
	MUITQ	MUIA_Text_HiChar,"C"
	MUITQ	MUIA_ControlChar,"c"
	Endi
	isLab	CryptGad


;strip gadget


	TextObject
	MUITQ	MUIA_CycleChain,TRUE
	MUITQ	MUIA_Frame,MUIV_Frame_Button
	MUITQ	MUIA_InputMode,MUIV_InputMode_RelVerify
	MUIT3	MUIA_Text_Contents,StripGadStr
	MUIT3	MUIA_ShortHelp,StripHelp
	MUIT	MUIA_Background,MUII_BACKGROUND
	MUITQ	MUIA_Text_HiChar,"r"
	MUITQ	MUIA_ControlChar,"r"
	Endi
	isLab	StripGad


;check gadget


	TextObject
	MUITQ	MUIA_CycleChain,TRUE
	MUITQ	MUIA_Frame,MUIV_Frame_Button
	MUITQ	MUIA_InputMode,MUIV_InputMode_RelVerify
	MUIT3	MUIA_Text_Contents,CheckGadStr
	MUIT3	MUIA_ShortHelp,CheckHelp
	MUIT	MUIA_Background,MUII_BACKGROUND
	MUITQ	MUIA_Text_HiChar,"k"
	MUITQ	MUIA_ControlChar,"k"
	Endi
	isLab	CheckGad


;decrypt gadget


	TextObject
	MUITQ	MUIA_Disabled,TRUE
	MUITQ	MUIA_CycleChain,TRUE
	MUITQ	MUIA_Frame,MUIV_Frame_Button
	MUITQ	MUIA_InputMode,MUIV_InputMode_RelVerify
	MUIT3	MUIA_Text_Contents,DecryptGadStr
	MUIT3	MUIA_ShortHelp,DecryptHelp
	MUIT	MUIA_Background,MUII_BACKGROUND
	MUITQ	MUIA_Text_HiChar,"D"
	MUITQ	MUIA_ControlChar,"d"
	Endi
	isLab	DecryptGad


;execute group


	GroupObject
	MUITQ	MUIA_Group_Horiz,TRUE
	MUIT	MUIA_Group_Child
	MUIT2	CryptGad-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	StripGad-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	CheckGad-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	DecryptGad-VBase(a5)
	Endi
	isLab	GROUP_FOUR


;status txtgad


	TextObject
	MUIT	MUIA_Background,MUII_BACKGROUND
	MUITQ	MUIA_Frame,MUIV_Frame_Text
	MUIT3	MUIA_ShortHelp,ActionHelp
	MUIT3	MUIA_Text_Contents,_OkStr
	Endi
	isLab	ActionGad


;status group


	GroupObject
	MUIT	MUIA_Group_Child
	MUIT2	ActionGad-VBase(a5)
	Endi
	isLab	GROUP_FIVE


;main group


	GroupObject
	MUITQ	MUIA_Frame,MUIV_Frame_Group
	MUIT3	MUIA_FrameTitle,grpONEStr
	MUIT	MUIA_Group_Child
	MUIT2	Picture-VBase(a5)
;	MUIT	MUIA_Group_Child
;	MUIT2	TitleText-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	RectangleOne-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	GROUP_TWO-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	GROUP_FOUR-VBase(a5)
	MUIT	MUIA_Group_Child
	MUIT2	GROUP_FIVE-VBase(a5)
	Endi
	isLab	GROUP_ONE

	GroupObject
	MUIT	MUIA_Group_Child
	MUIT2	GROUP_ONE-VBase(a5)
	Endi
	isLab	MAIN_GROUP


;menu items


	MenuitemObject
	MUIT3	MUIA_Menuitem_Title,AboutTitle
	MUIT3	MUIA_Menuitem_Shortcut,AboutComm
	Endi
	isLab	AboutItem

	MenuitemObject
	MUIT3	MUIA_Menuitem_Title,AboutMUITitle
	MUIT3	MUIA_Menuitem_Shortcut,AboutMUIComm
	Endi
	isLab	AboutMUIItem

	BarLabel
	isLab	BARStrLabel

	MenuitemObject
	MUIT3	MUIA_Menuitem_Title,IconifyTitle
	MUIT3	MUIA_Menuitem_Shortcut,IconifyComm
	Endi
	isLab	IconifyItem

	BarLabel
	isLab	BARLABEL1

	MenuitemObject
	MUIT3	MUIA_Menuitem_Title,PrefsTitle
	MUIT3	MUIA_Menuitem_Shortcut,PrefsComm
	Endi
	isLab	PrefsItem

	BarLabel
	isLab	BARLABEL2

	MenuitemObject
	MUIT3	MUIA_Menuitem_Title,QuitTitle
	MUIT3	MUIA_Menuitem_Shortcut,QuitComm
	Endi
	isLab	QuitItem

	MenuitemObject
	MUIT3	MUIA_Menuitem_Title,ProjectTitle
	MUIT	MUIA_Family_Child
	MUIT2	AboutItem-VBase(a5)
	MUIT	MUIA_Family_Child
	MUIT2	AboutMUIItem-VBase(a5)
	MUIT	MUIA_Family_Child
	MUIT2	BARStrLabel-VBase(a5)
	MUIT	MUIA_Family_Child
	MUIT2	IconifyItem-VBase(a5)
	MUIT	MUIA_Family_Child
	MUIT2	BARLABEL1-VBase(a5)
	MUIT	MUIA_Family_Child
	MUIT2	PrefsItem-VBase(a5)
	MUIT	MUIA_Family_Child
	MUIT2	BARLABEL2-VBase(a5)
	MUIT	MUIA_Family_Child
	MUIT2	QuitItem-VBase(a5)
	Endi
	isLab	ProjectMenu

	MenuitemObject
	MUIT3	MUIA_Menuitem_Title,StripTitle
	MUIT3	MUIA_Menuitem_Shortcut,StripComm
	MUITQ	MUIA_Menuitem_Checkit,TRUE
	MUITQ	MUIA_Menuitem_Toggle,TRUE
	MUIT	MUIA_Menuitem_Checked
	MUIT2	StripSaveFlg-VBase(a5)
	Endi
	isLab	StripItem

	MenuitemObject
	MUIT3	MUIA_Menuitem_Title,SemTitle
	MUIT3	MUIA_Menuitem_Shortcut,SemComm
	MUITQ	MUIA_Menuitem_Checkit,TRUE
	MUITQ	MUIA_Menuitem_Toggle,TRUE
	MUIT	MUIA_Menuitem_Checked
	MUIT2	SemFlg-VBase(a5)
	Endi
	isLab	SemItem

	MenuitemObject
	MUIT3	MUIA_Menuitem_Title,EqualTitle
	MUIT3	MUIA_Menuitem_Shortcut,EqualComm
	MUITQ	MUIA_Menuitem_Checkit,TRUE
	MUITQ	MUIA_Menuitem_Toggle,TRUE
	MUIT	MUIA_Menuitem_Checked
	MUIT2	EqualFlg-VBase(a5)
	Endi
	isLab	EqualItem


	MenuitemObject
	MUIT3	MUIA_Menuitem_Title,OptionsTitle
	MUIT	MUIA_Family_Child
	MUIT2	StripItem-VBase(a5)
	MUIT	MUIA_Family_Child
	MUIT2	SemItem-VBase(a5)
	MUIT	MUIA_Family_Child
	MUIT2	EqualItem-VBase(a5)
	Endi
	isLab	OptionsMenu

	MenuitemObject
	MUIT3	MUIA_Menuitem_Title,MSettingsTitle
	MUIT3	MUIA_Menuitem_Shortcut,MSettingsComm
	Endi
	isLab	SettingsItem

	MenuitemObject
	MUIT3	MUIA_Menuitem_Title,SettingsTitle
	MUIT	MUIA_Family_Child
	MUIT2	SettingsItem-VBase(a5)
	Endi
	isLab	SettingsMenu



	MenustripObject
	MUIT	MUIA_Family_Child
	MUIT2	ProjectMenu-VBase(a5)
	MUIT	MUIA_Family_Child
	MUIT2	OptionsMenu-VBase(a5)
	MUIT	MUIA_Family_Child
	MUIT2	SettingsMenu-VBase(a5)
	Endi
	isLab	MainMenu


;create main window


	WindowObject
	MUIT3	MUIA_Window_Title,appProgName
	MUIT3	MUIA_Window_ScreenTitle,ScreenStr
	MUIT	MUIA_Window_Menustrip
	MUIT2	MainMenu-VBase(a5)
	MUIT	MUIA_Window_ID,"RC12"
	MUIT	WindowContents
	MUIT2	MAIN_GROUP-VBase(a5)
	Endi
	isLab	MainWindow

	ApplicationObject
	MUIT3	MUIA_Application_Author,appAuthor
	MUIT3	MUIA_Application_Base,appBase
	MUIT3	MUIA_Application_Title,appProgName
	MUIT3	MUIA_Application_Version,appVersion
	MUIT3	MUIA_Application_Copyright,appCopyright
	MUIT3	MUIA_Application_Description,appDescript
	MUIT	MUIA_Application_DiskObject
	MUIT2	DiskObject-VBase(a5)
	MUIT	MUIA_Application_Window
	MUIT2	MainWindow-VBase(a5)
	MUIT	MUIA_Application_Commands
	MUIT2	Commands-VBase(a5)
	Endi
	isLab	App


;set notifies


	clr.l	-(sp)	  ;8
	moveq	#MUIV_Application_ReturnID_Quit,d0
	move.l	d0,-(sp)	  ;7
	pea	MUIM_Application_ReturnID	  ;6
	moveq	#2,d0
	move.l	d0,-(sp)	  ;5
	move.l	App-VBase(a5),-(sp)	  ;4
	pea	MUIV_EveryTime	  ;3
	pea	MUIA_Menuitem_Trigger	  ;2
	pea	MUIM_Notify	  ;1
	move.l	QuitItem-VBase(a5),-(sp)	  ;0
	bsr	_DoMethod
;menuitem
	move.l	PrefsItem-VBase(a5),(sp)
	move.l	#ID_PREFS,7*4(sp)
	bsr	_DoMethod
	move.l	StripItem-VBase(a5),(sp)
	move.l	#ID_SSAVE,7*4(sp)
	bsr	_DoMethod
	move.l	SemItem-VBase(a5),(sp)
	move.l	#ID_SEM,7*4(sp)
	bsr	_DoMethod
	move.l	IconifyItem-VBase(a5),(sp)
	move.l	#ID_ICONIFY,7*4(sp)
	bsr	_DoMethod
	move.l	AboutMUIItem-VBase(a5),(sp)
	move.l	#ID_ABOUTMUI,7*4(sp)
	bsr	_DoMethod
	move.l	AboutItem-VBase(a5),(sp)
	move.l	#ID_ABOUT,7*4(sp)
	bsr	_DoMethod
	move.l	SettingsItem-VBase(a5),(sp)
	move.l	#ID_SETTINGS,7*4(sp)
	bsr	_DoMethod
	move.l	EqualItem-VBase(a5),(sp)
	move.l	#ID_EQUAL,7*4(sp)
	bsr	_DoMethod
;gad
;	move.l	TitleText-VBase(a5),(sp)
	move.l	#MUIA_Pressed,2*4(sp)
	clr.l	3*4(sp)
;	move.l	#ID_ABOUT,7*4(sp)
;	bsr	_DoMethod
	move.l	CryptGad-VBase(a5),(sp)
	move.l	#ID_CRYPT,7*4(sp)
	bsr	_DoMethod
	move.l	DecryptGad-VBase(a5),(sp)
	move.l	#ID_DECRYPT,7*4(sp)
	bsr	_DoMethod
	move.l	StripGad-VBase(a5),(sp)
	move.l	#ID_STRIP,7*4(sp)
	bsr	_DoMethod
	move.l	CheckGad-VBase(a5),(sp)
	move.l	#ID_CHECK,7*4(sp)
	bsr	_DoMethod
;window
	move.l	MainWindow-VBase(a5),(sp)
	move.l	#MUIA_Window_CloseRequest,2*4(sp)
	moveq	#TRUE,d0
	move.l	d0,3*4(sp)
	move.l	#ID_QUIT,7*4(sp)
	bsr	_DoMethod


	move.l	MainWindow-VBase(a5),-(sp)
	pea	MUIM_Window_SetCycleChain
	move.l	SourceGad-VBase(a5),-(sp)
	move.l	DestGad-VBase(a5),-(sp)
	move.l	CrunchGad-VBase(a5),-(sp)
	move.l	CryptModeGad-VBase(a5),-(sp)
	move.l	StripCYGad-VBase(a5),-(sp)
	move.l	PasswordGad-VBase(a5),-(sp)
	move.l	CryptGad-VBase(a5),-(sp)
	move.l	StripGad-VBase(a5),-(sp)
	move.l	DecryptGad-VBase(a5),-(sp)
	move.l	ActionGad-VBase(a5),-(sp)
	move.l	VerGad-VBase(a5),-(sp)
	move.l	CheckGad-VBase(a5),-(sp)
	clr.l	-(sp)
	bsr	_DoMethod
	lea	24*4(sp),sp


	move.l	_IntuitionBase-VBase(a5),a6
	clr.l	-(sp)
	moveq	#TRUE,d0
	move.l	d0,-(sp)
	pea	MUIA_Window_Open
	move.l	sp,a1
	move.l	MainWindow-VBase(a5),a0
	CALL	SetAttrsA
	lea	3*4(sp),sp
	move.l	d0,(a4)+
	move.l	StackSave-VBase(a5),sp
	rts



;*---------------------------------------------------------------------------
;* Application/Gadget strings
;*---------------------------------------------------------------------------



ArgsTemplate	dc.b	"SOURCE/A,DEST/A,PW=PASSWORD/K,STRIP/S,D=DECOMPILE/S,V=$VER/K,RP=REXXPORT/A",0
ErrorTitle	dc.b	"Error...",0
QuitGad	dc.b	"Quit",0
OkGad	dc.b	"_Ok",0
MUI_TAG_SPACE	EQU	TAG_SPACE
	INCLUDE	"misc/mui_asm.i"
ScreenStr	dc.b	"Copyright © 1997 by Sunbeam/Shelter. All Rights Reserved.",0
;TitleTextStr	dc.b	$1B,"c"
;	dc.b	"RexxCompile 1.3 - 27.5.97 (MUI)",10
;	dc.b	"Copyright ® 1997 by Sunbeam/Shelter!",0
SourceGadStr	dc.b	"_Source:",0
DestGadStr	dc.b	"D_est:",0
CrunchGadStr	dc.b	"Cr_unch:",0
CryptModeStr	dc.b	"Crypt _Mode:",0
StripCYGadStr	dc.b	"Str_ip:",0
PasswordGadStr	dc.b	"_Password:",0
CryptGadStr	dc.b	$1B,"cCompile",0
StripGadStr	dc.b	$1B,"cStrip",0
DecryptGadStr	dc.b	$1B,"cDecompile",0
CheckGadStr	dc.b	$1B,"cCheck",0
VerGadStr	dc.b	"$_VER:",0
DestRexxGadStr	dc.b	"Re_xxPort:",0
DestRexxDef	dc.b	"REXX",0
AboutTitle	dc.b	"About...",0
AboutComm	dc.b	"A",0
AboutMUITitle	dc.b	"About MUI...",0
AboutMUIComm	dc.b	"M",0
IconifyTitle	dc.b	"Iconify",0
IconifyComm	dc.b	"I",0
PrefsTitle	dc.b	"Save prefs",0
PrefsComm	dc.b	"W",0
QuitTitle	dc.b	"Quit",0
QuitComm	dc.b	"Q",0
ProjectTitle	dc.b	"Project",0
OptionsTitle	dc.b	"Options",0
SettingsTitle	dc.b	"Settings",0
StripTitle	dc.b	"Save .strip file",0
StripComm	dc.b	"T",0
SemTitle	dc.b	"LF -> "
SemComm	dc.b	";",0
EqualTitle	dc.b	"== -> "
EqualComm	dc.b	"=",0
MSettingsTitle	dc.b	"MUI.."
MSettingsComm	dc.b	".",0
appProgName	dc.b	"RexxCompile",0
appAuthor	dc.b	"Sunbeam/Shelter",0
appBase	dc.b	"RC",0
appVersion	dc.b	"$VER: RexxCompile 1.3 (27.5.97)",0
appCopyright	dc.b	"©97 SNB/SLT",0
appDescript	dc.b	"ARexx-Script Crypter.",0
ActionHelp	dc.b	"This is the action bar.",10
	dc.b	"You can fallow all actions here.",0
PasswordHelp	dc.b	"Insert here your password.",10
	dc.b	"Only available in password encryptions.",0
StripCYHelp	dc.b	"Do you wish to strip the file?",0
StripHelp	dc.b	"This options strips only an ARexx-Script.",0
CryptModeHelp	dc.b	"Select here the encrypt aloryhtm.",0
CrunchHelp	dc.b	"Crunch ARexx-Script with StoneCracker?",10
	dc.b	"Make sure you have the 'stc.library' V3+!",0
DestHelp	dc.b	"Select the destination file.",0
SourceHelp	dc.b	"Select an ARexx-Script or an RC1.3 executable.",0
;AboutHelp	dc.b	"Open about requester.",0
CryptHelp	dc.b	"Encrypt ARexx-Script.",0
DecryptHelp	dc.b	"Decrypt RC1.3 executable file.",0
VerHelp	dc.b	"Insert here your Version string.",10
	dc.b	"For the 'Version' command. ($VER:)",0
DestRexxHelp	dc.b	"Enter here the destination port.",10
	dc.b	"Default is 'REXX'.",0
CheckHelp	dc.b	"Check ARexx-Script for errors.",0
grpONEStr	dc.b	"RexxCompile",0
grpTWOStr	dc.b	"Setup",0
_OkStr	dc.b	"Ok.",0
ListTitle	dc.b	$1b,"bSelect destination port:",0
UncrunchedStr	dc.b	"Don't Crunch",0
StoneCrackerStr
StripYesStr	dc.b	"Yes",0
StripNoStr	dc.b	"Don't Strip",0
CryptRndStr	dc.b	"Encrypt (Random)",0
CryptPwStr	dc.b	"Encrypt (Password)",0
CryptJn25Str	dc.b	"Encrypt (PWShell)",0
CryptNoStr	dc.b	"Don't Crypt",0
Comm1Name	dc.b	"ABOUT",0
Comm2Name	dc.b	"ABOUTMUI",0
Comm3Name	dc.b	"SAVEPREFS",0
Comm4Name	dc.b	"MUI",0
Comm5Name	dc.b	"COMPILE",0
Comm7Pat
Comm6Pat
Comm5Pat	dc.b	"SOURCE/A,DEST/A",0
Comm6Name	dc.b	"STRIP",0
Comm7Name	dc.b	"DECOMPILE",0



;*---------------------------------------------------------------------------
;* ActionStatus Strings
;*---------------------------------------------------------------------------



_DecrunchStr	dc.b	"Decrunching...",0
_PrefsStr	dc.b	"Saving prefs...",0
_CrunchStr	dc.b	"Crunching...",0
_LoadStr	dc.b	"Loading...",0
_SaveStr	dc.b	"Saving...",0
_CryptStr	dc.b	"Crypting...",0
_DecryptStr	dc.b	"Decrypting...",0
_ErrorStr	dc.b	"An error has occured!",0
_StripStr	dc.b	"Stripping&Optimizing...",0
_CheckStr	dc.b	"Checking...",0


;*---------------------------------------------------------------------------
;* Non MUI Strings
;*---------------------------------------------------------------------------



DOSName	dc.b	"dos.library",0
MUIMasterName	dc.b	"muimaster.library",0
StcName	dc.b	"stc.library",0
Stc020Name	dc.b	"stc020.library",0
IconName	dc.b	"icon.library",0
MUIMasterStr	dc.b	"Couldn't open 'muimaster.library' V19+!",0
AppStr	dc.b	"Couldn't create application!",0
OSErrorStr	dc.b	"You need OS2.04 or higher!",10,0
OSErrorLen	EQU	*-OSErrorStr



;*---------------------------------------------------------------------------
;* Normal Strings
;*---------------------------------------------------------------------------



EofStr	dc.b	"Failed. End of file reached.",0
CheckErrGadStr	dc.b	"_Continue|"
CheckAbGadStr	dc.b	"_Abort",0
CheckOkStr	dc.b	"Script checked %ld error(s) found.",0
EmptyStr	dc.b	"Empty script.",0
DestRexxStr	dc.b	"You must enter an destination port.",0
LowPasswordStr	dc.b	"You must enter min. 3 chars for the password.",0
HighPasswordStr	dc.b	"You can use only max. %ld chars for the password.",0
SmallStr	dc.b	"File is to small for crunching.",0
ShellStr	dc.b	"RexxCompile 1.3 - 27.5.97",10
	dc.b	"Copyright © 1997 by Sunbeam/Shelter.",10,10,0
AboutStr	dc.b	$1B,"c",$1B,"b"
	dc.b	"RexxCompile 1.3 - 27.5.97 (MUI)",10,10
	dc.b	$1B,"n"
	dc.b	"RexxCompile is an ARexx-Script to ExeCrypter.",10
	dc.b	"Public Version!",10,10
	dc.b	"Regards to:",10,10
	dc.b	"Shallow - for the idea.",10
	dc.b	"Daryl - the OS-Guru-Master.",10
	dc.b	"Steven - for the A4000.",10
	dc.b	"Sputnik - for the keys.",10
	dc.b	"Deadbeat - for cool sound.",10
	dc.b	"Mindstorm - cool sound.",10,10
	dc.b	$1B,"b"
	dc.b	"MUI"
	dc.b	$1B,"n"
	dc.b	" Copyright © 1992-97 by Stefan Stuntz.",0
MessageTitle	dc.b	"RC Message...",0
OpenStr	dc.b	"Couldn't open source file '%s'.",0
SaveStr	dc.b	"Couldn't open output file '%s'.",0
MemoryStr	dc.b	"Couldn't allocate %ld bytes for file '%s'.",0
StripStr	dc.b	"Error: "
	dc.b	$1B,"b"
	dc.b	"%s"
	dc.b	$1B,"n"
	dc.b	" in line %ld.",0

BigStr	dc.b	"symbol or string >65535 characters",0
BoolStr	dc.b	"boolean value not 0 or 1",0
ExpressStr	dc.b	"invalid expression",0
PartStr	dc.b	"unbalanced parentheses",0
CommentStr	dc.b	"unterminated comment",0
FuncArgStr	dc.b	"invalid function",0
QuoteStr	dc.b	"unmatched quote",0
SingleStr	dc.b	"single strip error",0

Linefeed	dc.b	10,0
VerID	dc.b	0,0,"$VER: "
PrefsHeader	dc.b	"RC13"
PrefsName	dc.b	"ENV:RC.prefs",0
Prefs2Name	dc.b	"ENVARC:RC.prefs",0
PrefsLoadStr	dc.b	"Couldn't load prefs file.",10,0
CrunchFailStr	dc.b	"Crunch failed.",0
DecrunchMemStr	dc.b	"Not enough memory for decrunching.",0
CrunchMemStr	dc.b	"Not enough memory for crunching.",0
NoStcLibStr	dc.b	"Couldn't open 'stc.library' V3+!",0
PasswordStr	dc.b	"This option requires an password.",0
WrongPWStr	dc.b	"Wrong password.",0
NoSourceStr	dc.b	"No source file selected.",0
NoDestStr	dc.b	"No destination file selected.",0
DoneStr	dc.b	"File '%s' converted and saved.",0
Done2Str	dc.b	$1B,"c"
	dc.b	"File '%s' stripped (%ld bytes won)",10
	dc.b	"converted and saved.",0
Done3Str	dc.b	"File '%s' stripped %ld bytes won (%ld%%).",0
NoARexxStr	dc.b	"File '%s' is not an ARexx-Script.",0
NoRCStr	dc.b	"File '%s' is not an RexxCompile 1.3 file.",0
DecryptStr	dc.b	"File '%s' decrypted.",0
ChecksumStr	dc.b	"Script in file '%s' has an wrong checksum.",0
ChecksumGad	dc.b	"_Save|_Abort",0
RexxHeader	dc.b	"/* Decompiled with RexxCompile 1.3 */",10
RexxHeaderLen	EQU	*-RexxHeader
StripHeader	dc.b	"/* Stripped&Optimzed with RexxCompile 1.3 */",10
StripHeadLen	EQU	*-StripHeader
StcTempFile	dc.b	"RAM:S404CRUNCHTEMPRC13",0
SaveQuitStr	dc.b	"Are you sure want to quit?",0
SaveQuitGad	dc.b	"  _Quit  |_Iconify|_Cancel",0
	cnop	0,4



;*---------------------------------------------------------------------------
;* TagLists / Arrays
;*---------------------------------------------------------------------------



stcCrunchTags	dc.l	cdDESTINATION
stcFileBuffer	dc.l	0
	dc.l	cdLENGTH
stcFileLength	dc.l	0
	dc.l	cdABORTFLAGS
	dc.l	cdAbortNIL
	dc.l	cdOUTPUTFLAGS
	dc.l	cdOutPutNIL
	dc.l	cdDISTBITS
	dc.l	cdDist16K
	dc.l	cdBUFFER
stcBuffer	dc.l	0
	dc.l	TAG_DONE


Comm5Hook	dc.l	0,0,CompileRX-Comm5Hook,0,0
Comm6Hook	dc.l	0,0,StripRX-Comm5Hook,0,0
Comm7Hook	dc.l	0,0,DecompileRX-Comm5Hook,0,0


Comm1	dc.l	Comm1Name-Comm1
	dc.l	MC_TEMPLATE_ID
	dc.l	ID_ABOUT
	dc.l	0
	ds.l	5
Comm2	dc.l	Comm2Name-Comm2
	dc.l	MC_TEMPLATE_ID
	dc.l	ID_ABOUTMUI
	dc.l	0
	ds.l	5
Comm3	dc.l	Comm3Name-Comm3
	dc.l	MC_TEMPLATE_ID
	dc.l	ID_PREFS
	dc.l	0
	ds.l	5
Comm4	dc.l	Comm4Name-Comm4
	dc.l	MC_TEMPLATE_ID
	dc.l	ID_SETTINGS
	dc.l	0
	ds.l	5
Comm5	dc.l	Comm5Name-Comm5
	dc.l	Comm5Pat-Comm5
	dc.l	2
	dc.l	Comm5Hook-Comm5
	ds.l	5
Comm6	dc.l	Comm6Name-Comm6
	dc.l	Comm6Pat-Comm6
	dc.l	2
	dc.l	Comm6Hook-Comm6
	ds.l	5
Comm7	dc.l	Comm7Name-Comm7
	dc.l	Comm7Pat-Comm7
	dc.l	2
	dc.l	Comm7Hook-Comm7
	ds.l	5
CommEnd	ds.l	9

Colors	dc.l	$B1000000
	dc.l	$B4000000
	dc.l	$B4000000
	dc.l	0
	dc.l	0
	dc.l	0
	dc.l	$77000000
	dc.l	$77000000
	dc.l	$77000000
	dc.l	$FF000000
	dc.l	0
	dc.l	0



;*---------------------------------------------------------------------------
;* Variables (DX)
;*---------------------------------------------------------------------------



Bitmap	dc.w	12
	dc.w	HEIGHT
	dc.b	BMA_HEIGHT
	dc.b	DEPTH
	dc.w	0
	ds.l	8


CrunchList	dc.l	0,0,0
CryptModeList	dc.l	0,0,0,0,0
StripList	dc.l	0,0,0
Commands	dc.l	0,0,0,0,0,0,0,0


MainMenu	dc.l	0
ProjectMenu	dc.l	0
AboutItem	dc.l	0
AboutMUIItem	dc.l	0
BARStrLabel	dc.l	0
IconifyItem	dc.l	0
BARLABEL1	dc.l	0
PrefsItem	dc.l	0
BARLABEL2	dc.l	0
QuitItem	dc.l	0
OptionsMenu	dc.l	0
StripItem	dc.l	0
SemItem	dc.l	0
EqualItem	dc.l	0
SettingsMenu	dc.l	0
SettingsItem	dc.l	0

MAIN_GROUP	dc.l	0
GROUP_ONE	dc.l	0
GROUP_TWO	dc.l	0
GROUP_FOUR	dc.l	0
GROUP_FIVE	dc.l	0


StripText	dc.l	0
CrunchText	dc.l	0
SourceText	dc.l	0
_PortList	dc.l	0
VerText	dc.l	0
DestRexxText	dc.l	0
;TitleText	dc.l	0
PasswordText	dc.l	0
DestText	dc.l	0
CryptModeText	dc.l	0

CryptGad	dc.l	0
DecryptGad	dc.l	0
PasswordGad	dc.l	0
StripCYGad	dc.l	0
CryptModeGad	dc.l	0
SourceGad	dc.l	0
CrunchGad	dc.l	0
ActionGad	dc.l	0
StripGad	dc.l	0
DestRexxGad	dc.l	0
VerGad	dc.l	0
DestGad	dc.l	0
CheckGad	dc.l	0

DestRexxList	dc.l	0

SourceName	dc.l	0
DestName	dc.l	0
Password	dc.l	0
ShellStrip	dc.l	0
ShellDecrypt	dc.l	0
_Version	dc.l	0
DestRexx	dc.l	0


ActiList	dc.l	0
MainWindow	dc.l	0
App	dc.l	0
Signal	dc.l	0
RectangleOne	dc.l	0
STR_SourceGad	dc.l	0
STR_DestGad	dc.l	0
STR_DestRexxGad	dc.l	0
StripFlag	dc.l	0
CrunchMode	dc.l	0
SemFlg	dc.l	0
EqualFlg	dc.l	0
_WBStartup	dc.l	0
DirLock	dc.l	0
_StcBase	dc.l	0
_DOSBase	dc.l	0
_IntuitionBase	dc.l	0
_MUIMasterBase	dc.l	0
_IconBase	dc.l	0
_SysBase	dc.l	0
DiskObject	dc.l	0
StackSave	dc.l	0
CryptMode	dc.l	0
FileLength	dc.l	0
FileLengthStrip	dc.l	0
RDArgs	dc.l	0
LineCounter	dc.l	0
StripSaveFlg	dc.l	0
stcCrunchedLen	dc.l	0
Array	dc.l	0,0,0
Picture	dc.l	0
VBase	ds.l	0

	SECTION	Graphics,DATA_C

Bitplane	INCBIN	"RC:rcincludes/picture.raw"
	END