MOS 6502 emulator written in Rust
Go to file
Matthias 363dc47755 Format code 2022-06-07 19:30:29 +02:00
.github Upgrade to GitHub-native Dependabot 2021-04-29 15:24:26 +00:00
examples Format code 2022-06-07 19:30:29 +02:00
notes add org files 2014-10-07 23:51:30 -04:00
src Format code 2022-06-07 19:30:29 +02:00
tests Add no_std support 2018-11-04 20:26:51 +01:00
.gitattributes Add GitHub default client .gitattributes. 2014-09-25 21:16:46 -04:00
.gitignore Format code 2022-06-07 19:30:29 +02:00
AUTHORS.txt Fix compilation with latest rustc 2017-08-08 23:24:41 +02:00
COPYRIGHT Add copyright, authorship, and license information 2014-09-26 02:26:26 -04:00
Cargo.lock Bump log from 0.4.16 to 0.4.17 2022-05-03 04:11:28 +00:00
Cargo.toml Bump log from 0.4.16 to 0.4.17 2022-05-03 04:11:28 +00:00
LICENSE Add copyright, authorship, and license information 2014-09-26 02:26:26 -04:00
README.md Add historical background 2021-04-07 14:05:38 +02:00
build.rs Add no_std support 2018-11-04 20:26:51 +01:00

README.md

mos6502

docs.rs

An emulator for the MOS 6502 CPU written in Rust.
It builds on stable Rust and supports #[no_std] targets.

What is the MOS 6502?

The MOS Technology 6502 (typically pronounced "sixty-five-oh-two" or "six-five-oh-two") is an 8-bit microprocessor that was designed by a small team led by Chuck Peddle for MOS Technology. [...]

When it was introduced in 1975, the 6502 was the least expensive microprocessor on the market by a considerable margin. It initially sold for less than one-sixth the cost of competing designs from larger companies, such as the 6800 or Intel 8080. Its introduction caused rapid decreases in pricing across the entire processor market. Along with the Zilog Z80, it sparked a series of projects that resulted in the home computer revolution of the early 1980s.

Source: Wikipedia

How to use this library

use mos6502::address::Address;
use mos6502::cpu;

fn main() {
    // Calculate the greatest common divisor of 56 and 49
    // using Euclid's algorithm.
    let zero_page_data = [56, 49];

    let program = [
        // (F)irst | (S)econd
        // .algo
        0xa5, 0x00,       // Load from F to A
        // .algo_
        0x38,             // Set carry flag
        0xe5, 0x01,       // Substract S from number in A (from F)
        0xf0, 0x07,       // Jump to .end if diff is zero
        0x30, 0x08,       // Jump to .swap if diff is negative
        0x85, 0x00,       // Load A to F
        0x4c, 0x12, 0x00, // Jump to .algo_
        // .end
        0xa5, 0x00,       // Load from S to A
        0xff,
        // .swap
        0xa6, 0x00,       // load F to X
        0xa4, 0x01,       // load S to Y
        0x86, 0x01,       // Store X to F
        0x84, 0x00,       // Store Y to S
        0x4c, 0x10, 0x00, // Jump to .algo
    ];

    let mut cpu = cpu::CPU::new();

    cpu.memory.set_bytes(Address(0x00), &zero_page_data);
    cpu.memory.set_bytes(Address(0x10), &program);
    cpu.registers.program_counter = Address(0x10);

    cpu.run();

    // The expected GCD is 7
    assert_eq!(7, cpu.registers.accumulator);
}

Credits

This started off as a fork of amw-zero/6502-rs, which seems to be unmaintained at this point.