feat: placeholder for exec VU0Microprogram

This commit is contained in:
Ran-j
2025-05-29 16:21:00 -03:00
parent 342bb19607
commit a0314c9847
3 changed files with 48 additions and 3 deletions
+36 -3
View File
@@ -1976,17 +1976,50 @@ namespace ps2recomp
std::string CodeGenerator::translateVU_VCALLMS(const Instruction &inst)
{
return fmt::format("// Calls VU0 microprogram at address {} - not implemented in recompiled code", inst.immediate);
// VCALLMS calls a VU0 microprogram at the specified immediate address.
// VU0 micro memory is 4KB = 512 instructions (8 bytes each). Index is 0-511.
uint16_t instr_index = inst.immediate & 0x1FF; // Mask to 9 bits for VU0
uint32_t target_byte_addr = (uint32_t)instr_index << 3; // Convert instruction index to byte address
return fmt::format(
"{{ "
" ctx->vu0_tpc = 0x{:X}; " // Set target program counter
" runtime->executeVU0Microprogram(rdram, ctx, 0x{:X}); "
"}}",
target_byte_addr, target_byte_addr);
}
std::string CodeGenerator::translateVU_VCALLMSR(const Instruction &inst)
{
return fmt::format("// Calls VU0 microprogram at address {} - not implemented in recompiled code", inst.immediate);
// VCALLMSR calls a VU0 microprogram at address stored in integer register
uint8_t vis_reg_idx = inst.rs; // Source integer register
return fmt::format(
"{{ "
" uint16_t instr_index = ctx->vi[{}] & 0x1FF; " // Get instruction index from VI[IS], mask to 9 bits
" uint32_t target_byte_addr = (uint32_t)instr_index << 3; " // Convert to byte address
" ctx->vu0_pc = target_byte_addr; "
" runtime->vu0StartMicroProgram(rdram, ctx, target_byte_addr); "
"}}",
vis_reg_idx);
}
std::string CodeGenerator::translateVU_VRNEXT(const Instruction &inst)
{
return fmt::format("// Unhandled VU0 VRNEXT instruction: 0x{:X}", inst.function);
return fmt::format(
"{{ "
" uint32_t r_vals[4]; "
" _mm_storeu_si128((__m128i*)r_vals, (__m128i)ctx->vu0_r); "
" "
" // Simple LFSR-based random number generation (PS2-like behavior) "
" uint32_t feedback = r_vals[0] ^ (r_vals[0] << 13) ^ (r_vals[1] >> 19) ^ (r_vals[2] << 7); "
" r_vals[0] = r_vals[1]; "
" r_vals[1] = r_vals[2]; "
" r_vals[2] = r_vals[3]; "
" r_vals[3] = feedback; "
" "
" ctx->vu0_r = _mm_loadu_si128((__m128i*)r_vals); "
"}}");
}
std::string CodeGenerator::translateVU_VMADD_Field(const Instruction &inst)
+1
View File
@@ -389,6 +389,7 @@ public:
RecompiledFunction lookupFunction(uint32_t address);
void SignalException(R5900Context* ctx, PS2Exception exception);
void executeVU0Microprogram(uint8_t* rdram, R5900Context* ctx, uint32_t address);
private:
void HandleIntegerOverflow(R5900Context* ctx);
+11
View File
@@ -180,6 +180,17 @@ void PS2Runtime::SignalException(R5900Context *ctx, PS2Exception exception)
}
}
void PS2Runtime::executeVU0Microprogram(uint8_t *rdram, R5900Context *ctx, uint32_t address)
{
std::cout << "VU0 microprogram call to address 0x" << std::hex << address
<< " - not implemented" << std::dec << std::endl;
// mayve implement like this or a vu0_interpreter
// Placeholder for VU0 microprogram execution
// auto microprog = findCompiledMicroprogram(address);
// if (microprog) microprog(rdram, ctx);
}
void PS2Runtime::HandleIntegerOverflow(R5900Context *ctx)
{
std::cerr << "Integer overflow exception at PC: 0x" << std::hex << ctx->pc << std::dec << std::endl;