/***************************************************************************************1* Genesis Plus2* Input peripherals support3*4* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Charles Mac Donald (original code)5* Copyright (C) 2007-2013 Eke-Eke (Genesis Plus GX)6*7* Redistribution and use of this code or any derivative works are permitted8* provided that the following conditions are met:9*10* - Redistributions may not be sold, nor may they be used in a commercial11* product or activity.12*13* - Redistributions that are modified from the original source must include the14* complete source code, including the source code for all components used by a15* binary built from the modified sources. However, as a special exception, the16* source code distributed need not include anything that is normally distributed17* (in either source or binary form) with the major components (compiler, kernel,18* and so on) of the operating system on which the executable runs, unless that19* component itself accompanies the executable.20*21* - Redistributions must reproduce the above copyright notice, this list of22* conditions and the following disclaimer in the documentation and/or other23* materials provided with the distribution.24*25* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"26* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE27* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE28* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE29* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR30* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF31* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS32* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN33* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)34* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE35* POSSIBILITY OF SUCH DAMAGE.36*37****************************************************************************************/3839#include "shared.h"40#include "gamepad.h"41#include "lightgun.h"42#include "mouse.h"43#include "activator.h"44#include "xe_a1p.h"45#include "teamplayer.h"46#include "paddle.h"47#include "sportspad.h"48#include "terebi_oekaki.h"4950t_input input;51int old_system[2] = {-1,-1};525354void input_init(void)55{56int i;57int player = 0;5859for (i=0; i<MAX_DEVICES; i++)60{61input.dev[i] = NO_DEVICE;62input.pad[i] = 0;63}6465/* PICO tablet */66if (system_hw == SYSTEM_PICO)67{68input.dev[0] = DEVICE_PICO;69return;70}7172/* Terebi Oekaki tablet */73if (cart.special & HW_TEREBI_OEKAKI)74{75input.dev[0] = DEVICE_TEREBI;76return;77}7879switch (input.system[0])80{81case SYSTEM_MS_GAMEPAD:82{83input.dev[0] = DEVICE_PAD2B;84player++;85break;86}8788case SYSTEM_MD_GAMEPAD:89{90input.dev[0] = config.input[player].padtype;91player++;92break;93}9495case SYSTEM_MOUSE:96{97input.dev[0] = DEVICE_MOUSE;98player++;99break;100}101102case SYSTEM_ACTIVATOR:103{104input.dev[0] = DEVICE_ACTIVATOR;105player++;106break;107}108109case SYSTEM_XE_A1P:110{111input.dev[0] = DEVICE_XE_A1P;112player++;113break;114}115116case SYSTEM_WAYPLAY:117{118for (i=0; i< 4; i++)119{120if (player < MAX_INPUTS)121{122input.dev[i] = config.input[player].padtype;123player++;124}125}126break;127}128129case SYSTEM_TEAMPLAYER:130{131for (i=0; i<4; i++)132{133if (player < MAX_INPUTS)134{135input.dev[i] = config.input[player].padtype;136player++;137}138}139teamplayer_init(0);140break;141}142143case SYSTEM_LIGHTPHASER:144{145input.dev[0] = DEVICE_LIGHTGUN;146player++;147break;148}149150case SYSTEM_PADDLE:151{152input.dev[0] = DEVICE_PADDLE;153player++;154break;155}156157case SYSTEM_SPORTSPAD:158{159input.dev[0] = DEVICE_SPORTSPAD;160player++;161break;162}163}164165if (player == MAX_INPUTS)166{167return;168}169170switch (input.system[1])171{172case SYSTEM_MS_GAMEPAD:173{174input.dev[4] = DEVICE_PAD2B;175player++;176break;177}178179case SYSTEM_MD_GAMEPAD:180{181input.dev[4] = config.input[player].padtype;182player++;183break;184}185186case SYSTEM_MOUSE:187{188input.dev[4] = DEVICE_MOUSE;189player++;190break;191}192193case SYSTEM_ACTIVATOR:194{195input.dev[4] = DEVICE_ACTIVATOR;196player++;197break;198}199200case SYSTEM_XE_A1P:201{202input.dev[4] = DEVICE_XE_A1P;203player++;204break;205}206207case SYSTEM_MENACER:208{209input.dev[4] = DEVICE_LIGHTGUN;210player++;211break;212}213214case SYSTEM_JUSTIFIER:215{216for (i=4; i<6; i++)217{218if (player < MAX_INPUTS)219{220input.dev[i] = DEVICE_LIGHTGUN;221player++;222}223}224break;225}226227case SYSTEM_TEAMPLAYER:228{229for (i=4; i<8; i++)230{231if (player < MAX_INPUTS)232{233input.dev[i] = config.input[player].padtype;234player++;235}236}237teamplayer_init(1);238break;239}240241case SYSTEM_LIGHTPHASER:242{243input.dev[4] = DEVICE_LIGHTGUN;244player++;245break;246}247248case SYSTEM_PADDLE:249{250input.dev[4] = DEVICE_PADDLE;251player++;252break;253}254255case SYSTEM_SPORTSPAD:256{257input.dev[4] = DEVICE_SPORTSPAD;258player++;259break;260}261}262263/* J-CART */264if (cart.special & HW_J_CART)265{266/* two additional gamepads */267for (i=5; i<7; i++)268{269if (player < MAX_INPUTS)270{271input.dev[i] = config.input[player].padtype;272player ++;273}274}275}276}277278void input_reset(void)279{280/* Reset input devices */281int i;282for (i=0; i<MAX_DEVICES; i++)283{284switch (input.dev[i])285{286case DEVICE_PAD2B:287case DEVICE_PAD3B:288case DEVICE_PAD6B:289{290gamepad_reset(i);291break;292}293294case DEVICE_LIGHTGUN:295{296lightgun_reset(i);297break;298}299300case DEVICE_MOUSE:301{302mouse_reset(i);303break;304}305306case DEVICE_ACTIVATOR:307{308activator_reset(i >> 2);309break;310}311312case DEVICE_XE_A1P:313{314xe_a1p_reset(i);315break;316}317318case DEVICE_PADDLE:319{320paddle_reset(i);321break;322}323324case DEVICE_SPORTSPAD:325{326sportspad_reset(i);327break;328}329330case DEVICE_TEREBI:331{332terebi_oekaki_reset();333break;334}335336default:337{338break;339}340}341}342343/* Team Player */344for (i=0; i<2; i++)345{346if (input.system[i] == SYSTEM_TEAMPLAYER)347{348teamplayer_reset(i);349}350}351}352353void input_refresh(void)354{355int i;356for (i=0; i<MAX_DEVICES; i++)357{358switch (input.dev[i])359{360case DEVICE_PAD6B:361{362gamepad_refresh(i);363break;364}365366case DEVICE_LIGHTGUN:367{368lightgun_refresh(i);369break;370}371}372}373}374375376