Small changes

This commit is contained in:
CocoSimone
2023-02-19 19:21:47 +01:00
parent bead7e55bc
commit a580b54579
3 changed files with 19 additions and 8 deletions

View File

@@ -5,17 +5,17 @@
Scheduler scheduler; Scheduler scheduler;
Scheduler::Scheduler() { Scheduler::Scheduler() {
events.push({UINT64_MAX, [](n64::Mem&, n64::Registers&){ enqueueAbsolute({UINT64_MAX, [](n64::Mem&, n64::Registers&){
Util::panic("How the fuck did we get here?!\n"); Util::panic("How the fuck did we get here?!\n");
}}); }});
} }
void Scheduler::enqueueRelative(const Event& event) { void Scheduler::enqueueRelative(const Event& event) {
events.push({event.time + ticks, event.handler}); enqueueAbsolute({event.time + ticks, event.handler});
} }
void Scheduler::enqueueAbsolute(const Event& event) { void Scheduler::enqueueAbsolute(const Event& e) {
events.push({event.time, event.handler}); events.push(e);
} }
void Scheduler::tick(u64 t, n64::Mem& mem, n64::Registers& regs) { void Scheduler::tick(u64 t, n64::Mem& mem, n64::Registers& regs) {

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <common.hpp> #include <common.hpp>
#include <queue> #include <queue>
#include <array>
namespace n64 { namespace n64 {
struct Mem; struct Mem;
@@ -8,11 +9,19 @@ struct Registers;
} }
struct Event { struct Event {
u64 time = UINT64_MAX; u64 time = 0;
void(*handler)(n64::Mem&, n64::Registers&) = nullptr; void(*handler)(n64::Mem&, n64::Registers&) = nullptr;
friend bool operator<(const Event& rhs, const Event& lhs) { friend bool operator<(const Event& rhs, const Event& lhs) {
return lhs.time < rhs.time; return rhs.time < lhs.time;
}
friend bool operator>(const Event& rhs, const Event& lhs) {
return rhs.time > lhs.time;
}
friend bool operator>=(const Event& rhs, const Event& lhs) {
return rhs.time >= lhs.time;
} }
}; };
@@ -21,8 +30,9 @@ struct Scheduler {
void enqueueRelative(const Event&); void enqueueRelative(const Event&);
void enqueueAbsolute(const Event&); void enqueueAbsolute(const Event&);
void tick(u64, n64::Mem&, n64::Registers&); void tick(u64, n64::Mem&, n64::Registers&);
std::priority_queue<Event> events; std::priority_queue<Event, std::vector<Event>, std::greater<>> events;
u64 ticks = 0; u64 ticks = 0;
u8 index = 0;
}; };
extern Scheduler scheduler; extern Scheduler scheduler;

View File

@@ -60,13 +60,14 @@ void SI::Write(Mem& mem, Registers& regs, u32 addr, u32 val) {
status.dmaBusy = true; status.dmaBusy = true;
toDram = true; toDram = true;
scheduler.enqueueRelative({SI_DMA_DELAY, DMA}); scheduler.enqueueRelative({SI_DMA_DELAY, DMA});
Util::debug("SI DMA from PIF RAM to RDRAM ({:08X} to {:08X})\n", pifAddr, dramAddr);
} break; } break;
case 0x04800010: { case 0x04800010: {
pifAddr = val & 0x1FFFFFFF; pifAddr = val & 0x1FFFFFFF;
status.dmaBusy = true; status.dmaBusy = true;
toDram = false; toDram = false;
scheduler.enqueueRelative({SI_DMA_DELAY, DMA}); scheduler.enqueueRelative({SI_DMA_DELAY, DMA});
Util::debug("SI DMA from RDRAM to PIF RAM ({:08X} to {:08X})\n", dramAddr, val & 0x1FFFFFFF); Util::debug("SI DMA from RDRAM to PIF RAM ({:08X} to {:08X})\n", dramAddr, pifAddr);
} break; } break;
case 0x04800018: case 0x04800018:
InterruptLower(mem.mmio.mi, regs, Interrupt::SI); InterruptLower(mem.mmio.mi, regs, Interrupt::SI);