Path: chuka.playstation.co.uk!scea!peter_alau@playstation.sony.com From: Michael Briere Newsgroups: scea.yaroze.beginners Subject: Re: JOYSTICK FUNCTION Date: Fri, 17 Jul 1998 18:57:40 -0400 Organization: SCEA News Server Lines: 74 Message-ID: <35AFD6E4.6BDB3993@accessv.com> References: <35AF83F8.4DDB67D@accessv.com> <35AF9512.8AE0DE7D@jps.net> NNTP-Posting-Host: 32.209.5.199.dialup.accessv.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 4.04 [en] (Win95; I) Hi Elliott! Thanks for your help! I really like your joystick lib as it does include the diagonal combinations. I also like your suggestion of using printfs to see the math behind this. I am confused though about what you've put in your reply to me and what you have in your padstuff.h header file. In your reply you say that controller 1 uses bits 16 to 31 and controller 2 uses bits 0 to 15, yet in your header file when you assign buttons to bits it's the reverse. Am I missing something here? I know I have to do some more reading on bitwise operators to get all of this, so I wouldn't be surprised if I'm the one who's getting it wrong. I've got to take a good look at your padstuff now. Thank you! Elliott Lee wrote: > 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 .:: > ''' '''