Sep-29-2019, 11:48 PM
Hello, I have this line of code
Then I created this self contained example to show it better:
print ("Identifier Byte: {}".format(self.identity_byte))that generates this output: Quote:120
216
169
Traceback (most recent call last):
File "emulator.py", line 19, in <module>
main ()
File "emulator.py", line 16, in main
cpu.process_instructions ()
File "/home/leopoldo/cpu.py", line 17, in process_instructions
instruction.process ()
File "/home/leopoldo/instruction.py", line 14, in process
print ("Identifier Byte: {}".format(self.identity_byte))
AttributeError: 'Instruction' object has no attribute 'identity_byte'
Then I created this self contained example to show it better:
import argparse
from abc import ABCMeta, abstractmethod
class Instruction (object):
__metaclass_ = ABCMeta
def __init__ (self,identification_byte):
identity_byte = identification_byte
def test (self):
print ("BOTO")
@abstractmethod
def process (self):
print ("Identifier Byte: {}".format(self.identity_byte))
@abstractmethod
def process2 (self):
print ("Identifier Byte2: ", self.identity_byte)
class LDAInstruction (Instruction):
def process (self):
super.process ()
def process2 (self):
super.process()
HEADER_SIZE = 16
KB_SIZE = 16384
class ROM (object) :
def __init__ (self, rom_bytes):
self.header = rom_bytes [0:HEADER_SIZE]
self.num_prg_blocks = self.header [4]
self.data_bytes = rom_bytes [HEADER_SIZE:HEADER_SIZE + (16 + KB_SIZE * self.num_prg_blocks)]
self.total_size = 16 + KB_SIZE * self.num_prg_blocks
def get_byte (self, pc):
return (self.data_bytes [pc])
from rom import ROM
from instruction import Instruction
class CPU (object):
def __init__(self, rom_bytes):
self.registers = []
self.rom = ROM (rom_bytes)
self.pc = 0
def process_instructions (self):
for byte in self.rom.data_bytes:
byte = self.rom.get_byte (self.pc)
self.pc+=1
print (byte)
if (byte == 169):
instruction = Instruction (byte)
instruction.process ()
instruction.process2 ()
if (self.pc == 3):
break
def main ():
parser = argparse.ArgumentParser (description='NES EMULATOR');
parser.add_argument ('rom_path',metavar='R',type=str,help='path to the rom')
args=parser.parse_args()
with open (args.rom_path, 'rb') as file:
rom_bytes = file.read ()
cpu = CPU(rom_bytes)
cpu.process_instructions ()
if __name__ == '__main__':
main () I do not know why its complaining about the lack of the 'identity_byte' attribute, which is clearly present. So what I am doing wrong/ Thanks for the support
