2026-01-12 05:18:12 -05:00
|
|
|
// SPDX-FileCopyrightText: 2002-2026 PCSX2 Dev Team
|
2024-07-30 13:42:36 +02:00
|
|
|
// SPDX-License-Identifier: GPL-3.0+
|
2009-09-08 12:08:10 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
// This module contains code shared by both the dynarec and interpreter versions
|
|
|
|
|
// of the VU0 micro.
|
|
|
|
|
|
2009-11-14 12:02:56 +00:00
|
|
|
#include "Common.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
#include "VUmicro.h"
|
2011-08-12 02:31:49 +00:00
|
|
|
#include "MTVU.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-06-18 08:20:19 +00:00
|
|
|
#ifdef PCSX2_DEBUG
|
2009-02-09 21:15:56 +00:00
|
|
|
u32 vudump = 0;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// This is called by the COP2 as per the CTC instruction
|
|
|
|
|
void vu1ResetRegs()
|
|
|
|
|
{
|
|
|
|
|
VU0.VI[REG_VPU_STAT].UL &= ~0xff00; // stop vu1
|
|
|
|
|
VU0.VI[REG_FBRST].UL &= ~0xff00; // stop vu1
|
2010-08-31 05:22:26 +00:00
|
|
|
vif1Regs.stat.VEW = false;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
2020-12-12 03:33:24 +00:00
|
|
|
void vu1Finish(bool add_cycles) {
|
2011-08-12 02:31:49 +00:00
|
|
|
if (THREAD_VU1) {
|
2021-06-27 04:55:16 +01:00
|
|
|
//if (VU0.VI[REG_VPU_STAT].UL & 0x100) DevCon.Error("MTVU: VU0.VI[REG_VPU_STAT].UL & 0x100");
|
2022-07-25 23:50:35 +01:00
|
|
|
if (INSTANT_VU1 || add_cycles)
|
|
|
|
|
{
|
|
|
|
|
vu1Thread.WaitVU();
|
|
|
|
|
}
|
2021-06-27 04:55:16 +01:00
|
|
|
vu1Thread.Get_MTVUChanges();
|
2011-08-12 02:31:49 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2026-03-15 11:04:19 +01:00
|
|
|
u64 vu1cycles = VU1.cycle;
|
2020-12-12 03:33:24 +00:00
|
|
|
if(VU0.VI[REG_VPU_STAT].UL & 0x100) {
|
2009-02-09 21:15:56 +00:00
|
|
|
VUM_LOG("vu1ExecMicro > Stalling until current microprogram finishes");
|
2010-02-24 07:20:33 +00:00
|
|
|
CpuVU1->Execute(vu1RunCycles);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
2020-12-12 03:33:24 +00:00
|
|
|
if (VU0.VI[REG_VPU_STAT].UL & 0x100) {
|
|
|
|
|
DevCon.Warning("Force Stopping VU1, ran for too long");
|
|
|
|
|
VU0.VI[REG_VPU_STAT].UL &= ~0x100;
|
|
|
|
|
}
|
|
|
|
|
if (add_cycles)
|
|
|
|
|
{
|
|
|
|
|
cpuRegs.cycle += VU1.cycle - vu1cycles;
|
|
|
|
|
}
|
2010-03-02 04:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-12 22:34:42 +10:00
|
|
|
void vu1ExecMicro(u32 addr)
|
2010-03-02 04:36:09 +00:00
|
|
|
{
|
2011-08-12 02:31:49 +00:00
|
|
|
if (THREAD_VU1) {
|
|
|
|
|
VU0.VI[REG_VPU_STAT].UL &= ~0xFF00;
|
2021-06-27 04:55:16 +01:00
|
|
|
// Okay this is a little bit of a hack, but with good reason.
|
|
|
|
|
// Most of the time with MTVU we want to pretend the VU has finished quickly as to gain the benefit from running another thread
|
|
|
|
|
// however with T-Bit games when the T-Bit is enabled, it needs to wait in case a T-Bit happens, so we need to set "Busy"
|
|
|
|
|
// We shouldn't do this all the time as it negates the extra thread and causes games like Ratchet & Clank to be no faster.
|
2022-06-25 16:32:54 +01:00
|
|
|
// if (VU0.VI[REG_FBRST].UL & 0x800)
|
|
|
|
|
// {
|
|
|
|
|
// VU0.VI[REG_VPU_STAT].UL |= 0x0100;
|
|
|
|
|
// }
|
|
|
|
|
// Update 25/06/2022: Disabled this for now, let games YOLO it, if it breaks MTVU, disable MTVU (it doesn't work properly anyway) - Refraction
|
2021-10-23 20:36:02 +01:00
|
|
|
vu1Thread.ExecuteVU(addr, vif1Regs.top, vif1Regs.itop, VU0.VI[REG_FBRST].UL);
|
2011-08-12 02:31:49 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2010-03-02 04:36:09 +00:00
|
|
|
static int count = 0;
|
2020-12-12 03:33:24 +00:00
|
|
|
vu1Finish(false);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2009-03-27 06:34:51 +00:00
|
|
|
VUM_LOG("vu1ExecMicro %x (count=%d)", addr, count++);
|
2020-08-09 08:30:24 +02:00
|
|
|
VU1.cycle = cpuRegs.cycle;
|
2010-01-25 06:42:09 +00:00
|
|
|
VU0.VI[REG_VPU_STAT].UL &= ~0xFF00;
|
|
|
|
|
VU0.VI[REG_VPU_STAT].UL |= 0x0100;
|
2021-07-09 23:14:26 +01:00
|
|
|
if ((s32)addr != -1) VU1.VI[REG_TPC].UL = addr & 0x7FF;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2020-12-04 13:03:32 +00:00
|
|
|
CpuVU1->SetStartPC(VU1.VI[REG_TPC].UL << 3);
|
|
|
|
|
_vuExecMicroDebug(VU1);
|
2020-12-12 03:33:24 +00:00
|
|
|
if(!INSTANT_VU1)
|
|
|
|
|
CpuVU1->ExecuteBlock(1);
|
|
|
|
|
else
|
|
|
|
|
CpuVU1->Execute(vu1RunCycles);
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
2022-07-25 20:54:23 +01:00
|
|
|
|
|
|
|
|
void MTVUInterrupt()
|
|
|
|
|
{
|
|
|
|
|
VU0.VI[REG_VPU_STAT].UL &= ~0xFF00;
|
|
|
|
|
}
|