m68k-rs
A safe, pure Rust implementation of the Motorola 68000 family CPU emulator.
Strong for both low-level hardware-accurate emulation and high-level emulation (HLE).
Features
- Complete CPU family support: M68000, M68010, M68020, M68030, M68040, and variants (EC/LC)
- Zero dependencies: Pure Rust with no external runtime dependencies
- Safe Rust: No unsafe code blocks
- FPU emulation: Full 68881/68882/68040 floating-point unit support
- MMU emulation: 68030/68040 PMMU with table walks and transparent translation
- HLE-ready: Built-in trap interception for High-Level Emulation
- Extensively tested: Validated against multiple industry-standard test suites
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
Basic Usage
use ;
// Implement your memory bus
High-Level Emulation (HLE)
Intercept traps for OS emulation or debugger integration with CPU/bus access:
use ;
;
Other HleHandler callbacks you can implement (all are optional):
handle_fline(cpu, bus, opcode): intercepts 0xFxxx (Line-F) instructions (e.g., FPU probes).handle_trap(cpu, bus, trap_num): interceptsTRAP #n.handle_breakpoint(cpu, bus, bp_num): interceptsBKPT #n.handle_illegal(cpu, bus, opcode): intercepts illegal instructions.
Return true to indicate the HLE handled the trap, or false to fall back to the real hardware exception.
Supported CPU Types
| CPU | Description |
|---|---|
M68000 |
Original 68000 (24-bit address bus) |
M68010 |
68010 with virtual memory support |
M68EC020 |
68020 embedded controller (no MMU) |
M68020 |
Full 68020 with 32-bit address bus |
M68EC030 |
68030 embedded controller (no MMU) |
M68030 |
Full 68030 with on-chip MMU |
M68EC040 |
68040 embedded controller (no FPU/MMU) |
M68LC040 |
68040 lite (no FPU) |
M68040 |
Full 68040 with FPU and MMU |
SCC68070 |
Philips SCC68070 variant |
Validation & Testing
This emulator has been rigorously validated against multiple industry-standard test suites to ensure correctness:
SingleStepTests (m68000)
The SingleStepTests project provides exhaustive per-instruction test vectors derived from real hardware and cycle-accurate emulators. Our test suite runs all 101 instruction categories with thousands of test cases each, covering:
- All addressing modes and operand sizes
- Edge cases for condition codes (CCR/SR)
- BCD arithmetic (ABCD, SBCD, NBCD)
- Multiply/divide overflow handling
- Exception frame generation
Musashi Reference Implementation
We validate against Musashi, the gold-standard M68000 emulator used in MAME and countless other projects. Our integration tests:
- Execute complete Musashi test binaries
- Verify register state, memory contents, and exception handling
- Cover 68000 through 68040 instruction sets
Cross-CPU Verification
Additional test suites verify behavior across CPU generations:
- 68040 FPU tests: Floating-point transcendental functions, rounding modes
- MMU translation tests: Table walks, TTR matching, fault handling
- Privilege tests: User/supervisor mode transitions, TRAP behavior
- Exception tests: Double-fault detection, address error frames
Test Coverage
tests/
├── singlestep_m68000_v1_tests.rs # 101 instruction test files
├── musashi_tests.rs # Musashi integration suite
├── cross_cpu_tests.rs # Multi-generation verification
├── m68040_tests.rs # 68040-specific features
├── mmu_fault_tests.rs # MMU and exception handling
├── hle_interception_tests.rs # Trap handler API tests
└── fixtures/
├── m68000/ # SingleStepTests submodule
└── Musashi/ # Musashi reference submodule
Architecture
m68k/
├── core/ # CPU core, registers, execution loop
├── dasm/ # Disassembler
├── fpu/ # 68881/68882/68040 FPU emulation
└── mmu/ # 68030/68040 PMMU emulation
Key Types
| Type | Description |
|---|---|
CpuCore |
Main CPU state and execution |
CpuType |
CPU model selection enum |
AddressBus |
Trait for memory/IO implementation |
HleHandler |
Trait for HLE interception |
StepResult |
Instruction execution result |
Performance
The emulator is designed for correctness first, with performance as a secondary goal. Typical use cases (classic computer emulation, game console emulation) run at many multiples of original hardware speed on modern CPUs.
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please ensure:
- All tests pass:
cargo test - No clippy warnings:
cargo clippy -- -D warnings - Code is formatted:
cargo fmt
Acknowledgments
- Musashi - Reference implementation and test fixtures
- SingleStepTests - Exhaustive instruction test vectors
- The M68000 Programmer's Reference Manual