mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-06 14:15:41 +12:00
Use CPU for counting ticks instead of scheduler
This commit is contained in:
parent
7343497f36
commit
97f97dc6e2
3 changed files with 36 additions and 36 deletions
|
@ -11,14 +11,16 @@
|
|||
#include "memory.hpp"
|
||||
#include "scheduler.hpp"
|
||||
|
||||
class Emulator;
|
||||
class CPU;
|
||||
|
||||
class MyEnvironment final : public Dynarmic::A32::UserCallbacks {
|
||||
public:
|
||||
u64 ticksLeft = 0;
|
||||
u64 totalTicks = 0;
|
||||
Memory& mem;
|
||||
Kernel& kernel;
|
||||
public:
|
||||
u64 ticksLeft = 0;
|
||||
u64 totalTicks = 0;
|
||||
Memory& mem;
|
||||
Kernel& kernel;
|
||||
Scheduler& scheduler;
|
||||
|
||||
u64 getCyclesForInstruction(bool isThumb, u32 instruction);
|
||||
|
||||
|
@ -77,39 +79,39 @@ public:
|
|||
std::terminate();
|
||||
}
|
||||
|
||||
void CallSVC(u32 swi) override {
|
||||
kernel.serviceSVC(swi);
|
||||
}
|
||||
void CallSVC(u32 swi) override {
|
||||
kernel.serviceSVC(swi);
|
||||
}
|
||||
|
||||
void ExceptionRaised(u32 pc, Dynarmic::A32::Exception exception) override {
|
||||
switch (exception) {
|
||||
case Dynarmic::A32::Exception::UnpredictableInstruction:
|
||||
Helpers::panic("Unpredictable instruction at pc = %08X", pc);
|
||||
break;
|
||||
void ExceptionRaised(u32 pc, Dynarmic::A32::Exception exception) override {
|
||||
switch (exception) {
|
||||
case Dynarmic::A32::Exception::UnpredictableInstruction:
|
||||
Helpers::panic("Unpredictable instruction at pc = %08X", pc);
|
||||
break;
|
||||
|
||||
default: Helpers::panic("Fired exception oops");
|
||||
}
|
||||
}
|
||||
default: Helpers::panic("Fired exception oops");
|
||||
}
|
||||
}
|
||||
|
||||
void AddTicks(u64 ticks) override {
|
||||
totalTicks += ticks;
|
||||
void AddTicks(u64 ticks) override {
|
||||
totalTicks += ticks;
|
||||
|
||||
if (ticks > ticksLeft) {
|
||||
ticksLeft = 0;
|
||||
return;
|
||||
}
|
||||
ticksLeft -= ticks;
|
||||
}
|
||||
if (ticks > ticksLeft) {
|
||||
ticksLeft = 0;
|
||||
return;
|
||||
}
|
||||
ticksLeft -= ticks;
|
||||
}
|
||||
|
||||
u64 GetTicksRemaining() override {
|
||||
return ticksLeft;
|
||||
}
|
||||
u64 GetTicksRemaining() override {
|
||||
return ticksLeft;
|
||||
}
|
||||
|
||||
u64 GetTicksForCode(bool isThumb, u32 vaddr, u32 instruction) override {
|
||||
return getCyclesForInstruction(isThumb, instruction);
|
||||
}
|
||||
u64 GetTicksForCode(bool isThumb, u32 vaddr, u32 instruction) override {
|
||||
return getCyclesForInstruction(isThumb, instruction);
|
||||
}
|
||||
|
||||
MyEnvironment(Memory& mem, Kernel& kernel) : mem(mem), kernel(kernel) {}
|
||||
MyEnvironment(Memory& mem, Kernel& kernel, Scheduler& scheduler) : mem(mem), kernel(kernel), scheduler(scheduler) {}
|
||||
};
|
||||
|
||||
class CPU {
|
||||
|
|
|
@ -18,12 +18,10 @@ struct Scheduler {
|
|||
using EventMap = boost::container::flat_multimap<Key, Val, std::less<Key>, boost::container::static_vector<std::pair<Key, Val>, size>>;
|
||||
|
||||
EventMap<u64, EventType, totalNumberOfEvents> events;
|
||||
u64 currentTimestamp = 0;
|
||||
u64 nextTimestamp = 0;
|
||||
|
||||
// Set nextTimestamp to the timestamp of the next event
|
||||
void updateNextTimestamp() { nextTimestamp = events.cbegin()->first; }
|
||||
void addCycles(u64 cycles) { currentTimestamp += cycles; }
|
||||
|
||||
void addEvent(EventType type, u64 timestamp) {
|
||||
events.emplace(timestamp, type);
|
||||
|
@ -40,8 +38,6 @@ struct Scheduler {
|
|||
};
|
||||
|
||||
void reset() {
|
||||
currentTimestamp = 0;
|
||||
|
||||
// Clear any pending events
|
||||
events.clear();
|
||||
// Add a dummy event to always keep the scheduler non-empty
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "arm_defs.hpp"
|
||||
|
||||
CPU::CPU(Memory& mem, Kernel& kernel) : mem(mem), env(mem, kernel) {
|
||||
CPU::CPU(Memory& mem, Kernel& kernel) : mem(mem), env(mem, kernel, scheduler) {
|
||||
cp15 = std::make_shared<CP15>();
|
||||
|
||||
Dynarmic::A32::UserConfig config;
|
||||
|
@ -32,6 +32,8 @@ void CPU::reset() {
|
|||
// Reset scheduler and add a VBlank event
|
||||
scheduler.reset();
|
||||
scheduler.addEvent(Scheduler::EventType::VBlank, ticksPerSec / 60);
|
||||
|
||||
printf("%lld\n", scheduler.nextTimestamp);
|
||||
}
|
||||
|
||||
#endif // CPU_DYNARMIC
|
Loading…
Add table
Reference in a new issue