Path: chuka.playstation.co.uk!news From: "Greg Cook" Newsgroups: scee.yaroze.freetalk.english Subject: Controller Questions Date: Fri, 21 Jun 2002 16:30:18 +1200 Organization: PlayStation Net Yaroze (SCEE) Lines: 229 Message-ID: NNTP-Posting-Host: 202.37.124.253 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 Well now ive been playing with the machine and getting graphics to work and kinda just following tutorials etc, ive decided i want to actually know a little more about the code that ive blindly used thats been supplied by sony. ive pasted some samples below so im asking questions about those. ok this is mainly about how the controllers work.. This code is from the Online Downloaded tutes from the yaroze site. This control file is significantly different to the stuff which most of us use, iv added the pad.h file that i use most often. IM not sure what this line is doing #define PAD_PRESS(x,y) (~(x)->data.pad & (y)) Can anyone explain this and how some of the structures below are used. ############################################################################ ###################################### More Questions Below. ############################################################################ ###################################### //-------------------------------------------------------------------------- // File: cntrl.h // Author: George Bain // Date: June 17, 1998 // Description: Controller type macros and defines. // Copyright (C) 1998 Sony Computer Entertainment Europe., // All Rights Reserved. Permission granted to whom ever. //-------------------------------------------------------------------------- #ifndef _CNTRL_H #define _CNTRL_H //-------------------------------------------------------------------------- // D E F I N E S //-------------------------------------------------------------------------- // quit macro #define DONE (PAD_PRESS(buffer1,PAD_SELECT) && PAD_PRESS(buffer1,PAD_START)) // terminal types #define MOUSE (0x1) #define NEGCON (0x2) #define NORMAL (0x4) #define ANALOG_JOY (0x5) #define GUNCON (0x6) #define ANALOG (0x7) // controller defines 14 buttons, 16 when in analog mode #define PAD_NOKEY (0xFFFF) #define PAD_BAD (0xFF) #define PAD_LEFT (1<<7) #define PAD_RIGHT (1<<5) #define PAD_UP (1<<4) #define PAD_DOWN (1<<6) #define PAD_TRIANGLE (1<<12) #define PAD_CIRCLE (1<<13) #define PAD_CROSS (1<<14) #define PAD_SQUARE (1<<15) #define PAD_SELECT (1<<0) #define PAD_START (1<<3) #define PAD_L1 (1<<10) #define PAD_L2 (1<<8) #define PAD_L3 (1<<1) #define PAD_R1 (1<<11) #define PAD_R2 (1<<9) #define PAD_R3 (1<<2) // controller check macros #define PAD_PRESS(x,y) (~(x)->data.pad & (y)) //-------------------------------------------------------------------------- // S T R U C T U R E S //-------------------------------------------------------------------------- typedef struct guncon_tag { // 2 bytes u_short buttons; // button A, B, and TRIGGER u_short guncon_x; // x offset u_short guncon_y; // y offset }guncon_data; typedef struct mouse_tag { char not_used; // not used char buttons; // 2nd bit: right, 3rd bit: left signed char x_offset; // movement in x direction: -128~127 signed char y_offset; // movement in y direction: -128~127 }mouse_data; typedef struct negcon_tag { u_short buttons; // LEFT, RIGHT, DOWN, UP, START, A, B, and R u_char twist; // the twist value u_char button_I; // I button u_char button_II; // II button u_char button_L; // L button }negcon_data; typedef struct analog_tag { u_short buttons; // 16 buttons u_char right_x; // movement on right stick x direction: 0~255 u_char right_y; // movement on right stick y direction: 0~255 u_char left_x; // movement on left stick x direction: 0~255 u_char left_y; // movement on left stick y direction: 0~255 }analog_data; typedef u_short pad_data; // 14 button controller typedef struct packet_tag { // 0-7 u_char status; // 0xff: no controller, 0x00 controller connected u_char type; // upper 4 bits: terminal type // lower 4 bits: size of data received / 2 // 2-6 bytes of data // 2 bytes for 14 button controller // add 4 bytes for analog, now total of 6 bytes of received data union { pad_data pad; mouse_data mouse; analog_data analog; negcon_data negcon; guncon_data guncon; }data; }cntrl_data, *cntrl_ptr; //-------------------------------------------------------------------------- // G L O B A L S //-------------------------------------------------------------------------- // 8 bytes for each buffer cntrl_data *buffer1, *buffer2; #endif //----------------------------------EOF------------------------------------- ############################################################################ ###################################### Questions Start Here. ############################################################################ ###################################### Ok so here is the stuff i generally use for my Pad Defs. #define PADLup (1<<12) #define PADLdown (1<<14) #define PADLleft (1<<15) #define PADLright (1<<13) #define PADRup (1<< 4) #define PADRdown (1<< 6) #define PADRleft (1<< 7) #define PADRright (1<< 5) #define PADi (1<< 9) #define PADj (1<<10) #define PADk (1<< 8) #define PADl (1<< 3) #define PADm (1<< 1) #define PADn (1<< 2) #define PADo (1<< 0) #define PADh (1<<11) #define PADL1 PADn #define PADL2 PADo #define PADR1 PADl #define PADR2 PADm #define PADstart PADh #define PADselect PADk 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... Im guessing its something to do with the PAD_PRESS Question i asked above out putting something different to the function that i generally use to get the pad output. u_long PadRead(void) { return(~(*(bb0+3) | *(bb0+2) << 8 | *(bb1+3) << 16 | *(bb1+2) << 24)); } 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. Has anyone written sample code on how to deal with all different variations of controllers ? Sorry for the long post, but i just need to get this stuff sorted in my head a little more :) Greg