unit Timer;

INTERFACE
uses Exec;


type
	ptimeval = ^ttimeval;
	ttimeval = record
		tv_secs: long;
		tv_micro: long;
		end;

	ptimerequest = ^ttimerequest;
	ttimerequest = record
		tr_node: tIORequest;
		tr_time: ttimeval;
		end;



var
	TimerBase: pLibrary;


const
	TR_ADDREQUEST = 9;
	TR_GETSYSTIME = $A;
	TR_SETSYSTIME = $B;
	UNIT_MICROHZ = 0;
	UNIT_VBLANK = 1;
	TIMERNAME = 'timer.device';


procedure AddTime
		(dest: ptimeval;
		src: ptimeval);

procedure SubTime
		(dest: ptimeval;
		src: ptimeval);

function CmpTime
		(dest: ptimeval;
		src: ptimeval): longint;



IMPLEMENTATION
procedure AddTime; xassembler;
asm
	move.l	a6,-(sp)
	lea		8(sp),a6
	move.l	(a6)+,a1
	move.l	(a6)+,a0
	move.l	TimerBase,a6
	jsr		-$2A(a6)
	move.l	(sp)+,a6
end;

procedure SubTime; xassembler;
asm
	move.l	a6,-(sp)
	lea		8(sp),a6
	move.l	(a6)+,a1
	move.l	(a6)+,a0
	move.l	TimerBase,a6
	jsr		-$30(a6)
	move.l	(sp)+,a6
end;

function CmpTime; xassembler;
asm
	move.l	a6,-(sp)
	lea		8(sp),a6
	move.l	(a6)+,a1
	move.l	(a6)+,a0
	move.l	TimerBase,a6
	jsr		-$36(a6)
	move.l	d0,$10(sp)
	move.l	(sp)+,a6
end;

end.
