2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
2009-02-09 21:15:56 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-02-09 21:15:56 +00:00
|
|
|
*/
|
|
|
|
|
2009-09-08 12:08:10 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "PrecompiledHeader.h"
|
|
|
|
#include "Common.h"
|
2009-11-14 12:02:56 +00:00
|
|
|
|
2009-02-09 21:15:56 +00:00
|
|
|
#include "VUmicro.h"
|
2011-08-12 02:31:49 +00:00
|
|
|
#include "MTVU.h"
|
2009-02-09 21:15:56 +00:00
|
|
|
|
|
|
|
extern void _vuFlushAll(VURegs* VU);
|
|
|
|
|
|
|
|
void _vu1ExecUpper(VURegs* VU, u32 *ptr) {
|
2010-04-25 00:31:27 +00:00
|
|
|
VU->code = ptr[1];
|
2013-01-28 23:05:18 +00:00
|
|
|
//IdebugUPPER(VU1);
|
2010-04-25 00:31:27 +00:00
|
|
|
VU1_UPPER_OPCODE[VU->code & 0x3f]();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _vu1ExecLower(VURegs* VU, u32 *ptr) {
|
2010-04-25 00:31:27 +00:00
|
|
|
VU->code = ptr[0];
|
2009-02-09 21:15:56 +00:00
|
|
|
IdebugLOWER(VU1);
|
2010-04-25 00:31:27 +00:00
|
|
|
VU1_LOWER_OPCODE[VU->code >> 25]();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int vu1branch = 0;
|
|
|
|
|
|
|
|
static void _vu1Exec(VURegs* VU)
|
|
|
|
{
|
|
|
|
_VURegsNum lregs;
|
|
|
|
_VURegsNum uregs;
|
|
|
|
VECTOR _VF;
|
|
|
|
VECTOR _VFc;
|
|
|
|
REG_VI _VI;
|
|
|
|
REG_VI _VIc;
|
|
|
|
u32 *ptr;
|
|
|
|
int vfreg;
|
|
|
|
int vireg;
|
|
|
|
int discard=0;
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
ptr = (u32*)&VU->Micro[VU->VI[REG_TPC].UL];
|
|
|
|
VU->VI[REG_TPC].UL+=8;
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
if (ptr[1] & 0x40000000) { /* E flag */
|
2009-02-09 21:15:56 +00:00
|
|
|
VU->ebit = 2;
|
|
|
|
}
|
|
|
|
if (ptr[1] & 0x10000000) { /* D flag */
|
|
|
|
if (VU0.VI[REG_FBRST].UL & 0x400) {
|
|
|
|
VU0.VI[REG_VPU_STAT].UL|= 0x200;
|
|
|
|
hwIntcIrq(INTC_VU1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ptr[1] & 0x08000000) { /* T flag */
|
|
|
|
if (VU0.VI[REG_FBRST].UL & 0x800) {
|
|
|
|
VU0.VI[REG_VPU_STAT].UL|= 0x400;
|
|
|
|
hwIntcIrq(INTC_VU1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-28 23:05:18 +00:00
|
|
|
//VUM_LOG("VU->cycle = %d (flags st=%x;mac=%x;clip=%x,q=%f)", VU->cycle, VU->statusflag, VU->macflag, VU->clipflag, VU->q.F);
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
VU->code = ptr[1];
|
2009-02-09 21:15:56 +00:00
|
|
|
VU1regs_UPPER_OPCODE[VU->code & 0x3f](&uregs);
|
|
|
|
#ifndef INT_VUSTALLHACK
|
|
|
|
_vuTestUpperStalls(VU, &uregs);
|
|
|
|
#endif
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
/* check upper flags */
|
|
|
|
if (ptr[1] & 0x80000000) { /* I flag */
|
2009-02-09 21:15:56 +00:00
|
|
|
_vu1ExecUpper(VU, ptr);
|
|
|
|
|
|
|
|
VU->VI[REG_I].UL = ptr[0];
|
|
|
|
} else {
|
|
|
|
VU->code = ptr[0];
|
|
|
|
VU1regs_LOWER_OPCODE[VU->code >> 25](&lregs);
|
|
|
|
#ifndef INT_VUSTALLHACK
|
|
|
|
_vuTestLowerStalls(VU, &lregs);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
vu1branch = lregs.pipe == VUPIPE_BRANCH;
|
|
|
|
|
|
|
|
vfreg = 0; vireg = 0;
|
|
|
|
if (uregs.VFwrite) {
|
|
|
|
if (lregs.VFwrite == uregs.VFwrite) {
|
2009-10-29 13:32:40 +00:00
|
|
|
// Console.Warning("*PCSX2*: Warning, VF write to the same reg in both lower/upper cycle");
|
2009-02-09 21:15:56 +00:00
|
|
|
discard = 1;
|
|
|
|
}
|
|
|
|
if (lregs.VFread0 == uregs.VFwrite ||
|
|
|
|
lregs.VFread1 == uregs.VFwrite) {
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
// Console.WriteLn("saving reg %d at pc=%x", i, VU->VI[REG_TPC].UL);
|
2009-02-09 21:15:56 +00:00
|
|
|
_VF = VU->VF[uregs.VFwrite];
|
|
|
|
vfreg = uregs.VFwrite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (uregs.VIread & (1 << REG_CLIP_FLAG)) {
|
|
|
|
if (lregs.VIwrite & (1 << REG_CLIP_FLAG)) {
|
2009-10-29 13:32:40 +00:00
|
|
|
Console.Warning("*PCSX2*: Warning, VI write to the same reg in both lower/upper cycle");
|
2009-02-09 21:15:56 +00:00
|
|
|
discard = 1;
|
|
|
|
}
|
|
|
|
if (lregs.VIread & (1 << REG_CLIP_FLAG)) {
|
|
|
|
_VI = VU->VI[REG_CLIP_FLAG];
|
|
|
|
vireg = REG_CLIP_FLAG;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_vu1ExecUpper(VU, ptr);
|
|
|
|
|
|
|
|
if (discard == 0) {
|
|
|
|
if (vfreg) {
|
|
|
|
_VFc = VU->VF[vfreg];
|
|
|
|
VU->VF[vfreg] = _VF;
|
|
|
|
}
|
|
|
|
if (vireg) {
|
|
|
|
_VIc = VU->VI[vireg];
|
|
|
|
VU->VI[vireg] = _VI;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vu1ExecLower(VU, ptr);
|
|
|
|
|
|
|
|
if (vfreg) {
|
|
|
|
VU->VF[vfreg] = _VFc;
|
|
|
|
}
|
|
|
|
if (vireg) {
|
|
|
|
VU->VI[vireg] = _VIc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_vuAddUpperStalls(VU, &uregs);
|
|
|
|
_vuAddLowerStalls(VU, &lregs);
|
|
|
|
|
|
|
|
_vuTestPipes(VU);
|
|
|
|
|
|
|
|
if (VU->branch > 0) {
|
|
|
|
if (VU->branch-- == 1) {
|
|
|
|
VU->VI[REG_TPC].UL = VU->branchpc;
|
2013-01-28 23:05:18 +00:00
|
|
|
if(VU->takedelaybranch == true)
|
2013-01-27 16:56:58 +00:00
|
|
|
{
|
2013-01-28 23:05:18 +00:00
|
|
|
//DevCon.Warning("VU1 - Branch/Jump in Delay Slot");
|
|
|
|
if(VU->firstbranchisjump == 1)
|
|
|
|
{
|
|
|
|
//DevCon.Warning("Jump first, so reading 1 instruction from first branch, then jumping second");
|
2013-01-27 16:56:58 +00:00
|
|
|
|
2013-01-28 23:05:18 +00:00
|
|
|
VU->branch = 1;
|
|
|
|
VU->branchpc = VU->delaybranchpc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//DevCon.Warning("Branch first, so ignoring second branch");
|
|
|
|
}
|
|
|
|
|
2012-05-30 21:18:31 +00:00
|
|
|
VU->delaybranchpc = 0;
|
|
|
|
VU->takedelaybranch = false;
|
|
|
|
}
|
2013-01-28 23:05:18 +00:00
|
|
|
|
|
|
|
VU->firstbranchisjump = 0;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( VU->ebit > 0 ) {
|
|
|
|
if( VU->ebit-- == 1 ) {
|
|
|
|
_vuFlushAll(VU);
|
2009-10-05 21:24:22 +00:00
|
|
|
VU0.VI[REG_VPU_STAT].UL &= ~0x100;
|
2010-08-31 05:22:26 +00:00
|
|
|
vif1Regs.stat.VEW = false;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void vu1Exec(VURegs* VU)
|
|
|
|
{
|
|
|
|
_vu1Exec(VU);
|
|
|
|
VU->cycle++;
|
|
|
|
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
if (VU->VI[0].UL != 0) DbgCon.Error("VI[0] != 0!!!!\n");
|
|
|
|
if (VU->VF[0].f.x != 0.0f) DbgCon.Error("VF[0].x != 0.0!!!!\n");
|
|
|
|
if (VU->VF[0].f.y != 0.0f) DbgCon.Error("VF[0].y != 0.0!!!!\n");
|
|
|
|
if (VU->VF[0].f.z != 0.0f) DbgCon.Error("VF[0].z != 0.0!!!!\n");
|
|
|
|
if (VU->VF[0].f.w != 1.0f) DbgCon.Error("VF[0].w != 1.0!!!!\n");
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
|
2009-12-07 14:00:39 +00:00
|
|
|
InterpVU1::InterpVU1()
|
2009-02-09 21:15:56 +00:00
|
|
|
{
|
2010-02-24 07:20:33 +00:00
|
|
|
m_Idx = 1;
|
2009-12-07 14:00:39 +00:00
|
|
|
IsInterpreter = true;
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2011-08-12 02:31:49 +00:00
|
|
|
void InterpVU1::Reset() {
|
|
|
|
vu1Thread.WaitVU();
|
|
|
|
}
|
|
|
|
|
2011-08-12 18:25:21 +00:00
|
|
|
void InterpVU1::Shutdown() throw() {
|
2011-08-12 02:31:49 +00:00
|
|
|
vu1Thread.WaitVU();
|
|
|
|
}
|
|
|
|
|
2009-12-07 14:00:39 +00:00
|
|
|
void InterpVU1::Step()
|
|
|
|
{
|
2010-08-27 03:21:16 +00:00
|
|
|
VU1.VI[REG_TPC].UL &= VU1_PROGMASK;
|
2009-12-07 14:00:39 +00:00
|
|
|
vu1Exec( &VU1 );
|
|
|
|
}
|
2009-02-09 21:15:56 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
void InterpVU1::Execute(u32 cycles)
|
2009-12-07 14:00:39 +00:00
|
|
|
{
|
2010-02-26 03:52:53 +00:00
|
|
|
for (int i = (int)cycles; i > 0 ; i--) {
|
|
|
|
if (!(VU0.VI[REG_VPU_STAT].UL & 0x100)) {
|
|
|
|
if (VU1.branch || VU1.ebit) {
|
2010-08-27 03:21:16 +00:00
|
|
|
Step(); // run branch delay slot?
|
2009-12-07 14:00:39 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
2010-08-27 03:21:16 +00:00
|
|
|
Step();
|
2009-02-09 21:15:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|