[Solved] DualShock code causes games to hang on real hardware
Posted: June 27th, 2016, 10:34 am
Solution:
I was not initializing the CD-ROM subsystem and this was causing the game to crash on real hardware.
You must call CdInit()/DsInit() even if you're not going to use it.
-- Original Topic --
I'm having problems with setting up dualshock without it causing the whole whole system to hang on the original hardware.
This doesn't happen on any emulators, and doesn't happen when testing on a PS2 Slim either.
After compiling and burning to a disc, the program will run for a random ammount of time then hang.
The dualshock code I've copied from here:
http://appleofeden.de-doc.com/index.php ... -handling/
[C]
#define PAD_A 0
#define vibBuffLen 8
static u_char align[6]={0,1,0xFF,0xFF,0xFF,0xFF};
static short connected = 0; // No. controllers connected.
int ctr;
u16 Pad_type, Type;
// pad buffer data
ControllerPacket pad_data[2];
u8 pad_state=PAD_STATE_CHECK, pad_id=INVALID_PAD;
u8 vibBuff[2][vibBuffLen];
void VibCallback();
void InputInit()
{
PadInitDirect((u8*)&pad_data[PAD_A],(u8*)&pad_data[PAD_B]);
PadSetAct(PAD_A,vibBuff[PAD_A],vibBuffLen);
PadStartCom();
}
void InputCheck(void)
{
int ret, i;
int type, set;
ret=PadGetState(0);
switch(ret)
{
case PadStateDiscon: // no pad has been connected
connected = 0;
return;
case PadStateFindPad: // currently finding pad
connected = NO_PADS;
pad_state = PAD_STATE_CHECK;
pad_id = INVALID_PAD;
set = 0;
// loop until it's stable or try next time
for (i = 0; i < 100 || !set; i++)
{
switch(PadGetState(PAD_A))
{
case PadStateStable: // found dual shock or analog
type=PadInfoMode(PAD_A,InfoModeCurID,0);
if(type)
{
// send transmission buffer
PadSetAct(PAD_A,vibBuff[PAD_A],vibBuffLen);
// wait until buffer is aligned
while(PadSetActAlign(PAD_A,align)==0)
for (ret = 0; ret < 6; ret++)
VSync(0);
}
set=1;
break;
case PadStateFindCTP1: // normal controller found
set=1;
}
}
connected=PAD_ONE;
return;
case PadStateStable:
// pad is stable, send vibration signal!
if(PadSetActAlign(PAD_A,align))
pad_state=PAD_STATE_STABLE;
break;
}
VibCallback();
type=PadInfoMode(PAD_A,InfoModeCurExID,0);
// dual shock detected with analog disabled or not
if(type==ANALOG_PAD)
connected=PAD_ONE | IS_DUAL_SHOCK;
// other pad type
else
{
type=PadInfoMode(PAD_A,InfoModeCurID,0);
switch(type)
{
case STD_PAD: // standard pad
case ANALOG_PAD: // old analog or dual shock in digital mode
connected=PAD_ONE;
break;
default: // other pads will be detected as nothing plugged in
connected=NO_PADS;
}
}
}
void VibCallback()
{
}
[/C]
I'm testing this only in a SCPH-103. I do have a SCPH-7000, but I can't test on it because it won't read burned discs.
Also there is the fact that it will run official games using dualshock just fine, so I guess the problem should be in my code.
-edit-
Also, some additional info:
This only happens when I use PadInitDirect(), the rest of my code it runs fine if I replace this with PadInit() and PadRead().
I was not initializing the CD-ROM subsystem and this was causing the game to crash on real hardware.
You must call CdInit()/DsInit() even if you're not going to use it.
-- Original Topic --
I'm having problems with setting up dualshock without it causing the whole whole system to hang on the original hardware.
This doesn't happen on any emulators, and doesn't happen when testing on a PS2 Slim either.
After compiling and burning to a disc, the program will run for a random ammount of time then hang.
The dualshock code I've copied from here:
http://appleofeden.de-doc.com/index.php ... -handling/
[C]
#define PAD_A 0
#define vibBuffLen 8
static u_char align[6]={0,1,0xFF,0xFF,0xFF,0xFF};
static short connected = 0; // No. controllers connected.
int ctr;
u16 Pad_type, Type;
// pad buffer data
ControllerPacket pad_data[2];
u8 pad_state=PAD_STATE_CHECK, pad_id=INVALID_PAD;
u8 vibBuff[2][vibBuffLen];
void VibCallback();
void InputInit()
{
PadInitDirect((u8*)&pad_data[PAD_A],(u8*)&pad_data[PAD_B]);
PadSetAct(PAD_A,vibBuff[PAD_A],vibBuffLen);
PadStartCom();
}
void InputCheck(void)
{
int ret, i;
int type, set;
ret=PadGetState(0);
switch(ret)
{
case PadStateDiscon: // no pad has been connected
connected = 0;
return;
case PadStateFindPad: // currently finding pad
connected = NO_PADS;
pad_state = PAD_STATE_CHECK;
pad_id = INVALID_PAD;
set = 0;
// loop until it's stable or try next time
for (i = 0; i < 100 || !set; i++)
{
switch(PadGetState(PAD_A))
{
case PadStateStable: // found dual shock or analog
type=PadInfoMode(PAD_A,InfoModeCurID,0);
if(type)
{
// send transmission buffer
PadSetAct(PAD_A,vibBuff[PAD_A],vibBuffLen);
// wait until buffer is aligned
while(PadSetActAlign(PAD_A,align)==0)
for (ret = 0; ret < 6; ret++)
VSync(0);
}
set=1;
break;
case PadStateFindCTP1: // normal controller found
set=1;
}
}
connected=PAD_ONE;
return;
case PadStateStable:
// pad is stable, send vibration signal!
if(PadSetActAlign(PAD_A,align))
pad_state=PAD_STATE_STABLE;
break;
}
VibCallback();
type=PadInfoMode(PAD_A,InfoModeCurExID,0);
// dual shock detected with analog disabled or not
if(type==ANALOG_PAD)
connected=PAD_ONE | IS_DUAL_SHOCK;
// other pad type
else
{
type=PadInfoMode(PAD_A,InfoModeCurID,0);
switch(type)
{
case STD_PAD: // standard pad
case ANALOG_PAD: // old analog or dual shock in digital mode
connected=PAD_ONE;
break;
default: // other pads will be detected as nothing plugged in
connected=NO_PADS;
}
}
}
void VibCallback()
{
}
[/C]
I'm testing this only in a SCPH-103. I do have a SCPH-7000, but I can't test on it because it won't read burned discs.
Also there is the fact that it will run official games using dualshock just fine, so I guess the problem should be in my code.
-edit-
Also, some additional info:
This only happens when I use PadInitDirect(), the rest of my code it runs fine if I replace this with PadInit() and PadRead().