Skip to content

PS2 games in the browser: static recompilation to WebAssembly with a native runtime

C++

Trace SPU2 interrupt delivery; include SPU2 memory in PS2_DUMP

Samir Nuricc8a72024829
diff --git a/runtime/src/iop/kernel.cpp b/runtime/src/iop/kernel.cpp
index 8729100..16e9667 100644
--- a/runtime/src/iop/kernel.cpp
+++ b/runtime/src/iop/kernel.cpp
@@ -456,6 +456,7 @@ void deliver_interrupts() {
auto it = g_interrupts.find(static_cast<unsigned>(line));
if (it == g_interrupts.end() || !it->second.handler) continue;
const Interrupt handler = it->second;
+ if (g_trace_modules && line == 9) std::fprintf(stderr, "[iop] spu2 interrupt -> 0x%08X at %llu\n", handler.handler, static_cast<unsigned long long>(g_now));
const std::uint32_t result = call_guest(handler.handler, handler.arg);
if (result == 0 && line < 32) hw::set_interrupt_mask(static_cast<unsigned>(line), false);
}
diff --git a/runtime/src/iop/spu2.cpp b/runtime/src/iop/spu2.cpp
index ec59274..795c260 100644
--- a/runtime/src/iop/spu2.cpp
+++ b/runtime/src/iop/spu2.cpp
@@ -83,7 +83,7 @@ void check_irq(std::uint32_t address, std::uint32_t words) {
if (((k.irqa - address) & kRamMask) >= words) continue;
k.irq = true;
static const bool trace = std::getenv("PS2_TRACE_SPU2") != nullptr;
- if (trace) std::fprintf(stderr, "[spu2] irq at 0x%05X\n", k.irqa);
+ if (trace) std::fprintf(stderr, "[spu2] irq at 0x%05X time %llu\n", k.irqa, static_cast<unsigned long long>(kernel::now()));
hw::raise_interrupt(kSpuLine);
}
}
diff --git a/runtime/src/system.cpp b/runtime/src/system.cpp
index 79c0466..b459c8a 100644
--- a/runtime/src/system.cpp
+++ b/runtime/src/system.cpp
@@ -256,6 +256,7 @@ int run() {
if (std::FILE *f = std::fopen(path, "wb")) {
std::fwrite(g_ram, 1, kRamSize, f);
std::fwrite(iop::ram_ptr(0), 1, iop::kRamSize, f);
+ std::fwrite(iop::spu2::ram(), 2, 1u << 20, f);
std::fclose(f);
}
}