From fa0f637bfd014e50d5e26b06c4583e71f53214e8 Mon Sep 17 00:00:00 2001 From: mark-summerfield Date: Fri, 21 Jul 2023 09:33:32 +0100 Subject: [PATCH 1/3] replaced poor-style eval() call with getattr() and method call --- m6502/processor.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/m6502/processor.py b/m6502/processor.py index c52923e..ef4fe27 100644 --- a/m6502/processor.py +++ b/m6502/processor.py @@ -234,7 +234,9 @@ def execute(self, cycles: int = 0) -> None: """ while (self.cycles < cycles) or (cycles == 0): opcode = self.fetch_byte() - eval("self.ins_" + self.OPCODES[opcode] + "_" + self.ADDRESSING[opcode] + "()") # noqa: PLW0123 + name = "ins_" + self.OPCODES[opcode] + "_" + self.ADDRESSING[opcode] + method = getattr(self, name) + method() def ins_nop_imp(self) -> None: """ From 564d94293edb8c9fd54819ecc117eb5185e89034 Mon Sep 17 00:00:00 2001 From: mark-summerfield Date: Fri, 21 Jul 2023 10:22:37 +0100 Subject: [PATCH 2/3] fixed memory size checks --- m6502/memory.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/m6502/memory.py b/m6502/memory.py index 01f4894..133dac2 100644 --- a/m6502/memory.py +++ b/m6502/memory.py @@ -13,9 +13,9 @@ def __init__(self, size: int = None) -> None: """ if size is None: size = 0xFFFF - if size < 0x0200: + elif size < 0x0200: raise ValueError("Memory size is not valid") - if size > 0xFFFF: + elif size > 0xFFFF: raise ValueError("Memory size is not valid") self.size = size self.memory = [0] * self.size @@ -27,7 +27,7 @@ def __getitem__(self, address: int) -> int: :param address: The address to read from :return: The value at the specified address """ - if 0x0000 < address > 0xFFFF: + if 0 > address or address > 0xFFFF: raise ValueError("Memory address is not valid") return self.memory[address] @@ -39,7 +39,7 @@ def __setitem__(self, address: int, value: int) -> int: :param value: The value to write to the address :return: None """ - if 0x0000 < address > 0xFFFF: + if 0 > address or address > 0xFFFF: raise ValueError("Memory address is not valid") if value.bit_length() > 8: raise ValueError("Value too large") From 1f5edef3d0b88546e01936e844fda5741a00e987 Mon Sep 17 00:00:00 2001 From: mark-summerfield Date: Fri, 28 Jul 2023 07:04:55 +0100 Subject: [PATCH 3/3] used an f-string rather than + --- m6502/processor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/m6502/processor.py b/m6502/processor.py index ef4fe27..19771b1 100644 --- a/m6502/processor.py +++ b/m6502/processor.py @@ -234,7 +234,7 @@ def execute(self, cycles: int = 0) -> None: """ while (self.cycles < cycles) or (cycles == 0): opcode = self.fetch_byte() - name = "ins_" + self.OPCODES[opcode] + "_" + self.ADDRESSING[opcode] + name = f"ins_{self.OPCODES[opcode]}_{self.ADDRESSING[opcode]}" method = getattr(self, name) method()