-1

我正在阅读可以在这里找到的c​​hip8 模拟器的源代码:https ://github.com/maranas/pyChip8Emu/blob/master/chip8.py 。在第 420 行,它是来自 0xF000 二进制文件的操作码。此外,它将操作码和或与内存中的下一个字节一起移动。为什么要进行这些转换?

# 1. get op (op code plus operand)
self.opcode = (self.memory[self.pc] << 8) | self.memory[self.pc + 1]
log("Current opcode: %X" % self.opcode)
self.pc += 2
self.vx = (self.opcode & 0x0f00) >> 8
self.vy = (self.opcode & 0x00f0) >> 4

# 2. check ops, lookup and execute
extracted_op = self.opcode & 0xf000
try:
  self.funcmap[extracted_op]()
except:
  print "Unknown instruction: %X" % self.opcode

if self.delay_timer > 0:
  self.delay_timer -= 1
if self.sound_timer > 0:
  self.sound_timer -= 1
  if self.sound_timer == 0:
    self.buzz.play()

以上是周围代码的摘录,我希望这是足够的上下文来提供帮助。

4

0 回答 0