Fixed a simple bug from one of arcum42's cleanups.

Cleaned up multitap code a little in both PCSX2 and LilyPad.

Some extra safety checks in LilyPad when loading state.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@906 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
mattmenke 2009-04-04 11:21:35 +00:00
parent 7744205a58
commit a6d330448c
5 changed files with 40 additions and 54 deletions

View File

@ -50,8 +50,8 @@ __forceinline void SIO_INT()
// wants to add support for using the extra memcard slots.
static bool IsMtapPresent( uint port ) {
switch(port) {
case 1: return 0 != PAD1queryMtap(port);
case 2: return 0 != PAD2queryMtap(port);
case 0: return 0 != PAD1queryMtap(port+1);
case 1: return 0 != PAD2queryMtap(port+1);
}
return 0;
}
@ -460,7 +460,7 @@ void SIO_CommandWrite(u8 value,int way) {
sio.bufcount = 6; // No idea why this is 6, saved from old code.
break;
}
// Commented out values are from original code. Break multitap in bios..
// Commented out values are from original code. Break multitap in bios.
sio.buf[sio.bufcount-1]=0;//'+';
sio.buf[sio.bufcount]=0;//'Z';
return;
@ -475,17 +475,11 @@ void SIO_CommandWrite(u8 value,int way) {
sio.packetsize++;
sio.parp++;
sio.mtapst = 2;
switch (sio.CtrlReg&0x2002) {
case 0x0002:
// Not sure if these checks are absolutely needed, but
// prefer to be safe.
if (IsMtapPresent(1))
sio.activePadSlot[0] = value;
break;
case 0x2002:
if (IsMtapPresent(2))
sio.activePadSlot[1] = value;
break;
if (sio.CtrlReg & 2)
{
int port = sio.GetMultitapPort();
if (IsMtapPresent(port))
sio.activePadSlot[port] = value;
}
SIO_INT();
return;
@ -494,17 +488,11 @@ void SIO_CommandWrite(u8 value,int way) {
sio.packetsize++;
sio.parp++;
sio.mtapst = 2;
switch (sio.CtrlReg&0x2002) {
case 0x0002:
// Not sure if these checks are absolutely needed, but
// prefer to be safe.
if (IsMtapPresent(1))
sio.activeMemcardSlot[0] = value;
break;
case 0x2002:
if (IsMtapPresent(2))
sio.activeMemcardSlot[1] = value;
break;
if (sio.CtrlReg & 2)
{
int port = sio.GetMultitapPort();
if (IsMtapPresent(port))
sio.activeMemcardSlot[port] = value;
}
SIO_INT();
return;
@ -561,33 +549,22 @@ void InitializeSIO(u8 value)
sio.mtapst = 1;
sio.count = 0;
sio2.packet.recvVal1 = 0x1D100; // Mtap is not connected :(
switch (sio.CtrlReg&0x2002) {
case 0x0002:
if (!IsMtapPresent(1)) {
// If "unplug" multitap, set slots to 0.
sio.activePadSlot[0] = 0;
sio.activeMemcardSlot[0] = 0;
break;
}
if (sio.CtrlReg & 2) // No idea if this test is needed. Pads use it, memcards don't.
{
int port = sio.GetMultitapPort();
if (!IsMtapPresent(port))
{
sio.activePadSlot[port] = 0;
sio.activeMemcardSlot[port] = 0;
}
else
{
sio.bufcount = 3;
sio.buf[0] = 0xFF;
sio.buf[1] = 0x80; // Have no idea if this is correct. From PSX mtap.
sio.buf[2] = 0x5A;
sio2.packet.recvVal1 = 0x1100; // Mtap is connected :)
break;
case 0x2002:
if (!IsMtapPresent(2)) {
// If "unplug" multitap, set slots to 0.
sio.activePadSlot[1] = 0;
sio.activeMemcardSlot[1] = 0;
break;
}
sio.bufcount = 3;
sio.buf[0] = 0xFF;
sio.buf[1] = 0x80; // Have no idea if this is correct. From PSX mtap.
sio.buf[2] = 0x5A;
sio2.packet.recvVal1 = 0x1100; // Mtap is connected :)
break;
}
}
SIO_INT();
return;

View File

@ -70,6 +70,11 @@ struct _sio {
{
return (CtrlReg&0x2000) >> 13;
}
int GetMultitapPort() const
{
return (CtrlReg&0x2000) >> 13;
}
};
extern _sio sio;

View File

@ -80,8 +80,9 @@ public:
int idx = LastIndex(startpc);
// fixme: I changed the parenthesis to be unambiguous, but this needs to be checked to see if ((x or y or z) and w)
// is correct, or ((x or y) or (z and w)), or some other variation. --arcum42
if (((idx == -1) || (startpc < blocks[idx].startpc) ||
(blocks[idx].size)) && (startpc >= blocks[idx].startpc + blocks[idx].size * 4))
// Mixing &&'s and ||'s is not actually ambiguous; &&'s take precedence. Reverted to old behavior -- ChickenLiver.
if ((idx == -1) || (startpc < blocks[idx].startpc) ||
((blocks[idx].size) && (startpc >= blocks[idx].startpc + blocks[idx].size * 4)))
return -1;
else
return idx;

View File

@ -1504,11 +1504,11 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM l
// Returns 0 if pad doesn't exist due to mtap settings, as a convenience.
int GetPadString(wchar_t *string, unsigned int port, unsigned int slot) {
if (!slot) {
if (!slot && !config.multitap[port]) {
wsprintfW(string, L"Pad %i", port+1);
}
else {
wsprintfW(string, L"Pad %i-%i", port+1, slot+1);
wsprintfW(string, L"Pad %i%c", port+1, 'A'+slot);
if (!config.multitap[port]) return 0;
}
return 1;

View File

@ -1318,7 +1318,7 @@ s32 CALLBACK PADfreeze(int mode, freezeData *data) {
strcmp(pdata.format, "PadMode")) return 0;
unsigned int port = pdata.port;
if (port >= 2) return 0;
if (pdata.query.port == port) {
if (pdata.query.port == port && pdata.query.slot < 4) {
query = pdata.query;
}
for (int slot=0; slot<4; slot++) {
@ -1330,7 +1330,8 @@ s32 CALLBACK PADfreeze(int mode, freezeData *data) {
// Note sure if the cast is strictly necessary, but feel safest with it there...
*(PadFreezeData*)&pads[port][slot] = pdata.padData[slot];
}
slots[port] = pdata.slot;
if (pdata.slot < 4)
slots[port] = pdata.slot;
}
else if (mode == FREEZE_SAVE) {
if (data->size != sizeof(PadPluginFreezeData)) return 0;
@ -1403,7 +1404,9 @@ s32 CALLBACK PADqueryMtap(u8 port) {
s32 CALLBACK PADsetSlot(u8 port, u8 slot) {
port--;
slot--;
if (port > 1 || slot > 3) return 0;
if (port > 1 || slot > 3) {
return 0;
}
// Even if no pad there, record the slot, as it is the active slot regardless.
slots[port] = slot;
return pads[port][slot].enabled;