timer.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. {
  2. This file is part of the Free Pascal run time library.
  3. A file in Amiga system run time library.
  4. Copyright (c) 1998-2003 by Nils Sjoholm
  5. member of the Amiga RTL development team.
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {
  13. History:
  14. Removed the var for all functions.
  15. 06 Sep 2000.
  16. Added the define use_amiga_smartlink.
  17. 13 Jan 2003.
  18. [email protected]
  19. }
  20. {$I useamigasmartlink.inc}
  21. {$ifdef use_amiga_smartlink}
  22. {$smartlink on}
  23. {$endif use_amiga_smartlink}
  24. unit timer;
  25. INTERFACE
  26. uses exec;
  27. Const
  28. { unit defintions }
  29. UNIT_MICROHZ = 0;
  30. UNIT_VBLANK = 1;
  31. UNIT_ECLOCK = 2;
  32. UNIT_WAITUNTIL = 3;
  33. UNIT_WAITECLOCK = 4;
  34. TIMERNAME : PChar = 'timer.device';
  35. Type
  36. ptimeval = ^ttimeval;
  37. ttimeval = record
  38. tv_secs : ULONG;
  39. tv_micro : ULONG;
  40. end;
  41. ptimerequest = ^ttimerequest;
  42. ttimerequest = record
  43. tr_node : tIORequest;
  44. tr_time : ttimeval;
  45. end;
  46. pEClockVal = ^tEClockVal;
  47. tEClockVal = record
  48. ev_hi : ULONG;
  49. ev_lo : ULONG;
  50. end;
  51. Const
  52. { IO_COMMAND to use for adding a timer }
  53. TR_ADDREQUEST = CMD_NONSTD;
  54. TR_GETSYSTIME = CMD_NONSTD + 1;
  55. TR_SETSYSTIME = CMD_NONSTD + 2;
  56. { To use any of the routines below, TimerBase must be set to point
  57. to the timer.device, either by calling CreateTimer or by pulling
  58. the device pointer from a valid TimeRequest, i.e.
  59. TimerBase := TimeRequest.io_Device;
  60. _after_ you have called OpenDevice on the timer.
  61. }
  62. var
  63. TimerBase : Pointer;
  64. Procedure AddTime( Dest, Source : ptimeval);
  65. Function CmpTime( Dest, Source : ptimeval) : ULONG;
  66. Procedure SubTime( Dest, Source : ptimeval);
  67. function ReadEClock(Dest : pEClockVal): longint;
  68. procedure GetSysTime( Dest : ptimeval);
  69. IMPLEMENTATION
  70. Procedure AddTime( Dest, Source : ptimeval);
  71. begin
  72. asm
  73. MOVE.L A6,-(A7)
  74. MOVE.L Dest,a0
  75. MOVE.L Source,a1
  76. MOVE.L TimerBase,A6
  77. JSR -042(A6)
  78. MOVE.L (A7)+,A6
  79. end;
  80. end;
  81. Function CmpTime( Dest, Source : ptimeval) : ULONG;
  82. begin
  83. asm
  84. MOVE.L A6,-(A7)
  85. MOVE.L Dest,a0
  86. MOVE.L Source,a1
  87. MOVE.L TimerBase,A6
  88. JSR -054(A6)
  89. MOVE.L (A7)+,A6
  90. MOVE.L d0,@RESULT
  91. end;
  92. end;
  93. Procedure SubTime( Dest, Source : ptimeval);
  94. begin
  95. asm
  96. MOVE.L A6,-(A7)
  97. MOVE.L Dest,a0
  98. MOVE.L Source,a1
  99. MOVE.L TimerBase,A6
  100. JSR -048(A6)
  101. MOVE.L (A7)+,A6
  102. end;
  103. end;
  104. function ReadEClock(Dest : pEClockVal): longint;
  105. begin
  106. asm
  107. MOVE.L A6,-(A7)
  108. MOVE.L Dest,a0
  109. MOVE.L TimerBase,A6
  110. JSR -060(A6)
  111. MOVE.L (A7)+,A6
  112. MOVE.L d0,@RESULT
  113. end;
  114. end;
  115. procedure GetSysTime( Dest : ptimeval);
  116. begin
  117. asm
  118. MOVE.L A6,-(A7)
  119. MOVE.L Dest,a0
  120. MOVE.L TimerBase,A6
  121. JSR -066(A6)
  122. MOVE.L (A7)+,A6
  123. end;
  124. end;
  125. end.