MOS 6502 emulator written in Rust
Go to file
Matthias Endler ad90d9294c Statically initialize CPU 2021-01-29 00:14:50 +01:00
.github Run unit tests for PRs 2021-01-27 21:19:00 +01:00
examples refactoring 2019-10-13 01:22:57 +03:00
no-std-example Statically initialize CPU 2021-01-29 00:14:50 +01:00
notes add org files 2014-10-07 23:51:30 -04:00
src Add Default impls 2021-01-28 23:34:41 +01:00
tests Add usage example 2018-10-25 20:12:54 +02:00
.gitattributes Add GitHub default client .gitattributes. 2014-09-25 21:16:46 -04:00
.gitignore Add example for no_std support 2018-11-04 21:35:50 +01:00
.travis.yml Don't build no_std on stable 2018-11-04 22:46:47 +01: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 version 2021-01-28 23:11:39 +01:00
Cargo.toml Update Cargo.toml 2021-01-28 23:10:26 +01:00
LICENSE Add copyright, authorship, and license information 2014-09-26 02:26:26 -04:00
README.md Merge branch 'master' of github.com:mre/mos6502 into no-std-example 2021-01-28 23:46:39 +01:00
build.rs Add usage example 2018-10-25 20:12:54 +02:00

README.md

mos6502

docs.rs

An emulator for the MOS 6502 CPU written in Rust.
This started off as a fork of amw-zero/6502-rs, which seems to be unmaintained at this point.

It builds with the latest stable Rust and supports #[no_std] targets. (See no-std-example folder for more info.)

Usage example

extern crate mos6502;
use mos6502::address::Address;
use mos6502::cpu;

fn main() {

    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();

    assert_eq!(7, cpu.registers.accumulator);
    
}