{"id":15640527,"url":"https://github.com/mre/mos6502","last_synced_at":"2025-04-05T21:07:22.761Z","repository":{"id":31798852,"uuid":"106186425","full_name":"mre/mos6502","owner":"mre","description":" MOS 6502 emulator written in Rust","archived":false,"fork":false,"pushed_at":"2024-10-21T08:51:42.000Z","size":493,"stargazers_count":89,"open_issues_count":8,"forks_count":16,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T20:08:47.747Z","etag":null,"topics":["6502","cpu","emulator","retrocomputing"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mre.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.txt","dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"mre","patreon":"hellorust"}},"created_at":"2017-10-08T15:18:40.000Z","updated_at":"2025-03-16T02:59:55.000Z","dependencies_parsed_at":"2024-04-26T10:35:14.020Z","dependency_job_id":"3128728a-aa40-43e0-8b7d-3a3e3392bb8b","html_url":"https://github.com/mre/mos6502","commit_stats":{"total_commits":287,"total_committers":18,"mean_commits":"15.944444444444445","dds":0.7526132404181185,"last_synced_commit":"6c6a68aa3a9c15e02d774ffd325492fc87e597df"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2Fmos6502","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2Fmos6502/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2Fmos6502/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mre%2Fmos6502/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mre","download_url":"https://codeload.github.com/mre/mos6502/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247399876,"owners_count":20932876,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["6502","cpu","emulator","retrocomputing"],"created_at":"2024-10-03T11:36:56.450Z","updated_at":"2025-04-05T21:07:22.746Z","avatar_url":"https://github.com/mre.png","language":"Rust","funding_links":["https://github.com/sponsors/mre","https://patreon.com/hellorust"],"categories":[],"sub_categories":[],"readme":"# mos6502\n\n![MOS6502](assets/6502.jpg)\n\n![](https://github.com/mre/mos6502/workflows/test/badge.svg)\n[![docs.rs](https://docs.rs/mos6502/badge.svg)](https://docs.rs/mos6502)\n\nAn emulator for the [MOS 6502 CPU](https://en.wikipedia.org/wiki/MOS_Technology_6502) written in Rust.  \nTested and validated by [solid65](https://github.com/omarandlorraine/solid65).  \nIt builds on stable Rust and supports `#[no_std]` targets.\n\n## What is the MOS 6502?\n\n\u003e 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. [...]\n\u003e\n\u003e 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.**\n\nSource: [Wikipedia](https://en.wikipedia.org/wiki/MOS_Technology_6502)\n\n\n## How to use this library\n\n```rust\nuse mos6502::memory::Bus;\nuse mos6502::memory::Memory;\nuse mos6502::instruction::Nmos6502;\nuse mos6502::cpu;\n\nfn main() {\n    // Calculate the greatest common divisor of 56 and 49\n    // using Euclid's algorithm.\n    let zero_page_data = [56, 49];\n\n    let program = [\n        // (F)irst | (S)econd\n        // .algo\n        0xa5, 0x00,       // Load from F to A\n        // .algo_\n        0x38,             // Set carry flag\n        0xe5, 0x01,       // Substract S from number in A (from F)\n        0xf0, 0x07,       // Jump to .end if diff is zero\n        0x30, 0x08,       // Jump to .swap if diff is negative\n        0x85, 0x00,       // Load A to F\n        0x4c, 0x12, 0x00, // Jump to .algo_\n        // .end\n        0xa5, 0x00,       // Load from S to A\n        0xff,\n        // .swap\n        0xa6, 0x00,       // load F to X\n        0xa4, 0x01,       // load S to Y\n        0x86, 0x01,       // Store X to F\n        0x84, 0x00,       // Store Y to S\n        0x4c, 0x10, 0x00, // Jump to .algo\n    ];\n\n    let mut cpu = cpu::CPU::new(Memory::new(), Nmos6502);\n\n    cpu.memory.set_bytes(0x00, \u0026zero_page_data);\n    cpu.memory.set_bytes(0x10, \u0026program);\n    cpu.registers.program_counter = 0x10;\n\n    cpu.run();\n\n    // The expected GCD is 7\n    assert_eq!(7, cpu.registers.accumulator);\n}\n```\n\nThe same can be achieved, by compiling the euclid example yourself.\n\nFirst install a 6502 assembler and linker, e.g. [cc65](https://cc65.github.io/cc65/).\n\n```sh\nbrew install cc65\n```\n\nThen compile and link the assembly file:\n\n```sh\ncd examples/asm/euclid\nca65 euclid.a65\nld65 -C ../linker.cfg -o euclid.bin euclid.o\n```\n\nThis will create a binary file `euclid.bin` that you can load into the emulator:\n\n```rust\nuse mos6502::memory::Bus;\nuse mos6502::memory::Memory;\nuse mos6502::instruction::Nmos6502;\nuse mos6502::cpu;\nuse std::fs::read;\n\nfn main() {\n    // Calculate the greatest common divisor of 56 and 49\n    // using Euclid's algorithm.\n    let zero_page_data = [56, 49];\n\n    // Load the binary file from disk\n    let program = match read(\"examples/asm/euclid/euclid.bin\") {\n        Ok(data) =\u003e data,\n        Err(err) =\u003e {\n            println!(\"Error reading euclid.bin: {}\", err);\n            return;\n        }\n    };\n\n    let mut cpu = cpu::CPU::new(Memory::new(), Nmos6502);\n\n    cpu.memory.set_bytes(0x00, \u0026zero_page_data);\n    cpu.memory.set_bytes(0x10, \u0026program);\n    cpu.registers.program_counter = 0x10;\n\n    cpu.run();\n\n    // The expected GCD is 7\n    assert_eq!(7, cpu.registers.accumulator);\n}\n```\n\n## Credits\n\nThis started off as a fork of [amw-zero/6502-rs](https://github.com/amw-zero/6502-rs),\nwhich seems to be [unmaintained](https://github.com/amw-zero/6502-rs/pull/36) at this point.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmre%2Fmos6502","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmre%2Fmos6502","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmre%2Fmos6502/lists"}