Add support for four controllers.

This commit is contained in:
raphkoster
2019-06-23 23:03:59 -07:00
parent af0ba7263b
commit 609378be70
3 changed files with 104 additions and 41 deletions
+29 -22
View File
@@ -63,7 +63,7 @@ int touch=-1; // gui mouse btn
//JOY //JOY
int al[2][2];//left analog1 int al[2][2];//left analog1
int ar[2][2];//right analog1 int ar[2][2];//right analog1
unsigned char MXjoy[2]; // joy unsigned char MXjoy[4]; // joy
#define JOYRANGE_UP_VALUE -16384 /* Joystick ranges in XY */ #define JOYRANGE_UP_VALUE -16384 /* Joystick ranges in XY */
#define JOYRANGE_DOWN_VALUE 16383 #define JOYRANGE_DOWN_VALUE 16383
@@ -171,7 +171,7 @@ int RSTOPON=-1;
int CTRLON=-1; int CTRLON=-1;
extern unsigned short int bmp[400*300]; extern unsigned short int bmp[400*300];
extern unsigned atari_devices[ 2 ]; extern unsigned atari_devices[ 4 ];
extern int UI_is_active; extern int UI_is_active;
extern int CURRENT_TV; extern int CURRENT_TV;
@@ -401,13 +401,13 @@ void Process_key()
if(i==RETROK_LALT){ if(i==RETROK_LALT){
KBMOD=-KBMOD; KBMOD=-KBMOD;
printf("Modifier alt pressed %d \n",KBMOD); printf("Modifier alt pressed %d \n",KBMOD);
continue; continue;
} }
//printf("press: %d \n",i); //printf("press: %d \n",i);
//retro_key_down(i); //retro_key_down(i);
} }
else if ( !Key_Sate[i] && Key_Sate[i]!=old_Key_Sate[i] ) else if ( !Key_Sate[i] && Key_Sate[i]!=old_Key_Sate[i] )
{ {
/* /*
@@ -417,25 +417,25 @@ void Process_key()
*/ */
if(i==RETROK_RCTRL){ if(i==RETROK_RCTRL){
CTRLON=-CTRLON; CTRLON=-CTRLON;
printf("Modifier crtl released %d \n",CTRLON); printf("Modifier crtl released %d \n",CTRLON);
continue; continue;
} }
if(i==RETROK_RSHIFT){ if(i==RETROK_RSHIFT){
SHIFTON=-SHIFTON; SHIFTON=-SHIFTON;
printf("Modifier shift released %d \n",SHIFTON); printf("Modifier shift released %d \n",SHIFTON);
continue; continue;
} }
if(i==RETROK_LALT){ if(i==RETROK_LALT){
KBMOD=-KBMOD; KBMOD=-KBMOD;
printf("Modifier alt released %d \n",KBMOD); printf("Modifier alt released %d \n",KBMOD);
continue; continue;
} }
//printf("release: %d \n",i); //printf("release: %d \n",i);
//retro_key_up(i); //retro_key_up(i);
} }
memcpy(old_Key_Sate,Key_Sate , sizeof(Key_Sate) ); memcpy(old_Key_Sate,Key_Sate , sizeof(Key_Sate) );
@@ -446,9 +446,11 @@ int Retro_PollEvent()
// RETRO B Y SLT STA UP DWN LEFT RGT A X L R L2 R2 L3 R3 // 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 // INDEX 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int SAVPAS=PAS; int SAVPAS=PAS;
int i,j; int i,j;
static int vbt[2][16]={ static int vbt[4][16]={
{0x0,0x0,0x0,0x0,0x01,0x02,0x04,0x08,0x80,0x40,0x0,0x0,0x0,0x0,0x0,0x0},
{0x0,0x0,0x0,0x0,0x01,0x02,0x04,0x08,0x80,0x40,0x0,0x0,0x0,0x0,0x0,0x0},
{0x0,0x0,0x0,0x0,0x01,0x02,0x04,0x08,0x80,0x40,0x0,0x0,0x0,0x0,0x0,0x0}, {0x0,0x0,0x0,0x0,0x01,0x02,0x04,0x08,0x80,0x40,0x0,0x0,0x0,0x0,0x0,0x0},
{0x0,0x0,0x0,0x0,0x01,0x02,0x04,0x08,0x80,0x40,0x0,0x0,0x0,0x0,0x0,0x0}, {0x0,0x0,0x0,0x0,0x01,0x02,0x04,0x08,0x80,0x40,0x0,0x0,0x0,0x0,0x0,0x0},
}; };
@@ -462,15 +464,16 @@ int Retro_PollEvent()
if(SHOWKEY==-1 && pauseg==0)Process_key(); if(SHOWKEY==-1 && pauseg==0)Process_key();
//Joy mode
//Joy mode for(j=0;j<4;j++){
for(j=0;j<2;j++){
for(i=4;i<10;i++) for(i=4;i<10;i++)
{ {
if( input_state_cb(j, RETRO_DEVICE_JOYPAD, 0, i)) if( input_state_cb(j, RETRO_DEVICE_JOYPAD, 0, i)) {
MXjoy[j] |= vbt[j][i]; // Joy press MXjoy[j] |= vbt[j][i]; // Joy press
else if( MXjoy[j]&vbt[j][i])MXjoy[j] &= ~vbt[j][i]; // Joy press fprintf(stderr, "[Libretro-atari800]: MXjoy press controller %u slot %u.\n", j, i);
}
else if( MXjoy[j]&vbt[j][i])MXjoy[j] &= ~vbt[j][i]; // Joy press
} }
} }
@@ -505,8 +508,10 @@ int Retro_PollEvent()
// 0 1 2 3 // 0 1 2 3
for(i=0;i<4;i++){ for(i=0;i<4;i++){
if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 ) if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 ) {
mbt[i]=1; mbt[i]=1;
fprintf(stderr, "[Libretro-atari800]: atari_devices press slot %u.\n", i);
}
else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) ) else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
{ {
mbt[i]=0; mbt[i]=0;
@@ -517,8 +522,10 @@ int Retro_PollEvent()
// 10 11 12 13 14 15 // 10 11 12 13 14 15
for(i=10;i<16;i++){ for(i=10;i<16;i++){
if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 ) if ( input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) && mbt[i]==0 ) {
fprintf(stderr, "[Libretro-atari800]: atari_devices press slot %u.\n", i);
mbt[i]=1; mbt[i]=1;
}
else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) ) else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
{ {
mbt[i]=0; mbt[i]=0;
@@ -559,7 +566,7 @@ int Retro_PollEvent()
if(mmbL==0 && mouse_l){ if(mmbL==0 && mouse_l){
mmbL=1; mmbL=1;
pushi=1; pushi=1;
touch=1; touch=1;
@@ -572,7 +579,7 @@ int Retro_PollEvent()
} }
if(mmbR==0 && mouse_r){ if(mmbR==0 && mouse_r){
mmbR=1; mmbR=1;
} }
else if(mmbR==1 && !mouse_r) { else if(mmbR==1 && !mouse_r) {
mmbR=0; mmbR=0;
+16 -7
View File
@@ -20,7 +20,7 @@ int retroh=300;
#define RETRO_DEVICE_ATARI_KEYBOARD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 0) #define RETRO_DEVICE_ATARI_KEYBOARD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 0)
#define RETRO_DEVICE_ATARI_JOYSTICK RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1) #define RETRO_DEVICE_ATARI_JOYSTICK RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1)
unsigned atari_devices[ 2 ]; unsigned atari_devices[ 4 ];
int keyboard_type=0; int keyboard_type=0;
int autorun5200=0; int autorun5200=0;
@@ -72,11 +72,20 @@ void retro_set_environment(retro_environment_t cb)
{ "ATARI Joystick", RETRO_DEVICE_ATARI_JOYSTICK }, { "ATARI Joystick", RETRO_DEVICE_ATARI_JOYSTICK },
{ "ATARI Keyboard", RETRO_DEVICE_ATARI_KEYBOARD }, { "ATARI Keyboard", RETRO_DEVICE_ATARI_KEYBOARD },
}; };
static const struct retro_controller_description p3_controllers[] = {
{ "ATARI Joystick", RETRO_DEVICE_ATARI_JOYSTICK },
{ "ATARI Keyboard", RETRO_DEVICE_ATARI_KEYBOARD },
};
static const struct retro_controller_description p4_controllers[] = {
{ "ATARI Joystick", RETRO_DEVICE_ATARI_JOYSTICK },
{ "ATARI Keyboard", RETRO_DEVICE_ATARI_KEYBOARD },
};
static const struct retro_controller_info ports[] = { static const struct retro_controller_info ports[] = {
{ p1_controllers, 2 }, // port 1 { p1_controllers, 2 }, // port 1
{ p2_controllers, 2 }, // port 2 { p2_controllers, 2 }, // port 2
{ p3_controllers, 2 }, // port 3
{ p4_controllers, 2 }, // port 4
{ NULL, 0 } { NULL, 0 }
}; };
@@ -551,7 +560,7 @@ unsigned retro_api_version(void)
void retro_set_controller_port_device( unsigned port, unsigned device ) void retro_set_controller_port_device( unsigned port, unsigned device )
{ {
if ( port < 2 ) if ( port < 4 )
{ {
atari_devices[ port ] = device; atari_devices[ port ] = device;
@@ -742,15 +751,15 @@ bool retro_unserialize(const void *data_, size_t size)
void *retro_get_memory_data(unsigned id) void *retro_get_memory_data(unsigned id)
{ {
if ( id == RETRO_MEMORY_SYSTEM_RAM ) if ( id == RETRO_MEMORY_SYSTEM_RAM )
return MEMORY_mem; return MEMORY_mem;
return NULL; return NULL;
} }
size_t retro_get_memory_size(unsigned id) size_t retro_get_memory_size(unsigned id)
{ {
if ( id == RETRO_MEMORY_SYSTEM_RAM ) if ( id == RETRO_MEMORY_SYSTEM_RAM )
return 65536; return 65536;
return 0; return 0;
} }
+59 -12
View File
@@ -49,7 +49,9 @@ extern int UI_is_active;
static int swap_joysticks = FALSE; static int swap_joysticks = FALSE;
int PLATFORM_kbd_joy_0_enabled = TRUE; /* enabled by default, doesn't hurt */ int PLATFORM_kbd_joy_0_enabled = TRUE; /* enabled by default, doesn't hurt */
int PLATFORM_kbd_joy_1_enabled = TRUE;//FALSE; /* disabled, would steal normal keys */ int PLATFORM_kbd_joy_1_enabled = TRUE;//FALSE; /* disabled, would steal normal keys */
extern unsigned char MXjoy[2]; // joy int PLATFORM_kbd_joy_2_enabled = TRUE;//FALSE; /* disabled, would steal normal keys */
int PLATFORM_kbd_joy_3_enabled = TRUE;//FALSE; /* disabled, would steal normal keys */
extern unsigned char MXjoy[4]; // joy
extern int mbt[16]; extern int mbt[16];
extern int retro_sound_finalized; extern int retro_sound_finalized;
@@ -655,10 +657,10 @@ void PLATFORM_PaletteUpdate(void)
retro_PaletteUpdate(); retro_PaletteUpdate();
} }
static void get_platform_PORT(unsigned char *s0, unsigned char *s1) static void get_platform_PORT(unsigned char *s0, unsigned char *s1, unsigned char *s2, unsigned char *s3)
{ {
int stick0, stick1; int stick0, stick1, stick2, stick3;
stick0 = stick1 = INPUT_STICK_CENTRE; stick0 = stick1 = stick2 = stick3 = INPUT_STICK_CENTRE;
if (PLATFORM_kbd_joy_0_enabled) { if (PLATFORM_kbd_joy_0_enabled) {
if (MXjoy[0]&0x04) if (MXjoy[0]&0x04)
@@ -680,24 +682,47 @@ static void get_platform_PORT(unsigned char *s0, unsigned char *s1)
stick1 &= INPUT_STICK_FORWARD; stick1 &= INPUT_STICK_FORWARD;
if (MXjoy[1]&0x02) if (MXjoy[1]&0x02)
stick1 &= INPUT_STICK_BACK; stick1 &= INPUT_STICK_BACK;
}
if (PLATFORM_kbd_joy_2_enabled) {
if (MXjoy[2]&0x04)
stick2 &= INPUT_STICK_LEFT;
if (MXjoy[2]&0x08)
stick2 &= INPUT_STICK_RIGHT;
if (MXjoy[2]&0x01)
stick2 &= INPUT_STICK_FORWARD;
if (MXjoy[2]&0x02)
stick2 &= INPUT_STICK_BACK;
}
if (PLATFORM_kbd_joy_3_enabled) {
if (MXjoy[3]&0x04)
stick3 &= INPUT_STICK_LEFT;
if (MXjoy[3]&0x08)
stick3 &= INPUT_STICK_RIGHT;
if (MXjoy[3]&0x01)
stick3 &= INPUT_STICK_FORWARD;
if (MXjoy[3]&0x02)
stick3 &= INPUT_STICK_BACK;
} }
if (swap_joysticks) { if (swap_joysticks) {
*s1 = stick0; *s1 = stick0;
*s0 = stick1; *s0 = stick1;
*s2 = stick2;
*s3 = stick3;
} }
else { else {
*s0 = stick0; *s0 = stick0;
*s1 = stick1; *s1 = stick1;
*s2 = stick2;
*s3 = stick3;
} }
} }
static void get_platform_TRIG(unsigned char *t0, unsigned char *t1) static void get_platform_TRIG(unsigned char *t0, unsigned char *t1, unsigned char *t2, unsigned char *t3)
{ {
int trig0, trig1; int trig0, trig1, trig2, trig3;
trig0 = trig1 = 1; trig0 = trig1 = trig2 = trig3 = 1;
if (PLATFORM_kbd_joy_0_enabled) { if (PLATFORM_kbd_joy_0_enabled) {
trig0 = MXjoy[0]&0x80?0:1; trig0 = MXjoy[0]&0x80?0:1;
@@ -707,13 +732,25 @@ static void get_platform_TRIG(unsigned char *t0, unsigned char *t1)
trig1 = MXjoy[1]&0x80?0:1; trig1 = MXjoy[1]&0x80?0:1;
} }
if (PLATFORM_kbd_joy_2_enabled) {
trig2 = MXjoy[2]&0x80?0:1;
}
if (PLATFORM_kbd_joy_3_enabled) {
trig3 = MXjoy[3]&0x80?0:1;
}
if (swap_joysticks) { if (swap_joysticks) {
*t1 = trig0; *t1 = trig0;
*t0 = trig1; *t0 = trig1;
*t2 = trig2;
*t3 = trig3;
} }
else { else {
*t0 = trig0; *t0 = trig0;
*t1 = trig1; *t1 = trig1;
*t2 = trig2;
*t3 = trig3;
} }
} }
@@ -721,25 +758,35 @@ static void get_platform_TRIG(unsigned char *t0, unsigned char *t1)
int PLATFORM_PORT(int num) int PLATFORM_PORT(int num)
{ {
if (num == 0) { if (num == 0) {
UBYTE a, b; UBYTE a, b, c, d;
get_platform_PORT(&a, &b); get_platform_PORT(&a, &b, &c, &d);
return (b << 4) | (a & 0x0f); return (b << 4) | (a & 0x0f);
} }
if (num == 1) {
UBYTE a, b, c, d;
get_platform_PORT(&a, &b, &c, &d);
return (d << 4) | (c & 0x0f);
}
return 0xff; return 0xff;
} }
int PLATFORM_TRIG(int num) int PLATFORM_TRIG(int num)
{ {
UBYTE a, b; UBYTE a, b, c, d;
get_platform_TRIG(&a, &b); get_platform_TRIG(&a, &b, &c, &d);
switch (num) { switch (num) {
case 0: case 0:
return a; return a;
case 1: case 1:
return b; return b;
case 2:
return c;
case 3:
return d;
default: default:
break; break;
} }