Hello I am receiving these messages when running my code:
So I don't see what is not defined there, especially when python does not complain about any other instruction. Thanks for the help.
Error:File "/home/leopoldo/cpu.py", line 28, in process_instructions
instruction = self.identify_instruction (byte)
File "/home/leopoldo/cpu.py", line 18, in identify_instruction
instruction = BPLInstruction (byte)
NameError: global name 'BPLInstruction' is not defined
The code:def process_instructions (self): counter=0 for byte in self.rom.data_bytes: byte = self.rom.get_byte (self.pc) instruction = self.identify_instruction (byte) if instruction is None: raise Exception ("Instruction not found") instruction.process () print ("self.pc, antes: ", self.pc) self.pc+= instruction.instruction_length print ("counter: ", counter) print ("self.pc, depois: ", self.pc) print ("") counter = counter + 1
def identify_instruction (self, byte): if byte==0x78: instruction = LDAInstruction (byte) elif byte==0xD8: instruction = SEIInstruction (byte) elif byte==0xA9: instruction = CLDInstruction (byte) elif byte==0x10: instruction = BPLInstruction (byte) else: instruction = None return instruction
class LDAInstruction (Instruction): def process (self): print ("Identifier Byte: LDAInstruction:",hex (self.identity_byte), self.identity_byte ) instruction_length = 2 class SEIInstruction (Instruction): def process (self): print ("Identifier Byte: SEIInstruction:",hex (self.identity_byte), self.identity_byte) instruction_length = 1 class CLDInstruction (Instruction): def process (self): print ("Identifier Byte: CLDInstruction:",hex (self.identity_byte), self.identity_byte) instruction_length = 1 class BPLinstruction (Instruction): def process (self): print ("Identifier Byte: BPLinstruction:",hex (self.identity_byte), self.identity_byte) instruction_length = 1I can't identify the source of trouble because I see no difference between the code related to BPL, whether is its class definition or its elif clause on "identify_instruction" to the others instruction's code.
So I don't see what is not defined there, especially when python does not complain about any other instruction. Thanks for the help.