This commit is contained in:
SimoneN64
2024-01-02 23:57:06 +01:00
parent 1058657f07
commit 12d744500f
5 changed files with 31 additions and 26 deletions

View File

@@ -33,14 +33,12 @@ void Core::LoadROM(const std::string& rom_) {
pause = false;
romLoaded = true;
std::string archive_types[] = {".zip",".7z",".rar",".tar"};
auto extension = fs::path(rom).extension().string();
bool isArchive = false;
for(const auto i : ARCHIVE_TYPES) {
if(extension == i) {
isArchive = true;
break;
}
}
bool isArchive = std::any_of(std::begin(archive_types), std::end(archive_types), [&extension](const auto& e) {
return e == extension;
});
cpu->mem.LoadROM(isArchive, rom);
GameDB::match(cpu->mem);

View File

@@ -13,16 +13,13 @@ void Scheduler::enqueueAbsolute(u64 t, const EventType type) {
}
u64 Scheduler::remove(EventType type) {
auto copy = events;
while(!copy.empty()) {
if(copy.top().type == type) {
u64 ret = copy.top().time - ticks;
copy.pop();
events.swap(copy);
for (auto& e : events) {
if(e.type == type) {
u64 ret = e.time - ticks;
e.type = NONE;
e.time = ticks;
return ret;
}
copy.pop();
}
return 0;
@@ -35,7 +32,7 @@ void Scheduler::tick(u64 t, n64::Mem& mem, n64::Registers& regs) {
n64::PI& pi = mem.mmio.pi;
while(ticks >= events.top().time) {
switch(events.top().type) {
switch(auto type = events.top().type) {
case SI_DMA:
si.status.dmaBusy = false;
si.DMA(mem, regs);
@@ -53,7 +50,7 @@ void Scheduler::tick(u64 t, n64::Mem& mem, n64::Registers& regs) {
case IMPOSSIBLE:
Util::panic("Congratulations on keeping the emulator on for about 5 billion years, I guess, nerd.");
default:
Util::panic("Unknown scheduler event type");
Util::panic("Unknown scheduler event type {}", static_cast<int>(type));
}
events.pop();
}

View File

@@ -34,17 +34,28 @@ struct Event {
}
};
struct IterableEvents {
std::priority_queue<Event, std::vector<Event>, std::greater<>> events;
public:
explicit IterableEvents() = default;
auto top() { return events.top(); }
auto pop() { events.pop(); }
auto begin() { return (Event*)(&events.top()); }
auto end() { return begin() + events.size(); }
auto push(Event e) { events.push(e); }
};
struct Scheduler {
Scheduler() {
enqueueAbsolute(std::numeric_limits<u64>::max(), IMPOSSIBLE);
}
void enqueueRelative(u64, const EventType);
void enqueueAbsolute(u64, const EventType);
u64 remove(const EventType);
void enqueueRelative(u64, EventType);
void enqueueAbsolute(u64, EventType);
u64 remove(EventType);
void tick(u64 t, n64::Mem&, n64::Registers&);
std::priority_queue<Event, std::vector<Event>, std::greater<>> events;
IterableEvents events;
u64 ticks = 0;
u8 index = 0;
};

View File

@@ -99,11 +99,13 @@ std::vector<u8> Mem::OpenArchive(const std::string &path, size_t& sizeAdjusted)
std::vector<u8> buf{};
std::string rom_exts[] = {".n64",".z64",".v64",".N64",".Z64",".V64"};
while(ar_parse_entry(archive)) {
auto filename = ar_entry_get_name(archive);
auto extension = fs::path(filename).extension();
if(std::any_of(std::begin(ROM_EXTENSIONS), std::end(ROM_EXTENSIONS), [&](auto x) {
if(std::any_of(std::begin(rom_exts), std::end(rom_exts), [&](auto x) {
return extension == x;
})) {
auto size = ar_entry_get_size(archive);

View File

@@ -39,9 +39,6 @@ static FORCE_INLINE constexpr u32 GetVideoFrequency(bool pal) {
#define HALF_ADDRESS(addr) ((addr) ^ 2)
#define BYTE_ADDRESS(addr) ((addr) ^ 3)
#define ARCHIVE_TYPES {".zip",".7z",".rar",".tar"}
#define ROM_EXTENSIONS {".n64",".z64",".v64",".N64",".Z64",".V64"}
#define RD(x) (((x) >> 11) & 0x1F)
#define RT(x) (((x) >> 16) & 0x1F)
#define RS(x) (((x) >> 21) & 0x1F)