Skip to content

Commit

Permalink
Auto-configuration script + second axis configuration
Browse files Browse the repository at this point in the history
Auto-configuration script: atari5200.py
You can configure the second axis id
  • Loading branch information
jfroco committed May 16, 2016
1 parent 489b753 commit b62f5c9
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 18 deletions.
34 changes: 28 additions & 6 deletions README.1ST
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ RPI version for Atari 5200 emulation
This is a port of Atari800 with focus on emulating Atarin 5200 that adds:

- Full Joystick support for RetroPie
- Autoconfiguration of buttons using Retroarch configuration
- Menu navigation using joystick
- Joystick Button configuration: trigger1, trigger 2 (Moon Patrol and H.E.R.O.!), asterisk and hash.
- Supports hat and axis for joysticks
- Use second analog stick in first as second player stick: Robotron and Space Dungeon!!!
- Use second analog stick in first as second player stick: Robotron and Space Dungeon!!! (configurable axis)
- Ability to define joysticks numbers

(Only player1)

Expand Down Expand Up @@ -38,10 +40,13 @@ SDL_JOY_0_TRIGGER1=1 <-- button ID
SDL_JOY_0_TRIGGER2=2 <-- button ID
SDL_JOY_0_ASTERISK=0 <-- button ID
SDL_JOY_0_HASH=3 <-- button ID
SDL_JOY_0_SECOND_AXIS=2 <-- axis ID
SDL_JOY_0_INDEX=0 <-- index of P1 joystick
SDL_JOY_1_INDEX=1 <-- index of P2 joystick

See sample.cfg

Use jstest application to get the button IDs for your joystick.
Use jstest application to get the axis and button IDs for your joystick.

Compiled and tested on RETROPIE 3.6 using a RPI2:

Expand All @@ -58,11 +63,28 @@ Check emulators.cfg for recommended configuration
Compiled version:
-----------------

cd /opt/retropie/emulators/atari800/bin/
sudo cp atari800 atari800.original
sudo wget https://github.com/jfroco/atari800-rpi/blob/master/atari800?raw=true -O atari800
sudo chmod +x atari800
cd /opt/retropie/emulators/atari800/bin/
sudo cp atari800 atari800.original
sudo wget https://github.com/jfroco/atari800-rpi/blob/master/atari800?raw=true -O atari800
sudo chmod +x atari800

Autoconfiguration
-----------------

You can auto-configure the first joystick to use the current joystick in EmulationStation/Retroarch:

cd /opt/retropie/emulators/atari800/bin/
sudo wget https://github.com/jfroco/atari800-rpi/blob/master/atari5200.py?raw=true -O atari5200.py
sudo chmod +x atari5200.py

Now edit your /opt/retropie/configs/atari5200/emulators.cfg, it should look like this:

atari800="/opt/retropie/emulators/atari800/bin/atari5200.py; /opt/retropie/emulators/atari800/bin/atari800 -5200 -cart-type 4 -cart %ROM%"
default="atari800"

Now everytime you start a game, the atari5200.py script will configure the atari800 emulator joystick for you, respecting current EmulationStation button configuration.

See emulator.cfg


Atari800 emulator version 3.1.0
Expand Down
104 changes: 104 additions & 0 deletions atari5200.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/python

import os, struct, array
from fcntl import ioctl

SDL_JOY_0_SELECT = 8
SDL_JOY_0_START = 9
SDL_JOY_0_TRIGGER1 = 0
SDL_JOY_0_TRIGGER2 = 1
SDL_JOY_0_ASTERISK = 2
SDL_JOY_0_HASH = 3
SDL_JOY_0_SECOND_AXIS = 2

# Iterate over the joystick devices.
# print('Available devices:')

devices = sorted(os.listdir('/dev/input'))
joysticks = []
for fn in devices:
if fn.startswith('js'):
# print(' /dev/input/%s' % fn)
joysticks.append("/dev/input/%s" % fn)

joysticks = sorted(joysticks)

print "First joystick is %s" % joysticks[0]

# Open the joystick device.
fn = joysticks[0]
# print('Opening %s...' % fn)
jsdev = open(fn, 'rb')

buf = array.array('c', ['\0'] * 64)
ioctl(jsdev, 0x80006a13 + (0x10000 * len(buf)), buf) # JSIOCGNAME(len)
js_name = ("%s" % buf.tostring()).partition(b'\0')[0]
# print('Device name: %s' % js_name)

jsdev.close()
js_cfg = "/opt/retropie/configs/all/retroarch-joypads/%s.cfg" % js_name.replace(" ", "")
print "Getting Retroarch configuration for %s" % js_cfg

# print(js_cfg)
f = open("%s" % js_cfg, "r")
content = f.read()
lines = content.split("\n")
for line in lines:
if line:
p = line.replace(" ", "").split("=")
# print "Processing %s" % p[0]
if p[0] == "input_select_btn":
SDL_JOY_0_SELECT = p[1].replace('"', '')
elif p[0] == "input_start_btn":
SDL_JOY_0_START = p[1].replace('"', '')
elif p[0] == "input_a_btn":
SDL_JOY_0_TRIGGER1 = p[1].replace('"', '')
elif p[0] == "input_b_btn":
SDL_JOY_0_TRIGGER2 = p[1].replace('"', '')
elif p[0] == "input_x_btn":
SDL_JOY_0_ASTERISK = p[1].replace('"', '')
elif p[0] == "input_y_btn":
SDL_JOY_0_HASH = p[1].replace('"', '')
elif p[0] == "input_r_x_minus_axis":
SDL_JOY_0_SECOND_AXIS = p[1].replace('"', '').replace("-", "")
f.close()

atari800_cfg = "/home/pi/.atari800.cfg"
print "Updating configuration in %s with" % atari800_cfg
print "SDL_JOY_0_SELECT=%s" % SDL_JOY_0_SELECT
print "SDL_JOY_0_START=%s" % SDL_JOY_0_START
print "SDL_JOY_0_TRIGGER1=%s" % SDL_JOY_0_TRIGGER1
print "SDL_JOY_0_TRIGGER2=%s" % SDL_JOY_0_TRIGGER2
print "SDL_JOY_0_ASTERISK=%s" % SDL_JOY_0_ASTERISK
print "SDL_JOY_0_HASH=%s" % SDL_JOY_0_HASH
print "SDL_JOY_0_SECOND_AXIS=%s" % SDL_JOY_0_SECOND_AXIS


f = open("%s" % atari800_cfg, "r")
content = f.read()
f.close()

new_data = ""
lines = content.split("\n")
for line in lines:
if line.startswith("SDL_JOY_0_SELECT"):
line = "SDL_JOY_0_SELECT=%s" % SDL_JOY_0_SELECT
elif line.startswith("SDL_JOY_0_START"):
line = "SDL_JOY_0_START=%s" % SDL_JOY_0_START
elif line.startswith("SDL_JOY_0_TRIGGER1"):
line = "SDL_JOY_0_TRIGGER1=%s" % SDL_JOY_0_TRIGGER1
elif line.startswith("SDL_JOY_0_TRIGGER2"):
line = "SDL_JOY_0_TRIGGER2=%s" % SDL_JOY_0_TRIGGER2
elif line.startswith("SDL_JOY_0_ASTERISK"):
line = "SDL_JOY_0_ASTERISK=%s" % SDL_JOY_0_ASTERISK
elif line.startswith("SDL_JOY_0_HASH"):
line = "SDL_JOY_0_HASH=%s" % SDL_JOY_0_HASH
elif line.startswith("SDL_JOY_0_SECOND_AXIS"):
line = "SDL_JOY_0_SECOND_AXIS=%s" % SDL_JOY_0_SECOND_AXIS
new_data += line + "\n"

# print new_data

f = open("%s" % atari800_cfg, 'w')
f.write(new_data)
f.close()
Binary file modified atari800
Binary file not shown.
2 changes: 1 addition & 1 deletion emulators.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
atari800="/opt/retropie/emulators/atari800/bin/atari800 -5200 -cart-type 4 -cart %ROM%"
atari800="/opt/retropie/emulators/atari800/bin/atari5200.py; /opt/retropie/emulators/atari800/bin/atari800 -5200 -cart-type 4 -cart %ROM%"
default="atari800"
11 changes: 7 additions & 4 deletions sample.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ MIO_ROM=
BLACK_BOX_ROM=
XLD_D_ROM=
XLD_V_ROM=
CARTRIDGE_FILENAME=/home/pi/RetroPie/roms/atari5200/Moon Patrol.a52
CARTRIDGE_FILENAME=/home/pi/RetroPie/roms/atari5200/H.E.R.O..a52
CARTRIDGE_TYPE=4
CARTRIDGE_PIGGYBACK_FILENAME=
CARTRIDGE_PIGGYBACK_TYPE=0
Expand Down Expand Up @@ -116,6 +116,9 @@ SDL_JOY_1_TRIGGER=306
SDL_JOY_0_SELECT=8
SDL_JOY_0_START=9
SDL_JOY_0_TRIGGER1=1
SDL_JOY_0_TRIGGER2=2
SDL_JOY_0_ASTERISK=0
SDL_JOY_0_HASH=3
SDL_JOY_0_TRIGGER2=0
SDL_JOY_0_ASTERISK=3
SDL_JOY_0_HASH=2
SDL_JOY_0_SECOND_AXIS=2
SDL_JOY_0_INDEX=0
SDL_JOY_1_INDEX=1
19 changes: 12 additions & 7 deletions src/sdl/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ static int JOY_0_ASTERISK = 3;
static int JOY_0_HASH= 0;
static int JOY_0_START = 9;
static int JOY_0_SELECT = 8;
static int JOY_0_SECOND_AXIS = 2;
static int JOY_0_INDEX=0;
static int JOY_1_INDEX=1;

Expand Down Expand Up @@ -203,11 +204,15 @@ int SDL_INPUT_ReadConfig(char *option, char *parameters)
if (parameters != NULL) JOY_0_HASH = atoi(parameters);
return TRUE;
}
else if (strcmp(option, "SDL_JOY_0_INDEX") == 0) {
else if (strcmp(option, "SDL_JOY_0_SECOND_AXIS") == 0) {
if (parameters != NULL) JOY_0_SECOND_AXIS = atoi(parameters);
return TRUE;
}
else if (strcmp(option, "SDL_JOY_0_INDEX") == 0) {
if (parameters != NULL) JOY_0_INDEX = atoi(parameters);
return TRUE;
}
else if (strcmp(option, "SDL_JOY_1_INDEX") == 0) {
else if (strcmp(option, "SDL_JOY_1_INDEX") == 0) {
if (parameters != NULL) JOY_1_INDEX = atoi(parameters);
return TRUE;
}
Expand Down Expand Up @@ -240,8 +245,9 @@ void SDL_INPUT_WriteConfig(FILE *fp)
fprintf(fp, "SDL_JOY_0_TRIGGER2=%d\n", JOY_0_TRIGGER2);
fprintf(fp, "SDL_JOY_0_ASTERISK=%d\n", JOY_0_ASTERISK);
fprintf(fp, "SDL_JOY_0_HASH=%d\n", JOY_0_HASH);
fprintf(fp, "SDL_JOY_0_INDEX=%d\n", JOY_0_INDEX);
fprintf(fp, "SDL_JOY_1_INDEX=%d\n", JOY_1_INDEX);
fprintf(fp, "SDL_JOY_0_SECOND_AXIS=%d\n", JOY_0_SECOND_AXIS);
fprintf(fp, "SDL_JOY_0_INDEX=%d\n", JOY_0_INDEX);
fprintf(fp, "SDL_JOY_1_INDEX=%d\n", JOY_1_INDEX);
}

void PLATFORM_SetJoystickKey(int joystick, int direction, int value)
Expand Down Expand Up @@ -1498,9 +1504,8 @@ static void update_SDL_joysticks(void)
}

/* Use second analog control in joystick0 as sencond player stick for ROBOTRON-like games*/
if (joystick0 != NULL && sdl_js_state[1].port == INPUT_STICK_CENTRE)
sdl_js_state[1].port = get_SDL_joystick_state(joystick0, 2);

if ((joystick0 != NULL) && ( joystick1 == NULL || sdl_js_state[1].port == INPUT_STICK_CENTRE))
sdl_js_state[1].port = get_SDL_joystick_state(joystick0, JOY_0_SECOND_AXIS);


}
Expand Down

0 comments on commit b62f5c9

Please sign in to comment.