Moved a couple of things around, fixed a couple of bugs i made, removed some unneeded/duplicate checks

This commit is contained in:
refractionpcsx2
2008-01-24 01:42:11 +00:00
parent 8221315810
commit a4caebdadc
4 changed files with 111 additions and 81 deletions

View File

@@ -1386,7 +1386,7 @@ int hwMFIFOWrite(u32 addr, u8 *data, int size) {
int hwDmacSrcChainWithStack(DMACh *dma, int id) {
u32 temp,finalAddress;
u32 temp;
switch (id) {
case 0: // Refe - Transfer Packet According to ADDR field
@@ -1411,25 +1411,26 @@ int hwDmacSrcChainWithStack(DMACh *dma, int id) {
case 5: // Call - Transfer QWC following the tag, save succeeding tag
temp = dma->madr; //Temporarily Store ADDR
finalAddress = dma->tadr + 16 + (dma->qwc << 4); //Store Address of Succeeding tag
dma->madr = dma->tadr + 16; //Set MADR to data following the tag
if ((dma->chcr & 0x30) == 0x0) { //Check if ASR0 is empty
dma->asr0 = finalAddress; //If yes store Succeeding tag
if ((dma->chcr & 0x30) == 0x0) { //Check if ASR0 is empty
dma->asr0 = dma->madr + (dma->qwc << 4); //If yes store Succeeding tag
dma->chcr = (dma->chcr & 0xffffffcf) | 0x10; //1 Address in call stack
}else if((dma->chcr & 0x30) == 0x10){
dma->chcr = (dma->chcr & 0xffffffcf) | 0x20; //2 Addresses in call stack
dma->asr1 = finalAddress; //If no store Succeeding tag in ASR1
dma->asr1 = dma->madr + (dma->qwc << 4); //If no store Succeeding tag in ASR1
}else {
SysPrintf("Call Stack Overflow (report if it fixes/breaks anything)\n");
return 1; //Return done
}
dma->tadr = temp; //Set TADR to temporarily stored ADDR
return 0;
case 6: // Ret - Transfer QWC following the tag, load next tag
dma->madr = dma->tadr + 16; //Set MADR to data following the tag
if ((dma->chcr & 0x30) == 0x20) { //If ASR1 is NOT equal to 0 (Contains address)
dma->chcr = (dma->chcr & 0xffffffcf) | 0x10; //1 Address left in call stack
dma->tadr = dma->asr1; //Read ASR1 as next tag

View File

@@ -19,7 +19,6 @@
#include <string.h>
#include "Common.h"
#include "SPR.h"
#include "iR5900.h"
#define spr0 ((DMACh*)&PS2MEM_HW[0xD000])
@@ -69,7 +68,6 @@ int _SPR0chain() {
u32 *pMem;
if (spr0->qwc == 0) return 0;
pMem = (u32*)dmaGetAddr(spr0->madr);
if (pMem == NULL) return -1;
@@ -105,7 +103,6 @@ void _SPR0interleave() {
int tqwc = (psHu32(DMAC_SQWC) >> 16) & 0xff;
int cycles = 0;
u32 *pMem;
if(tqwc == 0) tqwc = qwc;
//SysPrintf("dmaSPR0 interleave\n");
#ifdef SPR_LOG
@@ -134,31 +131,36 @@ void _SPR0interleave() {
}
void _dmaSPR0() {
u32 *ptag;
int id;
int cycles = 0;
int done = 0;
if ((psHu32(DMAC_CTRL) & 0x30) == 0x20) { // STS == fromSPR
SysPrintf("SPR0 stall %d\n", (psHu32(DMAC_CTRL)>>6)&3);
}
if ((spr0->chcr & 0xc) == 0x8) { // Interleave Mode
_SPR0interleave();
return;
}
// Transfer Dn_QWC from SPR to Dn_MADR
if ((spr0->chcr & 0xc) == 0 || spr0->qwc > 0) { // Normal Mode
if ((spr0->chcr & 0xc) == 0x0) { // Normal Mode
int cycles = 0;
SPR0chain();
INT(8, cycles);
INT(8, cycles);
return;
}
} else if ((spr0->chcr & 0xc) == 0x4) {
int cycles = 0;
u32 *ptag;
int id;
int done = 0;
if(spr0->qwc > 0){
SPR0chain();
INT(8, cycles);
return;
}
// Destination Chain Mode
while (done == 0) { // Loop while Dn_CHCR.STR is 1
@@ -211,9 +213,13 @@ void _dmaSPR0() {
hwDmacIrq(8);
return;
}*/
}
}
INT(8, cycles);
} else { // Interleave Mode
_SPR0interleave();
}
}
@@ -313,9 +319,8 @@ void _SPR1interleave() {
}
void dmaSPR1() { // toSPR
u32 *ptag;
int id, done=0;
int cycles = 0;
FreezeMMXRegs(1);
#ifdef SPR_LOG
SPR_LOG("dmaSPR1 chcr = 0x%x, madr = 0x%x, qwc = 0x%x\n"
@@ -324,21 +329,31 @@ void dmaSPR1() { // toSPR
spr1->tadr, spr1->sadr);
#endif
if ((spr1->chcr & 0xc) == 0x8) { // Interleave Mode
_SPR1interleave();
FreezeMMXRegs(0);
return;
}
if ((spr1->chcr & 0xc) == 0 || spr1->qwc > 0) { // Normal Mode
if ((spr1->chcr & 0xc) == 0) { // Normal Mode
int cycles = 0;
//if(spr1->qwc == 0 && (spr1->chcr & 0xc) == 1) spr1->qwc = 0xffff;
// Transfer Dn_QWC from Dn_MADR to SPR1
SPR1chain();
INT(9, cycles);
FreezeMMXRegs(0);
return;
} else if ((spr1->chcr & 0xc) == 0x4){
int cycles = 0;
u32 *ptag;
int id, done=0;
if(spr1->qwc > 0){
//if(spr1->qwc == 0 && (spr1->chcr & 0xc) == 1) spr1->qwc = 0xffff;
// Transfer Dn_QWC from Dn_MADR to SPR1
SPR1chain();
INT(9, cycles);
FreezeMMXRegs(0);
return;
}
// Chain Mode
while (done == 0) { // Loop while Dn_CHCR.STR is 1
@@ -384,9 +399,12 @@ void dmaSPR1() { // toSPR
break;
}
}
FreezeMMXRegs(0);
INT(9, cycles);
} else { // Interleave Mode
_SPR1interleave();
}
FreezeMMXRegs(0);
}
void SPRTOinterrupt()

View File

@@ -410,24 +410,26 @@ void UNPACK_V4_5(u32 *dest, u32 *data, int size) {
static int cycles;
extern int g_vifCycles;
int vifqwc = 0;
int mfifoVIF1rbTransfer() {
__inline int mfifoVIF1rbTransfer() {
u32 maddr = psHu32(DMAC_RBOR);
int msize = psHu32(DMAC_RBOR) + psHu32(DMAC_RBSR) + 16, ret;
int mfifoqwc = min(vif1ch->qwc, vifqwc);
u32 *src;
/* Check if the transfer should wrap around the ring buffer */
if ((vif1ch->madr+(mfifoqwc << 4)) >= (msize)) {
int s1 = (msize) - vif1ch->madr;
int s2 = (mfifoqwc << 4) - s1;
if ((vif1ch->madr+(mfifoqwc << 4)) > (msize)) {
int s1 = ((msize) - vif1ch->madr) >> 2;
#ifdef SPR_LOG
SPR_LOG("Split MFIFO\n");
#endif
/* it does, so first copy 's1' bytes from 'addr' to 'data' */
src = (u32*)PSM(vif1ch->madr);
if (src == NULL) return -1;
if(vif1.vifstalled == 1){
ret = VIF1transfer(src+vif1.irqoffset, s1/4-vif1.irqoffset, 0);
ret = VIF1transfer(src+vif1.irqoffset, s1-vif1.irqoffset, 0);
}else
ret = VIF1transfer(src, s1>>2, 0);
ret = VIF1transfer(src, s1, 0);
if(ret == -2) return ret;
/* and second copy 's2' bytes from 'maddr' to '&data[s1]' */
@@ -435,8 +437,11 @@ int mfifoVIF1rbTransfer() {
src = (u32*)PSM(maddr);
if (src == NULL) return -1;
ret = VIF1transfer(src, s2>>2, 0);
ret = VIF1transfer(src, ((mfifoqwc << 2) - s1), 0);
} else {
#ifdef SPR_LOG
SPR_LOG("Direct MFIFO\n");
#endif
/* it doesn't, so just transfer 'qwc*4' words */
src = (u32*)PSM(vif1ch->madr);
if (src == NULL) return -1;
@@ -451,7 +456,7 @@ int mfifoVIF1rbTransfer() {
return ret;
}
int mfifoVIF1chain() {
__inline int mfifoVIF1chain() {
int ret;
/* Is QWC = 0? if so there is nothing to transfer */
@@ -465,6 +470,9 @@ int mfifoVIF1chain() {
vifqwc -= startqwc - vif1ch->qwc;
} else {
u32 *pMem = (u32*)dmaGetAddr(vif1ch->madr);
#ifdef SPR_LOG
SPR_LOG("Non-MFIFO Location\n");
#endif
if (pMem == NULL) return -1;
if(vif1.vifstalled == 1){
ret = VIF1transfer(pMem+vif1.irqoffset, vif1ch->qwc*4-vif1.irqoffset, 0);
@@ -482,17 +490,18 @@ void mfifoVIF1transfer(int qwc) {
u32 *ptag;
int id;
int ret, temp;
vifqwc += qwc;
g_vifCycles = 0;
if(qwc > 0){
#ifdef VIF_LOG
VIF_LOG("Added %x qw to mfifo, total now %x\n", qwc, vifqwc);
vifqwc += qwc;
#ifdef SPR_LOG
SPR_LOG("Added %x qw to mfifo, total now %x\n", qwc, vifqwc);
#endif
if((vif1ch->chcr & 0x100) == 0 || vif1.vifstalled == 1) return;
}
if(vif1ch->qwc == 0 && vifqwc > 0){
if(vif1ch->qwc == 0){
/*if(vif1ch->tadr == spr0->madr) {
#ifdef PCSX2_DEVBUILD
@@ -510,16 +519,13 @@ void mfifoVIF1transfer(int qwc) {
if( vif1.stallontag == 1) ret = VIF1transfer(ptag+(2+vif1.irqoffset), 2-vif1.irqoffset, 1); //Transfer Tag on Stall
else ret = VIF1transfer(ptag+2, 2, 1); //Transfer Tag
if (ret == -2) {
#ifdef VIF_LOG
#ifdef SPR_LOG
VIF_LOG("MFIFO Stallon tag\n");
#endif
vif1.stallontag = 1;
INT(10,cycles+g_vifCycles);
return; //IRQ set by VIFTransfer
} else {
vif1.vifstalled = 0;
vif1.stallontag = 0;
}
}
}
id = (ptag[0] >> 28) & 0x7;
@@ -529,8 +535,8 @@ void mfifoVIF1transfer(int qwc) {
vif1ch->chcr = ( vif1ch->chcr & 0xFFFF ) | ( (*ptag) & 0xFFFF0000 );
#ifdef VIF_LOG
VIF_LOG("dmaChain %8.8x_%8.8x size=%d, id=%d, madr=%lx, tadr=%lx mfifo qwc = %x spr0 madr = %x\n",
#ifdef SPR_LOG
SPR_LOG("dmaChain %8.8x_%8.8x size=%d, id=%d, madr=%lx, tadr=%lx mfifo qwc = %x spr0 madr = %x\n",
ptag[1], ptag[0], vif1ch->qwc, id, vif1ch->madr, vif1ch->tadr, vifqwc, spr0->madr);
#endif
vifqwc--;
@@ -551,6 +557,7 @@ void mfifoVIF1transfer(int qwc) {
temp = vif1ch->madr; //Temporarily Store ADDR
vif1ch->madr = psHu32(DMAC_RBOR) + ((vif1ch->tadr + 16) & psHu32(DMAC_RBSR)); //Set MADR to QW following the tag
vif1ch->tadr = temp; //Copy temporarily stored ADDR to Tag
if((temp & psHu32(DMAC_RBSR)) != psHu32(DMAC_RBOR)) SysPrintf("Next tag = %x outside ring %x size %x\n", temp, psHu32(DMAC_RBOR), psHu32(DMAC_RBSR));
vif1.done = 0;
break;
@@ -568,7 +575,7 @@ void mfifoVIF1transfer(int qwc) {
}
if ((vif1ch->chcr & 0x80) && (ptag[0] >> 31)) {
#ifdef VIF_LOG
#ifdef SPR_LOG
VIF_LOG("dmaIrq Set\n");
#endif
vif1.done = 2;
@@ -594,8 +601,8 @@ void mfifoVIF1transfer(int qwc) {
INT(10,g_vifCycles);
#ifdef VIF_LOG
VIF_LOG("mfifoVIF1transfer end %x madr %x, tadr %x vifqwc %x\n", vif1ch->chcr, vif1ch->madr, vif1ch->tadr, vifqwc);
#ifdef SPR_LOG
SPR_LOG("mfifoVIF1transfer end %x madr %x, tadr %x vifqwc %x\n", vif1ch->chcr, vif1ch->madr, vif1ch->tadr, vifqwc);
#endif
}

View File

@@ -605,14 +605,15 @@ static void VIFunpack(u32 *data, vifCode *v, int size, const unsigned int VIFdma
if(unpackType == 0xC && vifRegs->cycle.cl == vifRegs->cycle.wl) { //No use when SSE is available
// v4-32
if(vifRegs->mode == 0 && !(vifRegs->code & 0x10000000)){
if(vifRegs->mode == 0 && !(vifRegs->code & 0x10000000) && vif->usn == 0){
if (v->size != size){
vifRegs->num -= size>>2;
ProcessMemSkip(size << 2, unpackType, VIFdmanum);
}
else vifRegs->num = 0;
memcpy_fast((u8*)dest, cdata, size << 2);
memcpy_fast((u8*)dest, cdata, size);
size = 0;
return;
}
@@ -866,7 +867,7 @@ __inline void _vif0mpgTransfer(u32 addr, u32 *data, int size) {
static int Vif0TransNull(u32 *data){ // Shouldnt go here
SysPrintf("VIF0 Shouldnt go here CMD = %x\n", vif0Regs->code);
vif0.cmd &= ~0x7f;
vif0.cmd = 0;
return 0;
}
static int Vif0TransSTMask(u32 *data){ // STMASK
@@ -876,7 +877,7 @@ static int Vif0TransSTMask(u32 *data){ // STMASK
VIF_LOG("STMASK == %x\n", vif0Regs->mask);
#endif
vif0.tag.size = 0;
vif0.cmd &= ~0x7f;
vif0.cmd = 0;
return 1;
}
@@ -899,7 +900,7 @@ static int Vif0TransSTRow(u32 *data){ // STROW
}
vif0.tag.addr += ret;
vif0.tag.size -= ret;
if(vif0.tag.size == 0) vif0.cmd &= ~0x7f;
if(vif0.tag.size == 0) vif0.cmd = 0;
return ret;
}
@@ -921,7 +922,7 @@ static int Vif0TransSTCol(u32 *data){ // STCOL
}
vif0.tag.addr += ret;
vif0.tag.size -= ret;
if(vif0.tag.size == 0) vif0.cmd &= ~0x7f;
if(vif0.tag.size == 0) vif0.cmd = 0;
return ret;
}
@@ -936,7 +937,7 @@ static int Vif0TransMPG(u32 *data){ // MPG
_vif0mpgTransfer(vif0.tag.addr, data, vif0.tag.size);
ret = vif0.tag.size;
vif0.tag.size = 0;
vif0.cmd &= ~0x7f;
vif0.cmd = 0;
return ret;
}
}
@@ -958,7 +959,7 @@ static int Vif0TransUnpack(u32 *data){ // UNPACK
//g_vifCycles+= vif0.tag.size >> 1;
ret = vif0.tag.size;
vif0.tag.size = 0;
vif0.cmd &= ~0x7f;
vif0.cmd = 0;
//FreezeXMMRegs(0);
return ret;
}
@@ -1052,7 +1053,7 @@ int VIF0transfer(u32 *data, int size, int istag) {
FreezeMMXRegs(1);
while (vif0.vifpacketsize > 0) {
if (vif0.cmd & 0x7f) {
if (vif0.cmd) {
//vif0Regs->stat |= VIF0_STAT_VPS_T;
ret = Vif0TransTLB[(vif0.cmd & 0x7f)](data);
data+= ret; vif0.vifpacketsize-= ret;
@@ -1093,19 +1094,21 @@ int VIF0transfer(u32 *data, int size, int istag) {
++data;
--vif0.vifpacketsize;
if ((vif0.cmd & 0x80) && !(vif0Regs->err & 0x1) ) { //i bit on vifcode and not masked by VIF0_ERR
if ((vif0.cmd & 0x80)) { //i bit on vifcode and not masked by VIF0_ERR
if(!(vif0Regs->err & 0x1)){
#ifdef VIF_LOG
VIF_LOG( "Interrupt on VIFcmd: %x (INTC_MASK = %x)\n", vif0.cmd, psHu32(INTC_MASK) );
#endif
++vif0.irq;
vif0.cmd &= 0x7f;
if(istag && vif0.tag.size == 0) vif0.stallontag = 1;
++vif0.irq;
if(istag && vif0.tag.size <= vif0.vifpacketsize) vif0.stallontag = 1;
}
vif0.cmd &= 0x7f;
}
}
FreezeXMMRegs(0);
FreezeMMXRegs(0);
transferred += size - vif1.vifpacketsize;
transferred += size - vif0.vifpacketsize;
g_vifCycles+= (transferred >> 2)*BIAS; /* guessing */
// use tag.size because some game doesn't like .cmd
//if( !vif0.cmd )
@@ -1561,7 +1564,7 @@ __inline void _vif1mpgTransfer(u32 addr, u32 *data, int size) {
static int Vif1TransNull(u32 *data){ // Shouldnt go here
SysPrintf("Shouldnt go here CMD = %x\n", vif1Regs->code);
vif1.cmd &= ~0x7f;
vif1.cmd = 0;
return 0;
}
static int Vif1TransSTMask(u32 *data){ // STMASK
@@ -1571,7 +1574,7 @@ static int Vif1TransSTMask(u32 *data){ // STMASK
VIF_LOG("STMASK == %x\n", vif1Regs->mask);
#endif
vif1.tag.size = 0;
vif1.cmd &= ~0x7f;
vif1.cmd = 0;
return 1;
}
@@ -1594,7 +1597,7 @@ static int Vif1TransSTRow(u32 *data){
}
vif1.tag.addr += ret;
vif1.tag.size -= ret;
if(vif1.tag.size == 0) vif1.cmd &= ~0x7f;
if(vif1.tag.size == 0) vif1.cmd = 0;
return ret;
}
@@ -1616,7 +1619,7 @@ static int Vif1TransSTCol(u32 *data){
}
vif1.tag.addr += ret;
vif1.tag.size -= ret;
if(vif1.tag.size == 0) vif1.cmd &= ~0x7f;
if(vif1.tag.size == 0) vif1.cmd = 0;
return ret;
}
@@ -1631,7 +1634,7 @@ static int Vif1TransMPG(u32 *data){
_vif1mpgTransfer(vif1.tag.addr, data, vif1.tag.size);
ret = vif1.tag.size;
vif1.tag.size = 0;
vif1.cmd &= ~0x7f;
vif1.cmd = 0;
return ret;
}
}
@@ -1668,7 +1671,7 @@ static int Vif1TransDirectHL(u32 *data){
/*FreezeMMXRegs(0);
FreezeXMMRegs(0);*/
}
if(vif1.tag.size == 0) vif1.cmd &= ~0x7f;
if(vif1.tag.size == 0) vif1.cmd = 0;
splitptr = 0;
return ret;
}
@@ -1689,7 +1692,7 @@ static int Vif1TransDirectHL(u32 *data){
} else {
ret = vif1.tag.size;
vif1.tag.size = 0;
vif1.cmd &= ~0x7f;
vif1.cmd = 0;
}
@@ -1730,7 +1733,7 @@ static int Vif1TransUnpack(u32 *data){
//g_vifCycles+= vif1.tag.size >> 1;
ret = vif1.tag.size;
vif1.tag.size = 0;
vif1.cmd &= ~0x7f;
vif1.cmd = 0;
//FreezeXMMRegs(0);
return ret;
}
@@ -2195,7 +2198,7 @@ void vif1Interrupt() {
INT(1, g_vifCycles);
return 0;
}*/
if ((vif1ch->chcr & 0x104) == 0x104 && vif1.done == 0 && vif1.vifstalled == 0) {
if ((vif1ch->chcr & 0x104) == 0x104 && vif1.done == 0) {
if( !(psHu32(DMAC_CTRL) & 0x1) ) {
SysPrintf("vif1 dma masked\n");
@@ -2273,6 +2276,7 @@ void dmaVIF1()
if (((psHu32(DMAC_CTRL) & 0xC) == 0x8)) { // VIF MFIFO
//SysPrintf("VIFMFIFO\n");
if(!(vif1ch->chcr & 0x4)) SysPrintf("MFIFO mode != Chain! %x\n", vif1ch->chcr);
if(vif1ch->madr != spr0->madr)vifMFIFOInterrupt();
return;
}