mirror of
https://github.com/RaySollium99/libpicofe.git
synced 2025-09-05 14:57:46 -04:00
extracted OSS code to sndout_oss_*, BTN->PBTN, refactoring
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@599 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
725d7f6c16
commit
b3972d826f
21 changed files with 386 additions and 478 deletions
|
@ -54,14 +54,14 @@ LD = $(CROSS)ld
|
|||
OBJCOPY = $(CROSS)objcopy
|
||||
|
||||
# frontend
|
||||
OBJS += main.o menu.o gp2x.o usbjoy.o emu.o squidgehack.o cpuctrl.o
|
||||
OBJS += main.o menu.o gp2x.o emu.o squidgehack.o cpuctrl.o
|
||||
# 940 core control
|
||||
OBJS += 940ctl.o
|
||||
|
||||
# common
|
||||
OBJS += platform/common/emu.o platform/common/menu.o platform/common/fonts.o platform/common/config.o \
|
||||
platform/common/arm_utils.o platform/common/arm_linux.o platform/common/readpng.o \
|
||||
platform/common/mp3_helix.o
|
||||
platform/common/mp3_helix.o platform/linux/usbjoy.o platform/linux/sndout_oss.o
|
||||
|
||||
# Pico
|
||||
ifeq "$(amalgamate)" "1"
|
||||
|
@ -116,8 +116,8 @@ endif
|
|||
vpath %.c = ../..
|
||||
vpath %.s = ../..
|
||||
vpath %.S = ../..
|
||||
DIRS = platform platform/gp2x platform/common pico pico/cd pico/pico pico/sound pico/carthw/svp \
|
||||
zlib unzip cpu cpu/musashi cpu/Cyclone/proj cpu/Cyclone/tools cpu/mz80 cpu/DrZ80
|
||||
DIRS = platform platform/gp2x platform/linux platform/common pico pico/cd pico/pico pico/sound \
|
||||
pico/carthw/svp zlib unzip cpu cpu/musashi cpu/Cyclone/proj cpu/Cyclone/tools cpu/mz80 cpu/DrZ80
|
||||
|
||||
|
||||
all: mkdirs PicoDrive.gpe
|
||||
|
|
15
gp2x/emu.c
15
gp2x/emu.c
|
@ -16,12 +16,13 @@
|
|||
|
||||
#include "emu.h"
|
||||
#include "gp2x.h"
|
||||
#include "usbjoy.h"
|
||||
#include "menu.h"
|
||||
#include "../linux/usbjoy.h"
|
||||
#include "../common/arm_utils.h"
|
||||
#include "../common/fonts.h"
|
||||
#include "../common/emu.h"
|
||||
#include "../common/config.h"
|
||||
#include "../linux/sndout_oss.h"
|
||||
#include "cpuctrl.h"
|
||||
|
||||
#include <pico/pico_int.h>
|
||||
|
@ -487,7 +488,7 @@ static void update_volume(int has_changed, int is_up)
|
|||
if (vol > 0) vol--;
|
||||
}
|
||||
wait_frames = 0;
|
||||
gp2x_sound_volume(vol, vol);
|
||||
sndout_oss_setvol(vol, vol);
|
||||
currentConfig.volume = vol;
|
||||
}
|
||||
sprintf(noticeMsg, "VOL: %02i", vol);
|
||||
|
@ -614,9 +615,9 @@ static void updateKeys(void)
|
|||
// add joy inputs
|
||||
if (num_of_joys > 0)
|
||||
{
|
||||
gp2x_usbjoy_update();
|
||||
usbjoy_update();
|
||||
for (joy = 0; joy < num_of_joys; joy++) {
|
||||
int btns = gp2x_usbjoy_check2(joy);
|
||||
int btns = usbjoy_check2(joy);
|
||||
for (i = 0; i < 32; i++) {
|
||||
if (btns & (1 << i)) {
|
||||
int acts = currentConfig.JoyBinds[joy][i];
|
||||
|
@ -662,7 +663,7 @@ static void updateSound(int len)
|
|||
|
||||
/* avoid writing audio when lagging behind to prevent audio lag */
|
||||
if (PicoSkipFrame != 2)
|
||||
gp2x_sound_write(PsndOut, len<<1);
|
||||
sndout_oss_write(PsndOut, len<<1);
|
||||
}
|
||||
|
||||
void emu_startSound(void)
|
||||
|
@ -683,8 +684,8 @@ void emu_startSound(void)
|
|||
snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;
|
||||
printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",
|
||||
PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal);
|
||||
gp2x_start_sound(PsndRate, 16, (PicoOpt&8)>>3);
|
||||
gp2x_sound_volume(currentConfig.volume, currentConfig.volume);
|
||||
sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3);
|
||||
sndout_oss_setvol(currentConfig.volume, currentConfig.volume);
|
||||
PicoWriteSound = updateSound;
|
||||
update_volume(0, 0);
|
||||
memset(sndBuffer, 0, sizeof(sndBuffer));
|
||||
|
|
81
gp2x/gp2x.c
81
gp2x/gp2x.c
|
@ -28,13 +28,12 @@
|
|||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/soundcard.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "gp2x.h"
|
||||
#include "usbjoy.h"
|
||||
#include "../linux/usbjoy.h"
|
||||
#include "../linux/sndout_oss.h"
|
||||
#include "../common/arm_utils.h"
|
||||
#include "../common/arm_linux.h"
|
||||
|
||||
|
@ -45,7 +44,7 @@ static void *gp2x_screens[4];
|
|||
static int screensel = 0;
|
||||
//static
|
||||
int memdev = 0;
|
||||
static int sounddev = -1, mixerdev = -1, touchdev = -1;
|
||||
static int touchdev = -1;
|
||||
static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 };
|
||||
|
||||
void *gp2x_screen;
|
||||
|
@ -210,9 +209,9 @@ unsigned long gp2x_joystick_read(int allow_usb_joy)
|
|||
|
||||
if (allow_usb_joy && num_of_joys > 0) {
|
||||
// check the usb joy as well..
|
||||
gp2x_usbjoy_update();
|
||||
usbjoy_update();
|
||||
for (i = 0; i < num_of_joys; i++)
|
||||
value |= gp2x_usbjoy_check(i);
|
||||
value |= usbjoy_check(i);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
@ -251,57 +250,6 @@ int gp2x_touchpad_read(int *x, int *y)
|
|||
}
|
||||
|
||||
|
||||
static int s_oldrate = 0, s_oldbits = 0, s_oldstereo = 0;
|
||||
|
||||
void gp2x_start_sound(int rate, int bits, int stereo)
|
||||
{
|
||||
int frag = 0, bsize, buffers;
|
||||
|
||||
// if no settings change, we don't need to do anything
|
||||
if (rate == s_oldrate && s_oldbits == bits && s_oldstereo == stereo) return;
|
||||
|
||||
if (sounddev > 0) close(sounddev);
|
||||
sounddev = open("/dev/dsp", O_WRONLY|O_ASYNC);
|
||||
if (sounddev == -1)
|
||||
printf("open(\"/dev/dsp\") failed with %i\n", errno);
|
||||
|
||||
ioctl(sounddev, SNDCTL_DSP_SETFMT, &bits);
|
||||
ioctl(sounddev, SNDCTL_DSP_SPEED, &rate);
|
||||
ioctl(sounddev, SNDCTL_DSP_STEREO, &stereo);
|
||||
// calculate buffer size
|
||||
buffers = 16;
|
||||
bsize = rate / 32;
|
||||
if (rate > 22050) { bsize*=4; buffers*=2; } // 44k mode seems to be very demanding
|
||||
while ((bsize>>=1)) frag++;
|
||||
frag |= buffers<<16; // 16 buffers
|
||||
ioctl(sounddev, SNDCTL_DSP_SETFRAGMENT, &frag);
|
||||
usleep(192*1024);
|
||||
|
||||
printf("gp2x_set_sound: %i/%ibit/%s, %i buffers of %i bytes\n",
|
||||
rate, bits, stereo?"stereo":"mono", frag>>16, 1<<(frag&0xffff));
|
||||
|
||||
s_oldrate = rate; s_oldbits = bits; s_oldstereo = stereo;
|
||||
}
|
||||
|
||||
|
||||
void gp2x_sound_write(void *buff, int len)
|
||||
{
|
||||
write(sounddev, buff, len);
|
||||
}
|
||||
|
||||
void gp2x_sound_sync(void)
|
||||
{
|
||||
ioctl(sounddev, SOUND_PCM_SYNC, 0);
|
||||
}
|
||||
|
||||
void gp2x_sound_volume(int l, int r)
|
||||
{
|
||||
l=l<0?0:l; l=l>255?255:l; r=r<0?0:r; r=r>255?255:r;
|
||||
l<<=8; l|=r;
|
||||
ioctl(mixerdev, SOUND_MIXER_WRITE_PCM, &l); /*SOUND_MIXER_WRITE_VOLUME*/
|
||||
}
|
||||
|
||||
|
||||
/* 940 */
|
||||
void Pause940(int yes)
|
||||
{
|
||||
|
@ -352,7 +300,7 @@ void gp2x_init(void)
|
|||
memdev = open("/dev/mem", O_RDWR);
|
||||
if (memdev == -1)
|
||||
{
|
||||
printf("open(\"/dev/mem\") failed with %i\n", errno);
|
||||
perror("open(\"/dev/mem\")");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
@ -360,7 +308,7 @@ void gp2x_init(void)
|
|||
printf("memregs are @ %p\n", gp2x_memregs);
|
||||
if(gp2x_memregs == MAP_FAILED)
|
||||
{
|
||||
printf("mmap(memregs) failed with %i\n", errno);
|
||||
perror("mmap(memregs)");
|
||||
exit(1);
|
||||
}
|
||||
gp2x_memregl = (unsigned long *) gp2x_memregs;
|
||||
|
@ -370,7 +318,7 @@ void gp2x_init(void)
|
|||
gp2x_screens[0] = mmap(0, FRAMEBUFF_WHOLESIZE, PROT_WRITE, MAP_SHARED, memdev, FRAMEBUFF_ADDR0);
|
||||
if(gp2x_screens[0] == MAP_FAILED)
|
||||
{
|
||||
printf("mmap(gp2x_screen) failed with %i\n", errno);
|
||||
perror("mmap(gp2x_screen)");
|
||||
exit(1);
|
||||
}
|
||||
printf("framebuffers point to %p\n", gp2x_screens[0]);
|
||||
|
@ -390,12 +338,10 @@ void gp2x_init(void)
|
|||
gp2x_memset_all_buffers(0, 0, 320*240*2);
|
||||
|
||||
// snd
|
||||
mixerdev = open("/dev/mixer", O_RDWR);
|
||||
if (mixerdev == -1)
|
||||
printf("open(\"/dev/mixer\") failed with %i\n", errno);
|
||||
sndout_oss_init();
|
||||
|
||||
/* init usb joys -GnoStiC */
|
||||
gp2x_usbjoy_init();
|
||||
usbjoy_init();
|
||||
|
||||
// touchscreen
|
||||
touchdev = open("/dev/touchscreen/wm97xx", O_RDONLY);
|
||||
|
@ -432,16 +378,15 @@ void gp2x_deinit(void)
|
|||
munmap(gp2x_screens[0], FRAMEBUFF_WHOLESIZE);
|
||||
munmap((void *)gp2x_memregs, 0x10000);
|
||||
close(memdev);
|
||||
close(mixerdev);
|
||||
if (sounddev >= 0) close(sounddev);
|
||||
if (touchdev >= 0) close(touchdev);
|
||||
|
||||
gp2x_usbjoy_deinit();
|
||||
sndout_oss_exit();
|
||||
usbjoy_deinit();
|
||||
|
||||
printf("all done, running ");
|
||||
|
||||
// Zaq121's alternative frontend support from MAME
|
||||
if(ext_menu && ext_state) {
|
||||
if (ext_menu && ext_state) {
|
||||
printf("%s -state %s\n", ext_menu, ext_state);
|
||||
execl(ext_menu, ext_menu, "-state", ext_state, NULL);
|
||||
} else if(ext_menu) {
|
||||
|
|
|
@ -20,12 +20,6 @@ void gp2x_memcpy_all_buffers(void *data, int offset, int len);
|
|||
void gp2x_memset_all_buffers(int offset, int byte, int len);
|
||||
void gp2x_pd_clone_buffer2(void);
|
||||
|
||||
/* sound */
|
||||
void gp2x_start_sound(int rate, int bits, int stereo);
|
||||
void gp2x_sound_write(void *buff, int len);
|
||||
void gp2x_sound_volume(int l, int r);
|
||||
void gp2x_sound_sync(void);
|
||||
|
||||
/* input */
|
||||
unsigned long gp2x_joystick_read(int allow_usb_joy);
|
||||
int gp2x_touchpad_read(int *x, int *y);
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include "gp2x.h"
|
||||
#include "emu.h"
|
||||
#include "menu.h"
|
||||
#include "usbjoy.h"
|
||||
#include "../linux/usbjoy.h"
|
||||
#include "../common/emu.h"
|
||||
#include "../common/menu.h"
|
||||
#include "../common/arm_utils.h"
|
||||
|
@ -90,9 +90,9 @@ static unsigned long input2_read(unsigned long interesting, int *joy)
|
|||
{
|
||||
*joy = 0;
|
||||
if ((ret = gp2x_joystick_read(0) & interesting)) break;
|
||||
gp2x_usbjoy_update();
|
||||
usbjoy_update();
|
||||
for (i = 0; i < num_of_joys; i++) {
|
||||
ret = gp2x_usbjoy_check2(i);
|
||||
ret = usbjoy_check2(i);
|
||||
if (ret) { *joy = i + 1; break; }
|
||||
}
|
||||
if (ret) break;
|
||||
|
|
434
gp2x/usbjoy.c
434
gp2x/usbjoy.c
|
@ -1,434 +0,0 @@
|
|||
/* Title: USB Joystick library
|
||||
Version 0.2
|
||||
Written by Puck2099 (puck2099@gmail.com), (c) 2006.
|
||||
<http://www.gp32wip.com>
|
||||
|
||||
If you use this library or a part of it, please, let it know.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h> /* For the definition of NULL */
|
||||
#include <sys/types.h> // For Device open
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h> // For Device read
|
||||
|
||||
#include <string.h>
|
||||
#include <limits.h> /* For the definition of PATH_MAX */
|
||||
#include <linux/joystick.h>
|
||||
|
||||
#include "usbjoy.h"
|
||||
|
||||
/* This is a try to support analog joys. Untested. */
|
||||
#define DEAD_ZONE (8*1024)
|
||||
|
||||
/*
|
||||
Function: joy_open
|
||||
|
||||
Opens a USB joystick and fills its information.
|
||||
|
||||
Parameters:
|
||||
|
||||
joynumber - Joystick's identifier (0 reserved for GP2X's builtin Joystick).
|
||||
|
||||
Returns:
|
||||
|
||||
Filled usbjoy structure.
|
||||
|
||||
*/
|
||||
struct usbjoy *joy_open(int joynumber)
|
||||
{
|
||||
int fd;
|
||||
char path [128];
|
||||
struct usbjoy * joy = NULL;
|
||||
struct js_event event;
|
||||
#ifdef __GP2X__
|
||||
static char insmod_done = 0;
|
||||
// notaz: on my system I get unresolved input_* symbols, so have to 'insmod input' too
|
||||
// also we should insmod only once, not on every joy_open() call.
|
||||
if (!insmod_done) {
|
||||
system ("insmod input");
|
||||
system ("insmod joydev"); // Loads joydev module
|
||||
insmod_done = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (joynumber == 0) {
|
||||
}
|
||||
else if (joynumber > 0) {
|
||||
sprintf (path, "/dev/input/js%d", joynumber-1);
|
||||
fd = open(path, O_RDONLY, 0);
|
||||
if (fd == -1) {
|
||||
sprintf (path, "/dev/js%d", joynumber-1);
|
||||
fd = open(path, O_RDONLY, 0);
|
||||
}
|
||||
if (fd != -1) {
|
||||
joy = (struct usbjoy *) malloc(sizeof(*joy));
|
||||
if (joy == NULL) { close(fd); return NULL; }
|
||||
memset(joy, 0, sizeof(*joy));
|
||||
|
||||
// Set the joystick to non-blocking read mode
|
||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||
|
||||
// notaz: maybe we should flush init events now.
|
||||
// My pad returns axis as active when I plug it in, which is kind of annoying.
|
||||
while (read(fd, &event, sizeof(event)) > 0);
|
||||
|
||||
// Joystick's file descriptor
|
||||
joy->fd = fd;
|
||||
|
||||
// Joystick's name
|
||||
ioctl(joy->fd, JSIOCGNAME(128*sizeof(char)), joy->name);
|
||||
|
||||
// Joystick's device
|
||||
strcpy(joy->device, path);
|
||||
|
||||
// Joystick's buttons
|
||||
ioctl(joy->fd, JSIOCGBUTTONS, &joy->numbuttons);
|
||||
|
||||
// Joystick's axes
|
||||
ioctl(joy->fd, JSIOCGAXES, &joy->numaxes);
|
||||
|
||||
// Joystick's type (derived from name)
|
||||
if (strncasecmp(joy->name, "logitech", strlen("logitech")) == 0)
|
||||
joy->type = JOY_TYPE_LOGITECH;
|
||||
else joy->type = JOY_TYPE_GENERIC;
|
||||
} else {
|
||||
// printf ("ERROR: No Joystick found\n");
|
||||
}
|
||||
}
|
||||
return joy;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: joy_name
|
||||
|
||||
Returns Joystick's name.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's name or NULL if <usbjoy> struct is empty.
|
||||
*/
|
||||
char * joy_name (struct usbjoy * joy) {
|
||||
if (joy != NULL) return joy->name;
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_device
|
||||
|
||||
Returns Joystick's device.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's device or NULL if <usbjoy> struct is empty.
|
||||
*/
|
||||
char * joy_device (struct usbjoy * joy) {
|
||||
if (joy != NULL) return joy->device;
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_buttons
|
||||
|
||||
Returns Joystick's buttons number.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's buttons or 0 if <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_buttons (struct usbjoy * joy) {
|
||||
if (joy != NULL) return joy->numbuttons;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_axes
|
||||
|
||||
Returns Joystick's axes number.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's axes or 0 if <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_axes (struct usbjoy * joy) {
|
||||
if (joy != NULL) return joy->numaxes;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_update
|
||||
|
||||
Updates Joystick's internal information (<statebuttons> and <stateaxes> fields).
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - No events registered (no need to update).
|
||||
1 - Events registered (a button or axe has been pushed).
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_update (struct usbjoy * joy) {
|
||||
struct js_event events[0xff];
|
||||
int i, len;
|
||||
int event = 0;
|
||||
if (joy != NULL) {
|
||||
if ((len=read(joy->fd, events, (sizeof events))) >0) {
|
||||
len /= sizeof(events[0]);
|
||||
for ( i=0; i<len; ++i ) {
|
||||
switch (events[i].type & ~JS_EVENT_INIT) {
|
||||
case JS_EVENT_AXIS:
|
||||
if (events[i].number == 0) {
|
||||
joy->stateaxes[JOYLEFT] = joy->stateaxes[JOYRIGHT] = 0;
|
||||
if (events[i].value < -DEAD_ZONE) joy->stateaxes[JOYLEFT] = 1;
|
||||
else if (events[i].value > DEAD_ZONE) joy->stateaxes[JOYRIGHT] = 1;
|
||||
joy->axevals[0] = events[i].value;
|
||||
}
|
||||
else if (events[i].number == 1) {
|
||||
joy->stateaxes[JOYUP] = joy->stateaxes[JOYDOWN] = 0;
|
||||
if (events[i].value < -DEAD_ZONE) joy->stateaxes[JOYUP] = 1;
|
||||
else if (events[i].value > DEAD_ZONE) joy->stateaxes[JOYDOWN] = 1;
|
||||
joy->axevals[1] = events[i].value;
|
||||
}
|
||||
event = 1;
|
||||
break;
|
||||
case JS_EVENT_BUTTON:
|
||||
joy->statebuttons[events[i].number] = events[i].value;
|
||||
event = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
event = -1;
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_getbutton
|
||||
|
||||
Returns Joystick's button information.
|
||||
|
||||
Parameters:
|
||||
|
||||
button - Button which value you want to know (from 0 to 31).
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - Button NOT pushed.
|
||||
1 - Button pushed.
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_getbutton (int button, struct usbjoy * joy) {
|
||||
if (joy != NULL) {
|
||||
if (button < joy_buttons(joy)) return joy->statebuttons[button];
|
||||
else return 0;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_getaxe
|
||||
|
||||
Returns Joystick's axes information.
|
||||
|
||||
Parameters:
|
||||
|
||||
axe - Axe which value you want to know (see <Axes values>).
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - Direction NOT pushed.
|
||||
1 - Direction pushed.
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_getaxe (int axe, struct usbjoy * joy) {
|
||||
if (joy != NULL) {
|
||||
if (axe < 4) return joy->stateaxes[axe];
|
||||
else return 0;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_close
|
||||
|
||||
Closes selected joystick's file descriptor and detroys it's fields.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - Joystick successfully closed.
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_close (struct usbjoy * joy) {
|
||||
if (joy != NULL) {
|
||||
close (joy->fd);
|
||||
free (joy);
|
||||
return 0;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
/* GP2X USB Joystick Handling -GnoStiC */
|
||||
/*********************************************************************/
|
||||
|
||||
#include "gp2x.h"
|
||||
|
||||
int num_of_joys = 0;
|
||||
struct usbjoy *joys[4];
|
||||
|
||||
void gp2x_usbjoy_init (void) {
|
||||
/* Open available joysticks -GnoStiC */
|
||||
int i, n = 0;
|
||||
|
||||
printf("\n");
|
||||
for (i = 0; i < 4; i++) {
|
||||
joys[n] = joy_open(i+1);
|
||||
if (joys[n] && joy_buttons(joys[n]) > 0) {
|
||||
printf ("+-Joystick %d: \"%s\", buttons = %i\n", i+1, joy_name(joys[n]), joy_buttons(joys[n]));
|
||||
n++;
|
||||
}
|
||||
}
|
||||
num_of_joys = n;
|
||||
|
||||
printf("Found %d Joystick(s)\n",num_of_joys);
|
||||
}
|
||||
|
||||
void gp2x_usbjoy_update (void) {
|
||||
/* Update Joystick Event Cache */
|
||||
int q, foo;
|
||||
for (q=0; q < num_of_joys; q++) {
|
||||
foo = joy_update (joys[q]);
|
||||
}
|
||||
}
|
||||
|
||||
int gp2x_usbjoy_check (int joyno) {
|
||||
/* Check Joystick */
|
||||
int q, joyExKey = 0;
|
||||
struct usbjoy *joy = joys[joyno];
|
||||
|
||||
if (joy != NULL) {
|
||||
if (joy_getaxe(JOYUP, joy)) { joyExKey |= GP2X_UP; }
|
||||
if (joy_getaxe(JOYDOWN, joy)) { joyExKey |= GP2X_DOWN; }
|
||||
if (joy_getaxe(JOYLEFT, joy)) { joyExKey |= GP2X_LEFT; }
|
||||
if (joy_getaxe(JOYRIGHT, joy)) { joyExKey |= GP2X_RIGHT; }
|
||||
|
||||
/* loop through joy buttons to check if they are pushed */
|
||||
for (q=0; q<joy_buttons (joy); q++) {
|
||||
if (joy_getbutton (q, joy)) {
|
||||
if (joy->type == JOY_TYPE_LOGITECH) {
|
||||
switch (q) {
|
||||
case 0: joyExKey |= GP2X_A; break;
|
||||
case 1: joyExKey |= GP2X_X; break;
|
||||
case 2: joyExKey |= GP2X_B; break;
|
||||
case 3: joyExKey |= GP2X_Y; break;
|
||||
}
|
||||
} else {
|
||||
switch (q) {
|
||||
case 0: joyExKey |= GP2X_Y; break;
|
||||
case 1: joyExKey |= GP2X_B; break;
|
||||
case 2: joyExKey |= GP2X_X; break;
|
||||
case 3: joyExKey |= GP2X_A; break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (q) {
|
||||
case 4: joyExKey |= GP2X_L; break;
|
||||
case 5: joyExKey |= GP2X_R; break;
|
||||
case 6: joyExKey |= GP2X_L; break; /* left shoulder button 2 */
|
||||
case 7: joyExKey |= GP2X_R; break; /* right shoulder button 2 */
|
||||
case 8: joyExKey |= GP2X_SELECT;break;
|
||||
case 9: joyExKey |= GP2X_START; break;
|
||||
case 10: joyExKey |= GP2X_PUSH; break;
|
||||
case 11: joyExKey |= GP2X_PUSH; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return joyExKey;
|
||||
}
|
||||
|
||||
int gp2x_usbjoy_check2 (int joyno) {
|
||||
/* Check Joystick, don't map to gp2x joy */
|
||||
int q, to, joyExKey = 0;
|
||||
struct usbjoy *joy = joys[joyno];
|
||||
|
||||
if (joy != NULL) {
|
||||
if (joy_getaxe(JOYUP, joy)) { joyExKey |= 1 << 0; }
|
||||
if (joy_getaxe(JOYDOWN, joy)) { joyExKey |= 1 << 1; }
|
||||
if (joy_getaxe(JOYLEFT, joy)) { joyExKey |= 1 << 2; }
|
||||
if (joy_getaxe(JOYRIGHT, joy)) { joyExKey |= 1 << 3; }
|
||||
|
||||
/* loop through joy buttons to check if they are pushed */
|
||||
to = joy->numbuttons;
|
||||
if (to > 32-4) to = 32-4;
|
||||
for (q=0; q < to; q++)
|
||||
if (joy->statebuttons[q]) joyExKey |= 1 << (q+4);
|
||||
}
|
||||
return joyExKey;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void gp2x_usbjoy_deinit (void) {
|
||||
int i;
|
||||
for (i=0; i<num_of_joys; i++) {
|
||||
joy_close (joys[i]);
|
||||
joys[i] = NULL;
|
||||
}
|
||||
num_of_joys = 0;
|
||||
}
|
||||
|
242
gp2x/usbjoy.h
242
gp2x/usbjoy.h
|
@ -1,242 +0,0 @@
|
|||
/* Title: USB Joystick library
|
||||
Version 0.2
|
||||
Written by Puck2099 (puck2099@gmail.com), (c) 2006.
|
||||
<http://www.gp32wip.com>
|
||||
|
||||
If you use this library or a part of it, please, let it know.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef USBJOY_H
|
||||
#define USBJOY_H
|
||||
|
||||
/* notaz: my Logitech has different button layout, and I want it to match gp2x's */
|
||||
typedef enum {
|
||||
JOY_TYPE_GENERIC,
|
||||
JOY_TYPE_LOGITECH
|
||||
} joy_type;
|
||||
|
||||
/*
|
||||
Enumeration: Axes values
|
||||
This enumeration contains shortcuts to the values used on axes.
|
||||
|
||||
Constants:
|
||||
JOYUP - Joystick Up
|
||||
JOYDOWN - Joystick Down
|
||||
JOYLEFT - Joystick Left
|
||||
JOYRIGHT - Joystick Right
|
||||
|
||||
See also:
|
||||
<joy_getaxe>
|
||||
*/
|
||||
#define JOYUP (0)
|
||||
#define JOYDOWN (1)
|
||||
#define JOYLEFT (2)
|
||||
#define JOYRIGHT (3)
|
||||
|
||||
|
||||
/*
|
||||
Struct: usbjoy
|
||||
|
||||
Contains all Joystick needed information.
|
||||
|
||||
Fields:
|
||||
fd - File descriptor used.
|
||||
name - Joystick's name.
|
||||
device - /dev/input/jsX device.
|
||||
numbuttons - Joystick's buttons.
|
||||
numaxes - Joystick's axes.
|
||||
numhats - Joystick's hats.
|
||||
statebuttons - Current state of each button.
|
||||
stateaxes - Current state of each direction.
|
||||
*/
|
||||
struct usbjoy {
|
||||
int fd;
|
||||
char name [128];
|
||||
char device [128];
|
||||
int numbuttons;
|
||||
int numaxes;
|
||||
int numhats;
|
||||
int statebuttons[32];
|
||||
int stateaxes[4];
|
||||
int axevals[2];
|
||||
joy_type type;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_open
|
||||
|
||||
Opens a USB joystick and fills its information.
|
||||
|
||||
Parameters:
|
||||
|
||||
joynumber - Joystick's identifier (0 reserved for GP2X's builtin Joystick).
|
||||
|
||||
Returns:
|
||||
|
||||
Filled usbjoy structure.
|
||||
*/
|
||||
struct usbjoy * joy_open (int joynumber);
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_name
|
||||
|
||||
Returns Joystick's name.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's name or NULL if <usbjoy> struct is empty.
|
||||
*/
|
||||
char * joy_name (struct usbjoy * joy);
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_device
|
||||
|
||||
Returns Joystick's device.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's device or NULL if <usbjoy> struct is empty.
|
||||
*/
|
||||
char * joy_device (struct usbjoy * joy);
|
||||
|
||||
/*
|
||||
Function: joy_buttons
|
||||
|
||||
Returns Joystick's buttons number.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's buttons or 0 if <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_buttons (struct usbjoy * joy);
|
||||
|
||||
/*
|
||||
Function: joy_axes
|
||||
|
||||
Returns Joystick's axes number.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
Joystick's axes or 0 if <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_axes (struct usbjoy * joy);
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_update
|
||||
|
||||
Updates Joystick's internal information (<statebuttons> and <stateaxes> fields).
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - No events registered (no need to update).
|
||||
1 - Events registered (a button or axe has been pushed).
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_update (struct usbjoy * joy);
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_getbutton
|
||||
|
||||
Returns Joystick's button information.
|
||||
|
||||
Parameters:
|
||||
|
||||
button - Button which value you want to know (from 0 to 31).
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - Button NOT pushed.
|
||||
1 - Button pushed.
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_getbutton (int button, struct usbjoy * joy);
|
||||
|
||||
|
||||
/*
|
||||
Function: joy_getaxe
|
||||
|
||||
Returns Joystick's axes information.
|
||||
|
||||
Parameters:
|
||||
|
||||
axe - Axe which value you want to know (see <Axes values>).
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - Direction NOT pushed.
|
||||
1 - Direction pushed.
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_getaxe (int axe, struct usbjoy * joy);
|
||||
|
||||
/*
|
||||
Function: joy_close
|
||||
|
||||
Closes selected joystick's file descriptor and detroys it's fields.
|
||||
|
||||
Parameters:
|
||||
|
||||
joy - Selected joystick.
|
||||
|
||||
Returns:
|
||||
|
||||
0 - Joystick successfully closed.
|
||||
-1 - Error: <usbjoy> struct is empty.
|
||||
*/
|
||||
int joy_close (struct usbjoy * joy);
|
||||
|
||||
|
||||
|
||||
/* gp2x stuff */
|
||||
extern int num_of_joys;
|
||||
extern struct usbjoy *joys[4];
|
||||
|
||||
void gp2x_usbjoy_update(void);
|
||||
void gp2x_usbjoy_init(void);
|
||||
int gp2x_usbjoy_check(int joyno);
|
||||
int gp2x_usbjoy_check2(int joyno);
|
||||
void gp2x_usbjoy_deinit(void);
|
||||
|
||||
|
||||
#endif // USBJOY_H
|
Loading…
Add table
Add a link
Reference in a new issue