diff --git a/include/cpu_dynarmic.hpp b/include/cpu_dynarmic.hpp index 96f692c7..5d54d6cb 100644 --- a/include/cpu_dynarmic.hpp +++ b/include/cpu_dynarmic.hpp @@ -30,7 +30,7 @@ public: } u64 MemoryRead64(u32 vaddr) override { - return u64(MemoryRead32(vaddr)) | u64(MemoryRead32(vaddr + 4)) << 32; + return mem.read64(vaddr); } void MemoryWrite8(u32 vaddr, u8 value) override { @@ -162,6 +162,7 @@ public: void runFrame() { env.ticksLeft = 268111856 / 60; + const auto exitReason = jit->Run(); if (static_cast(exitReason) != 0) [[unlikely]] { Helpers::panic("Exit reason: %d\nPC: %08X", static_cast(exitReason), getReg(15)); diff --git a/include/io_file.hpp b/include/io_file.hpp index d7b926ee..e835965a 100644 --- a/include/io_file.hpp +++ b/include/io_file.hpp @@ -71,7 +71,7 @@ public: return size; } - bool seek(std::int64_t offset, int origin = 0) { + bool seek(std::int64_t offset, int origin = SEEK_SET) { if (!isOpen() || fseeko(handle, offset, origin) != 0) return false; diff --git a/include/services/cfg.hpp b/include/services/cfg.hpp index 3db2772a..7539e470 100644 --- a/include/services/cfg.hpp +++ b/include/services/cfg.hpp @@ -8,6 +8,9 @@ class CFGService { Memory& mem; MAKE_LOG_FUNCTION(log, cfgLogger) + // Service functions + void getConfigInfoBlk2(u32 messagePointer); + public: CFGService(Memory& mem) : mem(mem) {} void reset(); diff --git a/include/services/dsp.hpp b/include/services/dsp.hpp index 36494083..0033bdc6 100644 --- a/include/services/dsp.hpp +++ b/include/services/dsp.hpp @@ -63,4 +63,10 @@ public: DSPService(Memory& mem) : mem(mem) {} void reset(); void handleSyncRequest(u32 messagePointer); + + enum class SoundOutputMode : u8 { + Mono = 0, + Stereo = 1, + Surround = 2 + }; }; \ No newline at end of file diff --git a/src/core/filesystem/archive_ncch.cpp b/src/core/filesystem/archive_ncch.cpp index aa731dac..4d72422e 100644 --- a/src/core/filesystem/archive_ncch.cpp +++ b/src/core/filesystem/archive_ncch.cpp @@ -42,7 +42,7 @@ std::optional SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32 } IOFile& ioFile = mem.CXIFile; - if (!ioFile.seek(cxi->fileOffset + romFSOffset + offset)) { + if (!ioFile.seek(cxi->fileOffset + romFSOffset + offset + 0x1000)) { Helpers::panic("Failed to seek while reading from RomFS"); } diff --git a/src/core/kernel/threads.cpp b/src/core/kernel/threads.cpp index cf0a1cb1..a47b579e 100644 --- a/src/core/kernel/threads.cpp +++ b/src/core/kernel/threads.cpp @@ -11,6 +11,7 @@ void Kernel::switchThread(int newThreadIndex) { auto& oldThread = threads[currentThreadIndex]; auto& newThread = threads[newThreadIndex]; newThread.status = ThreadStatus::Running; + printf("Switching from thread %d to %d\n", currentThreadIndex, newThreadIndex); // Bail early if the new thread is actually the old thread if (currentThreadIndex == newThreadIndex) [[unlikely]] { @@ -136,8 +137,8 @@ void Kernel::createThread() { u32 initialSP = regs[3] & ~7; // SP is force-aligned to 8 bytes s32 id = static_cast(regs[4]); - logSVC("CreateThread(entry = %08X, stacktop = %08X, priority = %X, processor ID = %d)\n", entrypoint, - initialSP, priority, id); + logSVC("CreateThread(entry = %08X, stacktop = %08X, arg = %X, priority = %X, processor ID = %d)\n", entrypoint, + initialSP, arg, priority, id); if (priority > 0x3F) [[unlikely]] { Helpers::panic("Created thread with bad priority value %X", priority); @@ -157,7 +158,6 @@ void Kernel::sleepThreadOnArbiter(u32 waitingAddress) { switchToNextThread(); } - void Kernel::getThreadID() { Handle handle = regs[1]; logSVC("GetThreadID(handle = %X)\n", handle); diff --git a/src/core/services/cfg.cpp b/src/core/services/cfg.cpp index 7e8273be..ffb9802d 100644 --- a/src/core/services/cfg.cpp +++ b/src/core/services/cfg.cpp @@ -1,7 +1,9 @@ #include "services/cfg.hpp" +#include "services/dsp.hpp" namespace CFGCommands { enum : u32 { + GetConfigInfoBlk2 = 0x00010082 }; } @@ -16,6 +18,23 @@ void CFGService::reset() {} void CFGService::handleSyncRequest(u32 messagePointer) { const u32 command = mem.read32(messagePointer); switch (command) { + case CFGCommands::GetConfigInfoBlk2: getConfigInfoBlk2(messagePointer); break; default: Helpers::panic("CFG service requested. Command: %08X\n", command); } +} + +void CFGService::getConfigInfoBlk2(u32 messagePointer) { + u32 size = mem.read32(messagePointer + 4); + u32 blockID = mem.read32(messagePointer + 8); + u32 output = mem.read32(messagePointer + 16); // Pointer to write the output data to + log("CFG::GetConfigInfoBlk2 (size = %X, block ID = %X, output pointer = %08X\n", size, blockID, output); + + // Implement checking the sound output mode + if (size == 1 && blockID == 0x70001) { + mem.write8(output, (u8) DSPService::SoundOutputMode::Stereo); + } else { + Helpers::panic("Unhandled GetConfigInfoBlk2 configuration"); + } + + mem.write32(messagePointer + 4, Result::Success); } \ No newline at end of file