| 1 |
(* BitWordOps.def provides a Logitech-3.0 compatible library. |
| 2 |
|
| 3 |
Copyright (C) 2007-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 8 |
GNU Modula-2 is free software; you can redistribute it and/or modify |
| 9 |
it under the terms of the GNU General Public License as published by |
| 10 |
the Free Software Foundation; either version 3, or (at your option) |
| 11 |
any later version. |
| 12 |
|
| 13 |
GNU Modula-2 is distributed in the hope that it will be useful, but |
| 14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
General Public License for more details. |
| 17 |
|
| 18 |
Under Section 7 of GPL version 3, you are granted additional |
| 19 |
permissions described in the GCC Runtime Library Exception, version |
| 20 |
3.1, as published by the Free Software Foundation. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License and |
| 23 |
a copy of the GCC Runtime Library Exception along with this program; |
| 24 |
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 25 |
<http://www.gnu.org/licenses/>. *) |
| 26 |
|
| 27 |
DEFINITION MODULE BitWordOps ; |
| 28 |
|
| 29 |
FROM SYSTEM IMPORT WORD ; |
| 30 |
|
| 31 |
|
| 32 |
(* |
| 33 |
GetBits - returns the bits firstBit..lastBit from source. |
| 34 |
Bit 0 of word maps onto the firstBit of source. |
| 35 |
*) |
| 36 |
|
| 37 |
PROCEDURE GetBits (source: WORD; firstBit, lastBit: CARDINAL) : WORD ; |
| 38 |
|
| 39 |
|
| 40 |
(* |
| 41 |
SetBits - sets bits in, word, starting at, firstBit, and ending at, |
| 42 |
lastBit, with, pattern. The bit zero of, pattern, will |
| 43 |
be placed into, word, at position, firstBit. |
| 44 |
*) |
| 45 |
|
| 46 |
PROCEDURE SetBits (VAR word: WORD; firstBit, lastBit: CARDINAL; |
| 47 |
pattern: WORD) ; |
| 48 |
|
| 49 |
|
| 50 |
(* |
| 51 |
WordAnd - returns a bitwise (left AND right) |
| 52 |
*) |
| 53 |
|
| 54 |
PROCEDURE WordAnd (left, right: WORD) : WORD ; |
| 55 |
|
| 56 |
|
| 57 |
(* |
| 58 |
WordOr - returns a bitwise (left OR right) |
| 59 |
*) |
| 60 |
|
| 61 |
PROCEDURE WordOr (left, right: WORD) : WORD ; |
| 62 |
|
| 63 |
|
| 64 |
(* |
| 65 |
WordXor - returns a bitwise (left XOR right) |
| 66 |
*) |
| 67 |
|
| 68 |
PROCEDURE WordXor (left, right: WORD) : WORD ; |
| 69 |
|
| 70 |
|
| 71 |
(* |
| 72 |
WordNot - returns a word with all bits inverted. |
| 73 |
*) |
| 74 |
|
| 75 |
PROCEDURE WordNot (word: WORD) : WORD ; |
| 76 |
|
| 77 |
|
| 78 |
(* |
| 79 |
WordShr - returns a, word, which has been shifted, count |
| 80 |
bits to the right. |
| 81 |
*) |
| 82 |
|
| 83 |
PROCEDURE WordShr (word: WORD; count: CARDINAL) : WORD ; |
| 84 |
|
| 85 |
|
| 86 |
(* |
| 87 |
WordShl - returns a, word, which has been shifted, count |
| 88 |
bits to the left. |
| 89 |
*) |
| 90 |
|
| 91 |
PROCEDURE WordShl (word: WORD; count: CARDINAL) : WORD ; |
| 92 |
|
| 93 |
|
| 94 |
(* |
| 95 |
WordSar - shift word arthemetic right. Preserves the top |
| 96 |
end bit and as the value is shifted right. |
| 97 |
*) |
| 98 |
|
| 99 |
PROCEDURE WordSar (word: WORD; count: CARDINAL) : WORD ; |
| 100 |
|
| 101 |
|
| 102 |
(* |
| 103 |
WordRor - returns a, word, which has been rotated, count |
| 104 |
bits to the right. |
| 105 |
*) |
| 106 |
|
| 107 |
PROCEDURE WordRor (word: WORD; count: CARDINAL) : WORD ; |
| 108 |
|
| 109 |
|
| 110 |
(* |
| 111 |
WordRol - returns a, word, which has been rotated, count |
| 112 |
bits to the left. |
| 113 |
*) |
| 114 |
|
| 115 |
PROCEDURE WordRol (word: WORD; count: CARDINAL) : WORD ; |
| 116 |
|
| 117 |
|
| 118 |
(* |
| 119 |
HighByte - returns the top byte only from, word. |
| 120 |
The byte is returned in the bottom byte |
| 121 |
in the return value. |
| 122 |
*) |
| 123 |
|
| 124 |
PROCEDURE HighByte (word: WORD) : WORD ; |
| 125 |
|
| 126 |
|
| 127 |
(* |
| 128 |
LowByte - returns the low byte only from, word. |
| 129 |
The byte is returned in the bottom byte |
| 130 |
in the return value. |
| 131 |
*) |
| 132 |
|
| 133 |
PROCEDURE LowByte (word: WORD) : WORD ; |
| 134 |
|
| 135 |
|
| 136 |
(* |
| 137 |
Swap - byte flips the contents of word. |
| 138 |
*) |
| 139 |
|
| 140 |
PROCEDURE Swap (word: WORD) : WORD ; |
| 141 |
|
| 142 |
|
| 143 |
END BitWordOps. |