Skip to main content

rustynes_cpu/
lib.rs

1//! Cycle-accurate Ricoh 2A03 CPU core (6502 derivative without BCD mode).
2//!
3//! See `docs/cpu-6502.md` in the workspace root for the implementation
4//! specification, and `ref-docs/research-report.md` §CPU for the source
5//! material this is derived from.
6//!
7//! All 151 documented 6502 opcodes plus the 105 unofficial / undocumented
8//! ones are implemented at per-cycle granularity, including the JAM/KIL/STP
9//! halt opcodes, NMI / IRQ / BRK handling, and the page-crossing dummy reads
10//! that the test ROMs check for.
11
12#![no_std]
13// The chip stack carries no `unsafe`; `forbid` makes that a compile-time
14// guarantee rather than an observation (core audit section 2.1). The FFI
15// and platform `unsafe` lives in the frontend, cheevos and mobile crates.
16#![forbid(unsafe_code)]
17#![warn(missing_docs)]
18
19extern crate alloc;
20
21mod bus;
22mod cpu;
23pub mod disasm;
24pub mod scheduler;
25mod snapshot;
26mod status;
27
28pub use bus::Bus;
29pub use cpu::Cpu;
30#[cfg(feature = "phi2-write-sweep")]
31pub use cpu::READ_PHI_BACKOFF;
32#[cfg(feature = "phi2-write-sweep")]
33pub use cpu::READ_PHI_OFFSET;
34#[cfg(feature = "phi2-write-sweep")]
35pub use cpu::WRITE_PHI_BACKOFF;
36#[cfg(feature = "phi2-write-sweep")]
37pub use cpu::WRITE_PHI_OFFSET;
38pub use disasm::{DisasmLine, disassemble_at};
39pub use scheduler::M2Phase;
40pub use snapshot::{CPU_SNAPSHOT_VERSION, CpuSnapshotError};
41pub use status::Status;
42
43/// Returns the crate version string.
44#[must_use]
45pub const fn version() -> &'static str {
46    env!("CARGO_PKG_VERSION")
47}
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn version_is_non_empty() {
55        assert_ne!(version(), "");
56    }
57}