		section	multiselect,code

		include	'includes:misc/os3_gst.i'

*-------------- Open dos library..

		move.l	4.w,a6
		lea	DOSName(pc),a1
		jsr	-408(a6)
		move.l	d0,_DOSBase
		beq.w	NoLib

		lea	About.txt,a0
		bsr.w	putstr

*-------------- Open reqtools library..

		lea	ReqName(pc),a1
		move.l	#REQTOOLSVERSION,d0
		jsr	-552(a6)
		move.l	d0,_RTBase
		beq.w	closedos
		move.l	d0,a6

******************************************************************************
*-------------- Allocate a Reqtools File Requester

		move.l	#RT_FILEREQ,d0
		suba.l	a0,a0
		jsr	_LVOrtAllocRequestA(a6)
		move.l	d0,filereq
		beq.w	ok17

*-------------- set default dir..

		lea	defdir_tags(pc),a0
		move.l	d0,a1
		jsr	_LVOrtChangeReqAttrA(a6)

*-------------- multiselect some filenames...

		move.l	filereq(pc),a1
		lea	filename,a2
		lea	Text66(pc),a3
		lea	Tags9(pc),a0
		jsr	_LVOrtFileRequestA(a6)
		move.l	d0,flist
		beq.w	ok16

******************************************************************************
*-------------- allocate a volume requester..

		move.l	#RT_FILEREQ,d0
		sub.l	a0,a0
		jsr	_LVOrtAllocRequestA(a6)
		move.l	d0,volreq
		beq.w	freelist			;free multilist..

*-------------- select destination path..

		lea	volpath,a1
		clr.b	(a1)

		suba.l	a2,a2
		lea	Text89(pc),a3
		lea	Tags11(pc),a0
		move.l	volreq(pc),a1
		jsr	_LVOrtFileRequestA(a6)
		tst.l	d0
		beq.s	vol_error

*-------------- selection ok...

		move.l	volreq(pc),a0
		move.l	rtfi_Dir(a0),a0
		lea	volpath,a1
get_volname:	move.b	(a0)+,(a1)+
		bne.s	get_volname
		bra.s	vol_free

*-------------- selection cancelled or failed..

vol_error	lea	NoPath.txt(pc),a0
		bsr.w	putstr

vol_free	move.l	volreq(pc),a1
		jsr	_LVOrtFreeRequest(a6)


******************************************************************************
*-------------- process all filenames in the list...
		
		move.l	flist(pc),a6
nextfile:
		lea	finalname,a5
		move.l	a5,a1

		move.l	filereq(pc),a0
		move.l	rtfi_Dir(a0),d0
		beq.s	no_slash
		move.l	d0,a0
		move.l	rtfl_Name(a6),d1
		beq.s	nextname
		
bytecopy:	move.b	(a0)+,(a1)+
		bne.s	bytecopy
		cmp.b	#":",-2(a1)
		bne.s	add_slash
		tst.b	-(a1)
		bra.s	no_slash
add_slash:	tst.b	-(a1)
		move.b	#"/",(a1)+
no_slash:	move.l	d1,a0
bytecopy2:	move.b	(a0)+,(a1)+
		bne.s	bytecopy2
		clr.b	(a1)+
		move.l	a5,d0

*-------------- d0.l = final filename..

		bsr.s	process			;process files in linked list.
		tst.l	d0			;abort processing of files??
		bne.s	aborted

nextname	move.l	rtfl_Next(a6),a6
		cmp.l	#0,a6
		bne.s	nextfile

		lea	Done.txt(pc),a0
		bsr.w	putstr

*-------------- free list of filenames..

freelist
aborted		move.l	flist(pc),a0
		move.l	_RTBase,a6
		jsr	_LVOrtFreeFileList(a6)

*-------------- free file requesters..

ok16		move.l	filereq(pc),a1
		jsr	_LVOrtFreeRequest(a6)

*-------------- close reqtools library..

closelibs
ok17		move.l	_RTBase(pc),a1
		move.l	4.w,a6
		jsr	-414(a6)

*-------------- close dos library..

closedos:	move.l	_DOSBase(pc),a1
		move.l	4.w,a6
		jsr	-414(a6)

NoLib:		moveq	#0,d0
		rts




process		movem.l	d1-d7/a0-a6,-(sp)

*-------------- Attempt to load this file..

LoadFile:	move.l	d0,-(sp)
		lea	Load.txt(pc),a0
		bsr.w	putstr
		move.l	(sp),a0
		bsr.w	putstr
		lea	LF.txt(pc),a0
		bsr.w	putstr
		lea	LF.txt(pc),a0
		bsr.w	putstr
		move.l	(sp),a0
		bsr.w	LoadDOSFile
		move.l	(sp)+,a0
		tst.l	d0
		beq.s	Load_Okay

		cmp.l	#-2,d0
		bne.s	notf

*-------------- out of memory

		move.l	a0,-(sp)
		lea	ErrorMem.txt(pc),a0
		bsr.w	putstr
		move.l	(sp)+,a0
		bra.b	nosave

*-------------- file not found
notf
		move.l	a0,-(sp)
		lea	ErrorLoad.txt(pc),a0
		bsr.w	putstr
		move.l	(sp)+,a0
		bra.b	nosave

Load_Okay:	bsr.w	sort_destname

		move.l	d0,-(sp)
		bsr.w	ScanIt
		move.l	(sp)+,a0		;a0=filename..

		move.l	a0,Savename

*-------------- Attempt to save this file..

SaveFile:	tst.b	patched
		beq.s	skip_save
		
		lea	Save.txt(pc),a0
		bsr.w	putstr
		move.l	Savename(pc),a0
		bsr.w	putstr
		lea	LF.txt(pc),a0
		bsr.w	putstr

*-------------- write file out..

		move.l	Savename,a0
		move.l	ProgBuff(pc),a1
		move.l	ProgSize(pc),d1
		bsr.w	SaveDOSFile
		tst.l	d0
		beq.s	Save_Okay

		lea	ErrorSave.txt(pc),a0
		bsr.w	putstr
Save_Okay

nosave		clr.b	patched

		bsr.w	FreeDOSFile

*-------------- abort processing of files if CTRL+C was pressed...

		bsr.b	_CheckBreak

		movem.l	(sp)+,d1-d7/a0-a6
		rts

skip_save:	lea	skip_save.txt(pc),a0
		bsr.w	putstr
		bra.s	nosave


_CheckBreak:	moveq	#0,d0
		moveq	#0,d1
		bset.l	#SIGBREAKB_CTRL_C,d1	;check for CTRL_C
		move.l	_DOSBase(pc),a6
		jsr	_LVOCheckSignal(a6)	;did user signal a break??

		btst.l	#SIGBREAKB_CTRL_C,d0
		beq.s	NoBreak
WasBroken:	moveq	#1,d0			;yes.. user tried to break..
		rts

NoBreak:	moveq	#0,d0			;no break
		rts

ScanIt:		movem.l	d0-d7/a0-a6,-(sp)


********************************************************************************
*-------------- scan for "Long Muls"

_PASS1:		lea	Find_Muls.l.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	SASC_Muls(pc),a2	;a2.l = Binary to find...
		moveq	#(SASC_Muls_End-SASC_Muls)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found1

		st	patched
		
*-------------- patch the Multiply Signed routine...

		lea	my020_Muls(pc),a1
		exg.l	a1,a0
		moveq	#30,d0			;no.of bytes to copy
		bsr.w	CopyMem

		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found1

*-------------- skip patching Multiply Signed routine..

not_found1:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found1:


********************************************************************************
_PASS2:

		lea	Find_Mulu.l.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	SASC_Mulu(pc),a2	;a2.l = Binary to find...
		moveq	#(SASC_Mulu_End-SASC_Mulu)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found2

		st	patched
		
*-------------- patch the Multiply Unsigned routine...

		lea	my020_Mulu(pc),a1
		exg.l	a1,a0
		moveq	#32,d0			;no.of bytes to copy
		bsr.w	CopyMem

		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found2

*-------------- skip patching Multiply Signed routine..

not_found2:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found2:





********************************************************************************
_PASS3:
		lea	Find_Divsl.l.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	SASC_Divsl(pc),a2	;a2.l = Binary to find...
		moveq	#54,d0			;length of binary.
		bsr.w	FindBinary
		bne.s	not_found3

		st	patched
		
*-------------- patch the Divide Unsigned routine...

		lea	50(a0),a0
		lea	my020_Divsl(pc),a1
		exg.l	a1,a0
		move.l	#32,d0			;no.of bytes to copy
		bsr.w	CopyMem

		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found3

*-------------- skip patching Multiply Signed routine..

not_found3:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found3:



********************************************************************************
_PASS4:		lea	Find_MulsOther.l.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	OTHER_Muls(pc),a2	;a2.l = Binary to find...
		moveq	#(OTHER_Muls_End-OTHER_Muls)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found4

		st	patched
		
*-------------- patch the Multiply Unsigned routine...

		lea	my020_Muls(pc),a1
		exg.l	a1,a0
		moveq	#6,d0			;no.of bytes to copy
		bsr.w	CopyMem

		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found4

*-------------- skip patching Multiply Signed routine..

not_found4:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found4:

********************************************************************************

_PASS5:		lea	Find_MulsOther2.l.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	OTHER2_Muls(pc),a2	;a2.l = Binary to find...
		moveq	#(OTHER2_Muls_End-OTHER2_Muls)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found5

		st	patched
		
*-------------- patch the Multiply Unsigned routine...

		lea	my020_Muls(pc),a1
		exg.l	a1,a0
		moveq	#6,d0			;no.of bytes to copy
		bsr.w	CopyMem

		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found5

*-------------- skip patching Multiply Signed routine..

not_found5:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found5:



*******************************************************************************
* Lets try to patch the "DICE Muls" routine...


_PASS6:		lea	Find_MulsDice.l.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	_Dice_Muls(pc),a2	;a2.l = Binary to find...
		moveq	#(_Dice_Muls_End-_Dice_Muls)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found6

		st	patched
		
*-------------- patch the Multiply Unsigned routine...

		lea	_Dice_Muls020(pc),a1
		exg.l	a1,a0
		moveq	#_Dice_Muls020_End-_Dice_Muls020,d0	;no.of bytes to copy
		bsr.w	CopyMem

		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found6

*-------------- skip patching Multiply Signed routine..

not_found6:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found6:

********************************************************************************

_PASS7:
		lea	Find_Divsl2.l.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	divides(pc),a2		;a2.l = Binary to find...
		move.l	#(divides_end-divides)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found7

		st	patched

		move.l	a0,-(sp)

*-------------- patch "divsl.l"
		lea	_Divsl.l.020(pc),a0		;00
		move.l	(sp),a1
		move.l	#_Divsl.l.020_end-_Divsl.l.020,d0
		bsr.w	CopyMem
		
*-------------- patch "divsl.r"
		lea	_Divsl.r020(pc),a0		;40
		move.l	(sp),a1
		lea	40(a1),a1
		move.l	#_Divsl.r020_end-_Divsl.r020,d0
		bsr.w	CopyMem
				
*-------------- patch "divul.r"
		lea	_Divul.r020(pc),a0		;66
		move.l	(sp),a1
		lea	66(a1),a1
		move.l	#_Divul.r020_end-_Divul.r020,d0
		bsr.w	CopyMem

*-------------- patch "divul.l"
		lea	_Divul.l.020(pc),a0		;78
		move.l	(sp)+,a1
		lea	78(a1),a1
		move.l	#_Divul.l.020_end-_Divul.l.020,d0
		bsr.w	CopyMem
		
		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found7

*-------------- skip patching Multiply Signed routine..

not_found7:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found7:


********************************************************************************

_PASS8:
		lea	Find_Divsl3.l.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	divides2(pc),a2		;a2.l = Binary to find...
		move.l	#(divides2_end-divides2)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found8

		st	patched

		move.l	a0,-(sp)

*-------------- patch "divul.rem"

		lea	Divul.rem(pc),a0		;00
		move.l	(sp),a1
		move.l	#Divul.rem_end-Divul.rem,d0
		bsr.w	CopyMem

*-------------- patch "divsl.neg"

		lea	Divsl.neg(pc),a0		;78
		move.l	(sp)+,a1
		lea	78(a1),a1
		move.l	#Divsl.neg_end-Divsl.neg,d0
		bsr.w	CopyMem
		
		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found8

*-------------- skip patching Multiply Signed routine..

not_found8:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found8:


********************************************************************************

_PASS9:		lea	Find_MulsOther3.l.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	Mul3(pc),a2		;a2.l = Binary to find...
		moveq	#(Mul3_End-Mul3)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found9

		st	patched
		
*-------------- patch the Multiply Unsigned routine...

		lea	Mul3_020(pc),a1
		exg.l	a1,a0
		moveq	#Mul3_020_End-Mul3_020,d0	;no.of bytes to copy
		bsr.w	CopyMem

		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found9

*-------------- skip patching Multiply Signed routine..

not_found9:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found9:


********************************************************************************

_PASS10:
		lea	Find_Divsl4.l.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	divides3(pc),a2		;a2.l = Binary to find...
		move.l	#(divides3_end-divides3)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found10

		st	patched

*-------------- patch div

		lea	div(pc),a1		;00
		exg.l	a1,a0
		move.l	#div_end-div,d0
		bsr.w	CopyMem
		
		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found10

*-------------- skip patching Multiply Signed routine..

not_found10:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found10:


********************************************************************************

_PASS11:
		lea	Find_Divsl5.l.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	divides4(pc),a2		;a2.l = Binary to find...
		move.l	#(divides4_end-divides4)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found11

		st	patched

*-------------- patch div

		lea	div4(pc),a1		;00
		exg.l	a1,a0
		move.l	#div4_end-div4,d0
		bsr.w	CopyMem
		
		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found11

*-------------- skip patching Multiply Signed routine..

not_found11:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found11:


********************************************************************************
* Patch manx mulu routines...

_PASS12:
		lea	manxmulu.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	manxmulu(pc),a2		;a2.l = Binary to find...
		move.l	#(manxmulu_end-manxmulu)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found12

		st	patched

*-------------- patch mulu

		lea	manxmulu020(pc),a1		;00
		exg.l	a1,a0
		move.l	#manxmulu020_end-manxmulu020,d0
		bsr.w	CopyMem
		
		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found12

*-------------- skip patching Multiply Signed routine..

not_found12:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found12:


********************************************************************************
* Patch manx divs routines...

_PASS13:
		lea	manxdivs.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	manxdivs(pc),a2		;a2.l = Binary to find...
		move.l	#(manxdivs_end-manxdivs)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found13

		st	patched

*-------------- patch manx divs

		lea	manxdivs020(pc),a1		;00
		exg.l	a1,a0
		move.l	#manxdivs020_end-manxdivs020,d0
		bsr.w	CopyMem
		
		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found13

*-------------- skip patching Multiply Signed routine..

not_found13:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found13:



********************************************************************************
* Patch manx divneg routines...

_PASS14:
		lea	manxdivneg.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	manxdivneg(pc),a2		;a2.l = Binary to find...
		move.l	#(manxdivneg_end-manxdivneg)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found14

		st	patched

*-------------- patch manx divneg

		lea	manxdivneg020(pc),a1		;00
		exg.l	a1,a0
		move.l	#manxdivneg020_end-manxdivneg020,d0
		bsr.w	CopyMem
		
		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found14

*-------------- skip patching Multiply Signed routine..

not_found14:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found14:


********************************************************************************

_PASS15:
		lea	Find_Divsl6.l.txt(pc),a0
		bsr.w	PutString

		move.l	ProgBuff(pc),a0		;a0.l = Start of file SOF
		move.l	a0,a1
		add.l	ProgSize(pc),a1		;a1.l = End of file EOF
		lea	divides5(pc),a2		;a2.l = Binary to find...
		move.l	#(divides5_end-divides5)-2,d0	;length of binary.
		bsr.w	FindBinary
		bne.s	not_found15

		st	patched

*-------------- patch div

		lea	div5(pc),a1		;00
		exg.l	a1,a0
		move.l	#div5_end-div5,d0
		bsr.w	CopyMem
		
		lea	Patched.txt(pc),a0
		bsr.w	PutString
		bra.s	was_found15

*-------------- skip patching Multiply Signed routine..

not_found15:	lea	NotPatched.txt(pc),a0
		bsr.w	PutString

was_found15:


		movem.l	(sp)+,d0-d7/a0-a6
		rts
		


sort_destname:	lea	volpath,a3
		tst.b	(a3)
		beq.s	use_extension

		lea	finalname,a5
		move.l	a5,a1
		move.l	a3,a0
		move.l	rtfl_Name(a6),d1
		beq.w	nextname
		
_bytecopy:	move.b	(a0)+,(a1)+
		bne.s	_bytecopy
		cmp.b	#":",-2(a1)
		bne.s	_add_slash
		tst.b	-(a1)
		bra.s	_no_slash
_add_slash:	tst.b	-(a1)
		move.b	#"/",(a1)+
_no_slash:	move.l	d1,a0
_bytecopy2:	move.b	(a0)+,(a1)+
		bne.s	_bytecopy2
		clr.b	(a1)+
		move.l	a5,d0
		bra.s	done_name

use_extension:	move.l	a0,d0
		moveq	#-1,d3			;d4=0
getlen2		addq.l	#1,d3			;increase string length by 1
		tst.b	(a0)+			;increase position
		bne.s	getlen2			;nope not found, so keep on
		tst.b	-(a0)
		move.b	#".",(a0)+
		move.b	#"0",(a0)+
		move.b	#"2",(a0)+
		move.b	#"0",(a0)+
		clr.b	(a0)+
done_name:
*-------------- returns d0.l = filename..

		rts
		
*******************************************************************************
* putstr
* ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
* Sends a ascii text string to current console output
* 
* $Inputs:	a0.l = String ptr (null terminated)
*******************************************************************************

PutString
putstr:		movem.l	d0-d7/a1-a6,-(sp)
		move.l	a0,d2
		moveq	#-1,d3			;d4=0
getlen3		addq.l	#1,d3			;increase string length by 1
		tst.b	(a0)+			;increase position
		bne.s	getlen3			;nope not found, so keep on
		move.l	_DOSBase(pc),a6
		jsr	_LVOOutput(a6)		;get output base
		move.l	d0,d1
		jsr	_LVOWrite(a6)		;print error msg to cli
		movem.l	(sp)+,d0-d7/a1-a6
		rts
				
*******************************************************************************
* _LoadDOSFile :- Loads an AmigaDOS file from any device into memory
* ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
* INPUTS:	a0 (.L)	= Filename
*
* OUTPUTS:	d0 (.L) = Result Code (0=File Ok,-1=Load Failed!)	
*		d1 (.L) = Length
*******************************************************************************
	
LoadDOSFile:	movem.l	d2-d7/a0/a2-a6,-(sp)
		clr.l	ProgHandle
		clr.l	ProgBuff
		clr.l	ProgSize

;-------------- Open file
		move.l	a0,d1			;get filename
		move.l	#MODE_OLDFILE,d2
		move.l	_DOSBase(pc),a6
		jsr	_LVOOpen(a6)		;open file
		move.l	d0,ProgHandle
		beq.s	NotFound

;-------------- Get Length of file

		move.l	d0,d5			;ProgHandle
		move.l	d5,d1			;file handle
		moveq	#0,d2
		moveq	#1,d3
		jsr	_LVOSeek(a6)		;seek start of file
		move.l	d5,d1			;file handle
		moveq	#0,d2
		moveq	#-1,d3
		jsr	_LVOSeek(a6)		;seek end of file
		move.l	d0,ProgSize

;-------------- Allocate Memory for file

		move.l	4.w,a6			;get execbase
		move.l	#MEMF_PUBLIC,d1		;we want public mem
		jsr	_LVOAllocMem(a6)	;allocate it...
		move.l	d0,ProgBuff		;save base
		beq.b	TooBig			;fail?

;-------------- Load in whole file
				
		move.l	ProgHandle(pc),d1
		move.l	ProgBuff,d2
		move.l	ProgSize(pc),d3
		move.l	_DOSBase(pc),a6
		jsr	_LVORead(a6)		;read file

;-------------- Close file

CloseFile:	move.l	ProgHandle(pc),d1
		jsr	_LVOClose(a6)		;close file

		move.l	ProgSize(pc),d1		;d1=ProgSize
		move.l	ProgBuff(pc),a1		

		movem.l	(sp)+,d2-d7/a0/a2-a6
		moveq	#0,d0			;resultcode (okay)
		rts

NotFound:	movem.l	(sp)+,d2-d7/a0/a2-a6
		moveq	#-1,d0			;file not found error-code
		rts

TooBig:		move.l	ProgHandle(pc),d1
		move.l	_DOSBase(pc),a6
		jsr	_LVOClose(a6)		;close file
		movem.l	(sp)+,d2-d7/a0/a2-a6
		moveq	#-2,d0			;file too big error-code
NotAlloc	rts




;-------------- Free Memory for DOSFile

FreeDOSFile:	move.l	(AbsExecBase).w,a6	;get execbase

		move.l	ProgBuff(pc),d0		;ptr to our RS.Variables base
		beq.s	NotAlloc1
		move.l	d0,a1
		move.l	ProgSize(pc),d0		;no. of Bytes to free
		beq.s	NotAlloc1
		jsr	_LVOFreeMem(a6)		;free the memory
		clr.l	ProgBuff
		clr.l	ProgSize

NotAlloc1:	rts

*******************************************************************************
* SaveMem2File
* ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
* $Inputs:	a0.l	= Filename
*		a1.l	= Mem Address
*		d1.l	= Save Length
*
* $Outputs:	d0.l	= 0 - success
*		d0.l	= 1 - failure
*******************************************************************************

SaveDOSFile:	movem.l	d2-d7/a0-a6,-(sp)
		move.l	a1,d5			;progbuffer
		move.l	d1,d6			;proglength
		beq.s	_NoGain

		move.l	a0,d1			;filename
		move.l	#MODE_NEWFILE,d2
		move.l	_DOSBase(pc),a6
		jsr	_LVOOpen(a6)
		move.l	d0,d7
		beq.b	_SaveError

		move.l	d7,d1			;fh...
		move.l	d5,d2			;adr
		move.l	d6,d3			;length
		jsr	_LVOWrite(a6)		;write file

		move.l	d7,d1
		jsr	_LVOClose(a6)		;close file
_NoGain:	movem.l	(sp)+,d2-d7/a0-a6
		moveq	#0,d0
		rts
_SaveError:	movem.l	(sp)+,d2-d7/a0-a6
		moveq	#1,d0
		rts




*******************************************************************************
* FindString
* ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
* This routine will scan through Memory for a ascii (case dependant) string.
* The routine will not find its 'search string' if the start and end addresses 
* are within the same address range as an added precaution.
*
* INPUTS ;	a0.l=start address for search
*	 	a1.l=end address for search
*	 	a2.l=string to search for
*
* OUTPUTS;	d0.b=If failed to located string =$FF.B, else =$00.B FOUND!
*		a0.l=ptr to string
*******************************************************************************
		cnop	0,4
FindBinary:	movem.l	a1-a6,-(sp)
		move.l	d0,d4
		bsr.s	FindBin
		movem.l	(sp)+,a1-a6
		tst.l	d0
		rts
		
		cnop	0,4
FindStr:	move.l	a2,-(sp)
		moveq	#-3,d4			;d4=0
.getlen		addq.l	#1,d4			;increase string length by 1
		tst.b	(a2)+			;increase position
		bne.s	.getlen			;nope not found, so keep on
		move.l	(sp)+,a2

FindBin:	move.l	a2,a3			;copy string ptr
		lea	_kkeepon(pc),a4		;a4=Keepon sub routine
		moveq	#0,d5			;d5=0
_Not_It		move.l	a3,a2			;a3=search string ptr
		move.b	(a2)+,d2		;put char to test into d2

_kkeepon:	move.b	(a0)+,d1		;incr search pos
		cmp.l	a1,a0			;end of Memory region reached?
		blt.s	_contt			;yes,so string wasn`t found!
		moveq	#-1,d0			;d0=not found!
		rts

		cnop	0,4
_contt		cmp.b	d1,d2			;does this Byte match string Byte?
		beq.s	_nByte			;yes!,lets investigate more...
		jmp	(a4)			;nope so keep on searching

		cnop	0,4
_nByte:		move.l	d4,d3
_nloop		move.b	(a0)+,d5
		cmp.b	(a2)+,d5
		dbne	d3,_nloop
		bne.s	_Not_It

		move.l	a0,d0			;d0=ptr to text found!
		sub.l	d4,d0
		subq	#2,d0			;correct offset ptr

		move.l	d0,a0
		moveq	#0,d0
		rts

		cnop	0,4
Start20		dc.l	'*Art'
CopyMem
Quicker:	moveq	#16,d1
		cmp.l	d1,d0
		bcs.s	tinycpy
		move.w	a0,d1
		ror.l	#2,d1
		move.w	a1,d1
		rol.l	#2,d1
		andi.w	#15,d1
		beq.s	xa0la1l
		move.w	tbl(pc,d1.w*2),d1
		jmp	tbl(pc,d1.w)

		ds.b	2
		ds.b	2

tbl	dc.w	xa0la1l-tbl
	dc.w	xa0la11-tbl
	dc.w	xa0la1e-tbl
	dc.w	xa0la13-tbl
	dc.w	xa01a1l-tbl
	dc.w	xa01a11-tbl
	dc.w	xa01a1e-tbl
	dc.w	xa01a13-tbl
	dc.w	xa0ea1l-tbl
	dc.w	xa0ea11-tbl
	dc.w	xa0ea1e-tbl
	dc.w	xa0ea13-tbl
	dc.w	xa03a1l-tbl
	dc.w	xa03a11-tbl
	dc.w	xa03a1e-tbl
	dc.w	xa03a13-tbl

tloop1		move.b	(a0)+,(a1)+
tinycpy		dbf	d0,tloop1
		rts

xa01a13:
xa03a11:
xa03a13:	move.b	(a0)+,(a1)+
		subq.l	#1,d0
		bra.s	xa0la1l

		ds.b	2
		ds.b	2
		ds.b	2
		ds.b	2
		ds.b	2

xa01a11:
	move.b	(a0)+,(a1)+
	subq.l	#1,d0
xa0ea1e:
	move.w	(a0)+,(a1)+
	subq.l	#2,d0
xa0la1l:
xa0la1e:
xa0ea1l:
	cmpi.l	#48*8,d0
	bcs.s	smlmov
	moveq	#48,d1		; 12 registers of 4 bytes
	sub.l	d1,d0
	movem.l	d2-d7/a2-a6,-(sp)
bigmov	movem.l	(a0)+,d1-d7/a2-a6
	movem.l	d1-d7/a2-a6,(a1)
	moveq	#48,d1
	adda.l	d1,a1
	sub.l	d1,d0
	bcc.s	bigmov
	add.w	d1,d0
	movem.l	(sp)+,d2-d7/a2-a6
smlmov	lsr.w	#1,d0
	beq.s	even01
	bcs.s	sm13
	lsr.w	#1,d0
	beq.s	even2
	bcs.s	sm2
sm0	subq.w	#1,d0
loop0	move.l	(a0)+,(a1)+
	dbf	d0,loop0
even0	rts

even01	bcs.s	even1
	rts

sm3	subq.w	#1,d0
loop3	move.l	(a0)+,(a1)+
	dbf	d0,loop3
even3	move.w	(a0)+,(a1)+
even1	move.b	(a0),(a1)
	rts

sm13	lsr.w	#1,d0
	beq.s	even3
	bcs.s	sm3
sm1	subq.w	#1,d0
loop1	move.l	(a0)+,(a1)+
	dbf	d0,loop1
	move.b	(a0),(a1)
	rts

sm2	subq.w	#1,d0
loop2	move.l	(a0)+,(a1)+
	dbf	d0,loop2
even2	move.w	(a0),(a1)
	rts

xa0ea11:
xa0ea13:
	move.w	(a0)+,d1
	ror.w	#8,d1
	move.b	d1,(a1)+
	rol.w	#8,d1
	move.b	d1,(a1)+
	subq.l	#2,d0
	bra.s	xa0la11

xa01a1l:
xa01a1e:
	move.b	(a0)+,(a1)+
	move.b	(a0)+,(a1)+
	subq.l	#2,d0
xa03a1e:
xa03a1l:
	move.b	(a0)+,(a1)+
	subq.l	#1,d0
	bra.w	xa0la11

xa0la13:
xa0la11:

	moveq	#36,d1		; 8 regs of 4 bytes + roundoff bytes
	cmp.l	d1,d0
	bcs.s	tinycp2
* This is tricky!  They said it couldn't be done...
unevcpy	movem.l	a2-a4/d2-d7,-(sp)
	movea.w	d1,a4
	sub.l	d1,d0
	movea.l	d0,a2
	moveq	#32,d1		; 8 registers of 4 bytes
	movea.w	d1,a3
uloop	movem.l	(a0)+,d0-d7
	rol.l	#8,d0
	rol.l	#8,d1
	rol.l	#8,d2
	rol.l	#8,d3
	rol.l	#8,d4
	rol.l	#8,d5
	rol.l	#8,d6
	rol.l	#8,d7
	move.b	d0,(a1)+
	move.b	d1,d0
	move.b	d2,d1
	move.b	d3,d2
	move.b	d4,d3
	move.b	d5,d4
	move.b	d6,d5
	move.b	d7,d6
	move.b	(a0)+,d7
	movem.l	d0-d7,(a1)
	adda.l	a3,a1
	move.b	(a0)+,(a1)+	; even up to next word
	move.b	(a0)+,(a1)+
	move.b	(a0)+,(a1)+	; ... and to next longword
	suba.l	a4,a2
	move.l	a2,d0
	bpl.s	uloop
	add.w	a4,d0
	movem.l	(sp)+,a2-a4/d2-d7
	bra.s	tinycp2
tloop2	move.b	(a0)+,(a1)+
tinycp2	dbf	d0,tloop2
tdone	rts

	ds.b	2
	ds.b	2
	ds.b	2
	ds.b	2
	ds.b	2
	ds.b	2
	ds.b	4
Quickest
	bftst	d0{0:16}
	bne.s	bigq
	lsr.w	#2,d0
	cmp.w	#96,d0
	bcs.s	smlmovQ
	moveq	#12,d1
	sub.w	d1,d0
	divu.w	d1,d0
	movem.l	d2-d7/a2-a6,-(sp)
bigmovQ	movem.l	(a0)+,d1-d7/a2-a6
	movem.l	d1-d7/a2-a6,(a1)
	lea	48(a1),a1
	dbf	d0,bigmovQ
	swap	d0
	movem.l	(sp)+,d2-d7/a2-a6
	bra.s	smlmovQ
qloop	move.l	(a0)+,(a1)+
smlmovQ	dbf	d0,qloop
done	rts

bigq	lsr.l	#2,d0
	moveq	#48,d1
	sub.l	d1,d0
	nop
	divul.l	d1,d1:d0
	movem.l	d1-d7/a2-a6,-(sp)
bmovQ2	movem.l	(a0)+,d1-d7/a2-a6
	movem.l	d1-d7/a2-a6,(a1)
	lea	48(a1),a1
	movem.l	(a0)+,d1-d7/a2-a6
	movem.l	d1-d7/a2-a6,(a1)
	lea	48(a1),a1
	movem.l	(a0)+,d1-d7/a2-a6
	movem.l	d1-d7/a2-a6,(a1)
	lea	48(a1),a1
	movem.l	(a0)+,d1-d7/a2-a6
	movem.l	d1-d7/a2-a6,(a1)
	lea	48(a1),a1
	dbf	d0,bmovQ2
	sub.l	#$10000,d0
	bcc.s	bmovQ2
	movem.l	(sp)+,d0/d2-d7/a2-a6
	bra.s	smlmovQ

Stop20
Quicker20	=	Quicker-Start20
Quickest20	=	Quickest-Start20
CopyLen20	=	Stop20-Start20

About.txt	dc.b	$1b,'c',$a
		dc.b	$1b,'[1mPatchFor020',$1b,'[1m',$1b,'[22m ',$1b,'[33m(Public) ',$1b,'[32m1.01',$1b,'[3m',$1b,'[31m by 2-Cool of ',$1b,'[23m',$1b,'[3mEX4! ',$1b,'[23m',$1b,'[3m',$1b,'[23m',$a
		dc.b	'Copyright İ 1995. All Rights Are Reserved.',$a
		dc.b	'Last Assembled: July-1995.',$a,$a,0
skip_save.txt:	dc.b	'No patches... skipping saving... ',$a,0
		even
LFs.Txt:
LF.txt		dc.b	10,0
Load.txt	dc.b	10,'Loading file.. ',0
Save.txt	dc.b	10,'Saving file.. ',0
NoPath.txt:	dc.b	10,'No Destination Path Specified!',10
		dc.b	'Adding ".020" extension to save filename(s)..',10,10,0
ErrorMem.txt:	dc.b	'Error: Out Of Memory.. not enough for load buffers...',0
ErrorLoad.txt	dc.b	'Error: Skipping file, failed to load..',10,0
ErrorSave.txt	dc.b	'Error: Skipping file, failed to save..',10,0
Done.txt:	dc.b	10,'Session Done...',10,0
		even
Find_Muls.l.txt	dc.b	'Scanning for 68k SAS/C Compiler "Unsigned Long Multiplication" routines...',$a,0
		even
Find_Mulu.l.txt	dc.b	'Scanning for 68k SAS/C Compiler "Signed Long Multiplication" routines...',$a,0
		even
Find_Divsl.l.txt  dc.b	'Scanning for 68k SAS/C Compiler "Signed Long Division" routines...',$a,0
Find_Divsl2.l.txt  dc.b	'Scanning for Compiler Strain #1 "Divu.l,Divs.l & remainder" routines...',$a,0
Find_Divsl3.l.txt  dc.b	'Scanning for Compiler Strain #2 "Divu.l,Divs.l & remainder" routines...',$a,0
Find_Divsl4.l.txt  dc.b	'Scanning for Compiler Strain #3 "Divu.l,Divs.l & remainder" routines...',$a,0
Find_Divsl5.l.txt  dc.b	'Scanning for Manx C Compiler "Modu.l" routines...',$a,0
Find_Divsl6.l.txt  dc.b	'Scanning for DICE C Compiler "Divs.l" routines...',$a,0
		even
manxmulu.txt:	dc.b	'Scanning for Manx C Compiler "Mulu.l" routines...',$a,0
		even
manxdivs.txt:	dc.b	'Scanning for Manx C Compiler "Divs.l" routines...',$a,0
		even
manxdivneg.txt:	dc.b	'Scanning for Manx C Compiler "Divs.l remainder" routines...',$a,0
		even
Find_MulsOther.l.txt	dc.b	'Scanning for C Compiler Strain #1 "Signed Long Multiply" routines...',$a,0
		even
Find_MulsOther2.l.txt	dc.b	'Scanning for Compiler Strain #2 "Signed Long Multiply" routines...',$a,0
		even
Find_MulsOther3.l.txt	dc.b	'Scanning for Compiler Strain #3 "Signed Long Multiply & Remainder" routines...',$a,0
		even
Find_MulsDice.l.txt	dc.b	'Scanning for 68k DICE C Compilers "Signed Long Multiplication" routines...',$a,0
		even
NotPatched.txt:	dc.b	'Not Found... ',$a,$a,0
		even
NotPatches.txt:	dc.b	'No patches... skipping saving... ',$a,$a,0
		even
Patched.txt:	dc.b	'A SPEEDUP GAIN! Found & Patched to MC68020+ !!!',$a,$a,0
		even
Loading.txt	dc.b	'Please select Executable File to Patch... ',0
saving.txt	dc.b	'Saving Program... ',0
alldone.txt	dc.b	$a,'All Done!',$a,$a,$a,0
		even

Text89		dc.b	"Select Destination Path..",0
Text66		dc.b	"Select File(s)...",0
		even
Tags9		dc.l	RTFI_Flags,FREQF_MULTISELECT
		dc.l	TAG_END
Tags11		dc.l	RTFI_Flags,FREQF_NOFILES
		dc.l	TAG_END

defdir_tags:	dc.l	RTFI_Dir,DefDir.txt
		dc.l	TAG_END

DefDir.txt:	dc.b	'SYS:',0

DOSName		dc.b	'dos.library',0
ReqName		dc.b	'reqtools.library',0
		cnop	0,2
_DOSBase:	ds.l	1
_RTBase:	ds.l	1

ProgHandle:	ds.l	1
ProgBuff:	ds.l	1
ProgSize:	ds.l	1

filereq		ds.l	1
volreq		ds.l	1
flist		ds.l	1
Savename	dc.l	0


		cnop	0,4		
*******************************************************************************
* Lattice SAS/C slow 68000 signed multiplication 

SASC_Muls	dc.w	$48E7		;32 bytes length
		dc.w	$3000
		dc.w	$2400
		dc.w	$2601
		dc.w	$4842
		dc.w	$4843
		dc.w	$C4C1
		dc.w	$C6C0
		dc.w	$C0C1
		dc.w	$D443
		dc.w	$4842
		dc.w	$4242
		dc.w	$D082
		dc.w	$4CDF
		dc.w	$000C
		dc.w	$4E75
SASC_Muls_End:

my020_Muls:	muls.l	d1,d0		;6 bytes, patch at offset 0
		rts
		dc.b	'MC68020 Patch SASC Muls'
my020_Muls_End:


*******************************************************************************
* Lattice SAS/C slow 68000 unsigned multiplication 

		cnop	0,4
SASC_Mulu:	dc.w	$48E7		;46 bytes
		dc.w	$7000
		dc.w	$2400
		dc.w	$6720
		dc.w	$4A81
		dc.w	$6604
		dc.w	$4280
		dc.w	$6018
		dc.w	$2600
		dc.w	$C6C1
		dc.w	$4842
		dc.w	$C4C1
		dc.w	$4842
		dc.w	$4242
		dc.w	$D682
		dc.w	$4841
		dc.w	$C0C1
		dc.w	$4840
		dc.w	$4240
		dc.w	$D083
		dc.w	$4CDF
		dc.w	$000E
		dc.w	$4E75
SASC_Mulu_End:

my020_Mulu:	mulu.l	d1,d0		;6 bytes, patch at offset 0
		rts
		dc.b	'MC68020 Patch for SAS/C Mulu.l'
		ds.b	20
my020_Mulu_End:

		cnop	0,4
OTHER_Muls:	movem.l	d2/d3,-(sp)
		move.w	d1,d2
		move.l	d1,d3
		mulu	d0,d2
		swap	d3
		mulu	d0,d3
		swap	d3
		clr.w	d3
		add.l	d3,d2
		swap	d0
		mulu	d1,d0
		swap	d0
		clr.w	d0
		add.l	d2,d0
		movem.l	(sp)+,d2/d3
		rts
OTHER_Muls_End


		cnop	0,4
OTHER2_Muls:	movem.l	d2/d3,-(sp)
		move.w	d1,d2
		mulu.w	d0,d2
		move.l	d1,d3
		swap	d3
		mulu.w	d0,d3
		swap	d3
		clr.w	d3
		add.l	d3,d2
		swap	d0
		mulu.w	d1,d0
		swap	d0
		clr.w	d0
		add.l	d2,d0
		movem.l	(sp)+,d2/d3
		rts	
OTHER2_Muls_End

*******************************************************************************
* Long Multiplication (SIGNED)
*
* DICE C (STACK COMPILED) VERSION
* -------------------------------

		cnop	0,4
_Dice_Muls:	movem.l	d0/d1,-(sp)
		swap	d0
		mulu	d1,d0
		swap	d1
		mulu	2(sp),d1
		add.l	d1,d0
		swap	d0
		clr.w	d0
		move.w	2(sp),d1
		mulu	6(sp),d1
		add.l	d1,d0
		addq.l	#8,sp
_Dice_Muls_End	rts

		cnop	0,4
_Dice_Muls020:	muls.l	d0,d1
		move.l	d1,d0
		rts
_Dice_Muls020_End:



		cnop	0,4

*******************************************************************************
* Lattice SAS/C slow 68000 signed division

SASC_Divsl:	dc.w	$4A80		;194 bytes length
		dc.w	$6A00
		dc.w	$001E
		dc.w	$4480
		dc.w	$4A81
		dc.w	$6A00
		dc.w	$000C
		dc.w	$4481
		dc.w	$6100
		dc.w	$0020
		dc.w	$4481
		dc.w	$4E75
		dc.w	$6100
		dc.w	$0018
		dc.w	$4480
		dc.w	$4481
		dc.w	$4E75
		dc.w	$4A81
		dc.w	$6A00
		dc.w	$000C
		dc.w	$4481
		dc.w	$6100
		dc.w	$0006
		dc.w	$4480
		dc.w	$4E75
		dc.w	$2F02
		dc.w	$4841
		dc.w	$3401
		dc.w	$6600
		dc.w	$0022
		dc.w	$4840
		dc.w	$4841
		dc.w	$4842
		dc.w	$3400
		dc.w	$6700
		dc.w	$0006
		dc.w	$84C1
		dc.w	$3002
		dc.w	$4840
		dc.w	$3400
		dc.w	$84C1
		dc.w	$3002
		dc.w	$4842
		dc.w	$3202
		dc.w	$241F
		dc.w	$4E75
		dc.w	$2F03
		dc.w	$7610
		dc.w	$0C41
		dc.w	$0080
		dc.w	$6400
		dc.w	$0006
		dc.w	$E199
		dc.w	$5143
		dc.w	$0C41
		dc.w	$0800
		dc.w	$6400
		dc.w	$0006
		dc.w	$E999
		dc.w	$5943
		dc.w	$0C41
		dc.w	$2000
		dc.w	$6400
		dc.w	$0006
		dc.w	$E599
		dc.w	$5543
		dc.w	$4A41
		dc.w	$6B00
		dc.w	$0006
		dc.w	$E399
		dc.w	$5343
		dc.w	$3400
		dc.w	$E6A8
		dc.w	$4842
		dc.w	$4242
		dc.w	$E6AA
		dc.w	$4843
		dc.w	$80C1
		dc.w	$3600
		dc.w	$3002
		dc.w	$3403
		dc.w	$4841
		dc.w	$C4C1
		dc.w	$9082
		dc.w	$6400
		dc.w	$0006
		dc.w	$5343
		dc.w	$D081
		dc.w	$7200
		dc.w	$3203
		dc.w	$4843
		dc.w	$E7B8
		dc.w	$4840
		dc.w	$C141
		dc.w	$261F
		dc.w	$241F
		dc.w	$4E75
SASC_Divsl_End:


my020_Divsl:	divsl.l	d1,d1:d0	;6 bytes, patch at offset 32 bytes in
		rts
		dc.b	'MC68020 Patch for SAS/C Divsl.l routines!'
		ds.b	147
my020_Divsl_End



		cnop	0,4
*-------------- divide signed long (result)

_Divsl.l.020:	divs.l	d1,d0			; 020 optimised version
		rts
_Divsl.l.020_end

		cnop	0,4
*-------------- divide signed long (remainder)

_Divsl.r020:	move.l	d1,-(sp)		* 020 optimised version
		divsl.l	d1,d1:d0
		move.l	d1,d0
		move.l	(sp)+,d1
;		tst.l	d0
		rts
_Divsl.r020_end

		cnop	0,4
*-------------- divide unsigned long (result)

_Divul.l.020:	divu.l	d1,d0			; 020 optimised version
		rts
_Divul.l.020_end

		cnop	0,4
*-------------- divide unsigned long (remainder)

_Divul.r020:	move.l	d1,-(sp)		* 020 optimised version
		divul.l	d1,d1:d0
		move.l	d1,d0
		move.l	(sp)+,d1
;		tst.l	d0
		rts
_Divul.r020_end:

		cnop	0,4
divides:	dc.w	$2F01
		dc.w	$3F04
		dc.w	$9844
		dc.w	$4A80
		dc.w	$6A04
		dc.w	$4480
		dc.w	$5244
		dc.w	$4A81
		dc.w	$6A06
		dc.w	$4481
		dc.w	$0A44
		dc.w	$0001
		dc.w	$613E
		dc.w	$4A44
		dc.w	$6702
		dc.w	$4480
		dc.w	$381F
		dc.w	$221F
		dc.w	$4A80
		dc.w	$4E75
		dc.w	$2F01
		dc.w	$3F04
		dc.w	$9844
		dc.w	$4A80
		dc.w	$6A04
		dc.w	$4480
		dc.w	$5244
		dc.w	$4A81
		dc.w	$6A02
		dc.w	$4481
		dc.w	$611A
		dc.w	$2001
		dc.w	$60D8
		dc.w	$2F01
		dc.w	$6112
		dc.w	$2001
		dc.w	$221F
		dc.w	$4A80
		dc.w	$4E75
		dc.w	$2F01
		dc.w	$6106
		dc.w	$221F
		dc.w	$4A80
		dc.w	$4E75
		dc.w	$4841
		dc.w	$4A41
		dc.w	$661C
		dc.w	$4841
		dc.w	$3F01
		dc.w	$3F00
		dc.w	$4240
		dc.w	$4840
		dc.w	$80C1
		dc.w	$2200
		dc.w	$4840
		dc.w	$321F
		dc.w	$82DF
		dc.w	$3001
		dc.w	$4241
		dc.w	$4841
		dc.w	$4E75
		dc.w	$4841
		dc.w	$3F02
		dc.w	$2F03
		dc.w	$2601
		dc.w	$2200
		dc.w	$4241
		dc.w	$4841
		dc.w	$4840
		dc.w	$4240
		dc.w	$343C
		dc.w	$000F
		dc.w	$D080
		dc.w	$D381
		dc.w	$B681
		dc.w	$6204
		dc.w	$9283
		dc.w	$5240
		dc.w	$51CA
		dc.w	$FFF2
		dc.w	$261F
		dc.w	$341F
		dc.w	$4E75
divides_end:





divides2:	dc	$2F02,$2401,$2200,$0C82,$0000,$FFFF,$6E1C,$3C41
		dc	$4241,$4841,$82C2,$2001,$4841,$300E,$80C2,$3200
		dc	$4240,$4840,$C141,$241F,$4E75,$2001,$4240,$4840
		dc	$4841,$4241,$2C42,$740F,$D281,$D180,$BDC0,$6E04
		dc	$908E,$5241,$51CA,$FFF2,$C141,$241F,$4E75,$3F03
		dc	$487A,$0016,$2F02,$2401,$5BC3,$6A02,$4482,$2200
		dc	$6AA4,$4481,$4603,$609E,$4A03,$6702,$4480,$361F,$4E75
divides2_end:
		
Divul.rem:	divul.l	d1,d1:d0		; 020 optimised version
		rts
Divul.rem_end

Divsl.neg:	divsl.l	d1,d1:d0		; 020 optimised version
		neg.l	d1
		rts
Divsl.neg_end:



*******************************************************************************
* Long Multiplication (SIGNED & REMAINDER)
*
* GENERIC COMPILER VERSION 3
* --------------------------

Mul3_020	muls.l	d1,d1:d0
		rts
Mul3_020_End

		
Mul3:
_LongMul1	movem.l	d2-d4,-(sp)
		move.l	d0,d2
		move.l	d0,d3
		swap	d3
		move.l	d1,d4
		swap	d4
		mulu	d1,d0
		mulu	d3,d1
		mulu	d4,d2
		mulu	d4,d3
		swap	d0
		add.w	d1,d0
		moveq	#0,d4
		addx.l	d4,d4
		add.w	d2,d0
		addx.l	d4,d3
		swap	d0
		clr.w	d1
		swap	d1
		clr.w	d2
		swap	d2
		add.l	d2,d1
		add.l	d3,d1
		beq.b	lskip
		ori.b	#2,ccr
lskip:		movem.l	(sp)+,d2-d4
		rts

_LongMul2:	movem.l	d2/d3,-(sp)
		move.l	d0,d2
		move.l	d1,d3
		bsr.b	_LongMul1
		tst.l	d2
		bpl.b	lm1
		sub.l	d3,d1
lm1:		tst.l	d3
		bpl.b	lm2
		sub.l	d2,d1
lm2:		tst.l	d0
		bpl.b	lm3
		not.l	d1
lm3:		tst.l	d1
		beq.b	lm4
		ori.b	#2,ccr
lm4:		movem.l	(sp)+,d2/d3
		rts
Mul3_End


		cnop	0,4
*-------------- divide signed long (remainder)

div		divsl.l	d1,d1:d0
		exg.l	d0,d1	
		rts
div_end

		cnop	0,4		
divides3:
	dc.w	$48E7
	dc.w	$3000
	dc.w	$7400
	dc.w	$B2BC
	dc.w	$0000
	dc.w	$FFFF
	dc.w	$621C
	dc.w	$80C1
	dc.w	$6810
	dc.w	$3600
	dc.w	$4240
	dc.w	$4840
	dc.w	$80C1
	dc.w	$3400
	dc.w	$4842
	dc.w	$3003
	dc.w	$80C1
	dc.w	$3400
	dc.w	$4240
	dc.w	$4840
	dc.w	$601A
	dc.w	$3400
	dc.w	$4842
	dc.w	$4240
	dc.w	$4840
	dc.w	$760F
	dc.w	$E38A
	dc.w	$E390
	dc.w	$B081
	dc.w	$6504
	dc.w	$9081
	dc.w	$5242
	dc.w	$51CB
	dc.w	$FFF2
	dc.w	$2202
	dc.w	$4CDF
	dc.w	12
	dc.w	$4E75
divides3_end:


*-------------- manx_c divide/modu

div4		divul.l	d1,d1:d0
		rts
div4_end

divides4:	dc.w	$48E7
		dc.w	$3000
		dc.w	$4841
		dc.w	$4A41
		dc.w	$6620
		dc.w	$4841
		dc.w	$3601
		dc.w	$3400
		dc.w	$4240
		dc.w	$4840
		dc.w	$80C3
		dc.w	$2200
		dc.w	$4840
		dc.w	$3202
		dc.w	$82C3
		dc.w	$3001
		dc.w	$4241
		dc.w	$4841
		dc.w	$4CDF
		dc.w	12
		dc.w	$4E75
divides4_end:


manxmulu020:	mulu.l	d1,d0
		rts
manxmulu020_end:

manxmulu:	movem.l	d1-d3,-(sp)
		move.w	d1,d2
		mulu	d0,d2
		move.l	d1,d3
		swap	d3
		mulu	d0,d3
		swap	d3
		clr.w	d3
		add.l	d3,d2
		swap	d0
		mulu	d1,d0
		swap	d0
		clr.w	d0
		add.l	d2,d0
		movem.l	(sp)+,d1-d3
		rts
manxmulu_end:




manxdivs020:	divs.l	d1,d0
		rts
manxdivs020_end:

manxdivs:	dc.w	$48E7
		dc.w	$4800
		dc.w	$4284
		dc.w	$4A80
		dc.w	$6A04
		dc.w	$4480
		dc.w	$5244
		dc.w	$4A81
		dc.w	$6A06
		dc.w	$4481
		dc.w	$0A44
		dc.w	$0001
		dc.w	$613E
		dc.w	$4A44
		dc.w	$6702
		dc.w	$4480
		dc.w	$4CDF
		dc.w	$0012
		dc.w	$4A80
		dc.w	$4E75
manxdivs_end:




manxdivneg020:	move.l	d1,-(sp)
		divsl.l	d1,d1:d0
		exg	d0,d1
		move.l	(sp)+,d1
		tst.l	d0
		rts
manxdivneg020_end:

manxdivneg:	dc.w	$48E7
		dc.w	$4800
		dc.w	$4284
		dc.w	$4A80
		dc.w	$6A04
		dc.w	$4480
		dc.w	$5244
		dc.w	$4A81
		dc.w	$6A02
		dc.w	$4481
		dc.w	$611A
		dc.w	$2001
		dc.w	$60D8
		dc.w	$2F01
		dc.w	$6112
		dc.w	$2001
		dc.w	$221F
		dc.w	$4A80
		dc.w	$4E75
		dc.w	$2F01
		dc.w	$6106
		dc.w	$221F
		dc.w	$4A80
		dc.w	$4E75
manxdivneg_end:


div5
dicediv020:	divs.l	d1,d0			; 020 optimised version
		rts
dicediv020_end
div5_end

divides5
dicediv:	dc.w	$4A81
		dc.w	$6B08
		dc.w	$4A80
		dc.w	$6B12
		dc.w	$6000
		dc.w	$22
		dc.w	$4481
		dc.w	$4A80
		dc.w	$6B12
		dc.w	$6100
		dc.w	$18
		dc.w	$4480
		dc.w	$4E75
		dc.w	$4480
		dc.w	$6100
		dc.w	14
		dc.w	$4480
		dc.w	$4E75
		dc.w	$4480
		dc.w	$6000
		dc.w	4
		dc.w	$4E71
		dc.w	$4A81
		dc.w	$671E
		dc.w	$4841
		dc.w	$4A41
		dc.w	$6642
		dc.w	$2F02
		dc.w	$4841
		dc.w	$2400
		dc.w	$84C1
		dc.w	$6914
		dc.w	$2202
		dc.w	$4241
		dc.w	$4841
		dc.w	$7000
		dc.w	$3002
		dc.w	$241F
		dc.w	$4E75
		dc.w	$2200
		dc.w	$70FF
		dc.w	$4E75
		dc.w	$2F03
		dc.w	$2400
		dc.w	$4242
		dc.w	$4842
		dc.w	$84C1
		dc.w	$3602
		dc.w	$4843
		dc.w	$4243
		dc.w	$3400
		dc.w	$84C1
		dc.w	$3602
		dc.w	$2003
		dc.w	$4242
		dc.w	$4842
		dc.w	$2202
		dc.w	$261F
		dc.w	$241F
		dc.w	$4E75
		dc.w	$48E7
		dc.w	$3800
		dc.w	$2400
		dc.w	$4242
		dc.w	$4842
		dc.w	$84C1
		dc.w	$3602
		dc.w	$7400
		dc.w	$3403
		dc.w	$C6C1
		dc.w	$4841
		dc.w	$3802
		dc.w	$C8C1
		dc.w	$4843
		dc.w	$D684
		dc.w	$9083
		dc.w	$6B0A
		dc.w	$2200
		dc.w	$2002
		dc.w	$4CDF
		dc.w	$1C
		dc.w	$4E75
		dc.w	$5382
		dc.w	$D081
		dc.w	$6BFA
		dc.w	$2200
		dc.w	$2002
		dc.w	$4CDF
		dc.w	$1C
		dc.w	$4E75
dicediv_end:	
divides5_end

		section	bssmem,bss

patched		ds.w	1		
Array		ds.l	6
Buffer		ds.b	128
filename	ds.b	34
finalname:	ds.b	256
volpath:	ds.b	128
hashbuff	ds.b	65536*2
