Path: chuka.playstation.co.uk!news From: "John \( QuietBloke \)" Newsgroups: scee.yaroze.freetalk.english Subject: Re: Help With Pads Date: Thu, 28 Dec 2000 01:34:20 -0000 Organization: PlayStation Net Yaroze (SCEE) Lines: 143 Message-ID: <92e56g$8d3@www.netyaroze-europe.com> References: <92bfd1$8c5@www.netyaroze-europe.com> NNTP-Posting-Host: freedu-181-49.libertysurf.co.uk X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 OK.. I'll give this one a go... and Im gonna assume the code needs explaining too ( If you understand the code sorry.. but it may be useful to someone else ). From the top you need to define then following volatile u_char *bb0, *bb1; This creates two pointers each of which point to a single byte of memory. Then you must initialize these pointers by calling GetPadBuf (&bb0, &bb1 ); This will basically set the two pointers to point to the appropriate bit of memory which contains the status of each controller ( bb0 = left controller, bb1 = right controller ) So now you simply look at the contents of the memory pointed to by these pointers to get the controller status. The pointers actually point to a single byte. Each controller returns 32 bits. The first 8 bits simply indicate if a controller is plugged in ( 0xff = You have a controller, 0x00 means you dont ). The second byte can tell you what kind of controller you have ( Im a bit vague on this data as currently I just assume you have a standard controller... shabby I know but what the hey ! ). Finally the next two bytes actually contain the info about what buttons are up.down. Therefore to check the buttons for controller 1 you need the contents of bytes 3 and 4. ( offsets 2 and 3 ). You'd want to store both bytes into a single variable therefore you do : unsigned int result = *(bb0+3) | *(bb0+2) << 8 *(bb0+2) will return the contents of the byte held in memory at the address pointed to by bb0 plus 2. This number is shifted 8 bits to the left ( << 8 ) and then we add the contents at offset 3 ( *(bb0+3) ). So.. there you have the bit values for all the buttons in controller 1. To look at controller 2 we do the same thing using bb1. Now.. for some reason ( Must be a hardware techy thing ) the bits returned are the opposite of what we would be expecting. ie If you wanted to see if the start button is down you would look at bit 11 but what you actually get is a 1 if its up and a zero when its down. So what we do is invert the bits by using ones-compliment ( the '~' ). So.. to return the result for controller 1 we do : result = ~(*(bb0+3) | *(bb0+2) << 8); and for controller 2 we do : result = ~(*(bb1+3) | *(bb1+2) << 8); If now for example you wanted to see if start had been hit for a controller you can just perform a bitwise AND if ( result & 0x0800 ) ... do something explanation ?.. you wont need this but Im on a roll so you might want to skip this bit Say for example the player has pressed several buttons including the start button : The binary values would be thus result = 0000100000001010 if we AND this value with 0x0800 0x0800 = 0000100000000000 we get 0000100000000000 The if statement will take any value other than zero as being true and viola.. we have found out the button was pressed and we can deal with it. The example app(s) supplied on the development CD actually have a pad.h file which defines all the bit tests you need to check the controller buttons. So you can make the code much readable by having something like if ( padd & PADstart ) instead. Or you can check the user guide in chapter 12 to get a full explanation of all the bits returned in the full 32 bits. As a final note : In the code you supplied what you've actually done is returned the results from both controllers in one hit. So the first ( rightmost ) two bytes contain controller 1 data and the next 2 bytes ( leftmost) contain controller 2 data. Hope this helps.. John ( QuietBloke ) PS.. I know... I know.. for a QuietBloke I sure do waffle !.. and if I stated the obvious too .. I'm sorry... I'd just rather explain everything than assume something. "Jeremy" wrote in message news:92bfd1$8c5@www.netyaroze-europe.com... > Hey, > > Just trying to remember some stuff . > > Anyone able to explain this (below), obviously code to read the pads, but im > looking for a bit more of an explanantion :) so that i can modify some of my > pad reading code. > > any info appreciated. I dont really have the greatest understanding of bit > shifts, so simple explanantion would be good. > > > return(~(*(pad1Buffer+3)|(pad1Buffer+2)<<8|(*pad2Buffer+3)<<16|*pad2Buffer+2 > )<<24)); > > > > Thanks > > J. > >