home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PASCAL / TBTREE16.ZIP / TIME.PAS < prev    next >
Pascal/Delphi Source File  |  1989-07-13  |  10KB  |  211 lines

  1. (* TBTree16             Copyright (c)  1988,1989       Dean H. Farwell II    *)
  2.  
  3. unit Time;
  4.  
  5. (*****************************************************************************)
  6. (*                                                                           *)
  7. (*                       T I M E    R O U T I N E S                          *)
  8. (*                                                                           *)
  9. (*****************************************************************************)
  10.  
  11.  
  12. (* This unit is completely redesigned as of version 1.4 and can be used to
  13.    track the sequence of events.  As opposed to previous versions, it does not
  14.    use actual time, but uses a counter to simulate time.  This counter is just
  15.    like an internal clock with each "tick" being noted by incrementing the
  16.    counter.  The clock is an internal variable of type TimeArr (defined in
  17.    this unit) which is nothing more than a record of two long integers.  This
  18.    gives the clock a range of over 2 billion squared which is larger than
  19.    anyone will ever need.  The use of this unit is straightforward.  The user
  20.    has variables of type TimeArr.  To assign a time call GetTime.  To compare
  21.    two times call CompareTime.  A routine to set the max time and to print
  22.    times is also provided.
  23.  
  24.    note - The idea to use the simulated clock rather than using my previous
  25.           method came from Chris Cardozo.  It was an extremely slick way to
  26.           get around compatibility problems which I would not have thought
  27.           of.                                                                *)
  28.  
  29. (* Version Information
  30.  
  31.    Version 1.1 - No Changes
  32.  
  33.    Version 1.2 - No Changes
  34.  
  35.    Version 1.3 - No Changes
  36.  
  37.    Version 1.4 - Redesigned complete unit.  The reason for the redesign was to
  38.                  alleviate any dependancies on specific memory locations which
  39.                  the previous version had.
  40.  
  41.    Version 1.5 - GetTime and CompareTime were redone using INLINE statements
  42.                  by Chris Cardozo.  They function the same way as in version
  43.                  1.4, but are faster and smaller (400 bytes verses 560).  His
  44.                  extensive efforts on all facets of TBTREE are appreciated.
  45.  
  46.                - The order of the fields in TimeArr are switched
  47.  
  48.    Version 1.6 - No Changes                                                  *)
  49.  
  50. (*!*)
  51. (*\*)
  52. (*////////////////////////// I N T E R F A C E //////////////////////////////*)
  53.  
  54. interface
  55.  
  56. uses
  57.     Compare,
  58.     Numbers;
  59.  
  60.  
  61. type
  62.     TimeArr = record
  63.         lsLongInt : LongInt;               (* least significant long integer *)
  64.         msLongInt : LongInt;                (* most significant long integer *)
  65.         end;
  66.  
  67.  
  68. (* This routine does two things that are important to understand when
  69.    using it.  It first increments the internal clock.  It then sets x to this
  70.    new "time".                                                               *)
  71.  
  72. procedure GetTime(var x : TimeArr);
  73.  
  74.  
  75. (* This function compares two time arrays.  LESSTHAN is returned if X is less
  76.    than Y (earlier).  GREATERTHAN is returned if X is greater than Y (later).
  77.    If they are equal then EQUALTO is returned                                *)
  78.  
  79. function CompareTime(var x : TimeArr;
  80.                      var y : TimeArr) : Comparison;
  81.  
  82.  
  83. (* This routine will print the two long integers that make up x (of type
  84.    TimeArr)                                                                  *)
  85.  
  86. procedure PrintTime(x : TimeArr);
  87.  
  88.  
  89. (* This routine sets both long integer fields of a timeArr variable to the
  90.    maximum possible value (MAXLONGINT)                                       *)
  91.  
  92. procedure SetMaxTime(var x : TimeArr);
  93.  
  94.  
  95. (*\*)
  96. (*///////////////////// I M P L E M E N T A T I O N /////////////////////////*)
  97.  
  98. implementation
  99.  
  100. var
  101.     clock : TimeArr;
  102.  
  103. (* This routine does two things that are important to understand when
  104.    using it.  It first increments the internal clock.  It then sets x to this
  105.    new "time".                                                               *)
  106.  
  107. procedure GetTime(var x : TimeArr);
  108.  
  109.     begin
  110.     Inline(
  111.         (* This was created from the original source code using the INLINE4
  112.            utility from CompuServe.  It has difficulty dealing with the lea
  113.            si, >CLOCK instruction.  This was hand coded using a listing of the
  114.            original assembled file.  Thus, if any future modifications require
  115.            changing this file and reassembling with INLINE, be sure to check
  116.            the output to make sure this instruction is OK.  INLINE does flag
  117.            an error here to remind you - I have not included the original
  118.            source code for simplicities sake.  If anyone wants it, I have it
  119.            - Dean                                                            *)
  120.  
  121.       $C4/$BE/>X/         (*  les di, >x[bp]           ; set es:di to point
  122.                                                          to the users time
  123.                                                          var                 *)
  124.       $8D/$36/>CLOCK/     (*  lea si, >CLOCK           ; set ds:si to point
  125.                                                          to the local
  126.                                                          database time var   *)
  127.       $83/$04/$01/        (*  add word ptr [si],1      ; inc the database
  128.                                                          time                *)
  129.       $83/$54/$02/$00/    (*  adc word ptr 2[si], 0    ;                     *)
  130.       $83/$54/$04/$00/    (*  adc word ptr 4[si], 0    ;                     *)
  131.       $83/$54/$06/$00/    (*  adc word ptr 6[si], 0    ;                     *)
  132.       $FC/                (*  cld                      ; copy new time to
  133.                                                          UserTime            *)
  134.       $B9/$04/$00/        (*  mov cx, 4                ;                     *)
  135.       $F2/$A5);           (*  rep   movsw              ; use movsw to save
  136.                                                          one memory access   *)
  137.  
  138.     end;                                           (* end of GetTime routine *)
  139.  
  140. (*\*)
  141. (* This function compares two time arrays.  LESSTHAN is returned if X is less
  142.    than Y (earlier).  GREATERTHAN is returned if X is greater than Y (later).
  143.    If they are equal then EQUALTO is returned                                *)
  144.  
  145. function CompareTime(var x : TimeArr;
  146.                      var y : TimeArr) : Comparison;
  147.  
  148.     begin
  149.     Inline(
  150.                           (*                           ; LI1 = StackOffs + 4 *)
  151.                           (*                           ; LI2 = StackOffs     *)
  152.       $8C/$DA/            (* mov dx, ds                ; save Turbo's ds     *)
  153.       $C5/$B6/>X/         (* lds si, >x[bp]            ; point ds:si to high
  154.                                                          word of first memory
  155.                                                          region              *)
  156.       $83/$C6/$03/        (* add si, 3                 ; region is 4 words
  157.                                                          long                *)
  158.       $C4/$BE/>Y/         (* les di, >y[bp]            ; point es:di to high
  159.                                                          word of second
  160.                                                          memory region       *)
  161.       $83/$C7/$03/        (* add di, 3                 ; region is 4 words
  162.                                                          long                *)
  163.       $FD/                (* std                       ; compare from high
  164.                                                          word to low word    *)
  165.       $B9/$04/$00/        (* mov cx, 4                 ; 4 words to compare  *)
  166.       $F3/$A7/            (* repe  cmpsw               ; do compare          *)
  167.       $B8/$01/$00/        (* mov ax, 1                 ; assume result was
  168.                                                          EQUAL               *)
  169.       $74/$0B/            (* je Done                   ; if so, then we are
  170.                                                          all done            *)
  171.       $77/$06/            (* ja GrThan                 ; was first parameter
  172.                                                          greater ?           *)
  173.       $B8/$00/$00/        (* mov ax, 0                 ; no, then it must
  174.                                                          have been less than
  175.                                                          second              *)
  176.       $E9/$03/$00/        (* jmp Done                  ;                     *)
  177.       $B8/$02/$00/        (* GrThan: mov ax, 2         ;                     *)
  178.       $8E/$DA/            (* Done:   mov ds, dx        ; all done so can
  179.                                                          restore Turbo's ds  *)
  180.       $88/$46/$FF);       (* mov [bp-1], al            ; store function
  181.                                                          result for Turbo    *)
  182.  
  183.     end;                                       (* end of CompareTime routine *)
  184.  
  185.  
  186. (* This routine will print the two long integers that make up x (of type
  187.    TimeArr)                                                                  *)
  188.  
  189. procedure PrintTime(x : TimeArr);
  190.  
  191.     begin
  192.     Writeln('Most Significant Long Integer = ',x.msLongInt);
  193.     Writeln('Least Significant Long Integer = ',x.lsLongInt);
  194.     end;                                         (* end of PrintTime routine *)
  195.  
  196. (*\*)
  197. (* This routine sets both long integer fields of a timeArr variable to the
  198.    maximum possible value (MAXLONGINT)                                       *)
  199.  
  200. procedure SetMaxTime(var x : TimeArr);
  201.  
  202.     begin
  203.     x.lsLongInt := MAXLONGINT;
  204.     x.msLongInt := MAXLONGINT;
  205.     end;                                        (* end of SetMaxTime routine *)
  206.  
  207. begin
  208. clock.msLongInt := 0;
  209. clock.lsLongInt := 0;
  210. end.                                                     (* end of Time unit *)
  211.