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

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