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


Python Memory.write方法代码示例

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


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

示例1: __init__

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import write [as 别名]

#.........这里部分代码省略.........
        for x in self.registernames:
            val = self.readreg(x)
            if(isinstance(val,NValue)):
                print self.registernames[x], val.as_long()
        
    def operandsize(self,i, idx):
        op = i.operands[idx]
        if(op.type == X86_OP_IMM or op.type == X86_OP_MEM):
            return i.op_size * 8
        elif op.type == X86_OP_REG:
            if op.reg in self.registernames:
                return 64
            elif(op.reg >= X86_REG_XMM0 and op.reg <=  X86_REG_XMM31):
                return 128
            elif op.reg in self.regs_32:
                return 32
            elif op.reg in self.regs_8:
                return 8
            else:
                raise MiscError()
    def solve_memoperand(self,op):
        value = NValue(op.disp)
        if(op.index != 0):
            if(op.scale == 1):
                value = value + self.regs[op.index]
            else:
                value = value + NValue(op.scale,64) * self.regs[op.index]
        if(op.base != 0):
            if(op.base == X86_REG_RIP):
                value = value + self.ip
            else:
                value = value + self.regs[op.base]
        return value
    def writeoperand(self,i,idx,expr):
        assert(expr.size == self.operandsize(i,idx))
        operand = i.operands[idx]
        if operand.type == X86_OP_REG:
            if operand.reg in self.registernames:
                # if operand.reg == X86_REG_R14:
                #     if isinstance(self.regs[X86_REG_R14], NFree):
                #         print "Free"
                #     else:
                #         print self.regs[X86_REG_R14].as_long()
                self.regs[operand.reg] = (expr)
            elif operand.reg in self.regs_32:
                self.regs[self.regs_32[operand.reg]] = expr.zeroext(32)
            elif operand.reg in self.regs_8:
                real_reg = self.regs_8[operand.reg]
                self.regs[real_reg] = ((expr & NValue(0xFF,64)) | (self.regs[real_reg] & ~NValue(0xFF,64)))
            elif operand.reg >= X86_REG_XMM0 and operand.reg <=  X86_REG_XMM31: 
                return self.xmmregs[operand.reg- X86_REG_XMM0]
            else:
                raise MiscError()
        elif operand.type == X86_OP_MEM:
            addr = self.solve_memoperand(operand.mem)
            self.mem.write(addr,expr, i.op_size * 8)
        else:
            raise UnsupportedException()
    def readreg(self,reg):
        if reg in self.registernames:
            return self.regs[reg]
        elif reg in self.regs_32:
            return self.readreg(self.regs_32[reg]).extract(31,0)
        elif reg in self.regs_8:
            return self.readreg(self.regs_8[reg]).extract(7,0)
        elif reg >= X86_REG_XMM0 and reg <=  X86_REG_XMM31: 
开发者ID:jbangert,项目名称:schannel-sat,代码行数:70,代码来源:sat.py

示例2: __init__

# 需要导入模块: from memory import Memory [as 别名]
# 或者: from memory.Memory import write [as 别名]

#.........这里部分代码省略.........
        elif n1 == 0xd and n4 == 0: #DXYN Draws a sprite at (VX,VY) starting at M(I). VF = collision. If N=0, draws the 16 x 16 sprite, else an 8 x N sprite.
            print "TODO: not implemented"
            sys.exit(1)
        elif n1 == 0xd: # DXYN Draws a sprite at (VX,VY) starting at M(I). VF = collision. If N=0, draws the 16 x 16 sprite, else an 8 x N sprite.
            ylines = array.array('B')
            for i in range (n4):
                ylines.append(self.memory.read(self._I[0] + i))
            self._reg[0xf] = self.video.draw8(ylines, self._reg[n2], self._reg[n3])
        elif n1 == 0xe and n3 == 0x9 and n4 == 0xe: # EX9E skip next instruction if key VX pressed
            if self._keystate[n2] == 1:
                self._PC[0] = self._PC[0] + 2
        elif n1 == 0xe and n3 == 0xa and n4 == 0x1: # EXA1 Skip next instruction if key VX not pressed
            if self._keystate[n2] != 1:
                self._PC[0] = self._PC[0] + 2
        elif n1 == 0xf and n3 == 0x0 and n4 == 0x7: # FX07 VX = Delay timer
            self._reg[n2] = self._timer[0] & 0xff
        elif n1 == 0xf and n3 == 0x0 and n4 == 0xa: # FX0A Waits a keypress and stores it in VX
            quit = False
            while not quit:
                for i in range(16):
                    if self._keystate[i] == 1:
                        self._reg[n2] = i
                        quit = True
                self.handle_input()
        elif n1 == 0xf and n3 == 0x1 and n4 == 0x5: # FX15 Delay timer = VX
            self._timer[0] = self._reg[n2] & 0xff
        elif n1 == 0xf and n3 == 0x1 and n4 == 0x8: # FX18 Sound timer = VX
            self._timer[1] = self._reg[n2]
        elif n1 == 0xf and n3 == 0x1 and n4 == 0xe: # FX1E I = I + VX
            self._I[0] = self._I[0] + self._reg[n2] & 0xffff
        elif n1 == 0xf and n3 == 0x2 and n4 == 0x9: # FX29	I points to the 4 x 5 font sprite of hex char in VX
            self._I[0] = (self._reg[n2] * 5) & 0xffff
        elif n1 == 0xf and n3 == 0x3 and n4 == 0x3: # FX33 Store BCD representation of VX in M(I)...M(I+2)
            self.memory.write(self._I[0], self._reg[n2] / 100)
            self.memory.write(self._I[0]+1, (self._reg[n2] % 10) / 10)
            self.memory.write(self._I[0]+2, self._reg[n2] % 10)
        elif n1 == 0xf and n3 == 0x5 and n4 == 0x5: # FX55 Save V0...VX in memory starting at M(I)
            for i in range(n2 + 1):
                self.memory.write(self.memory.read(self._I[0] + i), self._reg[i])
        elif n1 == 0xf and n3 == 0x6 and n4 == 0x5: # FX65 Load V0...VX from memory starting at M(I)
            for i in range(n2 + 1):
                self._reg[i] = self.memory.read(self._I[0] + i) & 0xff
        elif n1 == 0xf and n3 == 0x7 and n4 == 0x5:
            print "FX75	Save V0...VX (X<8) in the HP48 flags (***)"
            sys.exit(1)
        elif n1 == 0xf and n3 == 0x8 and n4 == 0x5:
            print "FX85	Load V0...VX (X<8) from the HP48 flags (***)"
            sys.exit(1)
        else:
            print "Error %1x%1x%1x%1x" % (n1,n2,n3,n4)
            sys.exit(1)

        if self._timer[0] > 0:
            self._timer[0] = self._timer[0] - 1
        if self._timer[1] > 0:
            self._timer[1] = self._timer[1] - 1
    
    def read_rom(self, filename):
        self.memory.read_rom(filename)

    def handle_input(self):
        events = pygame.event.get()
        for event in events: 
            if self._verbose: print event 
            if event.type == pygame.QUIT:
                sys.exit(0)
开发者ID:mdurrer,项目名称:dev,代码行数:70,代码来源:cpu.py


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