pub struct Dmc {
pub irq_enable: bool,
pub loop_flag: bool,
pub current_addr: u16,
pub bytes_remaining: u16,
pub dac: u8,
pub irq_flag: bool,
/* private fields */
}Expand description
DMC channel state.
Fields§
§irq_enable: boolIRQ enable bit ($4010 bit 7).
loop_flag: boolLoop bit ($4010 bit 6).
current_addr: u16Current memory address.
bytes_remaining: u16Bytes remaining to fetch.
dac: u87-bit DAC value (0..=127).
irq_flag: boolLatched IRQ flag (cleared by writing $4015).
Implementations§
Source§impl Dmc
impl Dmc
Sourcepub fn write_ctrl(&mut self, value: u8)
pub fn write_ctrl(&mut self, value: u8)
$4010 write: IRQ enable + loop + rate index.
Note: the public NTSC/PAL rate tables are the period in CPU cycles
per output bit. The DMC timer ticks at the APU clock (= half CPU
rate), so the internal reload value is cpu_period / 2 - 1.
Sourcepub fn write_sample_addr(&mut self, value: u8)
pub fn write_sample_addr(&mut self, value: u8)
$4012 write: sample address.
Sourcepub fn write_sample_length(&mut self, value: u8)
pub fn write_sample_length(&mut self, value: u8)
$4013 write: sample length.
Sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
$4015 write effect on DMC: bit 4 set restarts sample if not running;
bit 4 clear silences (sets bytes-remaining=0). Always clears irq_flag.
Sourcepub const fn needs_dma(&self) -> bool
pub const fn needs_dma(&self) -> bool
Returns true if the DMC needs a DMA fetch right now (sample buffer
empty and bytes remaining). Caller is responsible for halting the
CPU and supplying the byte via Self::deliver_sample.
Sourcepub fn deliver_sample(&mut self, byte: u8)
pub fn deliver_sample(&mut self, byte: u8)
Consume a fetched byte from the DMA controller.
Sourcepub fn clock_timer(&mut self)
pub fn clock_timer(&mut self)
One APU clock — drives the timer, output unit, and (on buffer empty) loads the shift register from the sample buffer.
Sourcepub const fn timer(&self) -> u16
pub const fn timer(&self) -> u16
Diagnostic: current byte-timer countdown value. Used by the per-cycle
DMC-DMA cross-diff tracing (crates/rustynes-test-harness/src/bin/ trace_dma_4015.rs) to expose the internal byte-timer phase that the
abort-context reload arm depends on.
Sourcepub const fn bits_remaining(&self) -> u8
pub const fn bits_remaining(&self) -> u8
Diagnostic: bits remaining in the output shift register (0..=8).
Sourcepub const fn buffer_full(&self) -> bool
pub const fn buffer_full(&self) -> bool
Diagnostic: sample buffer occupied (a byte awaits transfer to the shift register).