Refactor CPU clock and instruction handling: improve variable naming for clarity and consistency

This commit is contained in:
scawful
2024-12-30 07:50:18 -05:00
parent 0e81df57fd
commit b904cfd8a4
3 changed files with 20 additions and 23 deletions

View File

@@ -7,7 +7,7 @@ namespace yaze {
namespace emu {
class Clock {
public:
public:
virtual ~Clock() = default;
virtual void UpdateClock(double delta) = 0;
virtual unsigned long long GetCycleCount() const = 0;
@@ -17,23 +17,23 @@ class Clock {
};
class ClockImpl : public Clock {
public:
public:
ClockImpl() = default;
virtual ~ClockImpl() = default;
void UpdateCycleCount(double deltaTime) {
accumulatedTime += deltaTime;
double cycleTime = 1.0 / frequency;
void UpdateCycleCount(double delta_time) {
accumulated_time += delta_time;
double cycle_time = 1.0 / frequency;
while (accumulatedTime >= cycleTime) {
while (accumulated_time >= cycle_time) {
Cycle();
accumulatedTime -= cycleTime;
accumulated_time -= cycle_time;
}
}
void Cycle() {
cycle++;
cycleCount++;
cycle_count++;
}
void UpdateClock(double delta) override {
@@ -41,22 +41,21 @@ class ClockImpl : public Clock {
ResetAccumulatedTime();
}
void ResetAccumulatedTime() override { accumulatedTime = 0.0; }
unsigned long long GetCycleCount() const override { return cycleCount; }
void ResetAccumulatedTime() override { accumulated_time = 0.0; }
unsigned long long GetCycleCount() const override { return cycle_count; }
float GetFrequency() const override { return frequency; }
void SetFrequency(float new_frequency) override {
this->frequency = new_frequency;
}
private:
private:
uint64_t cycle = 0; // Current cycle
float frequency = 0.0; // Frequency of the clock in Hz
unsigned long long cycleCount = 0; // Total number of cycles executed
double accumulatedTime = 0.0; // Accumulated time since the last cycle update
unsigned long long cycle_count = 0; // Total number of cycles executed
double accumulated_time = 0.0; // Accumulated time since the last cycle update
};
} // namespace emu
} // namespace emu
} // namespace yaze
} // namespace yaze
#endif // YAZE_APP_EMU_CLOCK_H_
#endif // YAZE_APP_EMU_CLOCK_H_

View File

@@ -2259,5 +2259,4 @@ uint8_t Cpu::GetInstructionLength(uint8_t opcode) {
*/
} // namespace emu
} // namespace yaze
} // namespace yaze

View File

@@ -36,8 +36,7 @@ class InstructionEntry {
class Cpu : public core::ExperimentFlags {
public:
explicit Cpu(memory::Memory& mem, Clock& vclock,
memory::CpuCallbacks& callbacks)
explicit Cpu(Memory& mem, Clock& vclock, CpuCallbacks& callbacks)
: memory(mem), clock(vclock), callbacks_(callbacks) {}
void Reset(bool hard = false);
@@ -792,8 +791,8 @@ class Cpu : public core::ExperimentFlags {
bool int_wanted_ = false;
bool int_delay_ = false;
memory::CpuCallbacks callbacks_;
memory::Memory& memory;
CpuCallbacks callbacks_;
Memory& memory;
Clock& clock;
};