Commit 429e27c3 authored by Chips-fr's avatar Chips-fr
Browse files

Two joystick support with automatic switching

parent d92c8007
......@@ -14,4 +14,7 @@ Basic port. Based on rtype version.
|Start|Toggle mouse emulation|
Right analog stick controls the mouse.
In mouse emulation dpad and fire buttons controls the mouse.
\ No newline at end of file
In mouse emulation dpad and fire buttons controls the mouse.
Two joysticks support. Switch automatically between mouse or second joystick when a mouse or joystick button is pressed.
\ No newline at end of file
#include "libretro.h"
#include "libretro-core.h"
#include "retroscreen.h"
//CORE VAR
#ifdef _WIN32
char slash = '\\';
......@@ -162,6 +163,7 @@ long GetTicks(void)
extern void retro_run_gui(void);
#endif
int slowdown=0;
int second_joystick_enable = 0;
//NO SURE FIND BETTER WAY TO COME BACK IN MAIN THREAD IN HATARI GUI
void gui_poll_events(void)
{
......@@ -484,8 +486,8 @@ void retro_virtualkb(void)
}
else if(i==-14) //JOY PORT TOGGLE
{
//cur joy toggle
//cur_port++;if(cur_port>2)cur_port=1;
//cur joy toggle
//cur_port++;if(cur_port>2)cur_port=1;
SHOWKEY=-SHOWKEY;
oldi=-1;
}
......@@ -616,11 +618,12 @@ extern int buttonstate[3];
int Retro_PollEvent()
{
// RETRO B Y SLT STA UP DWN LEFT RGT A X L R L2 R2 L3 R3
// INDEX 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// RETRO B Y SLT STA UP DWN LEFT RGT A X L R L2 R2 L3 R3
// INDEX 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
static char vbt[16]={0x10,0x00,0x00,0x00,0x01,0x02,0x04,0x08,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
int i;
static int vbt[16]={0x10,0x00,0x00,0x00,0x01,0x02,0x04,0x08,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
MXjoy[0]=0;
MXjoy[1]=0;
input_poll_cb();
......@@ -649,20 +652,31 @@ int Retro_PollEvent()
if(pauseg==0)
{ // if emulation running
//Joy mode
// Joy mode for first/main joystick.
for(i=RETRO_DEVICE_ID_JOYPAD_B;i<=RETRO_DEVICE_ID_JOYPAD_A;i++)
{
if( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i))
{
MXjoy[0] |= vbt[i]; // Joy press
MXjoy[1] |= vbt[i]; // Joy press
}
}
//if(SHOWKEY==-1)retro_joy0_test(MXjoy[0]);
// second joystick.
for(i=RETRO_DEVICE_ID_JOYPAD_B;i<=RETRO_DEVICE_ID_JOYPAD_A;i++)
{
if( input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, i))
{
MXjoy[1] |= vbt[i]; // Joy press
}
if ((0 != MXjoy[1]) && (0 == second_joystick_enable))
{
LOGI("Switch to joystick mode for Port 0.\n");
MXjoy[1] = 0;
second_joystick_enable = 1;
}
}
#if 0 // Non working at the moment...
if(amiga_devices[0]==RETRO_DEVICE_AMIGA_JOYSTICK)
{
//shortcut for joy mode only
......@@ -696,7 +710,7 @@ if(amiga_devices[0]==RETRO_DEVICE_AMIGA_JOYSTICK)
}
}//if amiga_devices=joy
#endif
}// if pauseg=0
else{
......@@ -704,6 +718,7 @@ else{
}
i=RETRO_DEVICE_ID_JOYPAD_SELECT; //show vkbd toggle
if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 )
{
......@@ -721,6 +736,12 @@ else{
else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) ){
mbt[i]=0;
MOUSE_EMULATED=-MOUSE_EMULATED;
if (MOUSE_EMULATED==1)
{
LOGI("Switch to mouse mode for Port 0.\n");
second_joystick_enable = 0; // disable 2nd joystick if mouse activated...
}
}
if(MOUSE_EMULATED==1){
......@@ -766,6 +787,12 @@ else{
mouse_l |= input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2);
mouse_r |= input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2);
if ((mouse_l || mouse_r) && (second_joystick_enable))
{
mouse_l = mouse_r = 0;
LOGI("Switch to mouse mode for Port 0.\n");
second_joystick_enable = 0; // disble 2nd joystick if mouse activated...
}
static int mmbL=0,mmbR=0;
......
......@@ -96,7 +96,7 @@ void retro_set_environment(retro_environment_t cb)
},
*/
{
"leds_on_screen",
"uae4arm_leds_on_screen",
"Led:; on|off",
},
......@@ -138,7 +138,7 @@ static void update_variables(void)
changed_prefs.gfx_size.height = retroh;
changed_prefs.gfx_resolution = changed_prefs.gfx_size.width > 600 ? 1 : 0;
LOGI("[libretro-vice]: Got size: %u x %u.\n", retrow, retroh);
LOGI("[libretro-uae4arm]: Got size: %u x %u.\n", retrow, retroh);
CROP_WIDTH =retrow;
CROP_HEIGHT= (retroh-80);
......@@ -147,7 +147,7 @@ static void update_variables(void)
//reset_screen();
}
var.key = "leds_on_screen";
var.key = "uae4arm_leds_on_screen";
var.value = NULL;
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
......@@ -382,9 +382,9 @@ LOGI(" (%d)=%d \n",port,device);
void retro_get_system_info(struct retro_system_info *info)
{
memset(info, 0, sizeof(*info));
info->library_name = "uae4arm";
info->library_version = "0.1";
info->valid_extensions = "adf|dms|zip|ipf|adz";
info->library_name = "uae4arm chips/rtype version";
info->library_version = "0.2";
info->valid_extensions = "adf|dms|zip|ipf|hdf|lha|uae";
info->need_fullpath = true;
info->block_extract = false;
}
......
......@@ -239,14 +239,20 @@ void do_mouse_hack (void)
}
extern int second_joystick_enable;
uae_u16 JOY0DAT (void)
{
do_mouse_hack ();
#if defined(__LIBRETRO__)
if (second_joystick_enable)
return joy0dir;
else
return ((uae_u8)mouse_x) | ((uae_u16)mouse_y << 8);
#endif
#ifdef RASPBERRY
if (currprefs.pandora_custom_dpad == 0)
return joy0dir;
......@@ -325,6 +331,7 @@ void inputdevice_vsync (void)
getjoystate (0, &joy1dir, &joy1button);
getjoystate (1, &joy0dir, &joy0button);
if (joy0button!=back_joy0button)
{
back_joy0button= joy0button;
......
......@@ -18,7 +18,7 @@
#include "custom.h"
#include "joystick.h"
extern int MXjoy[2];
extern unsigned char MXjoy[2];
#include "core-log.h"
void read_joystick(int nr, unsigned int *dir, int *button)
......@@ -53,7 +53,7 @@ int but2= b1| b2<< 1;
*button =but2;
//if(MXjoy[nr]!=0)LOGI("joy%d rt:%d db(%d,%d) %d %d\n",nr,MXjoy[nr],*dir,*button,dir2,but2);
//if(MXjoy[nr]!=0)LOGI("AP joy%d u:%d d:%d r:%d l:%d b1:%d b2:%d \n",up,down,right,left,b1,b2);
//if(MXjoy[nr]!=0)LOGI("AP joy%d u:%d d:%d r:%d l:%d b1:%d b2:%d \n",nr,up,down,right,left,b1,b2);
/*
if((nr == 0 && currprefs.pandora_joyPort == 1) || (nr == 1 && currprefs.pandora_joyPort == 0) )
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment