2009-05-21 17:48:31 +02:00
|
|
|
/* gameplaySP
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Exophase <exophase@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
2020-11-10 13:03:10 +01:00
|
|
|
bool libretro_supports_bitmasks = false;
|
|
|
|
bool libretro_supports_ff_override = false;
|
|
|
|
bool libretro_ff_enabled = false;
|
|
|
|
bool libretro_ff_enabled_prev = false;
|
|
|
|
|
2021-05-17 14:02:41 +02:00
|
|
|
unsigned turbo_period = TURBO_PERIOD_MIN;
|
|
|
|
unsigned turbo_pulse_width = TURBO_PULSE_WIDTH_MIN;
|
|
|
|
unsigned turbo_a_counter = 0;
|
|
|
|
unsigned turbo_b_counter = 0;
|
|
|
|
|
2014-12-10 12:29:19 +01:00
|
|
|
static u32 old_key = 0;
|
|
|
|
static retro_input_state_t input_state_cb;
|
|
|
|
|
|
|
|
void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; }
|
2009-05-21 17:48:31 +02:00
|
|
|
|
2020-11-10 13:03:10 +01:00
|
|
|
extern void set_fastforward_override(bool fastforward);
|
|
|
|
|
2014-12-13 05:01:02 +01:00
|
|
|
static void trigger_key(u32 key)
|
2009-05-21 17:48:31 +02:00
|
|
|
{
|
2021-06-27 01:16:28 +02:00
|
|
|
u32 p1_cnt = read_ioreg(REG_P1CNT);
|
2009-05-21 17:48:31 +02:00
|
|
|
|
|
|
|
if((p1_cnt >> 14) & 0x01)
|
|
|
|
{
|
|
|
|
u32 key_intersection = (p1_cnt & key) & 0x3FF;
|
|
|
|
|
|
|
|
if(p1_cnt >> 15)
|
|
|
|
{
|
|
|
|
if(key_intersection == (p1_cnt & 0x3FF))
|
|
|
|
raise_interrupt(IRQ_KEYPAD);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(key_intersection)
|
|
|
|
raise_interrupt(IRQ_KEYPAD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-09 01:59:02 +01:00
|
|
|
u32 update_input(void)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
uint32_t new_key = 0;
|
2021-05-17 14:02:41 +02:00
|
|
|
bool turbo_a = false;
|
|
|
|
bool turbo_b = false;
|
2014-12-09 01:59:02 +01:00
|
|
|
|
|
|
|
if (!input_state_cb)
|
|
|
|
return 0;
|
|
|
|
|
2020-11-10 13:03:10 +01:00
|
|
|
if (libretro_supports_bitmasks)
|
|
|
|
{
|
|
|
|
int16_t ret = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_MASK);
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof(btn_map) / sizeof(map); i++)
|
|
|
|
new_key |= (ret & (1 << btn_map[i].retropad)) ? btn_map[i].gba : 0;
|
|
|
|
|
|
|
|
libretro_ff_enabled = libretro_supports_ff_override &&
|
|
|
|
(ret & (1 << RETRO_DEVICE_ID_JOYPAD_R2));
|
2021-05-17 14:02:41 +02:00
|
|
|
|
|
|
|
turbo_a = (ret & (1 << RETRO_DEVICE_ID_JOYPAD_X));
|
|
|
|
turbo_b = (ret & (1 << RETRO_DEVICE_ID_JOYPAD_Y));
|
2020-11-10 13:03:10 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (i = 0; i < sizeof(btn_map) / sizeof(map); i++)
|
|
|
|
new_key |= input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, btn_map[i].retropad) ? btn_map[i].gba : 0;
|
|
|
|
|
|
|
|
libretro_ff_enabled = libretro_supports_ff_override &&
|
|
|
|
input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2);
|
2021-05-17 14:02:41 +02:00
|
|
|
|
|
|
|
turbo_a = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X);
|
|
|
|
turbo_b = input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle turbo buttons */
|
|
|
|
if (turbo_a)
|
|
|
|
{
|
|
|
|
new_key |= (turbo_a_counter < turbo_pulse_width) ?
|
|
|
|
BUTTON_A : 0;
|
|
|
|
|
|
|
|
turbo_a_counter++;
|
|
|
|
if (turbo_a_counter >= turbo_period)
|
|
|
|
turbo_a_counter = 0;
|
2020-11-10 13:03:10 +01:00
|
|
|
}
|
2021-05-17 14:02:41 +02:00
|
|
|
else
|
|
|
|
turbo_a_counter = 0;
|
|
|
|
|
|
|
|
if (turbo_b)
|
|
|
|
{
|
|
|
|
new_key |= (turbo_b_counter < turbo_pulse_width) ?
|
|
|
|
BUTTON_B : 0;
|
|
|
|
|
|
|
|
turbo_b_counter++;
|
|
|
|
if (turbo_b_counter >= turbo_period)
|
|
|
|
turbo_b_counter = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
turbo_b_counter = 0;
|
2014-12-09 01:59:02 +01:00
|
|
|
|
2014-12-10 12:29:19 +01:00
|
|
|
if ((new_key | old_key) != old_key)
|
2014-12-09 01:59:02 +01:00
|
|
|
trigger_key(new_key);
|
|
|
|
|
2014-12-10 12:29:19 +01:00
|
|
|
old_key = new_key;
|
2021-06-27 01:16:28 +02:00
|
|
|
write_ioreg(REG_P1, (~old_key) & 0x3FF);
|
2014-12-09 01:59:02 +01:00
|
|
|
|
2020-11-10 13:03:10 +01:00
|
|
|
/* Handle fast forward button */
|
|
|
|
if (libretro_ff_enabled != libretro_ff_enabled_prev)
|
|
|
|
{
|
|
|
|
set_fastforward_override(libretro_ff_enabled);
|
|
|
|
libretro_ff_enabled_prev = libretro_ff_enabled;
|
|
|
|
}
|
|
|
|
|
2014-12-09 01:59:02 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2009-05-21 17:48:31 +02:00
|
|
|
|
2021-08-24 17:15:27 +02:00
|
|
|
bool input_read_savestate(const u8 *src)
|
|
|
|
{
|
|
|
|
const u8 *p = bson_find_key(src, "input");
|
|
|
|
if (p)
|
|
|
|
return bson_read_int32(p, "prevkey", &old_key);
|
|
|
|
return false;
|
2014-12-10 11:06:17 +01:00
|
|
|
}
|
2009-05-21 17:48:31 +02:00
|
|
|
|
2021-08-24 17:15:27 +02:00
|
|
|
unsigned input_write_savestate(u8 *dst)
|
|
|
|
{
|
|
|
|
u8 *wbptr1, *startp = dst;
|
|
|
|
bson_start_document(dst, "input", wbptr1);
|
|
|
|
bson_write_int32(dst, "prevkey", old_key);
|
|
|
|
bson_finish_document(dst, wbptr1);
|
|
|
|
return (unsigned int)(dst - startp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|