home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pmos2002.zip / DEF / LOWLEVEL.DEF < prev    next >
Text File  |  1996-09-03  |  12KB  |  309 lines

  1. DEFINITION MODULE LowLevel;
  2.  
  3.         (********************************************************)
  4.         (*                                                      *)
  5.         (*         Miscellaneous low-level procedures           *)
  6.         (*                                                      *)
  7.         (*  Programmer:         P. Moylan                       *)
  8.         (*  Last edited:        3 September 1996                *)
  9.         (*  Status:             Working on XDS port             *)
  10.         (*                                                      *)
  11.         (*      Now appears to be working, but:                 *)
  12.         (*       (a) untested, more checking needed;            *)
  13.         (*       (b) it's still not clear that what's           *)
  14.         (*           provided is what the clients needed,       *)
  15.         (*           particularly in relation to 16 bit/32 bit  *)
  16.         (*           distinctions.                              *)
  17.         (*                                                      *)
  18.         (*      Note that the implementation of this module     *)
  19.         (*      is heavily compiler-dependent.  This version    *)
  20.         (*      is for use with the XDS compiler,               *)
  21.         (*                                                      *)
  22.         (*      NOTE: Much of this module was originally        *)
  23.         (*      designed for 16-bit words, and I'm gradually    *)
  24.         (*      changing that.  What I need to look at is what  *)
  25.         (*      the client modules really need (e.g. who really *)
  26.         (*      uses a procedure like "HighByte").              *)
  27.         (*                                                      *)
  28.         (*      NOTE: Some procedures commented out, because I  *)
  29.         (*      haven't yet worked out the details.             *)
  30.         (*                                                      *)
  31.         (********************************************************)
  32.  
  33. FROM SYSTEM IMPORT
  34.     (* type *)  CARD8, INT8, CARD16, INT16, ADDRESS;
  35.  
  36. FROM Types IMPORT
  37.     (* type *)  FarPointer;
  38.  
  39. (************************************************************************)
  40. (*                          BITWISE LOGIC                               *)
  41. (************************************************************************)
  42.  
  43. PROCEDURE IAND (first, second: CARDINAL): CARDINAL;
  44.  
  45.     (* Bit-by-bit logical AND.  *)
  46.  
  47. PROCEDURE IANDB (first, second: CARD8): CARD8;
  48.  
  49.     (* Bit-by-bit logical AND for bytes. *)
  50.  
  51. PROCEDURE IOR (first, second: CARDINAL): CARDINAL;
  52.  
  53.     (* Bit-by-bit inclusive OR. *)
  54.  
  55. PROCEDURE IORB (first, second: CARD8): CARD8;
  56.  
  57.     (* Bit-by-bit inclusive OR. *)
  58.  
  59. PROCEDURE IXOR (first, second: CARDINAL): CARDINAL;
  60.  
  61.     (* Bit-by-bit exclusive OR. *)
  62.  
  63. PROCEDURE IXORB (first, second: CARD8): CARD8;
  64.  
  65.     (* Bit-by-bit exclusive OR. *)
  66.  
  67. PROCEDURE INOT (value: CARDINAL): CARDINAL;
  68.  
  69.     (* Bit-by-bit Boolean complement.   *)
  70.  
  71. PROCEDURE INOTB (value: CARD8): CARD8;
  72.  
  73.     (* Bit-by-bit Boolean complement.   *)
  74.  
  75. PROCEDURE ROL (value: CARDINAL;  count: CARDINAL): CARDINAL;
  76.  
  77.     (* Left rotation of "value" by "count" bit positions.       *)
  78.  
  79. PROCEDURE ROLB (value: CARD8;  count: CARDINAL): CARD8;
  80.  
  81.     (* Left rotation of "value" by "count" bit positions.       *)
  82.  
  83. PROCEDURE LS (value: CARDINAL;  count: CARDINAL): CARDINAL;
  84.  
  85.     (* Left shift of "value" by "count" bit positions, with zero fill.  *)
  86.  
  87. PROCEDURE LSB (value: CARD8;  count: CARDINAL): CARD8;
  88.  
  89.     (* Left shift of "value" by "count" bit positions, with zero fill.  *)
  90.  
  91. PROCEDURE ROR (value: CARDINAL;  count: CARDINAL): CARDINAL;
  92.  
  93.     (* Right rotation of "value" by "count" bit positions.      *)
  94.  
  95. PROCEDURE RORB (value: CARD8;  count: CARDINAL): CARD8;
  96.  
  97.     (* Right rotation of "value" by "count" bit positions.      *)
  98.  
  99. PROCEDURE RS (value, count: CARDINAL): CARDINAL;
  100.  
  101.     (* Right shift of "value" by "count" bit positions, with zero fill. *)
  102.  
  103. PROCEDURE RSB (value: CARD8;  count: CARDINAL): CARD8;
  104.  
  105.     (* Right shift of "value" by "count" bit positions, with zero fill. *)
  106.  
  107. (************************************************************************)
  108. (*                          POINTER OPERATIONS                          *)
  109. (************************************************************************)
  110.  
  111. PROCEDURE Far (A: ADDRESS): FarPointer;
  112.  
  113.     (* Converts a pointer to a far pointer. *)
  114.  
  115. PROCEDURE MakePointer (segment: CARD16; offset: CARDINAL): FarPointer;
  116.  
  117.     (* Creates a pointer, given the segment and offset within segment.  *)
  118.  
  119. PROCEDURE SEGMENT (A: ADDRESS): CARD16;
  120.  
  121.     (* Returns the segment part of an address.  *)
  122.  
  123. PROCEDURE FarSEGMENT (A: FarPointer): CARD16;
  124.  
  125.     (* Returns the segment part of an address.  *)
  126.  
  127. PROCEDURE OFFSET (A: ADDRESS): CARDINAL;
  128.  
  129.     (* Returns the offset part of an address.   *)
  130.  
  131. PROCEDURE AddOffset (A: ADDRESS;  increment: CARDINAL): ADDRESS;
  132.  
  133.     (* Returns a pointer to the memory location whose physical address  *)
  134.     (* is Physical(A)+increment.  In the present version, it is assumed *)
  135.     (* that the caller will never try to run off the end of a segment.  *)
  136.  
  137. PROCEDURE SubtractOffset (A: ADDRESS;  decrement: CARDINAL): ADDRESS;
  138.  
  139.     (* Like AddOffset, except that we go backwards in memory.  Running  *)
  140.     (* off the beginning of the segment is an undetected error.         *)
  141.  
  142. PROCEDURE FarAddOffset (A: FarPointer;  increment: CARDINAL): FarPointer;
  143.  
  144.     (* Like AddOffset, except for the parameter types. *)
  145.  
  146. PROCEDURE FarSubtractOffset (A: FarPointer; decrement: CARDINAL): FarPointer;
  147.  
  148.     (* Like SubtractOffset, except for the parameter types. *)
  149.  
  150. (*PROCEDURE Virtual (PA: LONGCARD): FarPointer;*)
  151.  
  152.     (* Converts a physical address to a virtual address, if possible.   *)
  153.     (* There are no guarantees in the case where there is no such       *)
  154.     (* virtual address.                                                 *)
  155.  
  156. (*PROCEDURE Physical (A: ADDRESS): LONGCARD;*)
  157.  
  158.     (* Converts a virtual address to a physical address.  Use with care!*)
  159.  
  160. (************************************************************************)
  161. (*                      BYTE/WORD/LONGCARD CONVERSIONS                  *)
  162. (************************************************************************)
  163.  
  164. PROCEDURE LowByte (w: CARDINAL): CARD8;
  165.  
  166.     (* Returns the low-order byte of its argument.      *)
  167.  
  168. PROCEDURE HighByte (w: CARD16): CARD8;
  169.  
  170.     (* Returns the high-order byte of its argument.     *)
  171.  
  172. PROCEDURE MakeWord (high, low: CARD8): CARD16;
  173.  
  174.     (* Combines two bytes into a word.  The first argument becomes the  *)
  175.     (* most significant byte of the result.                             *)
  176.  
  177. PROCEDURE SignExtend (val: INT8): INTEGER;
  178.  
  179.     (* Converts a signed 8-bit number to signed integer. *)
  180.  
  181. PROCEDURE LowWord (w: CARDINAL): CARD16;
  182.  
  183.     (* Returns the low-order word of its argument.      *)
  184.  
  185. PROCEDURE HighWord (w: CARDINAL): CARD16;
  186.  
  187.     (* Returns the high-order word of its argument.     *)
  188.  
  189. PROCEDURE MakeLongword (high, low: CARD16): CARDINAL;
  190.  
  191.     (* Combines two words into a longword.  The first argument becomes  *)
  192.     (* the most significant word of the result.                         *)
  193.  
  194. (************************************************************************)
  195. (*                      MISCELLANEOUS ARITHMETIC                        *)
  196. (************************************************************************)
  197.  
  198. PROCEDURE INCV (VAR (*INOUT*) dest: CARDINAL;  src: CARDINAL): BOOLEAN;
  199.  
  200.     (* Computes dest := dest + src, and returns TRUE iff the addition   *)
  201.     (* produced a carry.                                                *)
  202.  
  203. PROCEDURE INCVB (VAR (*INOUT*) dest: CARD8;  src: CARD8): BOOLEAN;
  204.  
  205.     (* Computes dest := dest + src, and returns TRUE iff the addition   *)
  206.     (* produced a carry.                                                *)
  207.  
  208. PROCEDURE DECV (VAR (*INOUT*) dest: CARDINAL;  src: CARDINAL): BOOLEAN;
  209.  
  210.     (* Computes dest := dest - src, and returns TRUE iff the            *)
  211.     (* subtraction produced a borrow.                                   *)
  212.  
  213. PROCEDURE DECVB (VAR (*INOUT*) dest: CARD8;  src: CARD8): BOOLEAN;
  214.  
  215.     (* Computes dest := dest - src, and returns TRUE iff the            *)
  216.     (* subtraction produced a borrow.                                   *)
  217.  
  218. PROCEDURE Mul (A, B: CARD16): CARDINAL;
  219.  
  220.     (* Same as A*B, except for the type of the result.  We provide this *)
  221.     (* as a general-purpose function since this combination of operands *)
  222.     (* is often precisely what is wanted.                               *)
  223.  
  224. PROCEDURE MulB (A, B: CARD8): CARD16;
  225.  
  226.     (* Same as A*B, except for the type of the result.  We provide this *)
  227.     (* as a general-purpose function since this combination of operands *)
  228.     (* is often precisely what is wanted.                               *)
  229.  
  230. PROCEDURE IMul (A, B: INT16): INTEGER;
  231.  
  232.     (* Like Mul, but signed. *)
  233.  
  234. PROCEDURE IMulB (A, B: INT8): INT16;
  235.  
  236.     (* Like MulB, but signed. *)
  237.  
  238. PROCEDURE DivB (A: CARD16;  B: CARD8): CARD8;
  239.  
  240.     (* Same as A DIV B, except for the type of A.  We provide this as   *)
  241.     (* a general-purpose function since this combination of operands    *)
  242.     (* is often precisely what is wanted.                               *)
  243.  
  244. PROCEDURE Div (A: CARDINAL;  B: CARD16): CARD16;
  245.  
  246.     (* Same as A DIV B, except for the type of A.  We provide this as   *)
  247.     (* a general-purpose function since this combination of operands    *)
  248.     (* is often precisely what is wanted.                               *)
  249.  
  250. (************************************************************************)
  251. (*                           BLOCK MOVES                                *)
  252. (************************************************************************)
  253.  
  254. PROCEDURE Copy (source, destination: ADDRESS;  bytecount: CARDINAL);
  255.  
  256.     (* Copies an array of bytes from the source address to the          *)
  257.     (* destination address.  In the case where the two arrays overlap,  *)
  258.     (* the destination address should be lower in physical memory than  *)
  259.     (* the source address.                                              *)
  260.  
  261. PROCEDURE FarCopy (source, destination: FarPointer;  bytecount: CARDINAL);
  262.  
  263.     (* Copies an array of bytes from the source address to the          *)
  264.     (* destination address.  In the case where the two arrays overlap,  *)
  265.     (* the destination address should be lower in physical memory than  *)
  266.     (* the source address.                                              *)
  267.  
  268. PROCEDURE CopyUp (source, destination: FarPointer;  bytecount: CARDINAL);
  269.  
  270.     (* A variant of Copy which does the move backwards, in order        *)
  271.     (* to handle the case where the destination address is inside the   *)
  272.     (* source array.  In this special case Copy cannot be used,         *)
  273.     (* because it would overwrite data it was about to copy.            *)
  274.  
  275. PROCEDURE BlockFill (destination: FarPointer;
  276.                                 bytecount: CARDINAL;  value: CARD8);
  277.  
  278.     (* Fills the destination array with the given value.        *)
  279.  
  280. PROCEDURE BlockFillWord (destination: FarPointer;  wordcount: CARDINAL;
  281.                                                         value: CARD16);
  282.  
  283.     (* Fills the destination array with the given value.        *)
  284.  
  285. (************************************************************************)
  286. (*                          INPUT AND OUTPUT                            *)
  287. (*           I haven't yet worked out how to do this in OS/2            *)
  288. (************************************************************************)
  289.  
  290. (*PROCEDURE OutByte (port: CARDINAL; value: BYTE);*)
  291.  
  292.     (* Puts the value out to an output port.    *)
  293.  
  294. (*PROCEDURE InByte (port: CARDINAL): BYTE;*)
  295.  
  296.     (* Reads a byte from an input port. *)
  297.  
  298. (*PROCEDURE InStringWord (port: CARDINAL;  BufferAddress: ADDRESS;
  299.                                                 count: CARDINAL); *)
  300.  
  301.     (* Reads count words from an input port.    *)
  302.  
  303. (*PROCEDURE OutStringWord (port: CARDINAL;  BufferAddress: ADDRESS;
  304.                                                 count: CARDINAL);*)
  305.  
  306.     (* Writes count words to an output port.    *)
  307.  
  308. END LowLevel.
  309.