本文整理汇总了Python中video.Video.erase方法的典型用法代码示例。如果您正苦于以下问题:Python Video.erase方法的具体用法?Python Video.erase怎么用?Python Video.erase使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类video.Video
的用法示例。
在下文中一共展示了Video.erase方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from video import Video [as 别名]
# 或者: from video.Video import erase [as 别名]
class Cpu:
def __init__(self, verbose, scale):
#
self._verbose = verbose
# CPU properties
# 16 general purpose 8-bit registers
self._reg = array.array('B', [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
# 16-bit register
self._I = array.array('H', [0])
# Timers delay = 0 / sound = 1
self._timer = array.array('B', [0,0])
# Stack
self._stack = array.array('H', [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
# Program Counter
self._PC = array.array('H', [0x0200])
# Memory
self.memory = Memory()
# Video
self.video = Video(verbose, scale)
# Key states
self._keystate = array.array('B', [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
# private properties
self.__ips = 60
self.clock = pygame.time.Clock()
def execute(self):
word = (self.memory.read(self._PC[0]) << 8) | (self.memory.read(self._PC[0] + 1))
n1 = (word >> 12) & 0x0f
n2 = (word >> 8) & 0x0f
n3 = (word >> 4) & 0x0f
n4 = word & 0x0f
if self._verbose: print "Opcode: %x" % (word)
self._PC[0] = self._PC[0] + 2
if n1 == 0x0:
if n2 == 0:
if n3 == 0xc:
print "00CN Scroll down %i lines (***)" % (n4)
sys.exit(1)
elif n3 == 0xf and n4 == 0xb:
print "00FB Scroll 4 pixels right (***)"
sys.exit(1)
elif n3 == 0xf and n4 == 0xc:
print "00FC Scroll 4 pixels left (***)"
sys.exit(1)
elif n3 == 0xf and n4 == 0xd: # 00FD Quit the emulator (***)
sys.exit(1)
elif n3 == 0xf and n4 == 0xe: # 00FE Set CHIP-8 graphic mode (***)
print "TODO: not implemented"
sys.exit(1)
elif n3 == 0xf and n4 == 0xf: # 00FF Set SCHIP graphic mode (***)
print "TODO: not implemented"
sys.exit(1)
elif n3 == 0xe and n4 == 0x0: # 00E0 Erase the screen
self.video.erase()
elif n3 == 0xe and n4 == 0xe: # 00EE Return from a CHIP-8 sub-routine
self._PC[0] = self._stack.pop()
else:
print "Error %2x%2x%2x%2x" % (n1,n2,n3,n4)
sys.exit(1)
else: # 0NNN Call 1802 machine code program at NNN (not implemented)
print "0NNN Call 1802 machine code program at NNN (not implemented)"
sys.exit(1)
elif n1 == 0x1: # 1NNN Jump to NNN
self._PC[0] = word & 0x0fff
elif n1 == 0x2: # 2NNN Call CHIP-8 sub-routine at NNN (16 successive calls max)
self._stack.append(self._PC[0])
self._PC[0] = word & 0x0fff
elif n1 == 0x3: # 3XKK Skip next instruction if VX == KK
if self._reg[n2] == (word & 0x00ff):
self._PC[0] = self._PC[0] + 2
elif n1 == 0x4: # 4XKK Skip next instruction if VX != KK
if self._reg[n2] != (word & 0x00ff):
self._PC[0] = self._PC[0] + 2
elif n1 == 0x5 and n4 == 0x0: # 5XY0 Skip next instruction if VX == VY
if self._reg[n2] == self._reg[n3]:
self._PC[0] = self._PC[0] + 2
elif n1 == 0x6: # 6XKK VX = KK
self._reg[n2] = word & 0x00ff
elif n1 == 0x7: # 7XKK VX = VX + KK
self._reg[n2] = (self._reg[n2] + (word & 0x00ff)) & 0xff
elif n1 == 0x8:
if n4 == 0x0: # 8XY0 VX = VY
self._reg[n2] = self._reg[n3]
elif n4 == 0x1: # 8XY1 VX = VX OR VY
self._reg[n2] = self._reg[n2] | self._reg[n3]
elif n4 == 0x2: # 8XY2 VX = VX AND VY
self._reg[n2] = self._reg[n2] & self._reg[n3]
elif n4 == 0x3: #8XY3 VX = VX XOR VY (*)
self._reg[n2] = self._reg[n2] ^ self._reg[n3]
elif n4 == 0x4: # 8XY4 VX = VX + VY, VF = carry
if (self._reg[n2] + self._reg[n3]) > 0xff:
self._reg[0xf] = 1
else:
self._reg[0xf] = 0
self._reg[n2] = (self._reg[n2] + self._reg[n3]) & 0xff
elif n4 == 0x5: # 8XY5 VX = VX - VY, VF = not borrow (**)
if self._reg[n2] < self._reg[n3]:
self._reg[0xf] = 0
#.........这里部分代码省略.........