huc6280/
lib.rs

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