;	.        ___           .   _   .
;	|   _  _  | .. . _    /|  / \ /|
;	|  |_)/ \ | ||V||_)    | ( / ) |
;	|__|_,\_/ | |||||_,    |o \_/  |
;
;	1994-04-25
;
;	Another one disk blocker:
;	A small timing utility, requires at least OS 2 and 68020
;	Use parenthesis around the command if you require redirection, eg.
;	LeoTime "list all nohead >ram:MyList"

	include "AInclude:Include.i"
;	include "AInclude:Macros.i"



	section text,CODE

DOSBASE	equr	a4
STARTTIME equr	d6

	movem.l	d2-d7/a2-a6,-(sp)	; Save registers

	tst.l	d0			; no paramters?
	beq	exitcode		;  -- exit

	movem.l a0/d0,-(sp)		; save command address & length


	move.l	$4.w,a6			; This is SysBase ( = ExecBase )
	lea	DosName(pc),a1		; DosBase = OpenLib("intuition.library", 36);
	moveq.l	#36,d0
	jsr	_LVOOpenLibrary(a6)
	move.l	d0,DOSBASE
	tst.l	d0
	bne.s	go_on0

	movem.l (sp)+,a0/d0		: throw away command address & length
	bra	exitcode

go_on0:
	btst.b	#AFB_68020,297(a6)	; if (!(SysBase->AttnFlags))
	bne.s	go_on


	move.l	DOSBASE,a6		; 	Printf("Bad processor type\n");
	lea	BadProcessorText(pc),a0
	move.l	a0,d1
	jsr	_LVOPrintf(a6)

	movem.l (sp)+,a0/d0		: throw away command address & length
	bra	closelib

go_on:
	move.l	DOSBASE,a6		; DateStamp(&MyDate);
	lea	MyDate(pc),a0
	move.l	a0,d1
	jsr	_LVODateStamp(a6)

	lea	MyDate(pc),a0		; StartTime = Days*24*60 + Minutes*60*50 + Ticks
	move.l	(a0)+,STARTTIME
	mulu.l	#24*60,STARTTIME
	add.l	(a0)+,STARTTIME
	mulu.l	#60*50,STARTTIME
	add.l	(a0),STARTTIME

	movem.l (sp)+,a0/d0		; restore command address & length

	moveq.l	#'"',d1
	cmp.b	(a0),d1
	bne.s	no_parenthesis
	cmp.b	-2(a0,d0),d1
	bne.s	no_parenthesis		; if parameter string is surrounded with parenthesis
	addq.l	#1,a0			; 	... then leave the parentheses out
	subq.l	#2,d0

no_parenthesis:
	lea	-1(a0,d0),a3
	move.b	(a3),d7
	move.b	#0,(a3)			; Make command string NULL-terminated

	move.l	a0,-(sp)		; Store again the command line beginning argument

;	move.l	DOSBASE,a6		; Execute(Command,NULL,NULL);
	move.l	a0,d1
	moveq.l	#0,d2
	moveq.l	#0,d3
	jsr	_LVOExecute(a6)

okCode:
	move.l	(sp)+,a0		; Take command line beginning argument away from stack

;	move.l	DOSBASE,a6		; DateStamp(&MyDate);
	lea	MyDate(pc),a0
	move.l	a0,d1
	jsr	_LVODateStamp(a6)

	lea	MyDate(pc),a0		; EndTime = Days*24*60 + Minutes*60*50 + Ticks
	move.l	(a0)+,d0
	mulu.l	#24*60,d0
	add.l	(a0)+,d0
	mulu.l	#60*50,d0
	add.l	(a0),d0

	sub.l	STARTTIME,d0		; Time = EndTime - StartTime

	moveq.l	#0,d3
	moveq.l	#50,d4
	divu.l	d4,d3:d0
	asl.l	#1,d3
	moveq.l	#0,d2
	moveq.l	#60,d4
	divu.l	d4,d2:d0
	moveq.l	#0,d1
	divu.l	d4,d1:d0

	lea	PrintVars(pc),a0
	move.w	d0,(a0)+
	move.w	d1,(a0)+
	move.w	d2,(a0)+
	move.w	d3,(a0)+

;	move.l	DOSBASE,a6		; Printf();
	lea	SuccessText(pc),a0
	move.l	a0,d1
	lea	PrintVars(pc),a0
	move.l	a0,d2
	jsr	_LVOPrintf(a6)

	move.b	d7,(a3)			; Restore original command ending character


closelib:

	move.l	$4.w,a6			; This is SysBase ( = ExecBase )
	move.l	DOSBASE,a1		; CloseLib(DosBase);
	jsr	_LVOCloseLibrary(a6)

exitcode:
	movem.l	(sp)+,d2-d7/a2-a6	; restore registers
	moveq.l	#0,d0			; always return OK!
	rts

Ver:
	dc.b "$VER:LeoTime 1.0 (25.4.94) ©1994 Leopold-Soft",10,0
DosName:
	dc.b "dos.library",0
SuccessText:
	dc.b "LeoTime: %d:%02d:%02d.%02d real time.",10,0
BadProcessorText:
	dc.b "LeoTime: Requires at least 68020 to run!",10,0
	cnop 0,4

MyDate:
MyDate_Days:
	ds.l	1
PrintVars:
MyDate_Minutes:
	ds.l	1
MyDate_Ticks:
        ds.l    1

	END
