issue with input from the second controller

Discuss the development of software, tools, libraries and anything else that helps make ps2dev happen.

Moderators: cheriff, Herben

Post Reply
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

issue with input from the second controller

Post by kouky »

I'd like to add a 2 players feature in my project, but can't succesfully receive data from the second controler.

I init my pads with this:

Code: Select all

    int port = 0; // 0 -> Connector 1, 1 -> Connector 2
    int slot = 0; // Always zero if not using multitap
    if((ret = padPortOpen(port, slot, padBuf)) == 0) {
        scr_printf("padOpenPort failed: %d\n", ret);
        SleepThread();
    }
    else{scr_printf("ok-");}

    if(!initializePad(port, slot)) {
        scr_printf("pad initalization failed!\n");
        SleepThread();
    }
    else{scr_printf("ok-");}

    port = 1; // 0 -> Connector 1, 1 -> Connector 2
    slot = 0; // Always zero if not using multitap
    if((ret = padPortOpen(port, slot, padBuf)) == 0) {
        scr_printf("padOpenPort failed: %d\n", ret);
        SleepThread();
    }
    else{scr_printf("ok-");}

    if(!initializePad(port, slot)) {
        scr_printf("pad initalization failed!\n");
        SleepThread();
    }
    else{scr_printf("ok-");}
and 4 "ok" are printed, fine!

but how can I receive data from the second one?

i tried

Code: Select all

struct padButtonStatus buttons[2];
int port =1;
int slot=0;
int ret 
ret = padRead(port, slot, &buttons[port]); // port, slot, buttons

    if (ret != 0) {
        paddata[port] = 0xffff ^ buttons[port].btns;

        new_pad[port] = paddata[port] & ~old_pad[port];
        old_pad[port] = paddata[port];

        i=new_pad[port];
    }

    paddata[port] = 0xffff ^ buttons[port].btns;
    i=paddata[port];
but then

Code: Select all

    if (i&PAD_TRIANGLE) { ... }
just never works...
softwares for artists on video game systems - http://www.pikilipita.com
User avatar
Lukasz
Posts: 248
Joined: Mon Jan 19, 2004 8:37 pm
Location: Denmark
Contact:

Post by Lukasz »

From a quick glance at your description and code I can't spot the problem. I suggest you try the 3 different pad samples in ps2sdk (rpc/pad, rpc/padx, rpc/mtap) and go from there.
User avatar
kouky
Posts: 48
Joined: Tue Sep 25, 2007 5:38 am
Location: London
Contact:

Post by kouky »

Thanks, Lukasz,
I've found my error in those examples:
You need to have 2 padBuf, so the code has to be:

Code: Select all

static char *padBuf[2];
    padBuf[0] = memalign(64, 256);
    padBuf[1] = memalign(64, 256);


...



    int port = 0; // 0 -> Connector 1, 1 -> Connector 2
    int slot = 0; // Always zero if not using multitap
    if((ret = padPortOpen(port, slot, padBuf[0])) == 0) {
        scr_printf("padOpenPort failed: %d\n", ret);
        SleepThread();
    }

    if(!initializePad(port, slot)) {
        scr_printf("pad initalization failed!\n");
        SleepThread();
    }

    port = 1; // 0 -> Connector 1, 1 -> Connector 2
    slot = 0; // Always zero if not using multitap
    if((ret = padPortOpen(port, slot, padBuf[1])) == 0) {
        scr_printf("padOpenPort failed: %d\n", ret);
        SleepThread();
    }

    if(!initializePad(port, slot)) {
        scr_printf("pad initalization failed!\n");
        SleepThread();
    }
now it works :)
softwares for artists on video game systems - http://www.pikilipita.com
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Thanks for letting us know what it was that worked. Too often you see people post that they worked out the problem, but not what the solution was, and that doesn't help anyone.
Post Reply