Skip to main content

Dmc

Struct Dmc 

Source
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: bool

IRQ enable bit ($4010 bit 7).

§loop_flag: bool

Loop bit ($4010 bit 6).

§current_addr: u16

Current memory address.

§bytes_remaining: u16

Bytes remaining to fetch.

§dac: u8

7-bit DAC value (0..=127).

§irq_flag: bool

Latched IRQ flag (cleared by writing $4015).

Implementations§

Source§

impl Dmc

Source

pub const fn new(region: Region) -> Self

Construct a new DMC channel.

Source

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.

Source

pub fn write_dac(&mut self, value: u8)

$4011 write: direct 7-bit DAC.

Source

pub fn write_sample_addr(&mut self, value: u8)

$4012 write: sample address.

Source

pub fn write_sample_length(&mut self, value: u8)

$4013 write: sample length.

Source

pub const fn active(&self) -> bool

Status ($4015 read bit 4): bytes-remaining > 0.

Source

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.

Source

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.

Source

pub const fn dma_addr(&self) -> u16

The address the DMA controller must read.

Source

pub fn deliver_sample(&mut self, byte: u8)

Consume a fetched byte from the DMA controller.

Source

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.

Source

pub const fn output(&self) -> u8

Per-cycle output (0..=127).

Source

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.

Source

pub const fn bits_remaining(&self) -> u8

Diagnostic: bits remaining in the output shift register (0..=8).

Source

pub const fn silence(&self) -> bool

Diagnostic: output-unit silence flag.

Source

pub const fn buffer_full(&self) -> bool

Diagnostic: sample buffer occupied (a byte awaits transfer to the shift register).

Trait Implementations§

Source§

impl Clone for Dmc

Source§

fn clone(&self) -> Dmc

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Dmc

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Dmc

Auto Trait Implementations§

§

impl Freeze for Dmc

§

impl RefUnwindSafe for Dmc

§

impl Send for Dmc

§

impl Sync for Dmc

§

impl Unpin for Dmc

§

impl UnsafeUnpin for Dmc

§

impl UnwindSafe for Dmc

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.