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