1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! A safe, embeddable Motorola M68000-family CPU emulator.
//!
//! The core supports the M68000, M68010, M68EC020, M68020, M68EC030,
//! M68030, M68EC040, M68LC040, M68040, M68060, and SCC68070. It includes
//! generation-specific exception frames, instruction prefetch, integer and
//! floating-point execution, 68030/68040/68060 MMU translation, and
//! per-generation timing models.
//!
//! # Getting started
//!
//! Implement [`AddressBus`] for a machine with devices, or use
//! [`LinearMemoryBus`] for a contiguous RAM-backed address space:
//!
//! ```no_run
//! use m68k::{CpuCore, CpuType, LinearMemoryBus, StepResult};
//!
//! let mut memory = LinearMemoryBus::new(1024 * 1024);
//! memory.write_long_at(0, 0x0008_0000); // reset SSP
//! memory.write_long_at(4, 0x0000_1000); // reset PC
//! memory.write_word_at(0x1000, 0x4E71); // NOP
//!
//! let mut cpu = CpuCore::new();
//! cpu.set_cpu_type(CpuType::M68000);
//! cpu.reset(&mut memory);
//! assert!(matches!(cpu.step(&mut memory), StepResult::Ok { .. }));
//! ```
//!
//! [`CpuCore::step`] and [`CpuCore::execute`] preserve transaction-level bus
//! ordering and expose internal-clock gaps through [`AddressBus::sync`].
//! [`CpuCore::run_for_cycles`] retains cycle accounting with lower dispatch
//! overhead. [`CpuCore::run_for_cycles_with_hook`] additionally lets a host
//! synchronize devices and IRQ state between instructions, and
//! [`CpuCore::run_for_cycles_with_boundary_hook`] also reports interrupt
//! entry, while
//! [`CpuCore::run_batch`] is an instruction-budgeted throughput path that can
//! use [`FastMem`].
//!
//! # Cargo features
//!
//! - `serde` serializes the architectural CPU state for deterministic save
//! states. Decode tables, FastMem pointers, and trace caches are deliberately
//! omitted and rebuilt after loading.
//! - `jit` lowers eligible hot traces to native code with Cranelift on
//! non-WebAssembly targets. Without it—and on WebAssembly—the same trace
//! machinery uses the portable Rust executor.
//! - `trace-profile` adds opt-in trace and decoded-operation profiling,
//! activated at runtime with `M68K_TRACE_PROFILE=1`.
//!
//! No features are enabled by default.
// Re-export the embedding API at the crate root.
pub use CpuCore;
pub use ;
pub use ;
pub use ;