// SPDX-License-Identifier: MIT //! The opcode map: handler, addressing mode, mnemonic, operand form and base //! cycles (`_dispatch.py`). //! //! `OPCODES` is the fullest part, the W65C02S: 212 documented opcodes (DS //! Table 5-2) and 44 undefined ones, every one a NOP of the length and cycle //! count DS Table 7-1 gives. The other rows are this table with cells replaced //! ([`opcodes_for`]): a part without the bit instructions has a one-byte, //! one-cycle NOP at each `x7` and `xF` (GDS Table V, VDS Table 2, NDS; CAP on //! the G65SC12; against SST, C2), and a part without `WAI` and `STP` has one //! at `$CB` and `$DB` (GDS, VDS, NDS, RDS; not captured, U3). //! //! - `handler`: the `op_` method ([`Op`]). //! - `mode`: the method that makes the addressing cycles, or `Implied` (the //! reference's `None`) when the handler makes its own (implied, the stack, //! branches, jumps, the bit instructions, the NOPs). `rd_` returns the //! operand's value, `ea_` its address; `_fixed` is the indexed form //! that always takes the extra cycle (stores; `INC` and `DEC abs,X`, C11). //! - `mnemonic` and `form`: for the disassembler; [`FORM_BYTES`] gives the //! instruction length. //! - `cycles`: the count with D clear, no page crossed and no branch taken //! (DS Tables 4-1 and 7-1; CAP's measured counts in docs/timing.md), which //! rung 1 confirms by running the instruction. `step()` adds what the //! instruction adds (`extra`). //! //! The reference's rung 0 (tests/test_tables.py) holds every row against a //! transcription of the data sheets' tables and against the counts measured on //! real chips; here rung 1 (`scripts/check_tables.py`) holds every row's table //! against the reference's `opcodes_for`. //! //! The table below is generated from the reference's `OPCODES` dict by //! `scripts/gen_dispatch.py`. Differences forced by Rust: handlers, modes and //! forms are enums where the reference has strings and bound methods, and the //! dispatch is the table and three explicit matches (the mode's value or //! address, then the handler), as 6502-rust's; the reference resolves the //! same table into unbound functions once per class (`build_table`), here once //! per CPU. use crate::core::{Bus, Cmos65c02}; use crate::cpu::Row; /// A handler, named as the reference's `_op_` methods are. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Op { @HANDLERS@ } /// An addressing method, the reference's `_rd_` and `_ea_`. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Mode { /// The reference's `None`: the handler makes its own cycles. Implied, @MODES@ } /// An operand form, for the instruction length and the disassembler. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Form { @FORMS@ } /// One row of the map: (handler, mode, mnemonic, form, base cycles). pub type OpcodeRow = (Op, Mode, &'static str, Form, u32); // Evidence for the table (tags: emulator-lineage docs/methodology.md): // - which opcodes exist, mnemonics, lengths: DOC (DS Tables 5-2 and 7-1; GDS // Tables IV and V for the 178 common opcodes); // - base cycle counts: DOC (DS Tables 4-1 and 7-1), and MEASURED (CAP) for the // 253 opcodes the two captured parts executed (rung 0: all but `$00`, // `$CB`, `$DB`); BRK's 7 is DOC (DS) only, and `$CB` WAI and `$DB` STP are // DOC (DS; GF's bench notes); // - `x7`/`xF` bit instructions: MEASURED on the R65C02 (CAP), DOC (DS, RDS); // - every count is also OBSERVED in SST (rung 1), outside C1, C2 and C3. /// opcode: (handler, mode, mnemonic, form, base cycles), for the W65C02S. #[rustfmt::skip] pub const OPCODES: [OpcodeRow; 256] = [ @TABLE@ ];