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