From 44699ebf68681c15634babcd41273c7ea6c84f75 Mon Sep 17 00:00:00 2001 From: arcum42 Date: Mon, 10 Nov 2008 14:24:31 +0000 Subject: [PATCH] Remove some commented out code and inline a few defines. git-svn-id: http://pcsx2-playground.googlecode.com/svn/trunk@311 a6443dda-0b58-4228-96e9-037be469359c --- pcsx2/CdRom.c | 787 ++++++++++++++++++------------------------ pcsx2/CdRom.h | 1 + pcsx2/Linux/LnxMain.c | 2 - pcsx2/Misc.c | 183 ++-------- pcsx2/PsxDma.c | 73 ++-- pcsx2/Sif.c | 72 +--- pcsx2/Sif.h | 2 +- 7 files changed, 402 insertions(+), 718 deletions(-) diff --git a/pcsx2/CdRom.c b/pcsx2/CdRom.c index 4c505676b5..f1a5fc054b 100644 --- a/pcsx2/CdRom.c +++ b/pcsx2/CdRom.c @@ -88,38 +88,34 @@ unsigned long cdReadTime;// = ((PSXCLK / 75) / BIAS); #define btoi(b) ((b)/16*10 + (b)%16) /* BCD to u_char */ #define itob(i) ((i)/10*16 + (i)%10) /* u_char to BCD */ -/*static struct CdrStat stat; -static struct SubQ *subq;*/ - #define CDR_INT(eCycle) PSX_INT(17, eCycle) #define CDREAD_INT(eCycle) PSX_INT(18, eCycle) -#define StartReading(type) { \ - cdr.Reading = type; \ - cdr.FirstSector = 1; \ - cdr.Readed = 0xff; \ - AddIrqQueue(READ_ACK, 0x800); \ +static __inline void StartReading(unsigned long type) { + cdr.Reading = type; + cdr.FirstSector = 1; + cdr.Readed = 0xff; + AddIrqQueue(READ_ACK, 0x800); } -#define StopReading() { \ - if (cdr.Reading) { \ - cdr.Reading = 0; \ - psxRegs.interrupt&=~0x40000; \ - } \ +static __inline void StopReading() { + if (cdr.Reading) { + cdr.Reading = 0; + psxRegs.interrupt&=~0x40000; + } } -#define StopCdda() { \ - if (cdr.Play) { \ -/* if (!Config.Cdda) CDR_stop();*/ \ - cdr.StatP&=~0x80; \ - cdr.Play = 0; \ - } \ +static __inline void StopCdda() { + if (cdr.Play) { + cdr.StatP&=~0x80; + cdr.Play = 0; + } } -#define SetResultSize(size) { \ - cdr.ResultP = 0; \ - cdr.ResultC = size; \ - cdr.ResultReady = 1; \ +__inline void SetResultSize(u8 size) { + cdr.ResultP = 0; + cdr.ResultC = size; + cdr.ResultReady = 1; } s32 MSFtoLSN(u8 *Time) { @@ -144,9 +140,7 @@ void ReadTrack() { cdr.Prev[1] = itob(cdr.SetSector[1]); cdr.Prev[2] = itob(cdr.SetSector[2]); -#ifdef CDR_LOG CDR_LOG("KEY *** %x:%x:%x\n", cdr.Prev[0], cdr.Prev[1], cdr.Prev[2]); -#endif cdr.RErr = CDVDreadTrack(MSFtoLSN(cdr.SetSector), CDVD_MODE_2352); } @@ -181,39 +175,25 @@ void cdrInterrupt() { cdr.Ctrl&=~0x80; switch (Irq) { - case CdlSync: + case CdlSync: SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; break; - case CdlNop: + case CdlNop: SetResultSize(1); - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; -/* i = stat.Status; - if (CDR_getStatus(&stat) != -1) { - if (stat.Type == 0xff) cdr.Stat = DiskError; - if (stat.Status & 0x10) { - cdr.Stat = DiskError; - cdr.Result[0]|= 0x11; - cdr.Result[0]&=~0x02; - } - else if (i & 0x10) { - cdr.StatP |= 0x2; - cdr.Result[0]|= 0x2; - CheckCdrom(); - } - }*/ + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; break; case CdlSetloc: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; break; case CdlPlay: @@ -222,288 +202,257 @@ void cdrInterrupt() { cdr.Result[0] = cdr.StatP; cdr.Stat = Acknowledge; cdr.StatP|= 0x82; -// if ((cdr.Mode & 0x5) == 0x5) AddIrqQueue(REPPLAY, cdReadTime); break; - case CdlForward: + case CdlForward: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; break; - case CdlBackward: + case CdlBackward: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; break; - case CdlStandby: + case CdlStandby: cdr.CmdProcess = 0; SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; break; case CdlStop: cdr.CmdProcess = 0; SetResultSize(1); - cdr.StatP&=~0x2; + cdr.StatP&=~0x2; cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; -// cdr.Stat = Acknowledge; + cdr.Stat = Complete; + // cdr.Stat = Acknowledge; break; case CdlPause: SetResultSize(1); cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; + cdr.Stat = Acknowledge; AddIrqQueue(CdlPause + 0x20, 0x800); break; case CdlPause + 0x20: SetResultSize(1); - cdr.StatP&=~0x20; + cdr.StatP&=~0x20; cdr.StatP|= 0x2; cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; + cdr.Stat = Complete; break; - case CdlInit: + case CdlInit: SetResultSize(1); - cdr.StatP = 0x2; + cdr.StatP = 0x2; cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; -// if (!cdr.Init) { - AddIrqQueue(CdlInit + 0x20, 0x800); -// } + cdr.Stat = Acknowledge; + AddIrqQueue(CdlInit + 0x20, 0x800); break; case CdlInit + 0x20: SetResultSize(1); cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; + cdr.Stat = Complete; cdr.Init = 1; break; - case CdlMute: + case CdlMute: SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; break; - case CdlDemute: + case CdlDemute: SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; break; - case CdlSetfilter: + case CdlSetfilter: SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - break; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; + break; case CdlSetmode: SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; - break; - - case CdlGetmode: - SetResultSize(6); - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Result[1] = cdr.Mode; - cdr.Result[2] = cdr.File; - cdr.Result[3] = cdr.Channel; - cdr.Result[4] = 0; - cdr.Result[5] = 0; - cdr.Stat = Acknowledge; - break; - - case CdlGetlocL: - SetResultSize(8); -// for (i=0; i<8; i++) cdr.Result[i] = itob(cdr.Transfer[i]); - for (i=0; i<8; i++) cdr.Result[i] = cdr.Transfer[i]; - cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; break; - case CdlGetlocP: - SetResultSize(8); -/* subq = (struct SubQ*) CDR_getBufferSub(); - if (subq != NULL) { - cdr.Result[0] = subq->TrackNumber; - cdr.Result[1] = subq->IndexNumber; - memcpy(cdr.Result+2, subq->TrackRelativeAddress, 3); - memcpy(cdr.Result+5, subq->AbsoluteAddress, 3); - } else { -*/ cdr.Result[0] = 1; - cdr.Result[1] = 1; - cdr.Result[2] = cdr.Prev[0]; - cdr.Result[3] = itob((btoi(cdr.Prev[1])) - 2); - cdr.Result[4] = cdr.Prev[2]; - cdr.Result[5] = cdr.Prev[0]; - cdr.Result[6] = cdr.Prev[1]; - cdr.Result[7] = cdr.Prev[2]; -// } - cdr.Stat = Acknowledge; - break; + case CdlGetmode: + SetResultSize(6); + cdr.StatP|= 0x2; + cdr.Result[0] = cdr.StatP; + cdr.Result[1] = cdr.Mode; + cdr.Result[2] = cdr.File; + cdr.Result[3] = cdr.Channel; + cdr.Result[4] = 0; + cdr.Result[5] = 0; + cdr.Stat = Acknowledge; + break; - case CdlGetTN: + case CdlGetlocL: + SetResultSize(8); + for (i=0; i<8; i++) + cdr.Result[i] = cdr.Transfer[i]; + cdr.Stat = Acknowledge; + break; + + case CdlGetlocP: + SetResultSize(8); + cdr.Result[0] = 1; + cdr.Result[1] = 1; + cdr.Result[2] = cdr.Prev[0]; + cdr.Result[3] = itob((btoi(cdr.Prev[1])) - 2); + cdr.Result[4] = cdr.Prev[2]; + cdr.Result[5] = cdr.Prev[0]; + cdr.Result[6] = cdr.Prev[1]; + cdr.Result[7] = cdr.Prev[2]; + cdr.Stat = Acknowledge; + break; + + case CdlGetTN: cdr.CmdProcess = 0; SetResultSize(3); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - if (CDVDgetTN(&cdr.ResultTN) == -1) { + cdr.Result[0] = cdr.StatP; + if (CDVDgetTN(&cdr.ResultTN) == -1) { cdr.Stat = DiskError; cdr.Result[0]|= 0x01; - } else { - cdr.Stat = Acknowledge; - cdr.Result[1] = itob(cdr.ResultTN.strack); - cdr.Result[2] = itob(cdr.ResultTN.etrack); - } - break; - - case CdlGetTD: - cdr.CmdProcess = 0; - cdr.Track = btoi(cdr.Param[0]); - SetResultSize(4); - cdr.StatP|= 0x2; - if (CDVDgetTD(cdr.Track, &trackInfo) == -1) { - cdr.Stat = DiskError; - cdr.Result[0]|= 0x01; - } else { - LSNtoMSF(cdr.ResultTD, trackInfo.lsn); - cdr.Stat = Acknowledge; - cdr.Result[0] = cdr.StatP; - cdr.Result[1] = itob(cdr.ResultTD[0]); - cdr.Result[2] = itob(cdr.ResultTD[1]); - cdr.Result[3] = itob(cdr.ResultTD[2]); - } + } else { + cdr.Stat = Acknowledge; + cdr.Result[1] = itob(cdr.ResultTN.strack); + cdr.Result[2] = itob(cdr.ResultTN.etrack); + } break; - case CdlSeekL: + case CdlGetTD: + cdr.CmdProcess = 0; + cdr.Track = btoi(cdr.Param[0]); + SetResultSize(4); + cdr.StatP|= 0x2; + if (CDVDgetTD(cdr.Track, &trackInfo) == -1) { + cdr.Stat = DiskError; + cdr.Result[0]|= 0x01; + } else { + LSNtoMSF(cdr.ResultTD, trackInfo.lsn); + cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + cdr.Result[1] = itob(cdr.ResultTD[0]); + cdr.Result[2] = itob(cdr.ResultTD[1]); + cdr.Result[3] = itob(cdr.ResultTD[2]); + } + break; + + case CdlSeekL: SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; AddIrqQueue(CdlSeekL + 0x20, 0x800); break; - case CdlSeekL + 0x20: + case CdlSeekL + 0x20: SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; break; - case CdlSeekP: + case CdlSeekP: SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; AddIrqQueue(CdlSeekP + 0x20, 0x800); break; - case CdlSeekP + 0x20: + case CdlSeekP + 0x20: SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; break; case CdlTest: - cdr.Stat = Acknowledge; - switch (cdr.Param[0]) { - case 0x20: // System Controller ROM Version + cdr.Stat = Acknowledge; + switch (cdr.Param[0]) { + case 0x20: // System Controller ROM Version SetResultSize(4); - *(int*)cdr.Result = *(int*)Test20; + *(int*)cdr.Result = *(int*)Test20; break; case 0x22: SetResultSize(8); - *(int*)cdr.Result = *(int*)Test22; + *(int*)cdr.Result = *(int*)Test22; break; case 0x23: case 0x24: SetResultSize(8); - *(int*)cdr.Result = *(int*)Test23; + *(int*)cdr.Result = *(int*)Test23; break; - } + } break; - case CdlID: + case CdlID: SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; AddIrqQueue(CdlID + 0x20, 0x800); break; case CdlID + 0x20: SetResultSize(8); -// if (CDR_getStatus(&stat) == -1) { cdr.Result[0] = 0x00; // 0x08 and cdr.Result[1]|0x10 : audio cd, enters cd player - cdr.Result[1] = 0x00; // 0x80 leads to the menu in the bios, else loads CD -/* } - else { - if (stat.Type == 2) { - cdr.Result[0] = 0x08; - cdr.Result[1] = 0x10; - } - else { - cdr.Result[0] = 0x00; - cdr.Result[1] = 0x00; - } - }*/ - if (!LoadCdBios) cdr.Result[1] |= 0x80; + cdr.Result[1] = 0x00; // 0x80 leads to the menu in the bios, else loads CD - cdr.Result[2] = 0x00; - cdr.Result[3] = 0x00; + if (!LoadCdBios) cdr.Result[1] |= 0x80; + cdr.Result[2] = 0x00; + cdr.Result[3] = 0x00; strncpy((char *)&cdr.Result[4], "PCSX", 4); cdr.Stat = Complete; break; case CdlReset: SetResultSize(1); - cdr.StatP = 0x2; + cdr.StatP = 0x2; cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; + cdr.Stat = Acknowledge; break; - case CdlReadToc: + case CdlReadToc: SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; AddIrqQueue(CdlReadToc + 0x20, 0x800); break; - case CdlReadToc + 0x20: + case CdlReadToc + 0x20: SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Complete; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Complete; break; case AUTOPAUSE: cdr.OCUP = 0; -/* SetResultSize(1); - StopCdda(); - StopReading(); - cdr.OCUP = 0; - cdr.StatP&=~0x20; - cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = DataEnd; -*/ AddIrqQueue(CdlPause, 0x400); + AddIrqQueue(CdlPause, 0x400); break; case READ_ACK: @@ -514,8 +463,8 @@ void cdrInterrupt() { SetResultSize(1); cdr.StatP|= 0x2; - cdr.Result[0] = cdr.StatP; - cdr.Stat = Acknowledge; + cdr.Result[0] = cdr.StatP; + cdr.Stat = Acknowledge; ReadTrack(); @@ -531,21 +480,8 @@ void cdrInterrupt() { break; case REPPLAY: - if ((cdr.Mode & 5) != 5) break; -/* if (CDR_getStatus(&stat) == -1) { - cdr.Result[0] = 0; - cdr.Result[1] = 0; - cdr.Result[2] = 0; - cdr.Result[3] = 0; - cdr.Result[4] = 0; - cdr.Result[5] = 0; - cdr.Result[6] = 0; - cdr.Result[7] = 0; - } else memcpy(cdr.Result, &stat.Track, 8); - cdr.Stat = 1; - SetResultSize(8); - AddIrqQueue(REPPLAY_ACK, cdReadTime); -*/ break; + //if ((cdr.Mode & 5) != 5) break; + break; case 0xff: psxRegs.interrupt&= ~(1 << 17); @@ -558,9 +494,7 @@ void cdrInterrupt() { if (cdr.Stat != NoIntr && cdr.Reg2 != 0x18) psxHu32(0x1070)|=0x4; -#ifdef CDR_LOG CDR_LOG("Cdr Interrupt %x\n", Irq); -#endif psxRegs.interrupt&= ~(1 << 17); } @@ -577,23 +511,19 @@ void cdrReadInterrupt() { return; } -#ifdef CDR_LOG CDR_LOG("KEY END"); -#endif - cdr.OCUP = 1; + cdr.OCUP = 1; SetResultSize(1); cdr.StatP|= 0x22; - cdr.Result[0] = cdr.StatP; + cdr.Result[0] = cdr.StatP; SysPrintf("Reading From CDR"); buf = CDVDgetBuffer(); if (buf == NULL) cdr.RErr = -1; if (cdr.RErr == -1) { -#ifdef CDR_LOG CDR_LOG(" err\n"); -#endif memset(cdr.Transfer, 0, 2340); cdr.Stat = DiskError; cdr.Result[0]|= 0x01; @@ -604,43 +534,25 @@ void cdrReadInterrupt() { FreezeMMXRegs(1); memcpy_fast(cdr.Transfer, buf+12, 2340); FreezeMMXRegs(0); - cdr.Stat = DataReady; + cdr.Stat = DataReady; -#ifdef CDR_LOG CDR_LOG(" %x:%x:%x\n", cdr.Transfer[0], cdr.Transfer[1], cdr.Transfer[2]); -#endif - -/* if ((cdr.Muted == 1) && (cdr.Mode & 0x40) && (!Config.Xa) && (cdr.FirstSector != -1)) { // CD-XA - if ((cdr.Transfer[4+2] & 0x4) && - ((cdr.Mode&0x8) ? (cdr.Transfer[4+1] == cdr.Channel) : 1) && - (cdr.Transfer[4+0] == cdr.File)) { - int ret = xa_decode_sector(&cdr.Xa, cdr.Transfer+4, cdr.FirstSector); - - if (!ret) { - SPU_playADPCMchannel(&cdr.Xa); - cdr.FirstSector = 0; - } - else cdr.FirstSector = -1; - } - }*/ cdr.SetSector[2]++; - if (cdr.SetSector[2] == 75) { - cdr.SetSector[2] = 0; - cdr.SetSector[1]++; - if (cdr.SetSector[1] == 60) { - cdr.SetSector[1] = 0; - cdr.SetSector[0]++; - } - } + + if (cdr.SetSector[2] == 75) { + cdr.SetSector[2] = 0; + cdr.SetSector[1]++; + if (cdr.SetSector[1] == 60) { + cdr.SetSector[1] = 0; + cdr.SetSector[0]++; + } + } - cdr.Readed = 0; + cdr.Readed = 0; if ((cdr.Transfer[4+2] & 0x80) && (cdr.Mode & 0x2)) { // EOF -#ifdef CDR_LOG CDR_LOG("AutoPausing Read\n"); -#endif -// AddIrqQueue(AUTOPAUSE, 0x800); AddIrqQueue(CdlPause, 0x800); } else { @@ -665,18 +577,20 @@ cdrRead0: */ u8 cdrRead0(void) { - if (cdr.ResultReady) cdr.Ctrl|= 0x20; - else cdr.Ctrl&=~0x20; + if (cdr.ResultReady) + cdr.Ctrl |= 0x20; + else + cdr.Ctrl &= ~0x20; - if (cdr.OCUP) cdr.Ctrl|= 0x40; - else cdr.Ctrl&=~0x40; + if (cdr.OCUP) + cdr.Ctrl |= 0x40; + else + cdr.Ctrl &= ~0x40; - // what means the 0x10 and the 0x08 bits? i only saw it used by the bios - cdr.Ctrl|=0x18; + // what means the 0x10 and the 0x08 bits? i only saw it used by the bios + cdr.Ctrl|=0x18; -#ifdef CDR_LOG CDR_LOG("CD0 Read: %x\n", cdr.Ctrl); -#endif return psxHu8(0x1800) = cdr.Ctrl; } @@ -686,12 +600,11 @@ cdrWrite0: */ void cdrWrite0(u8 rt) { -#ifdef CDR_LOG CDR_LOG("CD0 write: %x\n", rt); -#endif + cdr.Ctrl = rt | (cdr.Ctrl & ~0x3); - if (rt == 0) { + if (rt == 0) { cdr.ParamP = 0; cdr.ParamC = 0; cdr.ResultReady = 0; @@ -699,24 +612,22 @@ void cdrWrite0(u8 rt) { } u8 cdrRead1(void) { - if (cdr.ResultReady && cdr.Ctrl & 0x1) { + if (cdr.ResultReady && cdr.Ctrl & 0x1) { psxHu8(0x1801) = cdr.Result[cdr.ResultP++]; if (cdr.ResultP == cdr.ResultC) cdr.ResultReady = 0; - } else psxHu8(0x1801) = 0; -#ifdef CDR_LOG + } + else + psxHu8(0x1801) = 0; + CDR_LOG("CD1 Read: %x\n", psxHu8(0x1801)); -#endif return psxHu8(0x1801); } void cdrWrite1(u8 rt) { int i; -#ifdef CDR_LOG CDR_LOG("CD1 write: %x (%s)\n", rt, CmdName[rt]); -#endif -// psxHu8(0x1801) = rt; - cdr.Cmd = rt; + cdr.Cmd = rt; cdr.OCUP = 0; #ifdef CDRCMD_DEBUG @@ -730,211 +641,196 @@ void cdrWrite1(u8 rt) { if (cdr.Ctrl & 0x1) return; - switch(cdr.Cmd) { - case CdlSync: + switch(cdr.Cmd) { + case CdlSync: cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlNop: + case CdlNop: cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlSetloc: + case CdlSetloc: StopReading(); - for (i=0; i<3; i++) cdr.SetSector[i] = btoi(cdr.Param[i]); - cdr.SetSector[3] = 0; - if ((cdr.SetSector[0] | cdr.SetSector[1] | cdr.SetSector[2]) == 0) { + for (i=0; i<3; i++) cdr.SetSector[i] = btoi(cdr.Param[i]); + cdr.SetSector[3] = 0; + if ((cdr.SetSector[0] | cdr.SetSector[1] | cdr.SetSector[2]) == 0) { *(unsigned long *)cdr.SetSector = *(unsigned long *)cdr.SetSectorSeek; } cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlPlay: -/* if (!cdr.SetSector[0] & !cdr.SetSector[1] & !cdr.SetSector[2]) { - if (CDR_getTN(cdr.ResultTN) != -1) { - if (cdr.CurTrack > cdr.ResultTN[1]) cdr.CurTrack = cdr.ResultTN[1]; - if (CDR_getTD((u8)(cdr.CurTrack), cdr.ResultTD) != -1) { - int tmp = cdr.ResultTD[2]; - cdr.ResultTD[2] = cdr.ResultTD[0]; - cdr.ResultTD[0] = tmp; - if (!Config.Cdda) CDR_play(cdr.ResultTD); - } - } - } - else if (!Config.Cdda) CDR_play(cdr.SetSector); -*/ cdr.Play = 1; + case CdlPlay: + cdr.Play = 1; cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlForward: - if (cdr.CurTrack < 0xaa) cdr.CurTrack++; + case CdlForward: + if (cdr.CurTrack < 0xaa) cdr.CurTrack++; cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlBackward: - if (cdr.CurTrack > 1) cdr.CurTrack--; + case CdlBackward: + if (cdr.CurTrack > 1) cdr.CurTrack--; cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlReadN: + case CdlReadN: cdr.Irq = 0; StopReading(); cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; + cdr.Stat = NoIntr; StartReading(1); - break; + break; - case CdlStandby: + case CdlStandby: StopCdda(); StopReading(); cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlStop: + case CdlStop: StopCdda(); StopReading(); cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlPause: + case CdlPause: StopCdda(); StopReading(); cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x40000); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x40000); + break; case CdlReset: - case CdlInit: + case CdlInit: StopCdda(); StopReading(); cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlMute: - cdr.Muted = 0; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlDemute: - cdr.Muted = 1; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlSetfilter: - cdr.File = cdr.Param[0]; - cdr.Channel = cdr.Param[1]; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlSetmode: -#ifdef CDR_LOG - CDR_LOG("Setmode %x\n", cdr.Param[0]); -#endif - cdr.Mode = cdr.Param[0]; - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlGetmode: - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlGetlocL: - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; - - case CdlGetlocP: - cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; + cdr.Stat = NoIntr; AddIrqQueue(cdr.Cmd, 0x800); - break; + break; - case CdlGetTN: + case CdlMute: + cdr.Muted = 0; cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlGetTD: + case CdlDemute: + cdr.Muted = 1; cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlSeekL: - ((unsigned long *)cdr.SetSectorSeek)[0] = ((unsigned long *)cdr.SetSector)[0]; + case CdlSetfilter: + cdr.File = cdr.Param[0]; + cdr.Channel = cdr.Param[1]; cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlSeekP: - ((unsigned long *)cdr.SetSectorSeek)[0] = ((unsigned long *)cdr.SetSector)[0]; + case CdlSetmode: + CDR_LOG("Setmode %x\n", cdr.Param[0]); + + cdr.Mode = cdr.Param[0]; cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlTest: + case CdlGetmode: cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlID: + case CdlGetlocL: cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - case CdlReadS: + case CdlGetlocP: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlGetTN: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlGetTD: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlSeekL: + ((unsigned long *)cdr.SetSectorSeek)[0] = ((unsigned long *)cdr.SetSector)[0]; + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlSeekP: + ((unsigned long *)cdr.SetSectorSeek)[0] = ((unsigned long *)cdr.SetSector)[0]; + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlTest: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlID: + cdr.Ctrl|= 0x80; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; + + case CdlReadS: cdr.Irq = 0; StopReading(); cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; + cdr.Stat = NoIntr; StartReading(2); - break; + break; - case CdlReadToc: + case CdlReadToc: cdr.Ctrl|= 0x80; - cdr.Stat = NoIntr; - AddIrqQueue(cdr.Cmd, 0x800); - break; + cdr.Stat = NoIntr; + AddIrqQueue(cdr.Cmd, 0x800); + break; - default: -#ifdef CDR_LOG + default: CDR_LOG("Unknown Cmd: %x\n", cdr.Cmd); -#endif return; } if (cdr.Stat != NoIntr) psxHu32(0x1070)|=0x4; @@ -949,17 +845,14 @@ u8 cdrRead2(void) { ret = *cdr.pTransfer++; } -#ifdef CDR_LOG CDR_LOG("CD2 Read: %x\n", ret); -#endif return ret; } void cdrWrite2(u8 rt) { -#ifdef CDR_LOG CDR_LOG("CD2 write: %x\n", rt); -#endif - if (cdr.Ctrl & 0x1) { + + if (cdr.Ctrl & 0x1) { switch (rt) { case 0x07: cdr.ParamP = 0; @@ -972,38 +865,39 @@ void cdrWrite2(u8 rt) { cdr.Reg2 = rt; break; } - } else if (!(cdr.Ctrl & 0x1) && cdr.ParamP < 8) { - cdr.Param[cdr.ParamP++] = rt; - cdr.ParamC++; + } + else + if (!(cdr.Ctrl & 0x1) && cdr.ParamP < 8) { + cdr.Param[cdr.ParamP++] = rt; + cdr.ParamC++; + } } -} u8 cdrRead3(void) { if (cdr.Stat) { - if (cdr.Ctrl & 0x1) psxHu8(0x1803) = cdr.Stat | 0xE0; - else psxHu8(0x1803) = 0xff; + if (cdr.Ctrl & 0x1) + psxHu8(0x1803) = cdr.Stat | 0xE0; + else + psxHu8(0x1803) = 0xff; } else psxHu8(0x1803) = 0; -#ifdef CDR_LOG + CDR_LOG("CD3 Read: %x\n", psxHu8(0x1803)); -#endif return psxHu8(0x1803); } void cdrWrite3(u8 rt) { -#ifdef CDR_LOG CDR_LOG("CD3 write: %x\n", rt); -#endif - if (rt == 0x07 && cdr.Ctrl & 0x1) { + + if (rt == 0x07 && cdr.Ctrl & 0x1) { cdr.Stat = 0; if (cdr.Irq == 0xff) { cdr.Irq = 0; return; } if (cdr.Irq) { CDR_INT(cdr.eCycle); - }/* else if (cdr.Reading) { - CDREAD_INT((cdr.Mode & 0x80) ? (cdReadTime / 2) : cdReadTime); - }*/ + } return; } + if (rt == 0x80 && !(cdr.Ctrl & 0x1) && cdr.Readed == 0) { cdr.Readed = 1; cdr.pTransfer = cdr.Transfer; @@ -1019,17 +913,13 @@ void cdrWrite3(u8 rt) { void psxDma3(u32 madr, u32 bcr, u32 chcr) { u32 cdsize; -#ifdef CDR_LOG CDR_LOG("*** DMA 3 *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif switch (chcr) { case 0x11000000: case 0x11400100: if (cdr.Readed == 0) { -#ifdef CDR_LOG CDR_LOG("*** DMA 3 *** NOT READY\n"); -#endif return; } @@ -1043,17 +933,10 @@ void psxDma3(u32 madr, u32 bcr, u32 chcr) { break; case 0x41000200: //SysPrintf("unhandled cdrom dma3: madr: %x, bcr: %x, chcr %x\n", madr, bcr, chcr); - // size = 16 * 32 * 4 (one sector) -/* PSXMu8(madr+0) = 0x10; - PSXMu8(madr+1) = 0x00; - PSXMu8(madr+2) = 0x03; - PSXMu8(madr+3) = 0x00;*/ return; default: -#ifdef CDR_LOG CDR_LOG("Unknown cddma %lx\n", chcr); -#endif break; } HW_DMA3_CHCR &= ~0x01000000; diff --git a/pcsx2/CdRom.h b/pcsx2/CdRom.h index 36d9016493..15a066f0f6 100644 --- a/pcsx2/CdRom.h +++ b/pcsx2/CdRom.h @@ -75,6 +75,7 @@ cdrStruct cdr; s32 MSFtoLSN(u8 *Time); void LSNtoMSF(u8 *Time, s32 lsn); +void AddIrqQueue(u8 irq, unsigned long ecycle); void cdrReset(); void cdrInterrupt(); diff --git a/pcsx2/Linux/LnxMain.c b/pcsx2/Linux/LnxMain.c index 1d5ae7069e..f83a280880 100644 --- a/pcsx2/Linux/LnxMain.c +++ b/pcsx2/Linux/LnxMain.c @@ -417,8 +417,6 @@ int SysInit() { if(cpuInit() == -1 ) return -1; - - applychanges = FALSE; // Just in case while (LoadPlugins() == -1) { if (Pcsx2Configure() == FALSE) diff --git a/pcsx2/Misc.c b/pcsx2/Misc.c index 547a981cb7..a35172029b 100644 --- a/pcsx2/Misc.c +++ b/pcsx2/Misc.c @@ -125,7 +125,8 @@ static struct { }; void GetRPCVersion(char *ioprp, char *rpcver){ - char *p=ioprp; int i; + char *p=ioprp; + int i; struct TocEntry te; if (p && (CDVD_findfile(p+strlen("cdromN:"), &te) != -1)){ @@ -135,6 +136,7 @@ void GetRPCVersion(char *ioprp, char *rpcver){ if (ioprps[i].size>0) p=ioprps[i].name; } + // fixme - Is p really supposed to be set in the middle of an if statement? if (p && (p=strstr(p, "IOPRP")+strlen("IOPRP"))){ for (i=0;(i<4) && p && (*p>='0') && (*p<='9');i++, p++) rpcver[i]=*p; for ( ; i<4 ;i++ ) rpcver[i]='0'; @@ -260,26 +262,24 @@ int IsBIOS(char *filename, char *description){ // LOAD STUFF +// fixme - Is there any reason why we shouldn't delete this define, and replace the array lengths +// with the actual numbers? #define ISODCL(from, to) (to - from + 1) struct iso_directory_record { - char length [ISODCL (1, 1)]; /* 711 */ - char ext_attr_length [ISODCL (2, 2)]; /* 711 */ - char extent [ISODCL (3, 10)]; /* 733 */ - char size [ISODCL (11, 18)]; /* 733 */ - char date [ISODCL (19, 25)]; /* 7 by 711 */ - char flags [ISODCL (26, 26)]; - char file_unit_size [ISODCL (27, 27)]; /* 711 */ - char interleave [ISODCL (28, 28)]; /* 711 */ - char volume_sequence_number [ISODCL (29, 32)]; /* 723 */ - unsigned char name_len [ISODCL (33, 33)]; /* 711 */ + char length [ISODCL (1, 1)]; /* length[1]; 711 */ + char ext_attr_length [ISODCL (2, 2)]; /* ext_attr_length[1]; 711 */ + char extent [ISODCL (3, 10)]; /* extent[8]; 733 */ + char size [ISODCL (11, 18)]; /* size[8]; 733 */ + char date [ISODCL (19, 25)]; /* date[7]; 7 by 711 */ + char flags [ISODCL (26, 26)]; /* flags[1]; */ + char file_unit_size [ISODCL (27, 27)]; /* file_unit_size[1]; 711 */ + char interleave [ISODCL (28, 28)]; /* interleave[1]; 711 */ + char volume_sequence_number [ISODCL (29, 32)]; /* volume_sequence_number[3]; 723 */ + unsigned char name_len [ISODCL (33, 33)]; /* name_len[1]; 711 */ char name [1]; }; -#define READTRACK(lsn) \ - if (CDVDreadTrack(lsn, CDVD_MODE_2352) == -1) return -1; \ - buf = CDVDgetBuffer(); if (buf == NULL) return -1; - int LoadCdrom() { return 0; } @@ -287,7 +287,12 @@ int LoadCdrom() { int CheckCdrom() { u8 *buf; - READTRACK(16); + if (CDVDreadTrack(16, CDVD_MODE_2352) == -1) + return -1; + buf = CDVDgetBuffer(); + if (buf == NULL) + return -1; + strncpy(CdromId, (char*)buf+52, 10); return 0; @@ -314,11 +319,11 @@ int GetPS2ElfName(char *name){ CDVDFS_close(f); buffer[tocEntry.fileSize]='\0'; - -// SysPrintf( -// "---------------------SYSTEM.CNF---------------------\n" -// "%s" -// "----------------------------------------------------\n", buffer); +// SysPrintf( +// "---------------------SYSTEM.CNF---------------------\n" +// "%s" +// "----------------------------------------------------\n", buffer); + pos=strstr(buffer, "BOOT2"); if (pos==NULL){ pos=strstr(buffer, "BOOT"); @@ -336,14 +341,12 @@ int GetPS2ElfName(char *name){ return 0; sscanf(pos, "%s", name); - //SysPrintf("ELF name: '%s'\n", name); if (strncmp("cdrom0:\\", name, 8) == 0) { strncpy(CdromId, name+8, 11); CdromId[11] = 0; } - -// inifile_read(CdromId); - + + // inifile_read(CdromId); fp = fopen("System.map", "r"); if (fp) { u32 addr; @@ -370,73 +373,6 @@ int GetPS2ElfName(char *name){ return 2; } -/*#define PSX_EXE 1 -#define CPE_EXE 2 -#define COFF_EXE 3 -#define INVALID_EXE 4 - -static int PSXGetFileType(FILE *f) { - unsigned long current; - unsigned long mybuf[2048]; - EXE_HEADER *exe_hdr; - FILHDR *coff_hdr; - - current = ftell(f); - fseek(f,0L,SEEK_SET); - fread(mybuf,2048,1,f); - fseek(f,current,SEEK_SET); - - exe_hdr = (EXE_HEADER *)mybuf; - if (memcmp(exe_hdr->id,"PS-X EXE",8)==0) - return PSX_EXE; - - if (mybuf[0]=='C' && mybuf[1]=='P' && mybuf[2]=='E') - return CPE_EXE; - - coff_hdr = (FILHDR *)mybuf; - if (coff_hdr->f_magic == 0x0162) - return COFF_EXE; - - return INVALID_EXE; -} - -int Load(char *ExePath) { - FILE *tmpFile; - EXE_HEADER tmpHead; - int type; - - strcpy(CdromId, "SLUS_999.99"); - - tmpFile = fopen(ExePath,"rb"); - if (tmpFile == NULL) { SysMessage("Error opening file: %s", ExePath); return 0; } - - type = PSXGetFileType(tmpFile); - switch (type) { - case PSX_EXE: - fread(&tmpHead,sizeof(EXE_HEADER),1,tmpFile); - fseek(tmpFile, 0x800, SEEK_SET); - fread((void *)PSXM(tmpHead.t_addr), tmpHead.t_size,1,tmpFile); - fclose(tmpFile); - psxRegs.pc = tmpHead.pc0; - psxRegs.GPR.n.gp = tmpHead.gp0; - psxRegs.GPR.n.sp = tmpHead.s_addr; - if (psxRegs.GPR.n.sp == 0) psxRegs.GPR.n.sp = 0x801fff00; - break; - case CPE_EXE: - SysMessage("Pcsx found that you wanna use a CPE file. CPE files not support yet"); - break; - case COFF_EXE: - SysMessage("Pcsx found that you wanna use a COFF file.COFF files not support yet"); - break; - case INVALID_EXE: - SysMessage("This file is not a psx file"); - break; - } - return 1; -} -*/ - - FILE *emuLog; #ifdef PCSX2_DEVBUILD @@ -617,7 +553,6 @@ int LoadState(const char *file) { #ifdef _DEBUG s_vucount = 0; - //dumplog |= 2; #endif SysPrintf("LoadState: %s\n", file); @@ -1083,6 +1018,7 @@ void injectIRX(char *filename){ rd[iBLANK].fileSize-=DIRENTRY_SIZE+DIRENTRY_SIZE; p=(char*)PS2MEM_ROM;for (i=0; iq){*((u64*)p)=*((u64*)p-4);*((u64*)p+1)=*((u64*)p-3);p-=DIRENTRY_SIZE;} *((u64*)p)=*((u64*)p+1)=0;p-=DIRENTRY_SIZE;rd[iIOPBTCONF].fileSize+=DIRENTRY_SIZE; @@ -1121,64 +1057,3 @@ void injectIRX(char *filename){ rd[i].extInfoSize=0; } -// failed inline calls, this is because of inline hell and gcc syntax -#ifndef _WIN32 - -/*void InterlockedExchangePointer(PVOID volatile* Target, void* Value) -{ -#ifdef __x86_64__ - __asm__ __volatile__(".intel_syntax\n" - "lock xchg [%0], %%rax\n" - ".att_syntax\n" : : "r"(Target), "a"(Value) : "memory" ); -#else - __asm__ __volatile__(".intel_syntax\n" - "lock xchg [%0], %%eax\n" - ".att_syntax\n" : : "r"(Target), "a"(Value) : "memory" ); -#endif -} - -long InterlockedExchange(long volatile* Target, long Value) -{ - __asm__ __volatile__(".intel_syntax\n" - "lock xchg [%0], %%eax\n" - ".att_syntax\n" : : "r"(Target), "a"(Value) : "memory" ); - // fixme - This is supposed to return a long -} - -long InterlockedExchangeAdd(long volatile* Addend, long Value) -{ - __asm__ __volatile__(".intel_syntax\n" - "lock xadd [%0], %%eax\n" - ".att_syntax\n" : : "r"(Addend), "a"(Value) : "memory" ); - // fixme - This is supposed to return a long -}*/ - -/*u32 timeGetTime() -{ - struct timeb t; - ftime(&t); - return (u32)(t.time*1000+t.millitm); -} - -void* pcsx2_aligned_malloc(size_t size, size_t align) -{ - assert( align < 0x10000 ); - char* p = (char*)malloc(size+align); - int off = 2+align - ((int)(uptr)(p+2) % align); - - p += off; - *(u16*)(p-2) = off; - - return p; -} - -void pcsx2_aligned_free(void* pmem) -{ - if( pmem != NULL ) { - char* p = (char*)pmem; - free(p - (int)*(u16*)(p-2)); - } -}*/ - -#endif - diff --git a/pcsx2/PsxDma.c b/pcsx2/PsxDma.c index b6a6fe51e8..da718d7e36 100644 --- a/pcsx2/PsxDma.c +++ b/pcsx2/PsxDma.c @@ -24,24 +24,22 @@ // Dma3 in CdRom.c // Dma8 in PsxSpd.c // Dma11/12 in PsxSio2.c -//static int spudmaenable[2]; + int iopsifbusy[2] = { 0, 0 }; void psxDma4(u32 madr, u32 bcr, u32 chcr) { // SPU int size; - - /*if(chcr & 0x400) SysPrintf("SPU 2 DMA 4 linked list chain mode! chcr = %x madr = %x bcr = %x\n", chcr, madr, bcr); - if(chcr & 0x40000000) SysPrintf("SPU 2 DMA 4 Unusual bit set on 'to' direction chcr = %x madr = %x bcr = %x\n", chcr, madr, bcr); - if((chcr & 0x1) == 0) SysPrintf("SPU 2 DMA 4 loading from spu2 memory chcr = %x madr = %x bcr = %x\n", chcr, madr, bcr); -*/ + /*if (chcr & 0x400) SysPrintf("SPU 2 DMA 4 linked list chain mode! chcr = %x madr = %x bcr = %x\n", chcr, madr, bcr); + if (chcr & 0x40000000) SysPrintf("SPU 2 DMA 4 Unusual bit set on 'to' direction chcr = %x madr = %x bcr = %x\n", chcr, madr, bcr); + if ((chcr & 0x1) == 0) SysPrintf("SPU 2 DMA 4 loading from spu2 memory chcr = %x madr = %x bcr = %x\n", chcr, madr, bcr);*/ if(SPU2async) { - //if((psxRegs.cycle - psxCounters[6].sCycleT) >= psxCounters[6].CycleT){ - SPU2async(psxRegs.cycle - psxCounters[6].sCycleT); + SPU2async(psxRegs.cycle - psxCounters[6].sCycleT); + //SysPrintf("cycles sent to SPU2 %x\n", psxRegs.cycle - psxCounters[6].sCycleT); psxCounters[6].sCycleT = psxRegs.cycle; psxCounters[6].CycleT = ((bcr >> 16) * (bcr & 0xFFFF)) * 3; - //} + psxNextCounter -= (psxRegs.cycle-psxNextsCounter); psxNextsCounter = psxRegs.cycle; if(psxCounters[6].CycleT < psxNextCounter) psxNextCounter = psxCounters[6].CycleT; @@ -50,18 +48,16 @@ void psxDma4(u32 madr, u32 bcr, u32 chcr) { // SPU switch (chcr) { case 0x01000201: //cpu to spu transfer -#ifdef PSXDMA_LOG PSXDMA_LOG("*** DMA 4 - SPU mem2spu *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif //SysPrintf("DMA4 write blocks %x, size per block %x\n", (bcr >> 16), (bcr & 0xFFFF)); + size = (bcr >> 16) * (bcr & 0xFFFF); // Number of blocks to transfer SPU2writeDMA4Mem((u16 *)PSXM(madr), size*2); break; case 0x01000200: //spu to cpu transfer -#ifdef PSXDMA_LOG PSXDMA_LOG("*** DMA 4 - SPU spu2mem *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif //SysPrintf("DMA4 read blocks %x, size per block %x\n", (bcr >> 16), (bcr & 0xFFFF)); + size = (bcr >> 16) * (bcr & 0xFFFF); // Number of blocks to transfer SPU2readDMA4Mem((u16 *)PSXM(madr), size*2); psxCpu->Clear(HW_DMA4_MADR, size); @@ -71,8 +67,6 @@ void psxDma4(u32 madr, u32 bcr, u32 chcr) { // SPU SysPrintf("*** DMA 4 - SPU unknown *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); break; } - - //spudmaenable[0] = size; } int psxDma4Interrupt() { @@ -90,9 +84,7 @@ void psxDma2(u32 madr, u32 bcr, u32 chcr) { // GPU void psxDma6(u32 madr, u32 bcr, u32 chcr) { u32 *mem = (u32 *)PSXM(madr); -#ifdef PSXDMA_LOG PSXDMA_LOG("*** DMA 6 - OT *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif if (chcr == 0x11000002) { while (bcr--) { @@ -102,9 +94,7 @@ void psxDma6(u32 madr, u32 bcr, u32 chcr) { mem++; *mem = 0xffffff; } else { // Unknown option -#ifdef PSXDMA_LOG PSXDMA_LOG("*** DMA 6 - OT unknown *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif } HW_DMA6_CHCR &= ~0x01000000; psxDmaInterrupt(6); @@ -115,36 +105,31 @@ void psxDma7(u32 madr, u32 bcr, u32 chcr) { if(SPU2async) { - //if((psxRegs.cycle - psxCounters[6].sCycleT) >= psxCounters[6].CycleT){ SPU2async(psxRegs.cycle - psxCounters[6].sCycleT); //SysPrintf("cycles sent to SPU2 %x\n", psxRegs.cycle - psxCounters[6].sCycleT); + psxCounters[6].sCycleT = psxRegs.cycle; psxCounters[6].CycleT = ((bcr >> 16) * (bcr & 0xFFFF)) * 3; - //} + psxNextCounter -= (psxRegs.cycle-psxNextsCounter); psxNextsCounter = psxRegs.cycle; if(psxCounters[6].CycleT < psxNextCounter) psxNextCounter = psxCounters[6].CycleT; } - switch (chcr) { case 0x01000201: //cpu to spu2 transfer -#ifdef PSXDMA_LOG PSXDMA_LOG("*** DMA 7 - SPU2 mem2spu *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif //SysPrintf("DMA7 write blocks %x, size per block %x\n", (bcr >> 16), (bcr & 0xFFFF)); + size = (bcr >> 16) * (bcr & 0xFFFF); // Number of blocks to transfer - SPU2writeDMA7Mem((u16 *)PSXM(madr), size*2); break; case 0x01000200: //spu2 to cpu transfer -#ifdef PSXDMA_LOG PSXDMA_LOG("*** DMA 7 - SPU2 spu2mem *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif - //SysPrintf("DMA4 read blocks %x, size per block %x\n", (bcr >> 16), (bcr & 0xFFFF)); + //SysPrintf("DMA7 read blocks %x, size per block %x\n", (bcr >> 16), (bcr & 0xFFFF)); + size = (bcr >> 16) * (bcr & 0xFFFF); // Number of blocks to transfer - SPU2readDMA7Mem((u16 *)PSXM(madr), size*2); psxCpu->Clear(HW_DMA7_MADR, size); break; @@ -152,11 +137,9 @@ void psxDma7(u32 madr, u32 bcr, u32 chcr) { SysPrintf("*** DMA 7 - SPU unknown *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); break; } - } int psxDma7Interrupt() { - HW_DMA7_CHCR &= ~0x01000000; psxDmaInterrupt2(0); return 1; @@ -164,15 +147,11 @@ int psxDma7Interrupt() { } extern int eesifbusy[2]; void psxDma9(u32 madr, u32 bcr, u32 chcr) { - - //DMACh *dma = (DMACh*)&PS2MEM_HW[0xc000]; //Not used - -#ifdef SIF_LOG SIF_LOG("IOP: dmaSIF0 chcr = %lx, madr = %lx, bcr = %lx, tadr = %lx\n", chcr, madr, bcr, HW_DMA9_TADR); -#endif iopsifbusy[0] = 1; psHu32(0x1000F240) |= 0x2000; + if (eesifbusy[0] == 1 && iopsifbusy[0] == 1) { SIF0Dma(); psHu32(0x1000F240) &= ~0x20; @@ -181,14 +160,11 @@ void psxDma9(u32 madr, u32 bcr, u32 chcr) { } void psxDma10(u32 madr, u32 bcr, u32 chcr) { - //DMACh *dma = (DMACh*)&PS2MEM_HW[0xc400]; //Not used - -#ifdef SIF_LOG SIF_LOG("IOP: dmaSIF1 chcr = %lx, madr = %lx, bcr = %lx\n", chcr, madr, bcr); -#endif iopsifbusy[1] = 1; psHu32(0x1000F240) |= 0x4000; + if (eesifbusy[1] == 1 && iopsifbusy[1] == 1) { FreezeXMMRegs(1); SIF1Dma(); @@ -204,26 +180,21 @@ void psxDma8(u32 madr, u32 bcr, u32 chcr) { switch (chcr & 0x01000201) { case 0x01000201: //cpu to dev9 transfer -#ifdef PSXDMA_LOG PSXDMA_LOG("*** DMA 8 - DEV9 mem2dev9 *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif - size = (bcr >> 16) * (bcr & 0xFFFF); // Number of blocks to transfer + size = (bcr >> 16) * (bcr & 0xFFFF); // Number of blocks to transfer DEV9writeDMA8Mem((u32*)PSXM(madr), size*8); break; case 0x01000200: //dev9 to cpu transfer -#ifdef PSXDMA_LOG PSXDMA_LOG("*** DMA 8 - DEV9 dev9mem *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); -#endif + size = (bcr >> 16) * (bcr & 0xFFFF); // Number of blocks to transfer DEV9readDMA8Mem((u32*)PSXM(madr), size*8); break; -#ifdef PSXDMA_LOG default: PSXDMA_LOG("*** DMA 8 - DEV9 unknown *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); break; -#endif } HW_DMA8_CHCR &= ~0x01000000; psxDmaInterrupt2(1); @@ -231,11 +202,13 @@ void psxDma8(u32 madr, u32 bcr, u32 chcr) { void dev9Interrupt() { if (dev9Handler == NULL) goto irq; + if (dev9Handler() != 1) { psxRegs.interrupt&= ~(1 << 20); return; } -irq: + + irq: psxHu32(0x1070)|= 1<<13; //SBUS hwIntcIrq(INTC_SBUS); @@ -248,11 +221,13 @@ void dev9Irq(int cycles) { void usbInterrupt() { if (usbHandler == NULL) goto irq; + if (usbHandler() != 1) { psxRegs.interrupt&= ~(1 << 21); return; } -irq: + + irq: psxHu32(0x1070)|= 1<<22; //SBUS hwIntcIrq(INTC_SBUS); diff --git a/pcsx2/Sif.c b/pcsx2/Sif.c index d758ca276f..1723d8d5c0 100644 --- a/pcsx2/Sif.c +++ b/pcsx2/Sif.c @@ -30,8 +30,6 @@ #define FIFO_SIF0_W 128 #define FIFO_SIF1_W 128 -int eesifbusy[2] = { 0, 0 }; -extern int iopsifbusy[2]; typedef struct { u32 fifoData[FIFO_SIF0_W]; int fifoReadPos; @@ -58,14 +56,14 @@ typedef struct { _sif0 sif0; _sif1 sif1; -int sifInit() { +int wP0, wP1; +int eesifbusy[2] = { 0, 0 }; +extern int iopsifbusy[2]; + +void sifInit() { memset(&sif0, 0, sizeof(sif0)); memset(&sif1, 0, sizeof(sif1)); - - return 0; } -int wP0; -int wP1; _inline void SIF0write(u32 *from, int words) { /*if(FIFO_SIF0_W < (words+sif0.fifoWritePos)) {*/ @@ -84,15 +82,7 @@ _inline void SIF0write(u32 *from, int words) }*/ sif0.fifoSize += words; -#ifdef SIF_LOG SIF_LOG(" SIF0 + %d = %d (pos=%d)\n", words, sif0.fifoSize, sif0.fifoWritePos); -// { -// int i; -// for(i = 0; i < words; i += 4) { -// SIF_LOG(" EE SIF write data: %x %x %x %x\n", from[i], from[i+1], from[i+2], from[i+3]); -// } -// } -#endif /* if (sif0.fifoSize == FIFO_SIF0_W) { Cpu->ExecuteBlock(); @@ -118,9 +108,7 @@ _inline void SIF0read(u32 *to, int words) }*/ sif0.fifoSize -= words; -#ifdef SIF_LOG SIF_LOG(" SIF0 - %d = %d (pos=%d)\n", words, sif0.fifoSize, sif0.fifoReadPos); -#endif } _inline void SIF1write(u32 *from, int words) @@ -142,9 +130,7 @@ _inline void SIF1write(u32 *from, int words) }*/ sif1.fifoSize += words; -#ifdef SIF_LOG SIF_LOG(" SIF1 + %d = %d (pos=%d)\n", words, sif1.fifoSize, sif1.fifoWritePos); -#endif /* if (sif1.fifoSize == FIFO_SIF1_W) { psxCpu->ExecuteBlock(); @@ -170,21 +156,17 @@ _inline void SIF1read(u32 *to, int words) }*/ sif1.fifoSize -= words; -#ifdef SIF_LOG SIF_LOG(" SIF1 - %d = %d (pos=%d)\n", words, sif1.fifoSize, sif1.fifoReadPos); -#endif } _inline void SIF0Dma() { u32 *ptag; - int notDone; + int notDone = 1; int cycles = 0, psxCycles = 0; -#ifdef SIF_LOG SIF_LOG("SIF0 DMA start...\n"); -#endif -notDone = 1; + do { @@ -200,9 +182,7 @@ notDone = 1; // Note.. add normal mode here if (sif0.sifData.data & 0xC0000000) // If NORMAL mode or end of CHAIN, or interrupt then stop DMA { -#ifdef SIF_LOG SIF_LOG(" IOP SIF Stopped\n"); -#endif // Stop & signal interrupts on IOP //HW_DMA9_CHCR &= ~0x01000000; //reset TR flag @@ -230,31 +210,18 @@ notDone = 1; sif0.counter = sif0.sifData.words & 0xFFFFFF; notDone = 1; -#ifdef SIF_LOG SIF_LOG(" SIF0 Tag: madr=%lx, tadr=%lx, counter=%lx (%08X_%08X)\n", HW_DMA9_MADR, HW_DMA9_TADR, sif0.counter, sif0.sifData.words, sif0.sifData.data); -#endif if(sif0.sifData.data & 0x40000000) - { -#ifdef SIF_LOG SIF_LOG(" END\n"); -#endif - } else - { -#ifdef SIF_LOG SIF_LOG(" CNT %08X, %08X\n", sif0.sifData.data, sif0.sifData.words); -#endif - } } } else // There's some data ready to transfer into the fifo.. { int wTransfer = min(sif0.counter, FIFO_SIF0_W-sif0.fifoSize); // HW_DMA9_BCR >> 16; - -#ifdef SIF_LOG SIF_LOG("+++++++++++ %lX of %lX\n", wTransfer, sif0.counter /*(HW_DMA9_BCR >> 16)*/ ); -#endif SIF0write((u32*)PSXM(HW_DMA9_MADR), wTransfer); HW_DMA9_MADR += wTransfer << 2; @@ -279,9 +246,7 @@ notDone = 1; int readSize = min(size, (sif0.fifoSize>>2)); //SIF_LOG(" EE SIF doing transfer %04Xqw to %08X\n", readSize, sif0dma->madr); -#ifdef SIF_LOG SIF_LOG("----------- %lX of %lX\n", readSize << 2, size << 2 ); -#endif _dmaGetAddr(sif0dma, ptag, sif0dma->madr, 5); @@ -308,9 +273,8 @@ notDone = 1; if((sif0dma->chcr & 0x80000080) == 0x80000080) // Stop on tag IRQ { // Tag interrupt -#ifdef SIF_LOG SIF_LOG(" EE SIF interrupt\n"); -#endif + //sif0dma->chcr &= ~0x100; eesifbusy[0] = 0; INT(5, cycles*BIAS); @@ -320,9 +284,8 @@ notDone = 1; else if(sif0.end) // Stop on tag END { // End tag. -#ifdef SIF_LOG SIF_LOG(" EE SIF end\n"); -#endif + //sif0dma->chcr &= ~0x100; //hwDmacIrq(5); eesifbusy[0] = 0; @@ -333,9 +296,8 @@ notDone = 1; { static PCSX2_ALIGNED16(u32 tag[4]); SIF0read((u32*)&tag[0], 4); // Tag -#ifdef SIF_LOG - SIF_LOG(" EE SIF read tag: %x %x %x %x\n", tag[0], tag[1], tag[2], tag[3]); -#endif + SIF_LOG(" EE SIF read tag: %x %x %x %x\n", tag[0], tag[1], tag[2], tag[3]); + sif0dma->qwc = (u16)tag[0]; sif0dma->madr = tag[1]; sif0dma->chcr = (sif0dma->chcr & 0xffff) | (tag[0] & 0xffff0000); @@ -343,9 +305,8 @@ notDone = 1; /*if ((sif0dma->chcr & 0x80) && (tag[0] >> 31)) { SysPrintf("SIF0 TIE\n"); }*/ -#ifdef SIF_LOG SIF_LOG(" EE SIF dest chain tag madr:%08X qwc:%04X id:%X irq:%d(%08X_%08X)\n", sif0dma->madr, sif0dma->qwc, (tag[0]>>28)&3, (tag[0]>>31)&1, tag[1], tag[0]); -#endif + if ((psHu32(DMAC_CTRL) & 0x30) != 0 && ((tag[0]>>28)&3) == 0) psHu32(DMAC_STADR) = sif0dma->madr + (sif0dma->qwc * 16); notDone = 1; @@ -581,11 +542,8 @@ _inline void EEsif1Interrupt() { } _inline void dmaSIF0() { - -#ifdef SIF_LOG SIF_LOG("EE: dmaSIF0 chcr = %lx, madr = %lx, qwc = %lx, tadr = %lx\n", sif0dma->chcr, sif0dma->madr, sif0dma->qwc, sif0dma->tadr); -#endif if (sif0.fifoReadPos != sif0.fifoWritePos) { SysPrintf("warning, sif0.fifoReadPos != sif0.fifoWritePos\n"); @@ -608,11 +566,8 @@ _inline void dmaSIF0() { } _inline void dmaSIF1() { - -#ifdef SIF_LOG SIF_LOG("EE: dmaSIF1 chcr = %lx, madr = %lx, qwc = %lx, tadr = %lx\n", sif1dma->chcr, sif1dma->madr, sif1dma->qwc, sif1dma->tadr); -#endif if (sif1.fifoReadPos != sif1.fifoWritePos) { SysPrintf("warning, sif1.fifoReadPos != sif1.fifoWritePos\n"); @@ -637,11 +592,8 @@ _inline void dmaSIF1() { } _inline void dmaSIF2() { - -#ifdef SIF_LOG SIF_LOG("dmaSIF2 chcr = %lx, madr = %lx, qwc = %lx\n", sif2dma->chcr, sif2dma->madr, sif2dma->qwc); -#endif sif2dma->chcr&= ~0x100; hwDmacIrq(7); diff --git a/pcsx2/Sif.h b/pcsx2/Sif.h index b6918e2825..d6308e67b0 100644 --- a/pcsx2/Sif.h +++ b/pcsx2/Sif.h @@ -34,7 +34,7 @@ DMACh *sif0ch; DMACh *sif1ch; DMACh *sif2ch; -extern int sifInit(); +extern void sifInit(); extern void SIF0Dma(); extern void SIF1Dma(); extern void dmaSIF0();