From 614ad620540ec271d08de6b4843949de4368df7a Mon Sep 17 00:00:00 2001 From: Jordan Wiens Date: Mon, 19 Aug 2019 06:04:49 +0200 Subject: update nes example plugin for python3 support --- python/examples/nes.py | 49 +++++++++++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 24 deletions(-) (limited to 'python') diff --git a/python/examples/nes.py b/python/examples/nes.py index 305ebc43..f5b8c351 100644 --- a/python/examples/nes.py +++ b/python/examples/nes.py @@ -406,7 +406,7 @@ class M6502(Architecture): def decode_instruction(self, data, addr): if len(data) < 1: return None, None, None, None - opcode = ord(data[0]) + opcode = ord(data[0:1]) instr = InstructionNames[opcode] if instr is None: return None, None, None, None @@ -419,9 +419,9 @@ class M6502(Architecture): if OperandLengths[operand] == 0: value = None elif operand == REL: - value = (addr + 2 + struct.unpack("b", data[1])[0]) & 0xffff + value = (addr + 2 + struct.unpack("b", data[1:2])[0]) & 0xffff elif OperandLengths[operand] == 1: - value = ord(data[1]) + value = ord(data[1:2]) else: value = struct.unpack("> 4) - self.ram_banks = struct.unpack("B", hdr[8])[0] + self.rom_banks = struct.unpack("B", hdr[4:5])[0] + self.vrom_banks = struct.unpack("B", hdr[5:6])[0] + self.rom_flags = struct.unpack("B", hdr[6:7])[0] + self.mapper_index = struct.unpack("B", hdr[7:8])[0] | (self.rom_flags >> 4) + self.ram_banks = struct.unpack("B", hdr[8:9])[0] self.rom_offset = 16 if self.rom_flags & 4: self.rom_offset += 512 @@ -610,9 +610,10 @@ class NESView(BinaryView): self.file.filename + ".%x.nl" % (self.rom_banks - 1)] for f in sym_files: if os.path.exists(f): - sym_contents = open(f, "r").read() - lines = sym_contents.split('\n') + with open(f, "r") as f: + lines = f.readlines() for line in lines: + line = line.strip() sym = line.split('#') if len(sym) < 3: break -- cgit v1.3.1