1 (* BitWordOps.def provides a Logitech-3.0 compatible library.
3 Copyright (C) 2007-2023 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
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)
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.
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.
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/>. *)
27 DEFINITION MODULE BitWordOps ;
29 FROM SYSTEM IMPORT WORD ;
33 GetBits - returns the bits firstBit..lastBit from source.
34 Bit 0 of word maps onto the firstBit of source.
37 PROCEDURE GetBits (source: WORD; firstBit, lastBit: CARDINAL) : WORD ;
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.
46 PROCEDURE SetBits (VAR word: WORD; firstBit, lastBit: CARDINAL;
51 WordAnd - returns a bitwise (left AND right)
54 PROCEDURE WordAnd (left, right: WORD) : WORD ;
58 WordOr - returns a bitwise (left OR right)
61 PROCEDURE WordOr (left, right: WORD) : WORD ;
65 WordXor - returns a bitwise (left XOR right)
68 PROCEDURE WordXor (left, right: WORD) : WORD ;
72 WordNot - returns a word with all bits inverted.
75 PROCEDURE WordNot (word: WORD) : WORD ;
79 WordShr - returns a, word, which has been shifted, count
83 PROCEDURE WordShr (word: WORD; count: CARDINAL) : WORD ;
87 WordShl - returns a, word, which has been shifted, count
91 PROCEDURE WordShl (word: WORD; count: CARDINAL) : WORD ;
95 WordSar - shift word arthemetic right. Preserves the top
96 end bit and as the value is shifted right.
99 PROCEDURE WordSar (word: WORD; count: CARDINAL) : WORD ;
103 WordRor - returns a, word, which has been rotated, count
107 PROCEDURE WordRor (word: WORD; count: CARDINAL) : WORD ;
111 WordRol - returns a, word, which has been rotated, count
115 PROCEDURE WordRol (word: WORD; count: CARDINAL) : WORD ;
119 HighByte - returns the top byte only from, word.
120 The byte is returned in the bottom byte
124 PROCEDURE HighByte (word: WORD) : WORD ;
128 LowByte - returns the low byte only from, word.
129 The byte is returned in the bottom byte
133 PROCEDURE LowByte (word: WORD) : WORD ;
137 Swap - byte flips the contents of word.
140 PROCEDURE Swap (word: WORD) : WORD ;