The MOS Technology 6502 is an early 8-bit microprocessor introduced in 1975. It consists of only a few internal registers, 56 instructions with multiple addressing modes, and 64 KB of memory space (using 16-bit address words).
Given its relatively simple design, the 6502 is a fantastic architecture to learn how CPUs actually work and how they can be emulated.
The following is the complete set of instructions supported by the 6502 and whether they have been implemented in this project yet.
- LDA - Load Accumulator
- LDX - Load X Register
- LDY - Load Y Register
- STA - Store Accumulator
- STX - Store X Register
- STY - Store Y Register
- TAX - Transfer accumulator to X
- TAY - Transfer accumulator to Y
- TXA - Transfer X to accumulator
- TYA - Transfer Y to accumulator
- TSX - Transfer stack pointer to X
- TXS - Transfer X to stack pointer
- PHA - Push accumulator on stack
- PHP - Push processor status on stack
- PLA - Pull accumulator from stack
- PLP - Pull processor status from stack
- ADC - Add with Carry
- SBC - Subtract with Carry
- CMP - Compare accumulator
- CPX - Compare X register
- CPY - Compare Y register
- INC - Increment a memory location
- INX - Increment the X register
- INY - Increment the Y register
- DEC - Decrement a memory location
- DEX - Decrement the X register
- DEY - Decrement the Y register
- ASL - Arithmetic Shift Left
- LSR - Logical Shift Right
- ROL - Rotate Left
- ROR - Rotate Right
- JMP - Jump to another location
- JSR - Jump to a subroutine
- RTS - Return from subroutine
- BCC - Branch if carry flag clear
- BCS - Branch if carry flag set
- BEQ - Branch if zero flag set
- BMI - Branch if negative flag set
- BNE - Branch if zero flag clear
- BPL - Branch if negative flag clear
- BVC - Branch if overflow flag clear
- BVS - Branch if overflow flag set
- CLC - Clear carry flag
- CLD - Clear decimal mode flag
- CLI - Clear interrupt disable flag
- CLV - Clear overflow flag
- SEC - Set carry flag
- SED - Set decimal mode flag
- SEI - Set interrupt disable flag
- BRK - Force an interrupt
- NOP - No Operation
- RTI - Return from Interrupt
This project is a great opportunity for intermediate to advanced Rust developers, as well as more experienced developers coming from a C/C++ background who are interested in learning Rust. It is not only a fun challenge, but will also help you understand the low-level logic that drives everyday devices at a foundational level.
To get started, it would be helpful to compare the existing implementations in this codebase with the instruction set reference. Understanding these implementation patterns will make it easier to learn and write the remaining parts of the instruction set. Another way of helping is by writing more unit tests, with the aim of having at least one test per opcode.
If you're interested in making a contribution, please feel free to open a PR :) !