summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/amunits/src/coreunits/timer.pas
blob: caafc63c604baa5066131eb0a8a43ca2368f3f07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{
    This file is part of the Free Pascal run time library.

    A file in Amiga system run time library.
    Copyright (c) 1998-2003 by Nils Sjoholm
    member of the Amiga RTL development team.

    See the file COPYING.FPC, included in this distribution,
    for details about the copyright.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 **********************************************************************}

{
    History:
    Removed the var for all functions.
    06 Sep 2000.

    Added the define use_amiga_smartlink.
    13 Jan 2003.

    nils.sjoholm@mailbox.swipnet.se

}

{$I useamigasmartlink.inc}
{$ifdef use_amiga_smartlink}
    {$smartlink on}
{$endif use_amiga_smartlink}

unit timer;

INTERFACE

uses exec;

Const

{ unit defintions }
    UNIT_MICROHZ        = 0;
    UNIT_VBLANK         = 1;
    UNIT_ECLOCK         = 2;
    UNIT_WAITUNTIL      = 3;
    UNIT_WAITECLOCK     = 4;

    TIMERNAME : PChar   = 'timer.device';

Type

    ptimeval = ^ttimeval;
    ttimeval = record
        tv_secs         : ULONG;
        tv_micro        : ULONG;
    end;

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

    pEClockVal = ^tEClockVal;
    tEClockVal = record
        ev_hi : ULONG;
        ev_lo : ULONG;
    end;


Const

{ IO_COMMAND to use for adding a timer }
    TR_ADDREQUEST       = CMD_NONSTD;
    TR_GETSYSTIME       = CMD_NONSTD + 1;
    TR_SETSYSTIME       = CMD_NONSTD + 2;

{  To use any of the routines below, TimerBase must be set to point
   to the timer.device, either by calling CreateTimer or by pulling
   the device pointer from a valid TimeRequest, i.e.

        TimerBase := TimeRequest.io_Device;

    _after_ you have called OpenDevice on the timer.
 }

var
    TimerBase   : Pointer;

Procedure AddTime( Dest, Source : ptimeval);
Function CmpTime( Dest, Source : ptimeval) : ULONG;
Procedure SubTime( Dest, Source : ptimeval);
function ReadEClock(Dest : pEClockVal): longint;
procedure GetSysTime( Dest : ptimeval);

IMPLEMENTATION

Procedure AddTime( Dest, Source : ptimeval);
begin
   asm
       MOVE.L  A6,-(A7)
       MOVE.L  Dest,a0
       MOVE.L  Source,a1
       MOVE.L  TimerBase,A6
       JSR -042(A6)
       MOVE.L  (A7)+,A6
   end;
end;

Function CmpTime( Dest, Source : ptimeval) : ULONG;
begin
   asm
       MOVE.L  A6,-(A7)
       MOVE.L  Dest,a0
       MOVE.L  Source,a1
       MOVE.L  TimerBase,A6
       JSR -054(A6)
       MOVE.L  (A7)+,A6
       MOVE.L  d0,@RESULT
   end;
end;

Procedure SubTime( Dest, Source : ptimeval);
begin
   asm
       MOVE.L  A6,-(A7)
       MOVE.L  Dest,a0
       MOVE.L  Source,a1
       MOVE.L  TimerBase,A6
       JSR -048(A6)
       MOVE.L  (A7)+,A6
   end;
end;

function ReadEClock(Dest : pEClockVal): longint;
begin
   asm
       MOVE.L  A6,-(A7)
       MOVE.L  Dest,a0
       MOVE.L  TimerBase,A6
       JSR -060(A6)
       MOVE.L  (A7)+,A6
       MOVE.L  d0,@RESULT
   end;
end;

procedure GetSysTime( Dest : ptimeval);
begin
   asm
       MOVE.L  A6,-(A7)
       MOVE.L  Dest,a0
       MOVE.L  TimerBase,A6
       JSR -066(A6)
       MOVE.L  (A7)+,A6
   end;
end;


end.