当前位置: 首页>>代码示例>>Python>>正文


Python Memory.read_word方法代码示例

本文整理汇总了Python中memory.Memory.read_word方法的典型用法代码示例。如果您正苦于以下问题:Python Memory.read_word方法的具体用法?Python Memory.read_word怎么用?Python Memory.read_word使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在memory.Memory的用法示例。


在下文中一共展示了Memory.read_word方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Stack

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import read_word [as 别名]
class Stack(object):
    def __init__(self, size):
        self._stack = Memory(size)
        self._sp = 0

    def push(self, word):
        self._sp -= 2
        self._stack.write_word(self._sp, word)

    def pop(self):
        self._sp += 2
        return self._stack.read_word(self._sp-2)

    def set_position(self, position):
        self._sp = position

    def position(self):
        return self._sp

    def __repr__(self):
        return str(self._stack)
开发者ID:simontoft,项目名称:Py8080,代码行数:23,代码来源:stack.py

示例2: Chip8

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import read_word [as 别名]
class Chip8(object):
    ENTRY_POINT = 0x200
    REG_COUNT = 16
    KEY_COUNT = 16

    def __init__(self):
        self.registers = bytearray(self.REG_COUNT)
        self.index_register = 0
        self.program_counter = self.ENTRY_POINT

        self.memory = Memory()
        self.screen = Screen()
        self.keyboard = bytearray(self.KEY_COUNT)
        self.stack = []

        self.delay_timer = 0
        self.sound_timer = 0

        self.INSTRUCTION_SET = {
            0x00E0: self.op_00E0,
            0x00EE: self.op_00EE,
            0x1   : self.op_1NNN,
            0x2   : self.op_2NNN,
            0x3   : self.op_3XNN,
            0x4   : self.op_4XNN,
            0x5   : self.op_5XY0,
            0x6   : self.op_6XNN,
            0x7   : self.op_7XNN,
            0x8000: self.op_8XY0,
            0x8001: self.op_8XY1,
            0x8002: self.op_8XY2,
            0x8003: self.op_8XY3,
            0x8004: self.op_8XY4,
            0x8005: self.op_8XY5,
            0x8006: self.op_8XY6,
            0x8007: self.op_8XY7,
            0x800E: self.op_8XYE,
            0x9000: self.op_9XY0,
            0xA   : self.op_ANNN,
            0xB   : self.op_BNNN,
            0xC   : self.op_CXNN,
            0xD   : self.op_DXYN,
            0xE09E: self.op_EX9E,
            0xE0A1: self.op_EXA1,
            0xF007: self.op_FX07,
            0xF00A: self.op_FX0A,
            0xF015: self.op_FX15,
            0xF018: self.op_FX18,
            0xF01E: self.op_FX1E,
            0xF029: self.op_FX29,
            0xF033: self.op_FX33,
            0xF055: self.op_F055,
            0xF065: self.op_FX65,
        }

    def decode(self, op):
        if op in [0x00E0, 0x00EE]: # special case
            return (op, tuple())

        instruction = I(op)

        if instruction in [0x0, 0x1, 0x2, 0xA, 0xB]:
            args = (NNN(op),)

        elif instruction in [0x3, 0x4, 0x6, 0x7, 0xC]:
            args = X(op), NN(op)

        elif instruction == 0x5:
            args = X(op), Y(op)

        elif instruction == 0xD:
            args = X(op), Y(op), N(op)

        elif 0x8000 <= instruction <= 0x9000:
            args = X(op), Y(op)

        elif instruction >= 0xE:
            args = (X(op),)

        return instruction, args

    def execute(self, instruction, args):
        if instruction not in self.INSTRUCTION_SET:
            raise NotImplementedError('{:04x} - {}'.format(instruction, args))

        self.INSTRUCTION_SET.get(instruction)(*args)

    def fetch(self):
        return self.memory.read_word(self.program_counter)

    def cycle(self):
        word = self.fetch()
        instruction, args = self.decode(word)
        self.execute(instruction, args)

        if self.delay_timer > 0:
            self.delay_timer -= 1

        if self.sound_timer > 0:
            if self.sound_timer == 1:
#.........这里部分代码省略.........
开发者ID:dmalves,项目名称:chipy8,代码行数:103,代码来源:chip8.py


注:本文中的memory.Memory.read_word方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。