/* MrF - FCONTROL Routines ----------------------- web: http://www.netyaroze-europe.com/~mrfrosty e-mail: j.t.rutherford@sms.ed.ac.uk Copyright - Mr.Frosty / Hex Heroes 1997-8 First Code: 9th July 1997 Routines Last Updated: 17th April 1998 (v1:5) Documentation Last Updated: 4th January 1998 (v1:5) -> allows the Playstation control ports to be <- accessed easily and efficiently from within your programs --- Please Read This: You are free to use the FCONTROL routines as a library for your own Playstation programs if you wish. If you include this file then please leave this documentation intact. If you distribute your program, I would be grateful if you would e-mail me and tell me where to find it so I can see what good uses it's being put to. This listing is NOT TO BE USED OR DISTRIBUTED COMMERCIALLY without receiving prior written permission from me (James Rutherford). Please e-mail me if you find any inaccuracies in this documentation. Go Play! --- Variables and Constants: (u_char*) X_fcontportbuf[2] - This is the pointer to the PSX pad data buffer. The capital X means you SHOULD NOT touch this variable unless you know what you are doing. Also, DO NOT redefine this variable within your program code. PORT_ONE - Set to 0 (more sensible to call this than '0' because the port is labelled '1' on the machine). PORT_TWO - Set to 1 because the port is labelled '2' on the machine. SPADxxx - constants relating to particular pressed buttons on the standard pad. AJOYxxx - Additional buttons for the analogue joystick APADxxx - Additional sticks for the analogue joypad TRUE - Logical true (1) FALSE - Logical false (0) CONTYPE_xxx - Constants relating to the various controller types. --- Functions (and their prototypes): 1) void FSetPortBuffers(void); - FSetPortBuffers() should be called before any other controller-related procedures. It initialises X_fcontportbuf[2]. 2) u_char FControllerConnected(u_char port); - FControllerConnected(...) tests whether a controller is connected to the specified port. (u_char) port: is the port Id - 0 or 1 (or PORT_XXX). > Returns TRUE or FALSE. 3) u_char FControllerType(u_char port); - FControllerType(...) returns the controller type Id for the specified port. (u_char) port: is the port Id - 0 or 1 (or PORT_XXX). > Test the returned value against CONTYPE_XXX. 4a) u_short FSPadRead(u_char port); - FSPadRead(...) returns the data stream from the specified port for the standard pad. (u_char) port: is the port Id - 0 or 1 (or PORT_XXX). > Test the returned value against SPAD_XXX 4b) u_short FAPadRead(u_char port); - FAPadRead(...) returns the data stream from the specified port for the analogue pad (without sticks). (u_char) port: is the port Id - 0 or 1 (or PORT_XXX). > Test the returned value against APAD_XXX 4c) u_short FAJoyRead(u_char port); - FAJoyRead(...) returns the data stream from the specified port for the analogue joystick (without sticks). (u_char) port: is the port Id - 0 or 1 (or PORT_XXX). > Test the returned value against AJOY_XXX 5a) u_char FAPadStick255 (u_char port, u_char byte); - FAPadStick255(...) returns the analogue value specified at byte offset (the value is between 0 and 255) for an analogue pad stick. (u_char) port: is the port Id - 0 or 1 (or PORT_XXX). (u_char) byte: is the analogue byte (eg. APADl3x or APADr3y). 5b) u_char FAJoyStick255 (u_char port, u_char byte); - FAJoyStick255(...) returns the analogue value specified at byte offset (the value is between 0 and 255) for an analogue joystick stick. (u_char) port: is the port Id - 0 or 1 (or PORT_XXX). (u_char) byte: is the analogue byte (eg. AJOYly or AJOYrx). --- General Principles: FSetPortBuffers() initialises pointers to the two control port buffers. The rest of the procedures provide a smooth interface with the information produced by the controllers. The initial #definitions may be matched with the results from the procedures. should be more watertight than most pad controllers because it distinguishes controller types better. e.g. in some controller libraries, PAD_SQUARE would be accurate for a standard pad, but inaccurate for the analogue joystick. This library forces you to specify the pad type when you test. --- Future Extensions: I'd like to make compatible with as many controller types as possible. Most likely, I shall improve fcontrol for the mouse next. Lightgun, multitap and NeGCon compatibility would also be pretty neat, but don't hold your breath. */ #ifndef _fcontrol_h #define _fcontrol_h #include // Port definitions (for sensible access) #define PORT_ONE (0) #define PORT_TWO (1) // 0x4 >> STANDARD PAD << // .. controls #define SPADup (1<<12) #define SPADdown (1<<14) #define SPADleft (1<<15) #define SPADright (1<<13) // TRiangle, CIrcle, CRoss, SQuare #define SPADtr (1<< 4) #define SPADci (1<< 5) #define SPADcr (1<< 6) #define SPADsq (1<< 7) // Shoulder left and right (1 and 2) #define SPADl1 (1<< 2) #define SPADl2 (1<< 0) #define SPADr1 (1<< 3) #define SPADr2 (1<< 1) #define SPADstart (1<<11) #define SPADselect (1<< 8) // 0x5 >> ANALOGUE JOYSTICK << // .. Stick Controllers (byte offsets) // AJOYlx -> left horizontal, // AJOYry -> right vertical, etc... #define AJOYlx (6) #define AJOYly (7) #define AJOYrx (4) #define AJOYry (5) // .. Alternate Buttons // Does anybody know /why/ the standard pad and analogue joystick // are mixed up like this??? #define AJOYl1 (1<< 1) #define AJOYl2 (1<< 0) #define AJOYr1 (1<< 4) #define AJOYr2 (1<< 7) #define AJOYtr (1<< 3) #define AJOYci (1<< 5) #define AJOYcr (1<< 6) #define AJOYsq (1<< 2) // .. Control #define AJOYstart (1<<11) #define AJOYselect (1<< 8) // 0x7 >> ANALOGUE PAD << // The analogue pad uses the standard pad controls plus two additional // stick controls. #define APADup SPADup #define APADdown SPADdown #define APADleft SPADleft #define APADright SPADright #define APADtr SPADtr #define APADci SPADci #define APADcr SPADcr #define APADsq SPADsq #define APADl1 SPADl1 #define APADl2 SPADl2 #define APADr1 SPADr1 #define APADr2 SPADr2 #define APADstart SPADstart #define APADselect SPADselect // .. Stick Controllers (byte offsets) // Given ID 3 for a reason which currently isn't clear to me... #define APADl3x (6) #define APADl3y (7) #define APADr3x (4) #define APADr3y (5) // Logical Constants #define TRUE (1) #define FALSE (0) // Controller Type Ids #define CONTYPE_NONE (0xF) #define CONTYPE_MOUSE (0x1) #define CONTYPE_NEGCON (0x2) #define CONTYPE_STANDARD_PAD (0x4) #define CONTYPE_ANALOGUE_JOY (0x5) #define CONTYPE_ANALOGUE_PAD (0x7) volatile u_char* X_fcontportbuf[2]; /* --> Function Prototypes for "fcontrol.c" <--*/ void FSetPortBuffers(void); u_char FControllerConnected(u_char port); u_char FControllerType(u_char port); u_short FSPadRead (u_char port); u_short FAPadRead (u_char port); u_short FAJoyRead (u_char port); u_char FAPadStick255 (u_char port, u_char byte); u_char FAJoyStick255 (u_char port, u_char byte); #endif