#include <snes.h>
Public Member Functions | |
Snes () | |
~Snes ()=default | |
void | Init (std::vector< uint8_t > &rom_data) |
void | Reset (bool hard=false) |
void | RunFrame () |
void | CatchUpApu () |
void | HandleInput () |
void | RunCycle () |
void | RunCycles (int cycles) |
void | SyncCycles (bool start, int sync_cycles) |
uint8_t | ReadBBus (uint8_t adr) |
uint8_t | ReadReg (uint16_t adr) |
uint8_t | Rread (uint32_t adr) |
uint8_t | Read (uint32_t adr) |
void | WriteBBus (uint8_t adr, uint8_t val) |
void | WriteReg (uint16_t adr, uint8_t val) |
void | Write (uint32_t adr, uint8_t val) |
int | GetAccessTime (uint32_t adr) |
uint8_t | CpuRead (uint32_t adr) |
void | CpuWrite (uint32_t adr, uint8_t val) |
void | CpuIdle (bool waiting) |
void | InitAccessTime (bool recalc) |
void | SetSamples (int16_t *sample_data, int wanted_samples) |
void | SetPixels (uint8_t *pixel_data) |
void | SetButtonState (int player, int button, bool pressed) |
void | loadState (const std::string &path) |
void | saveState (const std::string &path) |
bool | running () const |
auto | cpu () -> Cpu & |
auto | ppu () -> Ppu & |
auto | apu () -> Apu & |
auto | memory () -> MemoryImpl & |
auto | get_ram () -> uint8_t * |
auto | mutable_cycles () -> uint64_t & |
auto | apu_handshake_tracker () -> debug::ApuHandshakeTracker & |
Public Attributes | |
std::vector< uint8_t > | access_time |
bool | fast_mem_ = false |
Private Attributes | |
MemoryImpl | memory_ |
Cpu | cpu_ {memory_} |
Ppu | ppu_ {memory_} |
Apu | apu_ {memory_} |
std::vector< uint8_t > | rom_data |
bool | running_ = false |
uint8_t | ram [0x20000] |
uint32_t | ram_adr_ |
uint32_t | frames_ = 0 |
uint64_t | cycles_ = 0 |
uint64_t | sync_cycle_ = 0 |
double | apu_catchup_cycles_ |
uint32_t | next_horiz_event |
bool | h_irq_enabled_ = false |
bool | v_irq_enabled_ = false |
bool | nmi_enabled_ = false |
uint16_t | h_timer_ = 0 |
uint16_t | v_timer_ = 0 |
bool | in_nmi_ = false |
bool | irq_condition_ = false |
bool | in_irq_ = false |
bool | in_vblank_ |
uint8_t | multiply_a_ |
uint16_t | multiply_result_ |
uint16_t | divide_a_ |
uint16_t | divide_result_ |
Input | input1 |
Input | input2 |
uint16_t | port_auto_read_ [4] |
bool | auto_joy_read_ = false |
uint16_t | auto_joy_timer_ = 0 |
bool | ppu_latch_ |
debug::ApuHandshakeTracker | apu_handshake_tracker_ |
|
inline |
Definition at line 27 of file snes.h.
References yaze::emu::Cpu::callbacks(), cpu_, CpuIdle(), CpuRead(), CpuWrite(), input1, and input2.
|
default |
void yaze::emu::Snes::Init | ( | std::vector< uint8_t > & | rom_data | ) |
Definition at line 36 of file snes.cc.
References apu_, apu_handshake_tracker_, yaze::emu::Apu::Init(), yaze::emu::Ppu::Init(), yaze::emu::MemoryImpl::Initialize(), LOG_DEBUG, memory_, ppu_, Reset(), rom_data, running_, and yaze::emu::Apu::set_handshake_tracker().
Referenced by DungeonTestHarness::GenerateHarnessState(), main(), yaze::emu::Emulator::Run(), and yaze::test::EmulatorTestSuite::RunApuHandshakeTest().
void yaze::emu::Snes::Reset | ( | bool | hard = false | ) |
Definition at line 54 of file snes.cc.
References apu_, apu_catchup_cycles_, auto_joy_read_, auto_joy_timer_, cpu_, yaze::emu::Input::current_state_, cycles_, divide_a_, divide_result_, fast_mem_, frames_, h_irq_enabled_, h_timer_, in_irq_, in_nmi_, in_vblank_, InitAccessTime(), input1, input2, irq_condition_, yaze::emu::Input::latch_line_, yaze::emu::Input::latched_state_, LOG_DEBUG, memory_, multiply_a_, multiply_result_, next_horiz_event, nmi_enabled_, yaze::emu::Cpu::PB, yaze::emu::Cpu::PC, port_auto_read_, ppu_, ppu_latch_, ram, ram_adr_, yaze::emu::Apu::Reset(), yaze::emu::Ppu::Reset(), yaze::emu::Cpu::Reset(), yaze::emu::ResetDma(), yaze::emu::MemoryImpl::set_h_pos(), yaze::emu::MemoryImpl::set_open_bus(), yaze::emu::MemoryImpl::set_v_pos(), sync_cycle_, v_irq_enabled_, and v_timer_.
Referenced by DungeonTestHarness::GenerateHarnessState(), Init(), and yaze::emu::Emulator::RenderModernCpuDebugger().
void yaze::emu::Snes::RunFrame | ( | ) |
Definition at line 98 of file snes.cc.
References cpu_, frames_, in_vblank_, LOG_DEBUG, yaze::emu::Cpu::PB, yaze::emu::Cpu::PC, and yaze::emu::Cpu::RunOpcode().
Referenced by main(), and yaze::emu::Emulator::Run().
void yaze::emu::Snes::CatchUpApu | ( | ) |
Definition at line 131 of file snes.cc.
References apu_, cycles_, and yaze::emu::Apu::RunCycles().
Referenced by ReadBBus(), RunCycle(), and WriteBBus().
void yaze::emu::Snes::HandleInput | ( | ) |
Definition at line 137 of file snes.cc.
References auto_joy_read_, yaze::emu::Input::current_state_, input1, input2, LOG_DEBUG, and port_auto_read_.
Referenced by RunCycle().
void yaze::emu::Snes::RunCycle | ( | ) |
Definition at line 173 of file snes.cc.
References apu_, auto_joy_read_, auto_joy_timer_, CatchUpApu(), yaze::emu::Ppu::CheckOverscan(), cpu_, cycles_, yaze::emu::Apu::dsp(), yaze::emu::Ppu::even_frame, yaze::emu::Ppu::frame_interlace, frames_, h_irq_enabled_, yaze::emu::MemoryImpl::h_pos(), h_timer_, yaze::emu::Ppu::HandleFrameStart(), HandleInput(), yaze::emu::Ppu::HandleVblank(), in_irq_, in_nmi_, in_vblank_, yaze::emu::MemoryImpl::init_hdma_request(), irq_condition_, LOG_DEBUG, memory_, next_horiz_event, yaze::emu::Cpu::Nmi(), nmi_enabled_, yaze::emu::MemoryImpl::pal_timing(), port_auto_read_, ppu_, yaze::emu::MemoryImpl::run_hdma_request(), yaze::emu::Ppu::RunLine(), yaze::emu::MemoryImpl::set_h_pos(), yaze::emu::MemoryImpl::set_v_pos(), yaze::emu::Cpu::SetIrq(), v_irq_enabled_, yaze::emu::MemoryImpl::v_pos(), and v_timer_.
Referenced by DungeonTestHarness::GenerateHarnessState(), and RunCycles().
void yaze::emu::Snes::RunCycles | ( | int | cycles | ) |
Definition at line 311 of file snes.cc.
References yaze::emu::MemoryImpl::h_pos(), memory_, and RunCycle().
Referenced by CpuIdle(), CpuRead(), CpuWrite(), yaze::emu::DoHdma(), yaze::emu::InitHdma(), SyncCycles(), and yaze::emu::WaitCycle().
void yaze::emu::Snes::SyncCycles | ( | bool | start, |
int | sync_cycles | ||
) |
Definition at line 321 of file snes.cc.
References cycles_, RunCycles(), and sync_cycle_.
Referenced by yaze::emu::DoDma(), yaze::emu::DoHdma(), and yaze::emu::InitHdma().
uint8_t yaze::emu::Snes::ReadBBus | ( | uint8_t | adr | ) |
Definition at line 332 of file snes.cc.
References apu_, CatchUpApu(), cpu_, cycles_, yaze::emu::Apu::GetCycles(), LOG_DEBUG, memory_, yaze::emu::MemoryImpl::open_bus(), yaze::emu::Apu::out_ports_, yaze::emu::Cpu::PB, yaze::emu::Cpu::PC, ppu_, ppu_latch_, ram, ram_adr_, and yaze::emu::Ppu::Read().
Referenced by Rread(), and yaze::emu::TransferByte().
uint8_t yaze::emu::Snes::ReadReg | ( | uint16_t | adr | ) |
Definition at line 359 of file snes.cc.
References auto_joy_timer_, cpu_, yaze::emu::Input::current_state_, divide_result_, yaze::emu::MemoryImpl::h_pos(), in_irq_, in_nmi_, in_vblank_, input1, LOG_DEBUG, memory_, multiply_result_, yaze::emu::MemoryImpl::open_bus(), yaze::emu::Cpu::PB, yaze::emu::Cpu::PC, port_auto_read_, ppu_latch_, and yaze::emu::Cpu::SetIrq().
Referenced by Rread().
uint8_t yaze::emu::Snes::Rread | ( | uint32_t | adr | ) |
Definition at line 426 of file snes.cc.
References yaze::emu::MemoryImpl::cart_read(), cpu_, input1, input2, LOG_DEBUG, memory_, yaze::emu::MemoryImpl::open_bus(), yaze::emu::Cpu::PC, ram, ReadBBus(), yaze::emu::ReadDma(), and ReadReg().
Referenced by Read().
uint8_t yaze::emu::Snes::Read | ( | uint32_t | adr | ) |
Definition at line 463 of file snes.cc.
References memory_, Rread(), and yaze::emu::MemoryImpl::set_open_bus().
Referenced by CpuRead(), yaze::emu::DoHdma(), DungeonTestHarness::GenerateHarnessState(), yaze::emu::InitHdma(), and yaze::emu::TransferByte().
void yaze::emu::Snes::WriteBBus | ( | uint8_t | adr, |
uint8_t | val | ||
) |
Definition at line 469 of file snes.cc.
References apu_, apu_handshake_tracker_, CatchUpApu(), cpu_, yaze::emu::Apu::in_ports_, LOG_DEBUG, yaze::emu::debug::ApuHandshakeTracker::OnCpuPortWrite(), yaze::emu::Cpu::PB, yaze::emu::Cpu::PC, ppu_, ram, ram_adr_, and yaze::emu::Ppu::Write().
Referenced by yaze::emu::TransferByte(), and Write().
void yaze::emu::Snes::WriteReg | ( | uint16_t | adr, |
uint8_t | val | ||
) |
Definition at line 514 of file snes.cc.
References auto_joy_read_, auto_joy_timer_, cpu_, divide_a_, divide_result_, fast_mem_, h_irq_enabled_, h_timer_, in_irq_, in_nmi_, yaze::emu::Ppu::LatchHV(), LOG_DEBUG, memory_, multiply_a_, multiply_result_, yaze::emu::Cpu::Nmi(), nmi_enabled_, yaze::emu::Cpu::PB, yaze::emu::Cpu::PC, ppu_, ppu_latch_, yaze::emu::Cpu::set_int_delay(), yaze::emu::Cpu::SetIrq(), yaze::emu::StartDma(), v_irq_enabled_, and v_timer_.
Referenced by Write().
void yaze::emu::Snes::Write | ( | uint32_t | adr, |
uint8_t | val | ||
) |
Definition at line 623 of file snes.cc.
References yaze::emu::MemoryImpl::cart_write(), input1, input2, memory_, ram, yaze::emu::MemoryImpl::set_open_bus(), WriteBBus(), yaze::emu::WriteDma(), and WriteReg().
Referenced by CpuWrite(), yaze::test::EmulatorTestSuite::RunApuHandshakeTest(), and yaze::emu::TransferByte().
int yaze::emu::Snes::GetAccessTime | ( | uint32_t | adr | ) |
uint8_t yaze::emu::Snes::CpuRead | ( | uint32_t | adr | ) |
Definition at line 667 of file snes.cc.
References access_time, cpu_, yaze::emu::HandleDma(), memory_, Read(), RunCycles(), and yaze::emu::Cpu::set_int_delay().
Referenced by Snes().
void yaze::emu::Snes::CpuWrite | ( | uint32_t | adr, |
uint8_t | val | ||
) |
Definition at line 678 of file snes.cc.
References access_time, cpu_, yaze::emu::HandleDma(), memory_, RunCycles(), yaze::emu::Cpu::set_int_delay(), and Write().
Referenced by Snes().
void yaze::emu::Snes::CpuIdle | ( | bool | waiting | ) |
Definition at line 686 of file snes.cc.
References cpu_, yaze::emu::HandleDma(), memory_, RunCycles(), and yaze::emu::Cpu::set_int_delay().
Referenced by Snes().
void yaze::emu::Snes::InitAccessTime | ( | bool | recalc | ) |
Definition at line 813 of file snes.cc.
References access_time, and GetAccessTime().
Referenced by Reset().
void yaze::emu::Snes::SetSamples | ( | int16_t * | sample_data, |
int | wanted_samples | ||
) |
Definition at line 692 of file snes.cc.
References apu_, yaze::emu::Apu::dsp(), memory_, and yaze::emu::MemoryImpl::pal_timing().
Referenced by main(), and yaze::emu::Emulator::Run().
void yaze::emu::Snes::SetPixels | ( | uint8_t * | pixel_data | ) |
Definition at line 696 of file snes.cc.
References ppu_, and yaze::emu::Ppu::PutPixels().
Referenced by main(), and yaze::emu::Emulator::Run().
void yaze::emu::Snes::SetButtonState | ( | int | player, |
int | button, | ||
bool | pressed | ||
) |
Definition at line 698 of file snes.cc.
References yaze::emu::Input::current_state_, input1, and input2.
Referenced by yaze::emu::input::InputManager::Poll().
void yaze::emu::Snes::loadState | ( | const std::string & | path | ) |
Definition at line 720 of file snes.cc.
References apu_, apu_catchup_cycles_, auto_joy_read_, auto_joy_timer_, cpu_, cycles_, divide_a_, divide_result_, fast_mem_, h_irq_enabled_, h_timer_, in_irq_, in_nmi_, in_vblank_, irq_condition_, multiply_a_, multiply_result_, next_horiz_event, nmi_enabled_, port_auto_read_, ppu_, ppu_latch_, ram, ram_adr_, READ_STATE, sync_cycle_, v_irq_enabled_, and v_timer_.
Referenced by main().
void yaze::emu::Snes::saveState | ( | const std::string & | path | ) |
Definition at line 768 of file snes.cc.
References apu_, apu_catchup_cycles_, auto_joy_read_, auto_joy_timer_, cpu_, cycles_, divide_a_, divide_result_, fast_mem_, h_irq_enabled_, h_timer_, in_irq_, in_nmi_, in_vblank_, irq_condition_, multiply_a_, multiply_result_, next_horiz_event, nmi_enabled_, port_auto_read_, ppu_, ppu_latch_, ram, ram_adr_, sync_cycle_, v_irq_enabled_, v_timer_, and WRITE_STATE.
Referenced by main().
|
inline |
Definition at line 70 of file snes.h.
References running_.
Referenced by yaze::emu::Emulator::IsEmulatorReady().
|
inline |
Definition at line 71 of file snes.h.
References cpu_.
Referenced by yaze::emu::Emulator::ClearAllBreakpoints(), yaze::emu::DoDma(), yaze::emu::DoHdma(), DungeonTestHarness::GenerateHarnessState(), yaze::emu::Emulator::GetBreakpoints(), yaze::emu::Emulator::GetCPUB(), yaze::emu::Emulator::GetCPUPC(), yaze::emu::Emulator::GetMetrics(), yaze::emu::InitHdma(), yaze::emu::Emulator::Initialize(), main(), yaze::emu::Emulator::RenderModernCpuDebugger(), yaze::emu::Emulator::SetBreakpoint(), and yaze::emu::Emulator::StepSingleInstruction().
|
inline |
Definition at line 72 of file snes.h.
References ppu_.
Referenced by DungeonTestHarness::GenerateHarnessState().
|
inline |
Definition at line 73 of file snes.h.
References apu_.
Referenced by main(), yaze::emu::Emulator::RenderModernCpuDebugger(), yaze::emu::Emulator::Run(), and yaze::test::EmulatorTestSuite::RunApuHandshakeTest().
|
inline |
Definition at line 74 of file snes.h.
References memory_.
Referenced by main(), yaze::emu::Emulator::RenderModernCpuDebugger(), and yaze::emu::Emulator::Run().
|
inline |
|
inline |
Definition at line 76 of file snes.h.
References cycles_.
Referenced by yaze::emu::Emulator::GetCurrentCycle(), yaze::emu::Emulator::GetMetrics(), yaze::emu::Emulator::RenderModernCpuDebugger(), and yaze::test::EmulatorTestSuite::RunApuHandshakeTest().
|
inline |
Definition at line 79 of file snes.h.
References apu_handshake_tracker_.
Referenced by yaze::test::EmulatorTestSuite::RunApuHandshakeTest().
std::vector<uint8_t> yaze::emu::Snes::access_time |
Definition at line 61 of file snes.h.
Referenced by CpuRead(), CpuWrite(), and InitAccessTime().
bool yaze::emu::Snes::fast_mem_ = false |
Definition at line 81 of file snes.h.
Referenced by GetAccessTime(), loadState(), Reset(), saveState(), and WriteReg().
|
private |
Definition at line 84 of file snes.h.
Referenced by CpuIdle(), CpuRead(), CpuWrite(), Init(), memory(), Read(), ReadBBus(), ReadReg(), Reset(), Rread(), RunCycle(), RunCycles(), SetSamples(), Write(), and WriteReg().
Definition at line 85 of file snes.h.
Referenced by cpu(), CpuIdle(), CpuRead(), CpuWrite(), loadState(), ReadBBus(), ReadReg(), Reset(), Rread(), RunCycle(), RunFrame(), saveState(), Snes(), WriteBBus(), and WriteReg().
Definition at line 86 of file snes.h.
Referenced by Init(), loadState(), ppu(), ReadBBus(), Reset(), RunCycle(), saveState(), SetPixels(), WriteBBus(), and WriteReg().
Definition at line 87 of file snes.h.
Referenced by apu(), CatchUpApu(), Init(), loadState(), ReadBBus(), Reset(), RunCycle(), saveState(), SetSamples(), and WriteBBus().
|
private |
|
private |
|
private |
Definition at line 94 of file snes.h.
Referenced by get_ram(), loadState(), ReadBBus(), Reset(), Rread(), saveState(), Write(), and WriteBBus().
|
private |
Definition at line 95 of file snes.h.
Referenced by loadState(), ReadBBus(), Reset(), saveState(), and WriteBBus().
|
private |
Definition at line 98 of file snes.h.
Referenced by Reset(), RunCycle(), and RunFrame().
|
private |
Definition at line 99 of file snes.h.
Referenced by CatchUpApu(), loadState(), mutable_cycles(), ReadBBus(), Reset(), RunCycle(), saveState(), and SyncCycles().
|
private |
Definition at line 100 of file snes.h.
Referenced by loadState(), Reset(), saveState(), and SyncCycles().
|
private |
Definition at line 101 of file snes.h.
Referenced by loadState(), Reset(), and saveState().
|
private |
Definition at line 102 of file snes.h.
Referenced by loadState(), Reset(), RunCycle(), and saveState().
|
private |
Definition at line 105 of file snes.h.
Referenced by loadState(), Reset(), RunCycle(), saveState(), and WriteReg().
|
private |
Definition at line 106 of file snes.h.
Referenced by loadState(), Reset(), RunCycle(), saveState(), and WriteReg().
|
private |
Definition at line 107 of file snes.h.
Referenced by loadState(), Reset(), RunCycle(), saveState(), and WriteReg().
|
private |
Definition at line 108 of file snes.h.
Referenced by loadState(), Reset(), RunCycle(), saveState(), and WriteReg().
|
private |
Definition at line 109 of file snes.h.
Referenced by loadState(), Reset(), RunCycle(), saveState(), and WriteReg().
|
private |
Definition at line 110 of file snes.h.
Referenced by loadState(), ReadReg(), Reset(), RunCycle(), saveState(), and WriteReg().
|
private |
Definition at line 111 of file snes.h.
Referenced by loadState(), Reset(), RunCycle(), and saveState().
|
private |
Definition at line 112 of file snes.h.
Referenced by loadState(), ReadReg(), Reset(), RunCycle(), saveState(), and WriteReg().
|
private |
Definition at line 113 of file snes.h.
Referenced by loadState(), ReadReg(), Reset(), RunCycle(), RunFrame(), and saveState().
|
private |
Definition at line 116 of file snes.h.
Referenced by loadState(), Reset(), saveState(), and WriteReg().
|
private |
Definition at line 117 of file snes.h.
Referenced by loadState(), ReadReg(), Reset(), saveState(), and WriteReg().
|
private |
Definition at line 118 of file snes.h.
Referenced by loadState(), Reset(), saveState(), and WriteReg().
|
private |
Definition at line 119 of file snes.h.
Referenced by loadState(), ReadReg(), Reset(), saveState(), and WriteReg().
|
private |
Definition at line 122 of file snes.h.
Referenced by HandleInput(), ReadReg(), Reset(), Rread(), SetButtonState(), Snes(), and Write().
|
private |
Definition at line 123 of file snes.h.
Referenced by HandleInput(), Reset(), Rread(), SetButtonState(), Snes(), and Write().
|
private |
Definition at line 124 of file snes.h.
Referenced by HandleInput(), loadState(), ReadReg(), Reset(), RunCycle(), and saveState().
|
private |
Definition at line 125 of file snes.h.
Referenced by HandleInput(), loadState(), Reset(), RunCycle(), saveState(), and WriteReg().
|
private |
Definition at line 126 of file snes.h.
Referenced by loadState(), ReadReg(), Reset(), RunCycle(), saveState(), and WriteReg().
|
private |
Definition at line 127 of file snes.h.
Referenced by loadState(), ReadBBus(), ReadReg(), Reset(), saveState(), and WriteReg().
|
private |
Definition at line 130 of file snes.h.
Referenced by apu_handshake_tracker(), Init(), and WriteBBus().