-
Notifications
You must be signed in to change notification settings - Fork 2
Refactor CPU instruction tests and enhance development setup #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
…memory operations - Removed redundant imports and cleaned up test functions for LDA, LDX, LDY, STA, STX, and STY instructions. - Consolidated test cases to improve readability and maintainability. - Updated memory test cases to directly use the Memory class from m6502. - Ensured all tests maintain functionality while enhancing clarity and structure.
…tings, and update documentation build tasks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the CPU instruction test suite and modernizes the development environment configuration to improve maintainability and streamline the development workflow.
- Consolidates individual CPU instruction test files into a single comprehensive test file
- Migrates from setup.cfg/tox.ini to modern pyproject.toml and tox.toml configuration files
- Reorganizes code structure with proper src/ layout and removes obsolete files
Reviewed Changes
Copilot reviewed 22 out of 24 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| tox.toml | New tox configuration with modern format and comprehensive testing environments |
| tests/test_memory.py | Updated import statements to use direct Memory import |
| tests/test_cpu_ins_*.py | Removed individual instruction test files (content consolidated) |
| tests/test_cpu.py | Expanded with comprehensive CPU instruction tests covering all addressing modes |
| src/m6502/ | New source directory structure with processor and memory modules |
| pyproject.toml | New project configuration with modern Python packaging standards |
| setup.cfg | Removed obsolete configuration file |
| .flake8 | New flake8 configuration file |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
tox.toml
Outdated
| dependency_groups = ["test"] | ||
| pass_env = ["PYTEST_*", "SSL_CERT_FILE"] | ||
| set_env.COVERAGE_FILE = { replace = "env", name = "COVERAGE_FILE", default = "{work_dir}{/}.coverage.{env_name}" } | ||
| set_env.COVERAGE_FILECOVERAGE_PROCESS_START = "{tox_root}{/}pyproject.toml" |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing underscore in environment variable name. Should be 'COVERAGE_FILE_COVERAGE_PROCESS_START' instead of 'COVERAGE_FILECOVERAGE_PROCESS_START'.
| set_env.COVERAGE_FILECOVERAGE_PROCESS_START = "{tox_root}{/}pyproject.toml" | |
| set_env.COVERAGE_FILE_COVERAGE_PROCESS_START = "{tox_root}{/}pyproject.toml" |
| after the opcode. The memory location is a two-byte address that can | ||
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incomplete documentation. The description is cut off mid-sentence and doesn't explain the addressing mode fully.
| after the opcode. The memory location is a two-byte address that can | |
| calculated by adding the X register to the two-byte address specified | |
| after the opcode. The base address can range from 0x0000 to 0xFFFF. |
src/m6502/processor.py
Outdated
| """ | ||
| while (self.cycles < cycles) or (cycles == 0): | ||
| opcode = self._fetch_byte() | ||
| eval("self._ins_" + self._OPCODES[opcode] + "_" + self._ADDRESSING[opcode] + "()") # noqa: PLW123 |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using eval() is a security risk and should be replaced with a safer alternative like getattr() or a dispatch dictionary.
| eval("self._ins_" + self._OPCODES[opcode] + "_" + self._ADDRESSING[opcode] + "()") # noqa: PLW123 | |
| method_name = "_ins_" + self._OPCODES[opcode] + "_" + self._ADDRESSING[opcode] | |
| getattr(self, method_name)() |
| :rtype: int | ||
| :raises ValueError: Memory address is not valid | ||
| """ | ||
| if 0x0000 < address > self.size: |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid comparison logic using chained comparison operators. This will always evaluate to False. Should use 'address < 0x0000 or address > self.size' instead.
| :raises ValueError: Memory address is not valid | ||
| :raises ValueError: Size of value exceed byte size | ||
| """ | ||
| if 0x0000 < address > self.size: |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid comparison logic using chained comparison operators. This will always evaluate to False. Should use 'address < 0x0000 or address > self.size' instead.
…ion, and enhance linting configuration
- Added blank lines for better separation of sections in multiple test files. - Updated parameterization syntax in several test functions for clarity. - Ensured consistent formatting across all test files related to CPU instructions and memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 46 out of 47 changed files in this pull request and generated 6 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| cpu.reg_a = value | ||
| cpu.reg_y = reg_y | ||
| memory[Processor.PC_INIT] = INS_STA_INY | ||
| memory[Processor.PC_INIT + 1] = 0x86 |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coded value 0x86 should use memory_zp parameter to be consistent with the test parameters and function signature.
| memory[Processor.PC_INIT + 1] = 0x86 | |
| memory[Processor.PC_INIT + 1] = memory_zp |
| cpu.stack_pointer, | ||
| cpu.cycles, | ||
| memory[memory_location], | ||
| ) == (0xFCE4, Processor.SP_INIT, 4, 0xF0) |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coded program counter value 0xFCE4 should use Processor.PC_INIT + size for consistency with other tests.
| ) == (0xFCE4, Processor.SP_INIT, 4, 0xF0) | |
| ) == (Processor.PC_INIT + 2, Processor.SP_INIT, 4, 0xF0) |
| cpu.stack_pointer, | ||
| cpu.cycles, | ||
| memory[memory_location], | ||
| ) == (0xFCE4, Processor.SP_INIT, 4, 0xF0) |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hard-coded program counter value 0xFCE4 should use Processor.PC_INIT + size for consistency with other tests.
| ) == (0xFCE4, Processor.SP_INIT, 4, 0xF0) | |
| ) == (Processor.PC_INIT + 2, Processor.SP_INIT, 4, 0xF0) |
| :return: None | ||
| """ | ||
| self._write_byte( | ||
| self._read_byte(self._read_word(self._fetch_byte()) + self.reg_y), |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line appears to have incorrect logic - it reads a byte from a memory location plus reg_y, but should read the word from memory location and then add reg_y to get the final address.
| self._read_byte(self._read_word(self._fetch_byte()) + self.reg_y), | |
| self._read_word(self._fetch_byte()) + self.reg_y, |
| :rtype: int | ||
| :raises ValueError: Memory address is not valid | ||
| """ | ||
| if 0x0000 < address > self.size: |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic error in address validation - should be address < 0x0000 or address > self.size to properly check bounds.
| :raises ValueError: Memory address is not valid | ||
| :raises ValueError: Size of value exceed byte size | ||
| """ | ||
| if 0x0000 < address > self.size: |
Copilot
AI
Oct 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic error in address validation - should be address < 0x0000 or address > self.size to properly check bounds.
… "Code example" to "Assembly example" and improve clarity. Remove redundant test file test_cpu_ins_lda.py.
Refactor tests for CPU instructions and memory operations to improve clarity and maintainability. Configure the development environment with updated linting tools and documentation tasks. Remove obsolete files and streamline package installation settings.