yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::emu::Apu Class Reference

The Apu class represents the Audio Processing Unit (APU) of a system. More...

#include <apu.h>

Public Member Functions

 Apu (MemoryImpl &memory)
 
void Init ()
 
void Reset ()
 
void RunCycles (uint64_t cycles)
 
void SaveState (std::ostream &stream)
 
void LoadState (std::istream &stream)
 
uint8_t SpcRead (uint16_t address)
 
void SpcWrite (uint16_t address, uint8_t data)
 
void SpcIdle (bool waiting)
 
void Cycle ()
 
uint8_t Read (uint16_t address)
 
void Write (uint16_t address, uint8_t data)
 
auto dsp () -> Dsp &
 
auto dsp () const -> const Dsp &
 
auto spc700 () -> Spc700 &
 
uint64_t GetCycles () const
 
void set_handshake_tracker (debug::ApuHandshakeTracker *tracker)
 
uint8_t GetStatus () const
 
uint8_t GetControl () const
 
void GetSamples (int16_t *buffer, int count, bool loop=false)
 
void WriteDma (uint16_t address, const uint8_t *data, int count)
 
void BootstrapDirect (uint16_t entry_point)
 Bootstrap SPC directly to driver code (bypasses IPL ROM handshake)
 
bool IsDriverRunning () const
 Check if SPC has completed IPL ROM boot and is running driver code.
 
const TimerGetTimer (int timer_index) const
 Get timer state for debug UI.
 
void WriteToDsp (uint8_t address, uint8_t value)
 Write directly to DSP register Used for direct instrument/note preview without going through driver.
 

Public Attributes

std::array< uint8_t, 6 > in_ports_
 
std::array< uint8_t, 4 > out_ports_
 
std::vector< uint8_t > ram = std::vector<uint8_t>(0x10000, 0)
 

Private Attributes

bool rom_readable_ = false
 
uint8_t dsp_adr_ = 0
 
uint64_t cycles_ = 0
 
uint64_t last_master_cycles_ = 0
 
uint8_t transfer_size_ = 0
 
bool in_transfer_ = false
 
MemoryImplmemory_
 
std::array< Timer, 3 > timer_
 
debug::ApuHandshakeTrackerhandshake_tracker_ = nullptr
 
ApuCallbacks callbacks_
 
Dsp dsp_ {ram}
 
Spc700 spc700_ {callbacks_}
 

Detailed Description

The Apu class represents the Audio Processing Unit (APU) of a system.

The Apu class is responsible for generating audio samples and managing the APU state. It interacts with the Memory, AudioRam, and Clock classes to read/write data and update the clock. The class also implements the Observer interface to receive notifications from the system.

IPL ROM Info
64 kilobytes of RAM are mapped across the 16-bit memory space of the SPC-700. Some regions of this space are overlaid with special hardware functions.
Range Note
$0000-00EF Zero Page RAM $00F0-00FF Sound CPU Registers $0100-01FF Stack Page RAM $0200-FFBF RAM $FFC0-FFFF IPL ROM or RAM

The region at $FFC0-FFFF will normally read from the 64-byte IPL ROM, but the underlying RAM can always be written to, and the high bit of the Control register $F1 can be cleared to unmap the IPL ROM and allow read access to this RAM.

Definition at line 53 of file apu.h.

Constructor & Destructor Documentation

◆ Apu()

yaze::emu::Apu::Apu ( MemoryImpl & memory)
inline

Definition at line 55 of file apu.h.

Member Function Documentation

◆ Init()

void yaze::emu::Apu::Init ( )

Definition at line 47 of file apu.cc.

References ram.

Referenced by yaze::emu::Snes::Init().

◆ Reset()

◆ RunCycles()

◆ SaveState()

void yaze::emu::Apu::SaveState ( std::ostream & stream)

Definition at line 426 of file apu.cc.

References cycles_, dsp_, dsp_adr_, in_ports_, in_transfer_, out_ports_, ram, rom_readable_, yaze::emu::Dsp::SaveState(), yaze::emu::Spc700::SaveState(), spc700_, timer_, and transfer_size_.

Referenced by yaze::emu::Snes::saveState().

Here is the call graph for this function:

◆ LoadState()

void yaze::emu::Apu::LoadState ( std::istream & stream)

◆ SpcRead()

uint8_t yaze::emu::Apu::SpcRead ( uint16_t address)

Definition at line 412 of file apu.cc.

References Cycle(), and Read().

Here is the call graph for this function:

◆ SpcWrite()

void yaze::emu::Apu::SpcWrite ( uint16_t address,
uint8_t data )

Definition at line 417 of file apu.cc.

References Cycle(), and Write().

Here is the call graph for this function:

◆ SpcIdle()

void yaze::emu::Apu::SpcIdle ( bool waiting)

Definition at line 422 of file apu.cc.

References Cycle().

Here is the call graph for this function:

◆ Cycle()

void yaze::emu::Apu::Cycle ( )

Definition at line 226 of file apu.cc.

References yaze::emu::Dsp::Cycle(), cycles_, dsp_, and timer_.

Referenced by RunCycles(), SpcIdle(), SpcRead(), and SpcWrite().

Here is the call graph for this function:

◆ Read()

uint8_t yaze::emu::Apu::Read ( uint16_t address)

Definition at line 253 of file apu.cc.

References dsp_, dsp_adr_, in_ports_, ram, yaze::emu::Dsp::Read(), rom_readable_, and timer_.

Referenced by SpcRead().

Here is the call graph for this function:

◆ Write()

void yaze::emu::Apu::Write ( uint16_t address,
uint8_t data )

◆ dsp() [1/2]

auto yaze::emu::Apu::dsp ( ) -> Dsp&
inline

Definition at line 74 of file apu.h.

References dsp_.

Referenced by yaze::emu::Snes::RunCycle(), and yaze::emu::Snes::SetSamples().

◆ dsp() [2/2]

auto yaze::emu::Apu::dsp ( ) const -> const Dsp&
inline

Definition at line 75 of file apu.h.

References dsp_.

◆ spc700()

auto yaze::emu::Apu::spc700 ( ) -> Spc700&
inline

Definition at line 76 of file apu.h.

References spc700_.

◆ GetCycles()

uint64_t yaze::emu::Apu::GetCycles ( ) const
inline

Definition at line 78 of file apu.h.

References cycles_.

Referenced by yaze::emu::Snes::ReadBBus().

◆ set_handshake_tracker()

void yaze::emu::Apu::set_handshake_tracker ( debug::ApuHandshakeTracker * tracker)
inline

Definition at line 81 of file apu.h.

References handshake_tracker_.

Referenced by yaze::emu::Snes::Init().

◆ GetStatus()

uint8_t yaze::emu::Apu::GetStatus ( ) const
inline

Definition at line 84 of file apu.h.

References ram.

◆ GetControl()

uint8_t yaze::emu::Apu::GetControl ( ) const
inline

Definition at line 85 of file apu.h.

References ram.

◆ GetSamples()

void yaze::emu::Apu::GetSamples ( int16_t * buffer,
int count,
bool loop = false )
inline

Definition at line 86 of file apu.h.

References dsp_, and yaze::emu::Dsp::GetSamples().

Here is the call graph for this function:

◆ WriteDma()

void yaze::emu::Apu::WriteDma ( uint16_t address,
const uint8_t * data,
int count )
inline

Definition at line 89 of file apu.h.

References ram.

◆ BootstrapDirect()

void yaze::emu::Apu::BootstrapDirect ( uint16_t entry_point)

Bootstrap SPC directly to driver code (bypasses IPL ROM handshake)

This method allows direct control of the SPC700 by:

  1. Disabling the IPL ROM
  2. Setting PC to the driver entry point
  3. Initializing SPC state for driver execution

Use this after uploading audio driver code via WriteDma() to bypass the normal IPL ROM handshake protocol.

Parameters
entry_pointThe ARAM address where the driver code starts (typically $0800)

Definition at line 478 of file apu.cc.

References yaze::emu::Spc700::A, yaze::emu::Spc700::Flags::B, yaze::emu::Spc700::Flags::C, yaze::emu::Spc700::Flags::H, yaze::emu::Spc700::Flags::I, in_ports_, in_transfer_, LOG_INFO, yaze::emu::Spc700::Flags::N, out_ports_, yaze::emu::Spc700::Flags::P, yaze::emu::Spc700::PC, yaze::emu::Spc700::PSW, ram, rom_readable_, yaze::emu::Spc700::SP, spc700_, transfer_size_, yaze::emu::Spc700::Flags::V, yaze::emu::Spc700::X, yaze::emu::Spc700::Y, and yaze::emu::Spc700::Flags::Z.

◆ IsDriverRunning()

bool yaze::emu::Apu::IsDriverRunning ( ) const
inline

Check if SPC has completed IPL ROM boot and is running driver code.

Returns
true if IPL ROM is disabled and SPC is executing from RAM

Definition at line 114 of file apu.h.

References rom_readable_.

◆ GetTimer()

const Timer & yaze::emu::Apu::GetTimer ( int timer_index) const
inline

Get timer state for debug UI.

Parameters
timer_index0, 1, or 2

Definition at line 120 of file apu.h.

References timer_.

◆ WriteToDsp()

void yaze::emu::Apu::WriteToDsp ( uint8_t address,
uint8_t value )
inline

Write directly to DSP register Used for direct instrument/note preview without going through driver.

Definition at line 130 of file apu.h.

References dsp_, and yaze::emu::Dsp::Write().

Here is the call graph for this function:

Member Data Documentation

◆ in_ports_

std::array<uint8_t, 6> yaze::emu::Apu::in_ports_

◆ out_ports_

std::array<uint8_t, 4> yaze::emu::Apu::out_ports_

◆ ram

std::vector<uint8_t> yaze::emu::Apu::ram = std::vector<uint8_t>(0x10000, 0)

◆ rom_readable_

bool yaze::emu::Apu::rom_readable_ = false
private

Definition at line 142 of file apu.h.

Referenced by BootstrapDirect(), IsDriverRunning(), LoadState(), Read(), Reset(), RunCycles(), SaveState(), and Write().

◆ dsp_adr_

uint8_t yaze::emu::Apu::dsp_adr_ = 0
private

Definition at line 144 of file apu.h.

Referenced by LoadState(), Read(), Reset(), SaveState(), and Write().

◆ cycles_

uint64_t yaze::emu::Apu::cycles_ = 0
private

Definition at line 145 of file apu.h.

Referenced by Cycle(), GetCycles(), LoadState(), Reset(), RunCycles(), SaveState(), and Write().

◆ last_master_cycles_

uint64_t yaze::emu::Apu::last_master_cycles_ = 0
private

Definition at line 146 of file apu.h.

Referenced by Reset(), and RunCycles().

◆ transfer_size_

uint8_t yaze::emu::Apu::transfer_size_ = 0
private

Definition at line 149 of file apu.h.

Referenced by BootstrapDirect(), LoadState(), Reset(), SaveState(), and Write().

◆ in_transfer_

bool yaze::emu::Apu::in_transfer_ = false
private

Definition at line 150 of file apu.h.

Referenced by BootstrapDirect(), LoadState(), Reset(), SaveState(), and Write().

◆ memory_

MemoryImpl& yaze::emu::Apu::memory_
private

Definition at line 152 of file apu.h.

Referenced by RunCycles().

◆ timer_

std::array<Timer, 3> yaze::emu::Apu::timer_
private

Definition at line 153 of file apu.h.

Referenced by Cycle(), GetTimer(), LoadState(), Read(), Reset(), SaveState(), and Write().

◆ handshake_tracker_

debug::ApuHandshakeTracker* yaze::emu::Apu::handshake_tracker_ = nullptr
private

Definition at line 156 of file apu.h.

Referenced by Reset(), RunCycles(), set_handshake_tracker(), and Write().

◆ callbacks_

ApuCallbacks yaze::emu::Apu::callbacks_
private
Initial value:
= {
[&](uint16_t adr, uint8_t val) { SpcWrite(adr, val); },
[&](uint16_t adr) { return SpcRead(adr); },
[&](bool waiting) { SpcIdle(waiting); },
}
uint8_t SpcRead(uint16_t address)
Definition apu.cc:412
void SpcIdle(bool waiting)
Definition apu.cc:422
void SpcWrite(uint16_t address, uint8_t data)
Definition apu.cc:417

Definition at line 158 of file apu.h.

◆ dsp_

Dsp yaze::emu::Apu::dsp_ {ram}
private

Definition at line 163 of file apu.h.

Referenced by Cycle(), dsp(), dsp(), GetSamples(), LoadState(), Read(), Reset(), SaveState(), Write(), and WriteToDsp().

◆ spc700_

Spc700 yaze::emu::Apu::spc700_ {callbacks_}
private

Definition at line 164 of file apu.h.

Referenced by BootstrapDirect(), LoadState(), Reset(), RunCycles(), SaveState(), spc700(), and Write().


The documentation for this class was generated from the following files: