Path: chuka.playstation.co.uk!scea!peter_alau@playstation.sony.com From: Elliott Lee Newsgroups: scea.yaroze.beginners Subject: Re: JOYSTICK FUNCTION Date: Fri, 17 Jul 1998 11:16:50 -0700 Organization: Cisco Systems Lines: 57 Message-ID: <35AF9512.8AE0DE7D@jps.net> References: <35AF83F8.4DDB67D@accessv.com> Reply-To: tenchi@jps.net NNTP-Posting-Host: dhcp-m-62-247.cisco.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.03 [en] (Win95; U) First of all, you might want to try my pad routine library (other people have also written some good ones) instead of using the book's, but it works similar: http://www.scea.sony.com/net/yaroze/pages/ftp/elee2/padstuff.zip (This corrects a #define error in the pad.h file.) Anyways, what happens is that every frame the controller is polled and the status stored in a fixed location in memory. The PadRead() just references that area. But what it returns is a 32-bit integer which looks like this: bits: 31 .. 16 15..0 use: Controller1 Controller2 The PadRead() just takes the relevant 2 bytes from the 2 controller pad status buffers and returns it to you in a form which you can then do bit testing on. If you want to see what I mean in real-time, you can do what I first did: make a simple program that just spits out the bit values to the screen or to STDOUT (via printf()). So, the defines you see in the Sony demo's pad.h are for controller 1. To get the bits for controller 2, just shift the mask over 16 bits to the left. Confused? Did this help? Michael Briere wrote: > > Hi! I need some explanation on how the joystick function u_long > PadRead(void) works. > Here's the complete function: > > u_long PadRead(void) > { > return(~(*(bb0+3) | *(bb0+2) <<8 | *(bb1 +3) << 16 | *(bb1+2) > <<24)); > } > > I understand that this reads the joystick and returns a value equal to > the button that was pressed as shown in the yellow manual. However I'd > love it if someone could show me the math behind this with an example. > ie. if PADLstart (bit 11) is pressed on joystick #1 which should be put > in the *bb0 pointer. I could spend hours trying to figure this out for > myself, but I'd really appreciate your help. I know the function works, > but I make it a habit of understanding the code I use in my programs. > Thanks! -- Mata ne, ... ... - e! ::' tenchi@shell.jps.net ':: (Protocol) :: ACiD -/- ACS -/- pHluid -/- Yaroze -/- Nemesis :: (Tenchikun) ::. http://www.jps.net/tenchi .:: ''' '''