def _get_values_sliced(index, value): """ Given the list of values retrieved in a get, combine into words if necessary, or delist if no stop value provided. """ if index.step is None or index.step == 1: pass elif index.step == 2: value = vm.to_words(value) else: raise ValueError('Invalid step: {}'.format(index.step)) if index.stop is None: value = value[0] return value
def _format_instruction(self): """ Formats the instruction name and arguments. """ i = self.instruction try: formatter, has_argument = FORMAT_TABLE[i.addressing_mode] except KeyError: raise ValueError('Invalid addressing mode: ' + str(i.addressing_mode)) if not has_argument: return formatter.format(i.operation) if self.argument is None: # Format the raw bytes if len(self.bytes) == 2: arg = vm.hex8(self.bytes[1]) else: arg = vm.hex16(vm.to_words(self.bytes[1:3])[0]) else: arg = self.argument return formatter.format(i.operation, arg)
def test_to_words(self): self.assertEquals([0x1234, 0x5678], vm.to_words([0x34, 0x12, 0x78, 0x56]))