Crate huc6280

Crate huc6280 

Source
Expand description

A Rust Hudson HuC6280 core transcribed from huc6280-python (built from v0.3.0, now at its clean rewrite 6ce348e, after v0.4.0) and proven equivalent to it at every processor boundary.

Each module is the transcription of one huc6280/*.py module, with the same handler names, the same explicit dispatch table, the named switches as fields and the hardware comments carried over: core, alu, bits, block, control, hudson, loads, shifts, dispatch, cpu, state and trace. It builds on 6502-rust’s frame (crate sixfiveohtwo: the interrupt requests, the poll and step()’s skeleton) as the reference builds on 6502-python’s CPUFrame. Where Rust forced a difference, the module header says so.

use huc6280::{Bus, HuC6280, Pins};

/// 2 MB of flat RAM over the 21-bit physical space.
struct Ram(Vec<u8>);
impl Bus for Ram {
    fn read(&mut self, address: u32, _: &mut Pins) -> u8 {
        self.0[address as usize]
    }
    fn write(&mut self, address: u32, value: u8, _: &mut Pins) {
        self.0[address as usize] = value;
    }
}

let mut ram = Ram(vec![0; 0x200000]);
ram.0[0x1F0000] = 0xE8; // INX, in work RAM (page $F8)
let mut cpu = HuC6280::new(ram);
cpu.mpr[2] = 0xF8; // logical $4000-$5FFF is page $F8
cpu.pc = 0x4000;
assert_eq!(cpu.step(), 2);
assert_eq!(cpu.x, 1);

Re-exports§

pub use crate::state::CpuState;

Modules§

state
Values for capturing and restoring HuC6280 processor state (state.py).
trace
Boundary traces in the reference’s version 1 JSON Lines schema (trace.py and the parts of debug.py a trace needs; 6502-python docs/trace-schema.md).

Structs§

Frame
The interrupt inputs and the poll’s memory, shared by every 65xx part.
HuC6280
A Hudson HuC6280 core whose memory and devices are a host’s Bus.
Pins
What a bus callback can see and change of the CPU while it runs: the frame’s requests (reset, NMI), the three maskable inputs and their disable register, the clock switch, the cycle’s kind and the opcode.
PollFields
The frame’s fields of a state snapshot (CPUFrame._poll_fields).

Enums§

DecimalFormula
C13: the decimal digit adjust of ADC and SBC (the reference’s DECIMAL_FORMULAS = ("mednafen", "mesen")).
Form
An operand form, for a disassembler and the instruction length (SW section 3).
IrqPollCycle
U25: when the boundary samples the lines. Hudson’s hardware manual says only that the inputs “are sampled in the last bus cycle of one instruction” (HW HB-12), not whether a change during that cycle counts.
Kind
A cycle’s kind, as Pins::kind shows it.
Mode
An addressing mode, the reference’s _ea_<mode> methods.
Op
A handler, named as the reference’s _op_<name> methods are.
TmaMultiple
C6: TMA with several mask bits. pcetech 2.0: “combined together… I have not figured out exactly how this works”. Or (default): all 2,418 SingleStepTests huc6280 cases with several bits record the OR of the registers (OBSERVED, provisional: the corpus is Mesen’s output, a closed box). Highest: MAME 0.285 (h6280.cpp tma, BSD-3-Clause, Bryan McPhail). Lowest: for completeness. No hardware result is known.
VanishedInterrupt
C18: what an entry does when a source the poll saw has gone by the boundary (it was acknowledged in the instruction’s last cycle). When nothing is left, the instruction runs instead.

Constants§

B
C
D
HARDWARE_ZERO_END
HARDWARE_ZERO_START
I
IRQ1_BIT
IRQ2_BIT
IRQ_LINE
The IRQ line, a level, as a bit of the requests.
N
NMI_LATCH
The NMI latch: an edge remembered until it is taken.
NO_POLL
In polled only: the last sequence (BRK, an interrupt entry, reset) did not poll, so nothing is taken until an instruction has run and polled.
OPCODES
STACK_PAGE
T
TIQ_BIT
V
VDC_ADDRESS
U12: ST0-ST2 write physical $1FE000, $1FE002 and $1FE003 whatever the mapper holds (HW HB-8, Table 2-2-3: A20 high, A1:A0 = 00, 10, 11; pcetech 2.0). The VDC’s registers are every 4 bytes.
VECTOR_IRQ1
VECTOR_IRQ2
VECTOR_NMI
VECTOR_RESET
VECTOR_TIQ
Z
ZERO_PAGE
Zero page and stack are logical pages $20 and $21, through MPR1 (U1; HW HB-3: the address bus high byte is $21 for the stack).

Traits§

Bus
The host’s side of the bus: exactly one call per cycle, in the chip’s order, with 21-bit physical addresses.
Part
A 65xx-family part on the frame: its four sequences, and the step that chooses between them (CPUFrame.step).

Functions§

add
ADC: (result, new P). Binary: N V Z C as the 6502 (SW SB-17); decimal: C13 (the module’s head).
subtract
SBC: (result, new P). Binary: N V Z C as the 6502 (SW SB-74); decimal: C13 (the module’s head).

Type Aliases§

Row
opcode: (handler, mode, mnemonic, form, base cycles)