本文整理汇总了Python中status.Status.to_int方法的典型用法代码示例。如果您正苦于以下问题:Python Status.to_int方法的具体用法?Python Status.to_int怎么用?Python Status.to_int使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类status.Status
的用法示例。
在下文中一共展示了Status.to_int方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CPU
# 需要导入模块: from status import Status [as 别名]
# 或者: from status.Status import to_int [as 别名]
#.........这里部分代码省略.........
def get_memory(self, location: int, num_bytes: int=1) -> int:
"""
returns a byte from a given memory location
"""
memory_owner = self._get_memory_owner(location)
return memory_owner.get(location, num_bytes)
def _get_memory_owner(self, location: int) -> MemoryOwnerMixin:
"""
return the owner of a memory location
"""
# check if memory owner
for memory_owner in self.memory_owners:
if memory_owner.memory_start_location <= location <= memory_owner.memory_end_location:
return memory_owner
raise Exception('Cannot find memory owner')
def set_memory(self, location: int, value: int, num_bytes: int=1):
"""
sets the memory at a location to a value
"""
memory_owner = self._get_memory_owner(location)
memory_owner.set(location, value, num_bytes)
def set_stack_value(self, value: int, num_bytes: int):
"""
sets a value on the stack, and decrements the stack pointer
"""
# store the value on the stack
self.set_memory(self.stack_offset + self.sp_reg, value, num_bytes=num_bytes)
# increases the size of the stack
self.sp_reg -= np.uint8(num_bytes)
def get_stack_value(self, num_bytes: int):
"""
gets a value on the stack, and increments the stack pointer
"""
# decrease the size of the stack
self.sp_reg += np.uint8(num_bytes)
# grab the stored value from the stack
return self.get_memory(self.stack_offset + self.sp_reg, num_bytes=num_bytes)
def load_rom(self, rom: ROM, testing):
# unload old rom
if self.rom is not None:
self.memory_owners.remove(self.rom)
# load rom
self.rom = rom
# load the rom program instructions into memory
self.memory_owners.append(self.rom)
if testing:
self.pc_reg = np.uint16(0xC000)
else:
self.pc_reg = np.uint16(int.from_bytes(self.get_memory(0xFFFC, 2), byteorder='little'))
def identify(self):
# get the current byte at pc
rom_instruction = True
self.instruction_byte = self._get_memory_owner(self.pc_reg).get(self.pc_reg)
if type(self.instruction_byte) is not bytes:
rom_instruction = False
self.instruction_byte = bytes([self.instruction_byte])
# turn the byte into an Instruction
self.instruction = self.instructions.get(self.instruction_byte, None) # type: Instruction
if self.instruction is None:
raise Exception('Instruction not found: {}'.format(self.instruction_byte.hex()))
# get the data bytes
if rom_instruction:
self.data_bytes = self.rom.get(self.pc_reg + np.uint16(1), self.instruction.data_length)
else:
if self.instruction.data_length > 0:
self.data_bytes = bytes([self.get_memory(self.pc_reg + np.uint16(1), self.instruction.data_length)])
else:
self.data_bytes = bytes()
# print out diagnostic information
# example: C000 4C F5 C5 JMP $C5F5 A:00 X:00 Y:00 P:24 SP:FD CYC: 0
print('{}, {}, {}, A:{}, X:{}, Y:{}, P:{}, SP:{}'.format(hex(self.pc_reg),
(self.instruction_byte + self.data_bytes).hex(),
self.instruction.__name__, hex(self.a_reg),
hex(self.x_reg), hex(self.y_reg),
hex(self.status_reg.to_int()), hex(self.sp_reg)))
def execute(self):
# increment the pc_reg
self.pc_reg += np.uint16(self.instruction.get_instruction_length())
# we have a valid instruction class
value = self.instruction.execute(self, self.data_bytes)
self.status_reg.update(self.instruction, value)