note description : "[ Utility functions for a HD44780 custom character generator {HD44780_CHARACTER_GENERATOR}. ]" author : "Paul Bates" revision : "$Revision$" date : "$Date$" class HD44780_CHARACTER_UTILITY feature -- Basic Operations xor_character (a_char: ARRAY [NATURAL_8]; a_other_char: ARRAY [NATURAL_8]): ARRAY [NATURAL_8] -- XORs two character maps together. -- -- 'a_char': Source character map. -- `a_other_char': Another character map to xor `a_char' with. -- `Result': The XOR merge result of the two supplied character maps. require a_char_attached: attached a_char a_other_char_attached: attached a_other_char local l_max_count: INTEGER l_min_count: INTEGER l_lower: INTEGER l_other_lower: INTEGER l_char: NATURAL_8 i: INTEGER do l_max_count := a_char.count.max (a_other_char.count) l_min_count := a_char.count.min (a_other_char.count) create Result.make (1, l_min_count) l_lower := a_char.lower l_other_lower := a_other_char.lower from i := 0 until i > l_max_count loop if i > l_lower then l_char := a_other_char[i + l_lower] elseif i > l_other_lower then l_char := a_char[i + l_lower] else l_char := (a_char[i + l_lower]).bit_xor (a_other_char[i + l_other_lower]) & 0b11111 end Result.put (l_char, i + 1) i := i + 1 end ensure result_attached: attached Result result_count_matched: Result.count = a_char.count.max (a_other_char.count) end invert_character (a_char: ARRAY [NATURAL_8]): ARRAY [NATURAL_8] -- Inverts the data in a character map. -- -- 'a_char': Source character map to invert. -- `Result': The new inverted character map require a_char_attached: attached a_char local l_upper, i: INTEGER do i := a_char.lower l_upper := a_char.upper create Result.make (i, l_upper) from until i > l_upper loop Result.put ((a_char[i]).bit_not & 0b11111, i) i := i + 1 end ensure result_attached: attached Result result_count_matched: Result.count = a_char.count end end