diff --git a/runtime/host/free_host.cpp b/runtime/host/free_host.cpp index 75f69fe..32e605d 100644 --- a/runtime/host/free_host.cpp +++ b/runtime/host/free_host.cpp @@ -36,6 +36,15 @@ namespace bozo::host if (registry) { vu0Programs_ = registry->vu0Programs(); + vu0ByPair_.clear(); + for (const BozoFunctionEntry &e : vu0Programs_) + if (e.address % 8u == 0 && e.address < kVu0TableBytes) + { + if (vu0ByPair_.empty()) + vu0ByPair_.assign(kVu0TableBytes / 8u, nullptr); + if (!vu0ByPair_[e.address / 8u]) + vu0ByPair_[e.address / 8u] = e.function; + } vu0Code_ = registry->vu0CodeMemory(); transfersAlwaysDone_ = registry->transfersAreAlwaysDone(); d.setSyncVAtVblank(registry->syncVCallbackIsAtVblank()); @@ -272,6 +281,12 @@ namespace bozo::host void FreeHost::vu0Microprogram(ee::Dispatcher &, R5900Context *ctx, uint32_t address) { ++stats_.vu0Calls; + if (address % 8u == 0 && address < kVu0TableBytes && !vu0ByPair_.empty()) + if (const RecompiledFunction f = vu0ByPair_[address / 8u]) + { + f(d_->runtime().memory.ram(), ctx, &d_->runtime()); + return; + } if (!vu0Programs_.empty()) { for (const BozoFunctionEntry &e : vu0Programs_) diff --git a/runtime/include/bozo/host/free_host.h b/runtime/include/bozo/host/free_host.h index 8374474..06e196b 100644 --- a/runtime/include/bozo/host/free_host.h +++ b/runtime/include/bozo/host/free_host.h @@ -151,6 +151,10 @@ namespace bozo::host port::InstructionHandler instructionHandler_ = nullptr; bool transfersAlwaysDone_ = false; std::vector vu0Programs_; + // The port's VU0 programs by pair (VCALLMS targets in the 16 KB a micro memory can hold), found without a search: + // a game can call thousands a frame. + static constexpr uint32_t kVu0TableBytes = 0x4000u; + std::vector vu0ByPair_; uint8_t *vu0Code_ = nullptr; // port::Registry::vu0CodeMemory void runOverride(R5900Context *ctx, uint32_t target, port::Function fn); // Ends the run when no frame ended for opt_.stallFields fields (a wait that never ends), saying where.