Move Apu cycling from SNES to Apu class
This commit is contained in:
@@ -17,6 +17,9 @@ namespace app {
|
||||
namespace emu {
|
||||
namespace audio {
|
||||
|
||||
static const double apuCyclesPerMaster = (32040 * 32) / (1364 * 262 * 60.0);
|
||||
static const double apuCyclesPerMasterPal = (32040 * 32) / (1364 * 312 * 50.0);
|
||||
|
||||
static const uint8_t bootRom[0x40] = {
|
||||
0xcd, 0xef, 0xbd, 0xe8, 0x00, 0xc6, 0x1d, 0xd0, 0xfc, 0x8f, 0xaa,
|
||||
0xf4, 0x8f, 0xbb, 0xf5, 0x78, 0xcc, 0xf4, 0xd0, 0xfb, 0x2f, 0x19,
|
||||
@@ -59,17 +62,14 @@ void Apu::Update() {
|
||||
}
|
||||
}
|
||||
|
||||
int Apu::RunCycles(uint32_t wanted_cycles) {
|
||||
int run_cycles = 0;
|
||||
uint32_t start_cycles = cycles_;
|
||||
void Apu::RunCycles(uint64_t cycles) {
|
||||
uint64_t sync_to =
|
||||
(uint64_t)cycles *
|
||||
(memory_.pal_timing() ? apuCyclesPerMasterPal : apuCyclesPerMaster);
|
||||
|
||||
while (run_cycles < wanted_cycles) {
|
||||
while (cycles_ < sync_to) {
|
||||
spc700_.RunOpcode();
|
||||
|
||||
run_cycles += (uint32_t)cycles_ - start_cycles;
|
||||
start_cycles = cycles_;
|
||||
}
|
||||
return run_cycles;
|
||||
}
|
||||
|
||||
void Apu::Cycle() {
|
||||
|
||||
@@ -56,14 +56,13 @@ typedef struct Timer {
|
||||
*/
|
||||
class Apu {
|
||||
public:
|
||||
Apu(MemoryImpl &memory, Clock &clock)
|
||||
: clock_(clock), memory_(memory) {}
|
||||
Apu(MemoryImpl &memory, Clock &clock) : clock_(clock), memory_(memory) {}
|
||||
|
||||
void Init();
|
||||
void Reset();
|
||||
void Update();
|
||||
|
||||
int RunCycles(uint32_t wanted_cycles);
|
||||
void RunCycles(uint64_t cycles);
|
||||
uint8_t SpcRead(uint16_t address);
|
||||
void SpcWrite(uint16_t address, uint8_t data);
|
||||
void SpcIdle(bool waiting);
|
||||
@@ -76,6 +75,7 @@ class Apu {
|
||||
void UpdateClock(int delta_time) { clock_.UpdateClock(delta_time); }
|
||||
|
||||
auto dsp() -> Dsp & { return dsp_; }
|
||||
auto spc700() -> Spc700 & { return spc700_; }
|
||||
|
||||
// Port buffers (equivalent to $2140 to $2143 for the main CPU)
|
||||
uint8_t in_ports_[6]; // includes 2 bytes of ram
|
||||
|
||||
@@ -87,18 +87,13 @@ void SNES::RunFrame() {
|
||||
while (!in_vblank_ && frame == frames_) {
|
||||
cpu_.RunOpcode();
|
||||
}
|
||||
CatchUpApu();
|
||||
}
|
||||
|
||||
void SNES::CatchUpApu() {
|
||||
int catchup_cycles = (int)apu_catchup_cycles_;
|
||||
int ran_cycles = apu_.RunCycles(catchup_cycles);
|
||||
apu_catchup_cycles_ -= ran_cycles;
|
||||
apu_.RunCycles(cycles_);
|
||||
}
|
||||
|
||||
namespace {
|
||||
static const double apuCyclesPerMaster = (32040 * 32) / (1364 * 262 * 60.0);
|
||||
static const double apuCyclesPerMasterPal = (32040 * 32) / (1364 * 312 * 50.0);
|
||||
|
||||
void input_latch(Input* input, bool value) {
|
||||
input->latchLine = value;
|
||||
@@ -132,8 +127,6 @@ void SNES::HandleInput() {
|
||||
}
|
||||
|
||||
void SNES::RunCycle() {
|
||||
apu_catchup_cycles_ +=
|
||||
(memory_.pal_timing() ? apuCyclesPerMasterPal : apuCyclesPerMaster) * 2.0;
|
||||
cycles_ += 2;
|
||||
|
||||
// check for h/v timer irq's
|
||||
|
||||
@@ -69,6 +69,7 @@ class SNES {
|
||||
bool running() const { return running_; }
|
||||
auto cpu() -> Cpu& { return cpu_; }
|
||||
auto ppu() -> video::Ppu& { return ppu_; }
|
||||
auto apu() -> audio::Apu& { return apu_; }
|
||||
auto Memory() -> memory::MemoryImpl& { return memory_; }
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user