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

  1. (* TBTree16             Copyright (c)  1988,1989       Dean H. Farwell II    *)
  2.  
  3. unit Math;
  4.  
  5. (*****************************************************************************)
  6. (*                                                                           *)
  7. (*                  M A T H M A T I C A L  R O U T I N E S                   *)
  8. (*                                                                           *)
  9. (*****************************************************************************)
  10.  
  11.  
  12. (* These routines augment the Turbo Pascal routines provided.
  13.  
  14.  
  15. (* Version Information
  16.  
  17.    Version 1.1 - No Changes
  18.  
  19.    Version 1.2 - No Changes
  20.  
  21.    Version 1.3 - Modified 11 July 1988  by Jack Dolby
  22.                                            Gately Communication Company
  23.                                            501 Industry Drive
  24.                                            Hampton, VA  23661
  25.  
  26.        These are inline assembly language macros to perform the same function
  27.        as the Pascal versions in versions prior to 1.3.
  28.  
  29.        Note that the entire code for inline macros must be in the INTERFACE
  30.        section.  The code in these macros is actually placed in the code the
  31.        compiler emits at each place they are invoked. This results in larger
  32.        code but eliminates the time overhead for calling a routine and
  33.        returning from it.  Only the pushing of parameters and extracting the
  34.        functional result are done rather than also pushing the return address,
  35.        preserving registers in the code, setting up a stack frame, and
  36.        restoring all registers and the stack on return.  This results in
  37.        faster code at the expense of code size (if called from more than one
  38.        place) and in loosing the ability to hide the code in the
  39.        IMPLEMENTATION SECTION.     j. dolby
  40.  
  41.        My special thanks goes to j. dolby who took the time to make these
  42.        improvements and graciously allowed me to include them for
  43.        distribution!!      Dean H. Farwell II
  44.  
  45.    Version 1.4 - Jack Dolby modified (cleaned up) all routines for this
  46.                  version
  47.  
  48.                - Deleted PowerInt routine since it is not really used for
  49.                  anything
  50.  
  51.    Version 1.5 - No Changes
  52.  
  53.    Version 1.6 - No Changes                                                  *)
  54.  
  55. (*\*)
  56. (*////////////////////////// I N T E R F A C E //////////////////////////////*)
  57.  
  58. interface
  59.  
  60. (* the following type supports the byte handling routine(s)                  *)
  61.  
  62. type
  63.     BytePosition = 0 .. 7;
  64.     BitValue = 0 .. 1;
  65.  
  66.  
  67. (* This function will determine if a certain bit within a target byte is
  68.    toggled on (equal to 1).  The bit position is is the position within the
  69.    byte of the bit to be tested.  The least significant bit is 0 then most
  70.    significant bit is 7.  If the bit is 1 TRUE will be returned.  If the bit
  71.    is 0 FALSE will be returned.  Notice that the target byte can be of any
  72.    type.  in this way, the routine will handle any a bit byte.  In other
  73.    words a character could also be passed in.                                *)
  74.  
  75. (* Boolean functions return zero flag set and AL=0 for false,
  76.                             zero flag reset and AL=1 for true                *)
  77.  
  78. function BitOn(var targetByte;
  79.                bitNum : BytePosition ):boolean;
  80.  
  81. (*      pop cx                   ;bitNum
  82.         pop bx                   ;offset of targetByte
  83.         pop es                   ;segment of targetByte
  84.         mov al, byte ptr es:[bx] ;get the byte
  85.         shr al,cl                ;get desired bit
  86.                                  ;in rightmost position
  87.         and al,01                ;check for bit set                          *)
  88.  
  89.     INLINE($59/$5B/$07/$26/$8A/$07/$D2/$E8/$24/$01);
  90.  
  91.  
  92. (*\*)
  93. (* This will set a given bit to a value of zero or one depending on what is
  94.    passed in as the last parameter.  See above for description of the other
  95.    parameters                                                                *)
  96.  
  97. procedure SetBit(var targetByte;
  98.                  bitNum : BytePosition;
  99.                  bit : BitValue );
  100.  
  101. (*      pop ax                  ;bit
  102.         pop cx                  ;bitNum
  103.         pop bx                  ;offset of targetByte
  104.         pop es                  ;segment of targetByte
  105.         mov ah,11111110b        ;mask to reset
  106.         rol ah,cl               ;get it in place
  107.         and byte ptr es:[bx],ah ;reset regardless
  108.         shl al,cl               ;mask to set/reset
  109.         or byte ptr es:[bx],al  ;make bit proper value                       *)
  110.  
  111.     INLINE($58/$59/$5B/$07/$B4/$FE/$D2/$C4/$26/$20/$27/$D2/$E0/$26/$08/$07);
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. (*!*)
  127. (*///////////////////// I M P L E M E N T A T I O N /////////////////////////*)
  128.  
  129. implementation
  130.  
  131. end.                                                     (* end of Math unit *)
  132.