;*---------------------------------------------------------------------------
;  :Program.    DeCloner.asm
;  :Contents.   Decruncher for XFDMaster.Library (various clones)
;  :History.    V 0.1 08.11.95
;  :Copyright.  Public Domain
;  :Language.   68000 Assembler
;  :Translator. Barfly V1.130
;---------------------------------------------------------------------------*
;##########################################################################

	INCDIR	Includes:
	INCLUDE	lvo/exec.i
	INCLUDE	libraries/xfdmaster.i
	INCLUDE	libraries/xfdmaster_lib.i

;##########################################################################
;----------------------------------------
; XFD-Library-Header

		moveq	#-1,d0
		rts	

		dc.l	XFDF_ID		;id
		dc.w	XFDF_VERSION	;version
		dc.w	0
		dc.l	0,0		;private
		dc.l	_xfdSlave1	;first slave

;----------------------------------------
; version string

		dc.b	'$VER: DeCloner V0.1 '
	DOSCMD	"WDate >T:date"
	INCBIN	T:date
		dc.b	' by WEPL for xfdmaster.library',0
	EVEN

;----------------------------------------
; xfdSlave-structure

_xfdSlave1	dc.l	_xfdSlave2	; next slave
		dc.w	XFDS_VERSION	; structure version
		dc.w	33		; req xfdmaster version
		dc.l	.name		; cruncher name
		dc.w	XFDPFF_DATA	; cruncher flags
		dc.w	0		; max length of special info (passwd)
		dc.l	.check		; check routine
		dc.l	.decrunch	; decrunch routine
		dc.l	0		; segment recog routine
		dc.l	0		; segment decrunch routine

.name		dc.b	'CHFI (IMP! clone)',0
	EVEN

;----------------------------------------
; code to check crunched
; Übergabe :	D0 = ULONG data size
;		A0 = APTR  data
; Rückgabe :	D0 = BOOL  success

.check		moveq	#32,d1		;minimum 32 bytes
		cmp.l	d1,d0
		blo	.no
		cmp.l	#"CHFI",(a0)
		bne	.no
		moveq	#-1,d0
		rts
.no		moveq	#0,d0
		rts
.decrunch	move.l	#"IMP!",d0
		bra	_CloneMaster

;----------------------------------------
; xfdSlave-structure

_xfdSlave2	dc.l	_xfdSlave3	; next slave
		dc.w	XFDS_VERSION	; structure version
		dc.w	33		; req xfdmaster version
		dc.l	.name		; cruncher name
		dc.w	XFDPFF_DATA	; cruncher flags
		dc.w	0		; max length of special info (passwd)
		dc.l	.check		; check routine
		dc.l	.decrunch	; decrunch routine
		dc.l	0		; segment recog routine
		dc.l	0		; segment decrunch routine

.name		dc.b	'Z&G! (S404 clone)',0
	EVEN
.check		moveq	#22,d1		;minimum 22 bytes
		cmp.l	d1,d0
		blo	.no
		cmp.l	#"Z&G!",(a0)
		bne	.no
		moveq	#-1,d0
		rts
.no		moveq	#0,d0
		rts
.decrunch	move.l	#"S404",d0
		bra	_CloneMaster

;----------------------------------------
; xfdSlave-structure

_xfdSlave3	dc.l	0		; next slave
		dc.w	XFDS_VERSION	; structure version
		dc.w	33		; req xfdmaster version
		dc.l	.name		; cruncher name
		dc.w	XFDPFF_DATA	; cruncher flags
		dc.w	0		; max length of special info (passwd)
		dc.l	.check		; check routine
		dc.l	.decrunch	; decrunch routine
		dc.l	0		; segment recog routine
		dc.l	0		; segment decrunch routine

.name		dc.b	'LR88 (PP20 clone)',0
	EVEN
.check		moveq	#16,d1		;minimum 16 bytes
		cmp.l	d1,d0
		blo	.no
		cmp.l	#"LR88",(a0)
		bne	.no
		moveq	#-1,d0
		rts
.no		moveq	#0,d0
		rts
.decrunch	move.l	#"PP20",d0
		bra	_CloneMaster

;----------------------------------------
; mastercode to decrunch the file
; Übergabe :	D0 = LONG new ID
;		A0 = APTR xfdBufferInfo
; Rückgabe :	D0 = BOOL success

_CloneMaster	move.l	(xfdbi_SourceBuffer,a0),a1
		move.l	(a1),-(a7)			;save old ID
		move.l	d0,(a1)				;write new
		move.l	a0,-(a7)			;save xfdBufferInfo
		jsr	(_LVOxfdRecogBuffer,a6)
		tst.l	d0
		beq	.error
		move.l	(a7),a0
		jsr	(_LVOxfdDecrunchBuffer,a6)
		move.l	(a7)+,a0
.cleanup	move.l	(xfdbi_SourceBuffer,a0),a1
		move.l	(a7)+,(a1)			;restore old ID
		rts

.error		move.l	(a7)+,a0
		move.w	#XFDERR_UNKNOWN,(xfdbi_Error,a0)
		moveq	#0,d0
		bra	.cleanup
		
;##########################################################################

	END

