note description: "[ Represents a single 8-bit register on a parallel port connection. ]" legal : "See notice at end of class." status : "See notice at end of class."; author : "Paul Bates (paul.a.bates@gmail.com)" date : "$Date$" revision: "$Revision$" deferred class PRT_PARALLEL_REGISTER inherit USABLE_I feature {NONE} -- Initialization make (a_connection: like connection) -- Creates and initializes a parallel port register. -- -- `a_connection': A parallel port connection to use the register with. require a_connection_attached: attached a_connection a_connection_is_interface_usable: a_connection.is_interface_usable do connection := a_connection ensure connection_set: connection = a_connection end feature -- Access data: NATURAL_8 assign set_data -- Last read data from `read', or current data. data_bit_mask: NATURAL_8 -- Register's data bit mask. deferred ensure result_non_zero: Result /= 0 end type: PRT_PARALLEL_REGISTER_TYPE -- Port register type. deferred end feature {NONE} -- Access connection: PRT_PARALLEL_CONNECTION -- Connection to parallel port connection_address_offset: NATURAL_8 -- Register address offset, in bytes. do Result := type.item end feature -- Element change set_data (a_data: like data) -- Sets register's data. -- Note: This routine does not actually send the data to the parallel port. Call `flush' when the -- client has finished setting the data. -- -- `a_data': The data to set. require is_interface_usable: is_interface_usable a_data_is_compatible_data: is_compatible_data (a_data) do data := a_data ensure data_set: data = a_data end feature -- Status report is_interface_usable: BOOLEAN -- do Result := connection.is_interface_usable ensure then result_implies_connection_is_usable: Result implies connection.is_interface_usable end is_readable: BOOLEAN -- Indicates if the register can be read from. do Result := is_interface_usable and then connection.is_readable ensure is_interface_usable: Result implies is_interface_usable connection_is_readable: Result implies connection.is_readable end is_writable: BOOLEAN -- Indicates if the register can be written to. do Result := is_interface_usable and then connection.is_writable ensure is_interface_usable: Result implies is_interface_usable connection_is_readable: Result implies connection.is_writable end bit_0: BOOLEAN assign set_bit_0 -- Bit 0 register state. -- Note: Be sure to call `receive' to query the register's state. do Result := ({NATURAL_8} 0b00000001 & data) = 1 end bit_1: BOOLEAN assign set_bit_1 -- Bit 1 register state. -- Note: Be sure to call `receive' to query the register's state. do Result := ({NATURAL_8} 0b00000010 & data) = 1 end bit_2: BOOLEAN assign set_bit_2 -- Bit 2 register state. -- Note: Be sure to call `receive' to query the register's state. do Result := ({NATURAL_8} 0b00000100 & data) = 1 end bit_3: BOOLEAN assign set_bit_3 -- Bit 3 register state. -- Note: Be sure to call `receive' to query the register's state. do Result := ({NATURAL_8} 0b00001000 & data) = 1 end bit_4: BOOLEAN assign set_bit_4 -- Bit 4 register state. -- Note: Be sure to call `receive' to query the register's state. do Result := ({NATURAL_8} 0b00010000 & data) = 1 end bit_5: BOOLEAN assign set_bit_5 -- Bit 5 register state. -- Note: Be sure to call `receive' to query the register's state. do Result := ({NATURAL_8} 0b00100000 & data) = 1 end bit_6: BOOLEAN assign set_bit_6 -- Bit 6 register state. -- Note: Be sure to call `receive' to query the register's state. do Result := ({NATURAL_8} 0b01000000 & data) = 1 end bit_7: BOOLEAN assign set_bit_7 -- Bit 7 register state. -- Note: Be sure to call `receive' to query the register's state. do Result := ({NATURAL_8} 0b10000000 & data) = 1 end feature -- Status setting set_bit_0 (a_set: BOOLEAN) -- Sets bit 0 register state. -- Note: require is_writable: is_writable do if a_set then set_data ({NATURAL_8} 0b00000001 & data) else set_data ({NATURAL_8} 0b11111110 | data) end ensure bit_0_set: bit_0 = a_set end set_bit_1 (a_set: BOOLEAN) -- Sets bit 1 register state. require is_writable: is_writable do if a_set then set_data ({NATURAL_8} 0b00000010 & data) else set_data ({NATURAL_8} 0b11111101 | data) end ensure bit_1_set: bit_1 = a_set end set_bit_2 (a_set: BOOLEAN) -- Sets bit 2 register state. require is_writable: is_writable do if a_set then set_data ({NATURAL_8} 0b00000100 & data) else set_data ({NATURAL_8} 0b11111011 | data) end ensure bit_2_set: bit_2 = a_set end set_bit_3 (a_set: BOOLEAN) -- Sets bit 3 register state. require is_writable: is_writable do if a_set then set_data ({NATURAL_8} 0b00001000 & data) else set_data ({NATURAL_8} 0b11110111 | data) end ensure bit_3_set: bit_3 = a_set end set_bit_4 (a_set: BOOLEAN) -- Sets bit 4 register state. require is_writable: is_writable do if a_set then set_data ({NATURAL_8} 0b00010000 & data) else set_data ({NATURAL_8} 0b11101111 | data) end ensure bit_4_set: bit_4 = a_set end set_bit_5 (a_set: BOOLEAN) -- Sets bit 5 register state. require is_writable: is_writable do if a_set then set_data ({NATURAL_8} 0b00100000 & data) else set_data ({NATURAL_8} 0b11011111 | data) end ensure bit_5_set: bit_5 = a_set end set_bit_6 (a_set: BOOLEAN) -- Sets bit 6 register state. require is_writable: is_writable do if a_set then set_data ({NATURAL_8} 0b01000000 & data) else set_data ({NATURAL_8} 0b10111111 | data) end ensure bit_6_set: bit_6 = a_set end set_bit_7 (a_set: BOOLEAN) -- Sets bit 7 register state. require is_writable: is_writable do if a_set then set_data ({NATURAL_8} 0b10000000 & data) else set_data ({NATURAL_8} 0b01111111 | data) end ensure bit_7_set: bit_7 = a_set end feature -- Query frozen is_compatible_data (a_data: like data): BOOLEAN -- Determines if a data value is compatible for a given register -- -- `a_data': Data to determines register capability for. -- `Result': True if the data is compatible, False otherwise. do Result := data_bit_mask.bit_and (a_data) = a_data end feature -- Basic operations reset -- Resets any cached data, and readies for next operation do data := 0 end feature -- Read Operations read -- Reads register's data from parallel port. -- Note: `data' is modified as a result of calling this routine. require is_interface_usable: is_interface_usable is_readable: is_readable do reset data := connection.reader.receive_8 (connection_address_offset) end feature -- Write Operations send (a_data: like data) -- Sets `data' with the specified data and flushes it to parallel port. -- -- `a_data': The data to set and send. require is_interface_usable: is_interface_usable a_data_is_compatible_data: is_compatible_data (a_data) do reset set_data (a_data) flush ensure data_set: data = a_data end flush -- Flushes `data' to parallel port register. require is_interface_usable: is_interface_usable do connection.writer.send_8 (data, connection_address_offset) -- Reset cached data reset end invariant connection_attached: attached connection data_is_compatible_data: is_compatible_data (data) end