Skip to content

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

C++

VIF1_STAT.FDR turns the FIFO around, and it reads as full for a GS download

Dusan Bakobee403d3c6bd
diff --git a/runtime/src/vif.cpp b/runtime/src/vif.cpp
index 38291ca..00cfdd7 100644
--- a/runtime/src/vif.cpp
+++ b/runtime/src/vif.cpp
@@ -326,7 +326,13 @@ bool stalled(int unit) { return state(unit).stalled; }
std::uint32_t read(int unit, std::uint32_t reg) {
const Unit &u = state(unit);
switch (reg) {
- case 0x00: return u.stat | (u.dbf ? 0x80u : 0u);
+ case 0x00: {
+ std::uint32_t stat = u.stat | (u.dbf ? 0x80u : 0u);
+ // With FDR set the FIFO runs from the GS, and a download keeps it as full as the
+ // game drains it: sceGsExecStoreImage polls FQC before each qword it reads.
+ if (unit == 1 && (u.stat & 0x800000u)) stat |= 16u << 24;
+ return stat;
+ }
case 0x20: return u.err;
case 0x30: return u.mark;
case 0x40: return u.cycle;
@@ -351,6 +357,9 @@ void write(int unit, std::uint32_t reg, std::uint32_t value) {
if (shadow(unit)) gs::queue::vu().post(gs::queue::kVif1Write, reg, value, nullptr, 0);
Unit &u = state(unit);
switch (reg) {
+ case 0x00:
+ if (unit == 1) u.stat = (u.stat & ~0x800000u) | (value & 0x800000u);
+ break;
case 0x10:
if (value & 1u) {
// A reset leaves the filling registers alone, as in PCSX2: Downhill