Skip to contentSkip to conversation

Joystick API

PATCH In review Jonathan Phenix 1 participant 2 messages May 11, 2007 – May 20, 2007 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Joystick API

Hi,

this is an attempt to add a simple joystick API to qemu. This API will be required for my upcoming Playstation emulator. It includes a "null" driver, I have a Linux and SDL driver as well, I will send them when this patch will be merged. Constructive comments are welcome.

Regards,

Jonathan Phénix

joystick/joystick.c +148 -0
diff -urN --exclude CVS qemu/joystick/joystick.c qemu-joystick/joystick/joystick.c
@@ -0,0 +1,148 @@
+/*  QEMU joystick API
+ *
+ *  Copyright (C) 2007 Jonathan Phénix
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "joystick_int.h"
+
+static const JoyDriver *joy_driver_table[] = {
+#if 0
+#ifdef CONFIG_JOY_LINUX
+    &joy_driver_linux,
+#endif
+#ifdef CONFIG_SDL
+    &joy_driver_sdl,
+#endif
+#endif
+    &joy_driver_null,
+    NULL,
+};
+
+JoyState *qemu_joy_init(JoyButtonCB but_cb, JoyAxisCB axis_cb, void *opaque)
+{
+    const JoyDriver **ptr;
+    JoyState *s;
+
+#ifdef JOY_SAFE
+    if (!but_cb || !axis_cb)
+        return NULL;
+#endif
+
+    ptr = joy_driver_table;
+
+    while (*ptr) {
+        if ((*ptr)->probe() == JOY_OK)
+            break;
+        ptr++;
+    }
+
+    if (!ptr) {
+        /* This should never happens, the null driver should catch it but we are never too careful */
+        qemu_joy_log("%s: No suitable joystick driver\n", __func__);
+        qemu_free(s);
+        return NULL;
+    }
+
+    s = qemu_mallocz(sizeof(*s) + (*ptr)->size);
+    if (!s)
+        return NULL;
+
+    s->driver = *ptr;
+
+    s->joy_but_cb = but_cb;
+    s->joy_axis_cb = axis_cb;
+    s->cb_opaque = opaque;
+
+    s->driver->init(s);
+
+    return s;
+}
+
+JoyError qemu_joy_open(JoyState *s, unsigned int devno)
+{
+#ifdef JOY_SAFE
+    if (devno >= JOY_MAX || !s)
+        return JOY_EINVAL;
+#endif
+    return s->driver->open(s, devno);
+}
+
+JoyError qemu_joy_close(JoyState *s, unsigned int devno)
+{
+#ifdef JOY_SAFE
+    if (devno >= JOY_MAX || !s)
+        return JOY_EINVAL;
+#endif
+
+    return s->driver->close(s, devno);
+}
+
+JoyError qemu_joy_get_info(JoyState *s, unsigned int devno, JoyInfo *info)
+{
+#ifdef JOY_SAFE
+    if (devno >= JOY_MAX || !s || !info)
+        return JOY_EINVAL;
+#endif
+
+    memset(info, 0, sizeof(*info));
+
+    return s->driver->get_info(s, devno, info);
+}
+
+unsigned int qemu_joy_nr(JoyState *s)
+{
+#ifdef JOY_SAFE
+    if (!s)
+        return 0;
+#endif
+
+    return s->driver->nr(s);
+}
+
+void qemu_joy_flush(JoyState *s)
+{
+#ifdef JOY_SAFE
+    if (!s)
+        return;
+#endif
+
+    if (s->driver->flush)
+        s->driver->flush(s);
+}
+
+void qemu_joy_enable(JoyState *s)
+{
+#ifdef JOY_SAFE
+    if (!s)
+        return;
+#endif
+
+    if (s->driver->enable)
+        s->driver->enable(s);
+}
+
+extern FILE *logfile;
+
+void qemu_joy_log(const char *fmt, ...)
+{
+    va_list ap;
+
+    va_start(ap, fmt);
+    vfprintf(logfile ? logfile : stderr, fmt, ap);
+    va_end(ap);
+}
+
joystick/joystick.h +84 -0

84 lines not on this page · raw message

joystick/joystick_int.h +58 -0

58 lines not on this page · raw message

joystick/nulljoy.c +63 -0

63 lines not on this page · raw message

Makefile.target +9 -1
diff -urN --exclude CVS qemu/Makefile.target qemu-joystick/Makefile.target
@@ -17,7 +17,7 @@
 TARGET_BASE_ARCH:=sparc
 endif
 TARGET_PATH=$(SRC_PATH)/target-$(TARGET_BASE_ARCH)
-VPATH=$(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/audio
+VPATH=$(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/audio:$(SRC_PATH)/joystick
 CPPFLAGS=-I. -I.. -I$(TARGET_PATH) -I$(SRC_PATH)
 ifdef CONFIG_DARWIN_USER
 VPATH+=:$(SRC_PATH)/darwin-user
@@ -416,6 +416,14 @@
 VL_OBJS += pcnet.o
 VL_OBJS += rtl8139.o
 
+JOYDRV = joystick.o nulljoy.o
+#ifdef CONFIG_JOY_LINUX
+#JOYDRV += linuxjoy.o
+#endif
+#ifdef CONFIG_SDL
+#JOYDRV += sdljoy.o
+#endif
+
 ifeq ($(TARGET_BASE_ARCH), i386)
 # Hardware support
 VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
#1 lore raw
Quoted 3 lines · Jonathan Phenix

Hi,

this is an attempt to add a simple joystick API to qemu. This API will be required for my upcoming Playstation emulator. It includes a "null" driver, I have a Linux and SDL driver as well, I will send them when this patch will be merged. Constructive comments are welcome.

No comment were posted about the patch and it was not committed in CVS, is it going to be done or some modifications are required? I can produce a patch that will include both the new subsystem as well as the 2 real drivers if needed.

Regards,

Jonathan Phénix