Skip to content

Conversation

@hspaans
Copy link
Owner

@hspaans hspaans commented Oct 13, 2025

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.

…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.
Copilot AI review requested due to automatic review settings October 13, 2025 00:45
@hspaans hspaans linked an issue Oct 13, 2025 that may be closed by this pull request
6 tasks
@hspaans hspaans self-assigned this Oct 13, 2025
Copy link

Copilot AI left a 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"
Copy link

Copilot AI Oct 13, 2025

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'.

Suggested change
set_env.COVERAGE_FILECOVERAGE_PROCESS_START = "{tox_root}{/}pyproject.toml"
set_env.COVERAGE_FILE_COVERAGE_PROCESS_START = "{tox_root}{/}pyproject.toml"

Copilot uses AI. Check for mistakes.
Comment on lines +1654 to +1655
after the opcode. The memory location is a two-byte address that can
Copy link

Copilot AI Oct 13, 2025

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.

Suggested change
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.

Copilot uses AI. Check for mistakes.
"""
while (self.cycles < cycles) or (cycles == 0):
opcode = self._fetch_byte()
eval("self._ins_" + self._OPCODES[opcode] + "_" + self._ADDRESSING[opcode] + "()") # noqa: PLW123
Copy link

Copilot AI Oct 13, 2025

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.

Suggested change
eval("self._ins_" + self._OPCODES[opcode] + "_" + self._ADDRESSING[opcode] + "()") # noqa: PLW123
method_name = "_ins_" + self._OPCODES[opcode] + "_" + self._ADDRESSING[opcode]
getattr(self, method_name)()

Copilot uses AI. Check for mistakes.
:rtype: int
:raises ValueError: Memory address is not valid
"""
if 0x0000 < address > self.size:
Copy link

Copilot AI Oct 13, 2025

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.

Copilot uses AI. Check for mistakes.
:raises ValueError: Memory address is not valid
:raises ValueError: Size of value exceed byte size
"""
if 0x0000 < address > self.size:
Copy link

Copilot AI Oct 13, 2025

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.

Copilot uses AI. Check for mistakes.
- 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.
Copilot AI review requested due to automatic review settings October 13, 2025 01:28
Copy link

Copilot AI left a 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
Copy link

Copilot AI Oct 13, 2025

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.

Suggested change
memory[Processor.PC_INIT + 1] = 0x86
memory[Processor.PC_INIT + 1] = memory_zp

Copilot uses AI. Check for mistakes.
cpu.stack_pointer,
cpu.cycles,
memory[memory_location],
) == (0xFCE4, Processor.SP_INIT, 4, 0xF0)
Copy link

Copilot AI Oct 13, 2025

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.

Suggested change
) == (0xFCE4, Processor.SP_INIT, 4, 0xF0)
) == (Processor.PC_INIT + 2, Processor.SP_INIT, 4, 0xF0)

Copilot uses AI. Check for mistakes.
cpu.stack_pointer,
cpu.cycles,
memory[memory_location],
) == (0xFCE4, Processor.SP_INIT, 4, 0xF0)
Copy link

Copilot AI Oct 13, 2025

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.

Suggested change
) == (0xFCE4, Processor.SP_INIT, 4, 0xF0)
) == (Processor.PC_INIT + 2, Processor.SP_INIT, 4, 0xF0)

Copilot uses AI. Check for mistakes.
:return: None
"""
self._write_byte(
self._read_byte(self._read_word(self._fetch_byte()) + self.reg_y),
Copy link

Copilot AI Oct 13, 2025

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.

Suggested change
self._read_byte(self._read_word(self._fetch_byte()) + self.reg_y),
self._read_word(self._fetch_byte()) + self.reg_y,

Copilot uses AI. Check for mistakes.
:rtype: int
:raises ValueError: Memory address is not valid
"""
if 0x0000 < address > self.size:
Copy link

Copilot AI Oct 13, 2025

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.

Copilot uses AI. Check for mistakes.
:raises ValueError: Memory address is not valid
:raises ValueError: Size of value exceed byte size
"""
if 0x0000 < address > self.size:
Copy link

Copilot AI Oct 13, 2025

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.

Copilot uses AI. Check for mistakes.
@hspaans hspaans marked this pull request as draft October 13, 2025 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Load/Store Operations

2 participants