Path: blob/main/misc/emulator/xnes/snes9x/controls.h
28547 views
/***********************************************************************************1Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.23(c) Copyright 1996 - 2002 Gary Henderson ([email protected]),4Jerremy Koot ([email protected])56(c) Copyright 2002 - 2004 Matthew Kendora78(c) Copyright 2002 - 2005 Peter Bortas ([email protected])910(c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/)1112(c) Copyright 2001 - 2006 John Weidman ([email protected])1314(c) Copyright 2002 - 2006 funkyass ([email protected]),15Kris Bleakley ([email protected])1617(c) Copyright 2002 - 2010 Brad Jorsch ([email protected]),18Nach ([email protected]),1920(c) Copyright 2002 - 2011 zones ([email protected])2122(c) Copyright 2006 - 2007 nitsuja2324(c) Copyright 2009 - 2011 BearOso,25OV2262728BS-X C emulator code29(c) Copyright 2005 - 2006 Dreamer Nom,30zones3132C4 x86 assembler and some C emulation code33(c) Copyright 2000 - 2003 _Demo_ ([email protected]),34Nach,35zsKnight ([email protected])3637C4 C++ code38(c) Copyright 2003 - 2006 Brad Jorsch,39Nach4041DSP-1 emulator code42(c) Copyright 1998 - 2006 _Demo_,43Andreas Naive ([email protected]),44Gary Henderson,45Ivar ([email protected]),46John Weidman,47Kris Bleakley,48Matthew Kendora,49Nach,50neviksti ([email protected])5152DSP-2 emulator code53(c) Copyright 2003 John Weidman,54Kris Bleakley,55Lord Nightmare ([email protected]),56Matthew Kendora,57neviksti5859DSP-3 emulator code60(c) Copyright 2003 - 2006 John Weidman,61Kris Bleakley,62Lancer,63z80 gaiden6465DSP-4 emulator code66(c) Copyright 2004 - 2006 Dreamer Nom,67John Weidman,68Kris Bleakley,69Nach,70z80 gaiden7172OBC1 emulator code73(c) Copyright 2001 - 2004 zsKnight,74pagefault ([email protected]),75Kris Bleakley76Ported from x86 assembler to C by sanmaiwashi7778SPC7110 and RTC C++ emulator code used in 1.39-1.5179(c) Copyright 2002 Matthew Kendora with research by80zsKnight,81John Weidman,82Dark Force8384SPC7110 and RTC C++ emulator code used in 1.52+85(c) Copyright 2009 byuu,86neviksti8788S-DD1 C emulator code89(c) Copyright 2003 Brad Jorsch with research by90Andreas Naive,91John Weidman9293S-RTC C emulator code94(c) Copyright 2001 - 2006 byuu,95John Weidman9697ST010 C++ emulator code98(c) Copyright 2003 Feather,99John Weidman,100Kris Bleakley,101Matthew Kendora102103Super FX x86 assembler emulator code104(c) Copyright 1998 - 2003 _Demo_,105pagefault,106zsKnight107108Super FX C emulator code109(c) Copyright 1997 - 1999 Ivar,110Gary Henderson,111John Weidman112113Sound emulator code used in 1.5-1.51114(c) Copyright 1998 - 2003 Brad Martin115(c) Copyright 1998 - 2006 Charles Bilyue'116117Sound emulator code used in 1.52+118(c) Copyright 2004 - 2007 Shay Green ([email protected])119120SH assembler code partly based on x86 assembler code121(c) Copyright 2002 - 2004 Marcus Comstedt ([email protected])1221232xSaI filter124(c) Copyright 1999 - 2001 Derek Liauw Kie Fa125126HQ2x, HQ3x, HQ4x filters127(c) Copyright 2003 Maxim Stepin ([email protected])128129NTSC filter130(c) Copyright 2006 - 2007 Shay Green131132GTK+ GUI code133(c) Copyright 2004 - 2011 BearOso134135Win32 GUI code136(c) Copyright 2003 - 2006 blip,137funkyass,138Matthew Kendora,139Nach,140nitsuja141(c) Copyright 2009 - 2011 OV2142143Mac OS GUI code144(c) Copyright 1998 - 2001 John Stiles145(c) Copyright 2001 - 2011 zones146147148Specific ports contains the works of other authors. See headers in149individual files.150151152Snes9x homepage: http://www.snes9x.com/153154Permission to use, copy, modify and/or distribute Snes9x in both binary155and source form, for non-commercial purposes, is hereby granted without156fee, providing that this license information and copyright notice appear157with all copies and any derived work.158159This software is provided 'as-is', without any express or implied160warranty. In no event shall the authors be held liable for any damages161arising from the use of this software or it's derivatives.162163Snes9x is freeware for PERSONAL USE only. Commercial users should164seek permission of the copyright holders first. Commercial use includes,165but is not limited to, charging money for Snes9x or software derived from166Snes9x, including Snes9x or derivatives in commercial game bundles, and/or167using Snes9x as a promotion for your commercial product.168169The copyright holders request that bug fixes and improvements to the code170should be forwarded to them so everyone can benefit from the modifications171in future versions.172173Super NES and Super Nintendo Entertainment System are trademarks of174Nintendo Co., Limited and its subsidiary companies.175***********************************************************************************/176177178#ifndef _CONTROLS_H_179#define _CONTROLS_H_180181#define S9xNoMapping 0182#define S9xButtonJoypad 1183#define S9xButtonMouse 2184#define S9xButtonSuperscope 3185#define S9xButtonJustifier 4186#define S9xButtonCommand 5187#define S9xButtonMulti 6188#define S9xAxisJoypad 7189#define S9xPointer 8190191#define S9xButtonPseudopointer 254192#define S9xAxisPseudopointer 253193#define S9xAxisPseudobuttons 252194195// These are automatically kicked out to the S9xHandlePortCommand function.196// If your port wants to define port-specific commands or whatever, use these values for the s9xcommand_t type field.197198#define S9xButtonPort 251199#define S9xAxisPort 250200#define S9xPointerPort 249201202#define S9xBadMapping 255203#define InvalidControlID ((uint32) -1)204205// S9xButtonPseudopointer and S9xAxisPseudopointer will report pointer motion using IDs PseudoPointerBase through PseudoPointerBase+7.206// S9xAxisPseudopointer command types. S9xAxisPseudobuttons will report buttons with IDs PseudoButtonBase to PseudoButtonBase+255.207208#define PseudoPointerBase (InvalidControlID - 8)209#define PseudoButtonBase (PseudoPointerBase - 256)210211typedef struct212{213uint8 type;214uint8 multi_press:2;215uint8 button_norpt:1;216217union218{219union220{221struct222{223uint8 idx:3; // Pad number 0-7224uint8 toggle:1; // If set, toggle turbo/sticky for the button225uint8 turbo:1; // If set, be a 'turbo' button226uint8 sticky:1; // If set, toggle button state (on/turbo or off) when pressed and do nothing on release227uint16 buttons; // Which buttons to actuate. Use SNES_*_MASK constants from snes9x.h228} joypad;229230struct231{232uint8 idx:1; // Mouse number 0-1233uint8 left:1; // buttons234uint8 right:1;235} mouse;236237struct238{239uint8 fire:1;240uint8 cursor:1;241uint8 turbo:1;242uint8 pause:1;243uint8 aim_offscreen:1; // Pretend we're pointing the gun offscreen (ignore the pointer)244} scope;245246struct247{248uint8 idx:3; // Pseudo-pointer number 0-7249uint8 speed_type:2; // 0=variable, 1=slow, 2=med, 3=fast250int8 UD:2; // -1=up, 1=down, 0=no vertical motion251int8 LR:2; // -1=left, 1=right, 0=no horizontal motion252} pointer;253254struct255{256uint8 idx:1; // Justifier number 0-1257uint8 trigger:1; // buttons258uint8 start:1;259uint8 aim_offscreen:1; // Pretend we're pointing the gun offscreen (ignore the pointer)260} justifier;261262int32 multi_idx;263uint16 command;264} button;265266union267{268struct269{270uint8 idx:3; // Pad number 0-7271uint8 invert:1; // 1 = positive is Left/Up/Y/X/L272uint8 axis:3; // 0=Left/Right, 1=Up/Down, 2=Y/A, 3=X/B, 4=L/R273uint8 threshold; // (threshold+1)/256% deflection is a button press274} joypad;275276struct277{278uint8 idx:3; // Pseudo-pointer number 0-7279uint8 speed_type:2; // 0=variable, 1=slow, 2=med, 3=fast280uint8 invert:1; // 1 = invert axis, so positive is up/left281uint8 HV:1; // 0=horizontal, 1=vertical282} pointer;283284struct285{286uint8 threshold; // (threshold+1)/256% deflection is a button press287uint8 negbutton; // Button ID for negative deflection288uint8 posbutton; // Button ID for positive deflection289} button;290} axis;291292struct // Which SNES-pointers to control with this pointer293{294uint16 aim_mouse0:1;295uint16 aim_mouse1:1;296uint16 aim_scope:1;297uint16 aim_justifier0:1;298uint16 aim_justifier1:1;299} pointer;300301uint8 port[4];302} input;303} s9xcommand_t;304305// Starting out...306307void S9xUnmapAllControls (void);308309// Setting which controllers are plugged in.310311enum controllers312{313CTL_NONE, // all ids ignored314CTL_JOYPAD, // use id1 to specify 0-7315CTL_MOUSE, // use id1 to specify 0-1316CTL_SUPERSCOPE,317CTL_JUSTIFIER, // use id1: 0=one justifier, 1=two justifiers318CTL_MP5 // use id1-id4 to specify pad 0-7 (or -1)319};320321void S9xSetController (int port, enum controllers controller, int8 id1, int8 id2, int8 id3, int8 id4); // port=0-1322void S9xGetController (int port, enum controllers *controller, int8 *id1, int8 *id2, int8 *id3, int8 *id4);323void S9xReportControllers (void);324325// Call this when you're done with S9xSetController, or if you change any of the controller Settings.*Master flags.326// Returns true if something was disabled.327328bool S9xVerifyControllers (void);329330// Functions for translation s9xcommand_t's into strings, and vice versa.331// free() the returned string after you're done with it.332333char * S9xGetCommandName (s9xcommand_t command);334s9xcommand_t S9xGetCommandT (const char *name);335336// Returns an array of strings naming all the snes9x commands.337// Note that this is only the strings for S9xButtonCommand!338// The idea is that this would be used for a pull-down list in a config GUI. DO NOT free() the returned value.339340const char ** S9xGetAllSnes9xCommands (void);341342// Generic mapping functions343344s9xcommand_t S9xGetMapping (uint32 id);345void S9xUnmapID (uint32 id);346347// Button mapping functions.348// If a button is mapped with poll=TRUE, then S9xPollButton will be called whenever snes9x feels a need for that mapping.349// Otherwise, snes9x will assume you will call S9xReportButton() whenever the button state changes.350// S9xMapButton() will fail and return FALSE if mapping.type isn't an S9xButton* type.351352bool S9xMapButton (uint32 id, s9xcommand_t mapping, bool poll);353void S9xReportButton (uint32 id, bool pressed);354355// Pointer mapping functions.356// If a pointer is mapped with poll=TRUE, then S9xPollPointer will be called whenever snes9x feels a need for that mapping.357// Otherwise, snes9x will assume you will call S9xReportPointer() whenever the pointer position changes.358// S9xMapPointer() will fail and return FALSE if mapping.type isn't an S9xPointer* type.359360// Note that position [0,0] is considered the upper-left corner of the 'screen',361// and either [255,223] or [255,239] is the lower-right.362// Note that the SNES mouse doesn't aim at a particular point,363// so the SNES's idea of where the mouse pointer is will probably differ from your OS's idea.364365bool S9xMapPointer (uint32 id, s9xcommand_t mapping, bool poll);366void S9xReportPointer (uint32 id, int16 x, int16 y);367368// Axis mapping functions.369// If an axis is mapped with poll=TRUE, then S9xPollAxis will be called whenever snes9x feels a need for that mapping.370// Otherwise, snes9x will assume you will call S9xReportAxis() whenever the axis deflection changes.371// S9xMapAxis() will fail and return FALSE if mapping.type isn't an S9xAxis* type.372373// Note that value is linear -32767 through 32767 with 0 being no deflection.374// If your axis reports differently you should transform the value before passing it to S9xReportAxis().375376bool S9xMapAxis (uint32 id, s9xcommand_t mapping, bool poll);377void S9xReportAxis (uint32 id, int16 value);378379// Do whatever the s9xcommand_t says to do.380// If cmd.type is a button type, data1 should be TRUE (non-0) or FALSE (0) to indicate whether the 'button' is pressed or released.381// If cmd.type is an axis, data1 holds the deflection value.382// If cmd.type is a pointer, data1 and data2 are the positions of the pointer.383384void S9xApplyCommand (s9xcommand_t cmd, int16 data1, int16 data2);385386//////////387// These functions are called by snes9x into your port, so each port should implement them.388389// If something was mapped with poll=TRUE, these functions will be called when snes9x needs the button/axis/pointer state.390// Fill in the reference options as appropriate.391392bool S9xPollButton (uint32 id, bool *pressed);393bool S9xPollPointer (uint32 id, int16 *x, int16 *y);394bool S9xPollAxis (uint32 id, int16 *value);395396// These are called when snes9x tries to apply a command with a S9x*Port type.397// data1 and data2 are filled in like S9xApplyCommand.398399void S9xHandlePortCommand (s9xcommand_t cmd, int16 data1, int16 data2);400401// Called before already-read SNES joypad data is being used by the game if your port defines SNES_JOY_READ_CALLBACKS.402403#ifdef SNES_JOY_READ_CALLBACKS404void S9xOnSNESPadRead (void);405#endif406407// These are for your use.408409s9xcommand_t S9xGetPortCommandT (const char *name);410char * S9xGetPortCommandName (s9xcommand_t command);411void S9xSetupDefaultKeymap (void);412bool8 S9xMapInput (const char *name, s9xcommand_t *cmd);413414//////////415// These functions are called from snes9x into this subsystem. No need to use them from a port.416417// Use when resetting snes9x.418419void S9xControlsReset (void);420void S9xControlsSoftReset (void);421422// Use when writing to $4016.423424void S9xSetJoypadLatch (bool latch);425426// Use when reading $4016/7 (JOYSER0 and JOYSER1).427428uint8 S9xReadJOYSERn (int n);429430// End-Of-Frame processing. Sets gun latch variables and tries to draw crosshairs431432void S9xControlEOF (void);433434// Functions and a structure for snapshot.435436struct SControlSnapshot437{438uint8 ver;439uint8 port1_read_idx[2];440uint8 dummy1[4]; // for future expansion441uint8 port2_read_idx[2];442uint8 dummy2[4];443uint8 mouse_speed[2];444uint8 justifier_select;445uint8 dummy3[8];446bool8 pad_read, pad_read_last;447uint8 internal[60]; // yes, we need to save this!448};449450void S9xControlPreSaveState (struct SControlSnapshot *s);451void S9xControlPostLoadState (struct SControlSnapshot *s);452453#endif454455456