1
0
mirror of https://github.com/mre/mos6502.git synced 2024-11-28 07:49:19 +00:00
MOS 6502 emulator written in Rust
Go to file
2019-10-22 15:15:26 +03:00
.github/workflows Add github actions 2019-10-22 09:44:18 +09:00
examples refactoring 2019-10-13 01:22:57 +03:00
notes add org files 2014-10-07 23:51:30 -04:00
src new example 2019-10-13 00:07:53 +03: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 Add no_std support 2018-11-04 20:26:51 +01:00
.travis.yml Typo 2018-10-25 14:40:57 +02:00
AUTHORS.txt Fix compilation with latest rustc 2017-08-08 23:24:41 +02:00
build.rs Add no_std support 2018-11-04 20:26:51 +01:00
Cargo.lock update bitflags 2019-10-06 18:56:51 +02:00
Cargo.toml update toml 2019-10-13 00:34:19 +03:00
COPYRIGHT Add copyright, authorship, and license information 2014-09-26 02:26:26 -04:00
LICENSE Add copyright, authorship, and license information 2014-09-26 02:26:26 -04:00
README.md update readme 2019-10-22 15:15:26 +03:00

mos6502

Build Status

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.

Usage example

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

fn main() {
    println!("Enter two numbers (< 128) to know their GCD:");
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();

    let zero_page_data = input
        .trim()
        .split(' ')
        .map(|s| s.parse::<u8>().unwrap())
        .collect::<Vec<u8>>();

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

    println!("GCD is {:?}", cpu.registers.accumulator);
}