Path: chuka.playstation.co.uk!news From: "Martin Keates" Newsgroups: scee.yaroze.freetalk.english Subject: Re: Controller Questions Date: Fri, 21 Jun 2002 13:29:02 +0100 Organization: PlayStation Net Yaroze (SCEE) Lines: 61 Message-ID: References: NNTP-Posting-Host: modem-3792.panther.dialup.pol.co.uk X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Hi Greg, > ok this is mainly about how the controllers work.. > #define PAD_PRESS(x,y) (~(x)->data.pad & (y)) x is the controller buffer (so either buffer1 or buffer2) and y is the button you're testing (e.g. PAD_LEFT) - so y is a single bit that gets checked against the pad buffer. The NOT (~) inverts the buffer because bits are set for up and reset for pressed (I assume). There should be a bunch of other #defines like this for the other types of controller. > I cant understand why The sample code at the top of the page by george uses > this define > > #define PAD_LEFT (1<<7) ( this is the left direct buttons ) > > as in the code just abouve #define PADRleft (1<< 7) would be the Square > Button... If you check all the buttons you'll find that they are all 8 bits shifted left or right from the #define in pad.h. This is because PadRead swaps the byte order for each buffer, whereas PAD_PRESS compares with the buffers directly. > u_long PadRead(void) > { > return(~(*(bb0+3) | *(bb0+2) << 8 | *(bb1+3) << 16 | *(bb1+2) << 24)); > } This is creating a 4 byte unsigned long containing 2 bytes from each buffer: (all inverted, so presses are 1). Erm, which on a PC would be the same ordering in memory, so I can only assume that yaroze is little endian. > Can Anyone explains this stuff above? i understand how the bit shifting etc > is working, i sat down and did all this stuff on paper, but what im > wondering is how to use the second method to determine which controller is > plugged in and what type of controller it is. if (!controller1->status) /* something plugged in */ { switch (controller1->type) { case MOUSE: . . case NEGCON: . . case ANALOG: etc. etc. } } There are examples of using the controllers in that tutorial. Martin.