	opt	l-
	
	incdir	:include/
	include	libraries/dos_lib.i
	include	exec/exec_lib.i
	
	movem.l	a0,-(sp)
	
	cmp.l	#$10C,$6C
	beq.s	Installato
	bsr	Routine
	
Installato	movem.l	(sp)+,a0
	lea	test,a1
	move.b	(a0)+,(a1)+
	move.b	(a0),(a1)
	
	cmp.w	#'go',-1(a1)	; si parte
	bne.s	stop
	
go	clr.l	$108		; azzero counter
	clr.l	d0
	rts
	
stop	move.l	$108,d0		; vecchio start
	divu	#50,d0
	andi.l	#$FFFF,d0		; secondi totali
	move.l	d0,d1
	divu	#60,d1		; minuti totali=d1
	move.l	d1,d2
	mulu	#60,d2
	sub.l	d2,d0		; secondi di resto=d0
	
	lea	TimeStr,a0
	move.l	d0,d2
	andi.l	#$FFFF,d2
	divu	#10,d2		; decine dei secondi
	add.b	d2,3(a0)
	mulu	#10,d2
	sub	d2,d0
	add.b	d0,4(a0)		; unita' dei secondi
	
	move.l	d1,d2
	andi.l	#$FFFF,d2
	divu	#10,d2		; decine dei minuti
	add.b	d2,(a0)
	mulu	#10,d2
	sub	d2,d1
	add.b	d1,1(a0)		; unita' dei minuti

scrivi	lea	DosName,a1
	clr.l	d0
	CALLEXEC	OpenLibrary
	move.l	d0,_DOSBase
	
	CALLDOS	Output
	move.l	d0,d1
	move.l	#Result,d2
	move.l	#lungh,d3
	CALLDOS	Write
	
	move.l	_DOSBase,a1
	CALLEXEC	CloseLibrary
	clr.l	d0
	rts
	
Routine	lea	Code,a0
	lea	$10C,a1
	move.l	#CodeL-1,d0
Loop	move.b	(a0)+,(a1)+
	dbra	d0,Loop
	clr.l	$108
	move.l	#$10C,$6C
	rts

Code	addq.l	#1,$108
	jmp	$FC0D14		; Old VBI

CodeL		equ	*-Code	
DosName		dc.b	'dos.library',0
_DOSBase		ds.l	1
Result		dc.b	'Il tempo totale è '
TimeStr		dc.b	'00:00 secondi',10,0	
lungh		equ	*-Result
	cnop	0,2
test		ds.b	2
