Skip to content

Commit

Permalink
Add support for four controllers.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphkoster committed Jun 24, 2019
1 parent af0ba72 commit 609378b
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 41 deletions.
51 changes: 29 additions & 22 deletions libretro/core-mapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ int touch=-1; // gui mouse btn
//JOY
int al[2][2];//left 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_DOWN_VALUE 16383
Expand Down Expand Up @@ -171,7 +171,7 @@ int RSTOPON=-1;
int CTRLON=-1;

extern unsigned short int bmp[400*300];
extern unsigned atari_devices[ 2 ];
extern unsigned atari_devices[ 4 ];

extern int UI_is_active;
extern int CURRENT_TV;
Expand Down Expand Up @@ -401,13 +401,13 @@ void Process_key()

if(i==RETROK_LALT){
KBMOD=-KBMOD;
printf("Modifier alt pressed %d \n",KBMOD);
printf("Modifier alt pressed %d \n",KBMOD);
continue;
}
//printf("press: %d \n",i);
//retro_key_down(i);
}

}
else if ( !Key_Sate[i] && Key_Sate[i]!=old_Key_Sate[i] )
{
/*
Expand All @@ -417,25 +417,25 @@ void Process_key()
*/
if(i==RETROK_RCTRL){
CTRLON=-CTRLON;
printf("Modifier crtl released %d \n",CTRLON);
printf("Modifier crtl released %d \n",CTRLON);
continue;
}
if(i==RETROK_RSHIFT){
SHIFTON=-SHIFTON;
printf("Modifier shift released %d \n",SHIFTON);
printf("Modifier shift released %d \n",SHIFTON);
continue;
}

if(i==RETROK_LALT){
KBMOD=-KBMOD;
printf("Modifier alt released %d \n",KBMOD);
printf("Modifier alt released %d \n",KBMOD);
continue;
}

//printf("release: %d \n",i);
//retro_key_up(i);
}

}

memcpy(old_Key_Sate,Key_Sate , sizeof(Key_Sate) );

Expand All @@ -446,9 +446,11 @@ 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

int SAVPAS=PAS;
int SAVPAS=PAS;
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},
};
Expand All @@ -462,15 +464,16 @@ int Retro_PollEvent()

if(SHOWKEY==-1 && pauseg==0)Process_key();


//Joy mode
for(j=0;j<2;j++){
//Joy mode
for(j=0;j<4;j++){

for(i=4;i<10;i++)
{
if( input_state_cb(j, RETRO_DEVICE_JOYPAD, 0, i))
MXjoy[j] |= vbt[j][i]; // Joy press
else if( MXjoy[j]&vbt[j][i])MXjoy[j] &= ~vbt[j][i]; // Joy press
if( input_state_cb(j, RETRO_DEVICE_JOYPAD, 0, 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
}

}
Expand Down Expand Up @@ -505,8 +508,10 @@ int Retro_PollEvent()
// 0 1 2 3
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;
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) )
{
mbt[i]=0;
Expand All @@ -517,8 +522,10 @@ int Retro_PollEvent()
// 10 11 12 13 14 15
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;
}
else if ( mbt[i]==1 && ! input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i) )
{
mbt[i]=0;
Expand Down Expand Up @@ -559,7 +566,7 @@ int Retro_PollEvent()

if(mmbL==0 && mouse_l){

mmbL=1;
mmbL=1;
pushi=1;
touch=1;

Expand All @@ -572,7 +579,7 @@ int Retro_PollEvent()
}

if(mmbR==0 && mouse_r){
mmbR=1;
mmbR=1;
}
else if(mmbR==1 && !mouse_r) {
mmbR=0;
Expand Down
23 changes: 16 additions & 7 deletions libretro/libretro-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ int retroh=300;
#define RETRO_DEVICE_ATARI_KEYBOARD RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_KEYBOARD, 0)
#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 autorun5200=0;
Expand Down Expand Up @@ -72,11 +72,20 @@ void retro_set_environment(retro_environment_t cb)
{ "ATARI Joystick", RETRO_DEVICE_ATARI_JOYSTICK },
{ "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[] = {
{ p1_controllers, 2 }, // port 1
{ p2_controllers, 2 }, // port 2
{ p3_controllers, 2 }, // port 3
{ p4_controllers, 2 }, // port 4
{ NULL, 0 }
};

Expand Down Expand Up @@ -551,7 +560,7 @@ unsigned retro_api_version(void)

void retro_set_controller_port_device( unsigned port, unsigned device )
{
if ( port < 2 )
if ( port < 4 )
{
atari_devices[ port ] = device;

Expand Down Expand Up @@ -742,15 +751,15 @@ bool retro_unserialize(const void *data_, size_t size)

void *retro_get_memory_data(unsigned id)
{
if ( id == RETRO_MEMORY_SYSTEM_RAM )
return MEMORY_mem;
if ( id == RETRO_MEMORY_SYSTEM_RAM )
return MEMORY_mem;
return NULL;
}

size_t retro_get_memory_size(unsigned id)
{
if ( id == RETRO_MEMORY_SYSTEM_RAM )
return 65536;
if ( id == RETRO_MEMORY_SYSTEM_RAM )
return 65536;
return 0;
}

Expand Down
71 changes: 59 additions & 12 deletions libretro/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ extern int UI_is_active;
static int swap_joysticks = FALSE;
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 */
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 retro_sound_finalized;

Expand Down Expand Up @@ -655,10 +657,10 @@ void PLATFORM_PaletteUpdate(void)
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;
stick0 = stick1 = INPUT_STICK_CENTRE;
int stick0, stick1, stick2, stick3;
stick0 = stick1 = stick2 = stick3 = INPUT_STICK_CENTRE;

if (PLATFORM_kbd_joy_0_enabled) {
if (MXjoy[0]&0x04)
Expand All @@ -680,24 +682,47 @@ static void get_platform_PORT(unsigned char *s0, unsigned char *s1)
stick1 &= INPUT_STICK_FORWARD;
if (MXjoy[1]&0x02)
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) {
*s1 = stick0;
*s0 = stick1;
*s2 = stick2;
*s3 = stick3;
}
else {
*s0 = stick0;
*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;
trig0 = trig1 = 1;
int trig0, trig1, trig2, trig3;
trig0 = trig1 = trig2 = trig3 = 1;

if (PLATFORM_kbd_joy_0_enabled) {
trig0 = MXjoy[0]&0x80?0:1;
Expand All @@ -707,39 +732,61 @@ static void get_platform_TRIG(unsigned char *t0, unsigned char *t1)
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) {
*t1 = trig0;
*t0 = trig1;
*t2 = trig2;
*t3 = trig3;
}
else {
*t0 = trig0;
*t1 = trig1;
*t2 = trig2;
*t3 = trig3;
}

}

int PLATFORM_PORT(int num)
{
if (num == 0) {
UBYTE a, b;
get_platform_PORT(&a, &b);
UBYTE a, b, c, d;
get_platform_PORT(&a, &b, &c, &d);

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;
}

int PLATFORM_TRIG(int num)
{
UBYTE a, b;
get_platform_TRIG(&a, &b);
UBYTE a, b, c, d;
get_platform_TRIG(&a, &b, &c, &d);

switch (num) {
case 0:
return a;
case 1:
return b;
case 2:
return c;
case 3:
return d;
default:
break;
}
Expand Down

0 comments on commit 609378b

Please sign in to comment.