	section	lard,code

code:	move.l	a0,Path
	
	IncDir	"DH0:Include/"
	
	include	"sc:MyReq.ii"
	
	move.l	#0,length
	move.l	#0,files

	Lea	DosName,A1
	Moveq	#0,D0
	CALLEXEC	OpenLibrary
	Move.l 	D0,_DOSBase
	Beq	Error

	bsr	_OpenMyReqs
	beq	Error

	move.l	Path,a0
.loop	add.l	#1,a0
	cmp.b	#32,(a0)
	bge	.loop
	move.b	#0,(a0)
	
	move.l	Path,d1
	move.l	#-2,d2
	CALLDOS	Lock
	move.l	d0,lock
	beq	lock_err

	lea	Checking_Text,a2
	bsr	setup_alert

	move.l	lock,d1
	CALLDOS	CurrentDir
	move.l	d0,oldlock
	
	move.l	lock,d1
	move.l	#ExBlock,d2
	CALLDOS	Examine
	beq	lock_err

	cmp.l	#0,ExBlock+4
	bmi	Single_File

	bsr	Get_Length
	cmp.b	#27,d7
	beq	Aborted
	
	cmp.l	#0,ExBlock+4
	bmi	Finished
	
.next	move.l	lock,d1
	move.l	#ExBlock,d2
	CALLDOS	ExNext
	beq	Finished
	bsr	Get_Length
	cmp.b	#27,d7
	bne	.next
	bra	Aborted
	
Finished	move.l	lock,d1
	CALLDOS	UnLock

	move.l	oldlock,d1
	CALLDOS	CurrentDir

	bsr	finish_alert

	bsr	Prepare_Final

	lea	Final_Text,a2
	bsr	setup_alert
	
Bye	Move.l	_DOSBase,A1
	CALLEXEC	CloseLibrary

	bsr	_CloseMyReqs

Error	Moveq	#0,D0
	Rts

Aborted:	move.l	lock,d1
	CALLDOS	UnLock

	move.l	oldlock,d1
	CALLDOS	CurrentDir

	bsr	finish_alert

	lea	Aborted_text,a2
	bsr	setup_alert
	
	Move.l	_DOSBase,A1
	CALLEXEC	CloseLibrary
	
	Move.l	_IntuitionBase,A1
	CALLEXEC	CloseLibrary

	Move.l	_GfxBase,a1
	CALLEXEC	CloseLibrary

	Moveq	#0,D0
	Rts

	*-------------------------------*

Get_Length:	move.l	#0,d7

	move.l	#ExBlock+8,d1
	move.l	#MODE_OLDFILE,d2
	CALLDOS	Open
	beq	Error
	
	move.l	d0,handle

	move.l	handle,d1
	move.l	#Temp,d2
	move.l	#4,d3
	CALLDOS	Read
	cmp.l	#"PP20",Temp
	bne	.NotPP

	move.l	#ExBlock+8,a0
	move.w	#-1,d7
.loop	add.w	#1,d7
	cmp.w	#31,d7
	beq	.stop
	cmp.b	#0,(a0,d7.w)
	bne	.loop	

.stop	Move.l	_MyReqWinRPort,a1
	move.w	#1,d0
	CALLGRAF	SetAPen

	Move.l	_MyReqWinRPort,a1
	move.w	#10,d0
	move.w	#41,d1
	CALLGRAF	Move

	Move.l	_MyReqWinRPort,a1
	move.l	#ClearLine,a0
	move.w	#31,d0
	CALLGRAF	Text
	
	Move.l	_MyReqWinRPort,a1
	move.w	d7,d0
	asl.w	#3,d0
	move.w	#260,d1
	sub.w	d0,d1
	lsr.w	#1,d1
	move.w	d1,d0
	move.w	#41,d1
	CALLGRAF	Move

	Move.l	_MyReqWinRPort,a1
	move.l	#ExBlock+8,a0
	move.w	d7,d0
	CALLGRAF	Text

	move.l	handle,d1
	move.l	#-4,d2
	move.l	#OFFSET_END,d3	
	CALLDOS	Seek
	
	move.l	handle,d1
	move.l	#Temp,d2
	move.l	#4,d3
	CALLDOS	Read

	move.l	handle,d1
	CALLDOS	Close

	move.l	Temp,d0
	lsr.l	#8,d0
	add.l	d0,length

	add.l	#1,files

	move.l	#0,d7

	rts		

.NotPP	move.l	handle,d1
	CALLDOS	Close

	lea	ExBlock+8,a0
	lea	flname1,a1
	bsr	CopyName
	lea	NotPP_text,a2
	bsr	setup_alert
	rts


Single_File:	move.l	#0,d7

	move.l	Path,d1
	move.l	#MODE_OLDFILE,d2
	CALLDOS	Open
	beq	Error
	
	move.l	d0,handle

	move.l	handle,d1
	move.l	#Temp,d2
	move.l	#4,d3
	CALLDOS	Read
	cmp.l	#"PP20",Temp
	bne	.NotPP

	move.l	#ExBlock+8,a0
	move.w	#-1,d7
.loop	add.w	#1,d7
	cmp.w	#31,d7
	beq	.stop
	cmp.b	#0,(a0,d7.w)
	bne	.loop	

.stop	Move.l	_MyReqWinRPort,a1
	move.w	#1,d0
	CALLGRAF	SetAPen

	Move.l	_MyReqWinRPort,a1
	move.w	#10,d0
	move.w	#41,d1
	CALLGRAF	Move

	Move.l	_MyReqWinRPort,a1
	move.l	#ClearLine,a0
	move.w	#31,d0
	CALLGRAF	Text
	
	Move.l	_MyReqWinRPort,a1
	move.w	d7,d0
	asl.w	#3,d0
	move.w	#260,d1
	sub.w	d0,d1
	lsr.w	#1,d1
	move.w	d1,d0
	move.w	#41,d1
	CALLGRAF	Move

	Move.l	_MyReqWinRPort,a1
	move.l	#ExBlock+8,a0
	move.w	d7,d0
	CALLGRAF	Text

	move.l	handle,d1
	move.l	#-4,d2
	move.l	#OFFSET_END,d3	
	CALLDOS	Seek
	
	move.l	handle,d1
	move.l	#Temp,d2
	move.l	#4,d3
	CALLDOS	Read

	move.l	handle,d1
	CALLDOS	Close

	move.l	Temp,d0
	lsr.l	#8,d0
	add.l	d0,length

	add.l	#1,files

	move.l	#0,d7

	bra	Finished

.NotPP	move.l	handle,d1
	CALLDOS	Close

	lea	ExBlock+8,a0
	lea	flname1,a1
	bsr	CopyName
	lea	NotPP_text,a2
	bsr	setup_alert

	Bra	Finished
	
CopyName:	
.loop	move.b	(a0)+,(a1)+
	cmp.b	#0,(a0)
	bne	.loop
	move.b	#0,(a1)
	rts

	*-------------------------------*

lock_err:	lea	le_text,a2
	bsr	setup_alert
	bsr	Bye
	rts

	*-------------------------------*

Prepare_Final:
	lea	num1,a0
	move.b	#"0",0(a0)
	move.b	#"0",1(a0)
	move.b	#"0",2(a0)
	move.b	#"0",3(a0)
	move.b	#"0",4(a0)
	move.b	#"0",5(a0)
	move.b	#"0",6(a0)
	move.b	#"0",7(a0)
	move.b	#"0",8(a0)

	move.l	length,d0

.l1	cmp.l	#100000000,d0
	blt	.l2
	add.b	#1,0(a0)
	sub.l	#100000000,d0
	bpl	.l1
.l2	cmp.l	#10000000,d0
	blt	.l3
	add.b	#1,1(a0)
	sub.l	#10000000,d0
	bpl	.l2
.l3	cmp.l	#1000000,d0
	blt	.l4
	add.b	#1,2(a0)
	sub.l	#1000000,d0
	bpl	.l3
.l4	cmp.l	#100000,d0
	blt	.l5
	add.b	#1,3(a0)
	sub.l	#100000,d0
	bpl	.l4
.l5	cmp.l	#10000,d0
	blt	.l6
	add.b	#1,4(a0)
	sub.l	#10000,d0
	bpl	.l5
.l6	cmp.l	#1000,d0
	blt	.l7
	add.b	#1,5(a0)
	sub.l	#1000,d0
	bpl	.l6
.l7	cmp.l	#100,d0
	blt	.l8
	add.b	#1,6(a0)
	sub.l	#100,d0
	bpl	.l7
.l8	cmp.l	#10,d0
	blt	.l9
	add.b	#1,7(a0)
	sub.l	#10,d0
	bpl	.l8
.l9	cmp.l	#1,d0
	blt	.l10
	add.b	#1,8(a0)
	sub.l	#1,d0
	bpl	.l9

.l10	cmp.b	#"0",0(a0)
	bne	.s1
	move.b	#" ",0(a0)
	add.l	#1,a0
	bra	.l10	

.s1	lea	num1,a0
	cmp.b	#" ",8(a0)
	bne	.s2
	move.b	#"0",8(a0)
		
.s2	rts
	
	*-------------------------------*

	include	"sc:myreq.i"

_DOSBase		Dc.l	0
DosName		DOSNAME

Path:		dc.l	0

lock:		dc.l	0
oldlock:		dc.l	0
length:		dc.l	0
files:		dc.l	0
handle:		dc.l	0
Temp:		dc.l	0,0
ClearLine:		dcb.b	31,32

		cnop	0,4
ExBlock:		ds.b	260

	*-------------------------------*

le_text:	dc.b	1
	dc.b	"** PP COUNT 1.0 **",0
	dc.b	" ",0
	dc.b	"CANT FIND DIRECTORY",0

Aborted_text:	
	dc.b	1
	dc.b	"** PP COUNT 1.0 **",0
	dc.b	" ",0
	dc.b	"Aborted",0

NotPP_text:	dc.b	1
	dc.b	"** PP COUNT 1.0 **",0
	dc.b	"File is not PowerPacked!",0
flname1:	ds.b	40

Checking_Text:	
	dc.b	0
	dc.b	"** PP COUNT 1.0 **",0
	dc.b	"Scanning File",0
	dc.b	"",0

Final_Text:	
	dc.b	1
	dc.b	"** PP COUNT 1.0 **",0
	dc.b	0
	dc.b	"PowerPacked Length : "
num1:	dc.b	"000000000",0


	end


