read from 0xff03 -> PIA 0 B side Control reg.
491031
def read_PIA0_B_control(self, cpu_cycles, op_address, address):
        
        value = self.pia_0_B_control.value
        log.error(
            "%04x| read $%04x (PIA 0 B side Control reg.) send $%02x (%s) back.\t|%s",
            op_address, address, value, byte2bit_string(value),
            self.cfg.mem_info.get_shortest(op_address)
        )
        return value
25216
def _winpath2bytes_py3(text, codec):
    """"""

    # merge surrogate codepoints
    if _normalize_codec(codec).startswith("utf-16"):
        # fast path, utf-16 merges anyway
        return text.encode(codec, _surrogatepass)
    return _decode_surrogatepass(
        text.encode("utf-16-le", _surrogatepass),
        "utf-16-le").encode(codec, _surrogatepass)
1288964
def _read_execute_info(path, parents):
  """"""
  path = os.path.join(path, "StarCraft II/ExecuteInfo.txt")
  if os.path.exists(path):
    with open(path, "rb") as f:  # Binary because the game appends a '\0' :(.
      for line in f:
        parts = [p.strip() for p in line.decode("utf-8").split("=")]
        if len(parts) == 2 and parts[0] == "executable":
          exec_path = parts[1].replace("\\", "/")  # For windows compatibility.
          for _ in range(parents):
            exec_path = os.path.dirname(exec_path)
          return exec_path
885308
def _parse(self, registers):
        """"""
        result = {'ip': self.ip, 'connected': True}
        decoder = BinaryPayloadDecoder.fromRegisters(registers,
                                                     byteorder=Endian.Big,
                                                     wordorder=Endian.Little)
        # Register 40001 is a collection of alarm status signals
        b = [decoder.decode_bits(), decoder.decode_bits()]
        reg_40001 = b[1] + b[0]
        # Bits 0-3 map to the monitor state
        monitor_integer = sum(1 << i for i, b in enumerate(reg_40001[:4]) if b)
        result['state'] = options['monitor state'][monitor_integer]
        # Bits 4-5 map to fault status
        fault_integer = sum(1 << i for i, b in enumerate(reg_40001[4:6]) if b)
        result['fault'] = {'status': options['fault status'][fault_integer]}
        # Bits 6 and 7 tell if low and high alarms are active
        low, high = reg_40001[6:8]
        result['alarm'] = options['alarm level'][low + high]
        # Bits 8-10 tell if internal sensor relays 1-3 are energized. Skipping.
        # Bit 11 is a heartbeat bit that toggles every two seconds. Skipping.
        # Bit 12 tells if relays are under modbus control. Skipping.
        # Remaining bits are empty. Skipping.
        # Register 40002 has a gas ID and a sensor cartridge ID. Skipping.
        decoder._pointer += 2
        # Registers 40003-40004 are the gas concentration as a float
        result['concentration'] = decoder.decode_32bit_float()
        # Register 40005 is the concentration as an int. Skipping.
        decoder._pointer += 2
        # Register 40006 is the number of the most important fault.
        fault_number = decoder.decode_16bit_uint()
        if fault_number != 0:
            code = ('m' if fault_number < 30 else 'F') + str(fault_number)
            result['fault']['code'] = code
            result['fault'].update(faults[code])
        # Register 40007 holds the concentration unit in the second byte
        # Instead of being an int, it's the position of the up bit
        unit_bit = decoder.decode_bits().index(True)
        result['units'] = options['concentration unit'][unit_bit]
        decoder._pointer += 1
        # Register 40008 holds the sensor temperature in Celsius
        result['temperature'] = decoder.decode_16bit_int()
        # Register 40009 holds number of hours remaining in cell life
        result['life'] = decoder.decode_16bit_uint() / 24.0
        # Register 40010 holds the number of heartbeats (16 LSB). Skipping.
        decoder._pointer += 2
        # Register 40011 is the sample flow rate in cc / min
        result['flow'] = decoder.decode_16bit_uint()
        # Register 40012 is blank. Skipping.
        decoder._pointer += 2
        # Registers 40013-40016 are the alarm concentration thresholds
        result['low-alarm threshold'] = round(decoder.decode_32bit_float(), 6)
        result['high-alarm threshold'] = round(decoder.decode_32bit_float(), 6)
        # Despite what the manual says, thresholds are always reported in ppm.
        # Let's fix that to match the concentration units.
        if result['units'] == 'ppb':
            result['concentration'] *= 1000
            result['low-alarm threshold'] *= 1000
            result['high-alarm threshold'] *= 1000
        return result
977168
public int /* reg12 */output() {
		// It may seem cleaner to use an array of member functions to return
		// waveform output; however a switch with inline functions is faster.

		switch (waveform) {
		default:
		case 0x0:
			return output____();
		case 0x1:
			return output___T();
		case 0x2:
			return output__S_();
		case 0x3:
			return output__ST();
		case 0x4:
			return output_P__();
		case 0x5:
			return output_P_T();
		case 0x6:
			return output_PS_();
		case 0x7:
			return output_PST();
		case 0x8:
			return outputN___();
		case 0x9:
			return outputN__T();
		case 0xa:
			return outputN_S_();
		case 0xb:
			return outputN_ST();
		case 0xc:
			return outputNP__();
		case 0xd:
			return outputNP_T();
		case 0xe:
			return outputNPS_();
		case 0xf:
			return outputNPST();
		}
	}
504578
private byte[] doCipher(byte[] input, int mode) throws
            DecoderException, InvalidKeyException, InvalidAlgorithmParameterException,
            IllegalBlockSizeException, BadPaddingException, EncoderException
    {
        if (input == null)
        {
            return null;
        }

        if (cipher == null)
        {
            throw new IllegalStateException("setCipher() has not been called.");
        }

        if (key == null && certificate == null)
        {
            throw new IllegalStateException("setInit() has not been called.");
        }

        if (mode == Cipher.DECRYPT_MODE)
        {
            input = decode(input);
        }

        initCipher(mode);

        byte[] output = cipher.doFinal(input);

        if (mode == Cipher.ENCRYPT_MODE)
        {
            output = encode(output);
        }

        return output;
    }
1199784
def get_trigger_data(value, mode=0):
    '''
    '''
    if mode == 2:
        return np.right_shift(np.bitwise_and(value, 0x7FFF0000), 16), np.bitwise_and(value, 0x0000FFFF)
    else:
        return np.bitwise_and(value, 0x7FFFFFFF)
424233
def vgcsUplinkGrant():
    """"""
    a = TpPd(pd=0x6)
    b = MessageType(mesType=0x9)  # 00001001
    c = RrCause()
    d = RequestReference()
    e = TimingAdvance()
    packet = a / b / c / d / e
    return packet
391884
def read_instruction(fio, start_pos):
    
    op = fio.read(1)

    if not op:
        return None

    op = ord(op)

    ins = opcode_table[op]
    operands = ins['operands']
    name = ins['mnemonic']

    final_operands = []
    # Most opcodes have simple operands.
    if operands:
        for fmt, type_ in operands:
            final_operands.append(
                Operand(
                    type_,
                    fmt.value.unpack(fio.read(fmt.value.size))[0]
                )
            )
    # Special case for lookupswitch.
    elif op == 0xAB:
        # Get rid of the alignment padding.
        padding = 4 - (start_pos + 1) % 4
        padding = padding if padding != 4 else 0
        fio.read(padding)

        # Default branch address and branch count.
        default, npairs = unpack('>ii', fio.read(8))

        pairs = {}
        for _ in repeat(None, npairs):
            match, offset = unpack('>ii', fio.read(8))
            pairs[match] = offset

        final_operands.append(pairs)
        final_operands.append(Operand(OperandTypes.BRANCH, default))
    # Special case for tableswitch
    elif op == 0xAA:
        # Get rid of the alignment padding.
        padding = 4 - (start_pos + 1) % 4
        padding = padding if padding != 4 else 0
        fio.read(padding)

        default, low, high = unpack('>iii', fio.read(12))
        final_operands.append(Operand(OperandTypes.BRANCH, default))
        final_operands.append(Operand(OperandTypes.LITERAL, low))
        final_operands.append(Operand(OperandTypes.LITERAL, high))

        for _ in repeat(None, high - low + 1):
            offset = unpack('>i', fio.read(4))[0]
            final_operands.append(Operand(OperandTypes.BRANCH, offset))
    # Special case for the wide prefix
    elif op == 0xC4:
        real_op = unpack('>B', fio.read(1))[0]
        ins = opcode_table[real_op]
        name = ins['mnemonic']

        final_operands.append(Operand(
            OperandTypes.LOCAL_INDEX,
            unpack('>H', fio.read(2))[0]
        ))
        # Further special case for iinc.
        if real_op == 0x84:
            final_operands.append(Operand(
                OperandTypes.LITERAL,
                unpack('>H', fio.read(2))[0]
            ))

    return Instruction(name, op, final_operands, start_pos)
546186
def read_vint32(self):
        
        result = 0
        count = 0
        while True:
            if count > 4:
                raise ValueError("Corrupt VarInt32")

            b = self.read_byte()
            result = result | (b & 0x7F) << (7 * count)
            count += 1

            if not b & 0x80:
                return result
1082882
def single_read(self, register):
        '''
         
        '''
        
        comm_reg = (0b00010 << 3) + register

        if register == self.AD7730_STATUS_REG:
            bytes_num = 1
        elif register == self.AD7730_DATA_REG:
            bytes_num = 3
        elif register == self.AD7730_MODE_REG:
            bytes_num = 2
        elif register == self.AD7730_FILTER_REG:
            bytes_num = 3
        elif register == self.AD7730_DAC_REG:
            bytes_num = 1
        elif register == self.AD7730_OFFSET_REG:
            bytes_num = 3
        elif register == self.AD7730_GAIN_REG:
            bytes_num = 3
        elif register == self.AD7730_TEST_REG:
            bytes_num = 3

        command = [comm_reg] + ([0x00] * bytes_num)
        spi.SPI_write(self.CS, command)
        data = spi.SPI_read(bytes_num + 1)        
        return data[1:]
471762
def systemInformationType3():
    """"""
    a = L2PseudoLength(l2pLength=0x12)
    b = TpPd(pd=0x6)
    c = MessageType(mesType=0x1b)  # 00011011
    d = CellIdentity()
    e = LocalAreaId()
    f = ControlChannelDescription()
    g = CellOptionsBCCH()
    h = CellSelectionParameters()
    i = RachControlParameters()
    j = Si3RestOctets()
    packet = a / b / c / d / e / f / g / h / i / j
    return packet
947557
def cipheringModeCommand():
    """"""
    a = TpPd(pd=0x6)
    b = MessageType(mesType=0x35)  # 00110101
    c = RrCause()
 #d=cipherModeSetting()
 #e=cipherResponse()
 # FIX
    d = CipherModeSettingAndcipherResponse()
    packet = a / b / c / d
    return packet
262506
def _read_regpol_file(reg_pol_path):
    '''
    
    '''
    returndata = None
    if os.path.exists(reg_pol_path):
        with salt.utils.files.fopen(reg_pol_path, 'rb') as pol_file:
            returndata = pol_file.read()
    return returndata
417946
def readGyroRange( self ):
        
        raw_data = self._readByte( self.REG_GYRO_CONFIG )
        raw_data = (raw_data | 0xE7) ^ 0xE7
        return raw_data
883538
def get_raw_input_register(self, name):
        """"""
        if self._update_on_read:
            self.update()
        return self._input_regs[name]
487318
def check_power_raw(self):
    """"""
    packet = bytearray(16)
    packet[0x00] = 0x0a
    packet[0x02] = 0xa5
    packet[0x03] = 0xa5
    packet[0x04] = 0x5a
    packet[0x05] = 0x5a
    packet[0x06] = 0xae
    packet[0x07] = 0xc0
    packet[0x08] = 0x01

    response = self.send_packet(0x6a, packet)
    err = response[0x22] | (response[0x23] << 8)
    if err == 0:
      payload = self.decrypt(bytes(response[0x38:]))
      if type(payload[0x4]) == int:
        state = payload[0x0e]
      else:
        state = ord(payload[0x0e])
      return state