huc6280/lib.rs
1// SPDX-License-Identifier: MIT
2//! A Rust Hudson HuC6280 core transcribed from
3//! [huc6280-python](https://github.com/alewman/huc6280-python) (built from
4//! `v0.3.0`, now at its clean rewrite `6ce348e`, after `v0.4.0`) and proven
5//! equivalent to it at every processor boundary.
6//!
7//! Each module is the transcription of one `huc6280/*.py` module, with the
8//! same handler names, the same explicit dispatch table, the named switches
9//! as fields and the hardware comments carried over: `core`, `alu`, `bits`,
10//! `block`, `control`, `hudson`, `loads`, `shifts`, `dispatch`, `cpu`,
11//! [`state`] and [`trace`]. It builds on 6502-rust's frame (crate
12//! `sixfiveohtwo`: the interrupt requests, the poll and `step()`'s
13//! skeleton) as the reference builds on 6502-python's `CPUFrame`. Where
14//! Rust forced a difference, the module header says so.
15//!
16//! ```
17//! use huc6280::{Bus, HuC6280, Pins};
18//!
19//! /// 2 MB of flat RAM over the 21-bit physical space.
20//! struct Ram(Vec<u8>);
21//! impl Bus for Ram {
22//! fn read(&mut self, address: u32, _: &mut Pins) -> u8 {
23//! self.0[address as usize]
24//! }
25//! fn write(&mut self, address: u32, value: u8, _: &mut Pins) {
26//! self.0[address as usize] = value;
27//! }
28//! }
29//!
30//! let mut ram = Ram(vec![0; 0x200000]);
31//! ram.0[0x1F0000] = 0xE8; // INX, in work RAM (page $F8)
32//! let mut cpu = HuC6280::new(ram);
33//! cpu.mpr[2] = 0xF8; // logical $4000-$5FFF is page $F8
34//! cpu.pc = 0x4000;
35//! assert_eq!(cpu.step(), 2);
36//! assert_eq!(cpu.x, 1);
37//! ```
38
39mod alu;
40mod bits;
41mod block;
42mod control;
43mod core;
44mod cpu;
45mod dispatch;
46mod hudson;
47mod loads;
48mod shifts;
49pub mod state;
50pub mod trace;
51
52pub use sixfiveohtwo::frame::{Frame, Part, PollFields, IRQ_LINE, NMI_LATCH, NO_POLL};
53
54pub use crate::alu::{add, subtract, DecimalFormula};
55pub use crate::block::{HARDWARE_ZERO_END, HARDWARE_ZERO_START};
56pub use crate::control::{
57 IrqPollCycle, VanishedInterrupt, IRQ1_BIT, IRQ2_BIT, TIQ_BIT, VECTOR_IRQ1, VECTOR_IRQ2,
58 VECTOR_NMI, VECTOR_RESET, VECTOR_TIQ,
59};
60pub use crate::core::{Bus, HuC6280, Kind, Pins, B, C, D, I, N, STACK_PAGE, T, V, Z, ZERO_PAGE};
61pub use crate::dispatch::{Form, Mode, Op, Row, OPCODES};
62pub use crate::hudson::{TmaMultiple, VDC_ADDRESS};
63pub use crate::state::CpuState;
64
65/// The README's example compiles and runs as a doctest.
66#[cfg(doctest)]
67#[doc = include_str!("../README.md")]
68struct ReadmeDoctests;