Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added xenon controller code, took another stab at audio

  • Loading branch information...
commit 7555a168214674364810937ddcb2bdee5c381220 1 parent cc9a19e
@lantus authored
View
4 Makefile.xenon
@@ -1,6 +1,6 @@
# Makefile to build the SDL library
-INCLUDE = -I./include -I./src/video -I./src/audio
+INCLUDE = -I./include -I./src/video -I./src/audio -I./src/joystick
CFLAGS = -g -O2 $(INCLUDE)
CC = xenon-gcc
AR = xenon-ar
@@ -27,7 +27,7 @@ SOURCES = \
src/audio/xenon/*.c \
src/video/xenon/*.c \
src/video/xenon/*.s \
- src/joystick/dummy/*.c \
+ src/joystick/xenon/*.c \
src/cdrom/dummy/*.c \
src/thread/xenon/*.c \
src/loadso/dummy/*.c \
View
3  include/SDL_config_xenon.h
@@ -40,9 +40,8 @@ typedef unsigned int size_t;
#define HAVE_MMAP 0
-#define SDL_BYTEORDER SDL_BIG_ENDIAN
+#define SDL_BYTEORDER SDL_BIG_ENDIAN
#define SDL_CDROM_DISABLED 1
-#define SDL_JOYSTICK_DISABLED 1
#define SDL_LOADSO_DISABLED 1
#define SDL_THREADS_DISABLED 1 //ugh
#define SDL_AUDIO_DRIVER_XENON 1
View
42 src/audio/xenon/SDL_xenonaudio.c
@@ -28,6 +28,9 @@
#include "SDL_audio.h"
#include "SDL_audio_c.h"
#include "SDL_xenonaudio.h"
+
+
+
/* Audio driver functions */
static int XENON_OpenAudio(_THIS, SDL_AudioSpec *spec);
@@ -113,11 +116,14 @@ static void XENON_WaitAudio_BusyWait(_THIS)
static void XENON_PlayAudio(_THIS)
{
- memcpy(&pAudioBuffers[currentBuffer * mixlen], locked_buf, mixlen);
- while(xenon_sound_get_unplayed()>(4*mixlen)) udelay(50);
- xenon_sound_submit(&pAudioBuffers[currentBuffer * mixlen], mixlen);
+ //while(xenon_sound_get_unplayed()>(4*mixlen)) udelay(50);
+
+
+ memcpy(&pAudioBuffers[currentBuffer * mixlen], locked_buf, mixlen);
+ xenon_sound_submit(&pAudioBuffers[currentBuffer * mixlen], mixlen);
+
currentBuffer++;
currentBuffer %= (NUM_BUFFERS);
@@ -163,35 +169,21 @@ static void XENON_CloseAudio(_THIS)
static int XENON_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
- /* Determine the audio parameters from the AudioSpec */
- switch ( spec->format & 0xFF ) {
- case 8:
- /* Unsigned 8 bit audio data */
- spec->format = AUDIO_U8;
- silence = 0x80;
- break;
- case 16:
- /* Signed 16 bit audio data */
- spec->format = AUDIO_S16;
- silence = 0x00;
- break;
- default:
- SDL_SetError("Unsupported audio format");
- return(-1);
- }
-
+ // Set up actual spec.
+ spec->freq = 48000;
+ spec->format = AUDIO_S16MSB;
+ spec->channels = 2;
+
/* Update the fragment size as size in bytes */
SDL_CalculateAudioSpec(spec);
- locked_buf = (unsigned char *)malloc(spec->size);
+ locked_buf = (unsigned char *)malloc(spec->size * 4);
/* Create the audio buffer to which we write */
- NUM_BUFFERS = -1;
+ NUM_BUFFERS = 2;
- if ( NUM_BUFFERS < 0 )
- NUM_BUFFERS = 4;
- pAudioBuffers = (unsigned char *)malloc(spec->size*NUM_BUFFERS);
+ pAudioBuffers = (unsigned char *)malloc(spec->size *NUM_BUFFERS * 4);
playing = 0;
mixlen = spec->size;
View
310 src/joystick/xenon/SDL_xenonjoystick.c
@@ -0,0 +1,310 @@
+#include <input/input.h>
+#include <usb/usbmain.h>
+
+#include <math.h>
+#include <stdio.h> /* For the definition of NULL */
+
+#include "SDL_error.h"
+#include "SDL_joystick.h"
+#include "SDL_sysjoystick.h"
+#include "SDL_joystick_c.h"
+#include "SDL_events.h"
+
+#define XBINPUT_DEADZONE 0.24f
+#define AXIS_MIN -32768 /* minimum value for axis coordinate */
+#define AXIS_MAX 32767 /* maximum value for axis coordinate */
+#define MAX_AXES 4 /* each joystick can have up to 5 axes */
+#define MAX_BUTTONS 12 /* and 12 buttons */
+#define MAX_HATS 2
+
+char joyName[50];
+
+/* The private structure used to keep track of a joystick */
+struct joystick_hwdata
+{
+ struct controller_data_s curpad;
+ struct controller_data_s oldpad;
+
+};
+
+int SDL_SYS_JoystickInit(void)
+{
+ SDL_numjoysticks = 4;
+ return(SDL_numjoysticks);
+}
+
+/* Function to get the device-dependent name of a joystick */
+const char *SDL_SYS_JoystickName(int index)
+{
+
+ sprintf(joyName,"XENON Gamepad %ld",index);
+ return(joyName);
+}
+
+int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
+{
+
+ /* allocate memory for system specific hardware data */
+ joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
+
+ if (joystick->hwdata == NULL)
+ {
+ SDL_OutOfMemory();
+ return(-1);
+ }
+
+ SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
+
+ /* fill nbuttons, naxes, and nhats fields */
+ joystick->nbuttons = MAX_BUTTONS;
+ joystick->naxes = MAX_AXES;
+ joystick->nhats = MAX_HATS;
+ return(0);
+}
+
+void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
+{
+ static int prev_buttons[4] = {0};
+ static Sint16 nX = 0, nY = 0;
+ static Sint16 nXR = 0, nYR = 0;
+ unsigned long b=0;
+ int hat=0, changed=0;
+
+ usb_do_poll();
+
+ get_controller_data(&joystick->hwdata->curpad, joystick->index);
+
+ if (joystick->hwdata->curpad.a)
+ {
+ if (!joystick->buttons[0])
+ SDL_PrivateJoystickButton(joystick, (Uint8)0, SDL_PRESSED);
+ }
+ else
+ {
+ if (joystick->buttons[0])
+ SDL_PrivateJoystickButton(joystick, (Uint8)0, SDL_RELEASED);
+ }
+
+ if (joystick->hwdata->curpad.b)
+ {
+ if (!joystick->buttons[1])
+ SDL_PrivateJoystickButton(joystick, (Uint8)1, SDL_PRESSED);
+ }
+ else
+ {
+ if (joystick->buttons[1])
+ SDL_PrivateJoystickButton(joystick, (Uint8)1, SDL_RELEASED);
+ }
+
+ if (joystick->hwdata->curpad.x)
+ {
+ if (!joystick->buttons[2])
+ SDL_PrivateJoystickButton(joystick, (Uint8)2, SDL_PRESSED);
+ }
+ else
+ {
+ if (joystick->buttons[2])
+ SDL_PrivateJoystickButton(joystick, (Uint8)2, SDL_RELEASED);
+ }
+
+ if (joystick->hwdata->curpad.y)
+ {
+ if (!joystick->buttons[3])
+ SDL_PrivateJoystickButton(joystick, (Uint8)3, SDL_PRESSED);
+ }
+ else
+ {
+ if (joystick->buttons[3])
+ SDL_PrivateJoystickButton(joystick, (Uint8)3, SDL_RELEASED);
+ }
+
+ if (joystick->hwdata->curpad.lb)
+ {
+ if (!joystick->buttons[4])
+ SDL_PrivateJoystickButton(joystick, (Uint8)4, SDL_PRESSED);
+ }
+ else
+ {
+ if (joystick->buttons[4])
+ SDL_PrivateJoystickButton(joystick, (Uint8)4, SDL_RELEASED);
+ }
+
+ if (joystick->hwdata->curpad.rb)
+ {
+ if (!joystick->buttons[5])
+ SDL_PrivateJoystickButton(joystick, (Uint8)5, SDL_PRESSED);
+ }
+ else
+ {
+ if (joystick->buttons[5])
+ SDL_PrivateJoystickButton(joystick, (Uint8)5, SDL_RELEASED);
+ }
+
+ if (joystick->hwdata->curpad.s1_z)
+ {
+ if (!joystick->buttons[6])
+ SDL_PrivateJoystickButton(joystick, (Uint8)6, SDL_PRESSED);
+ }
+ else
+ {
+ if (joystick->buttons[6])
+ SDL_PrivateJoystickButton(joystick, (Uint8)6, SDL_RELEASED);
+ }
+
+ if (joystick->hwdata->curpad.s2_z)
+ {
+ if (!joystick->buttons[7])
+ SDL_PrivateJoystickButton(joystick, (Uint8)7, SDL_PRESSED);
+ }
+ else
+ {
+ if (joystick->buttons[7])
+ SDL_PrivateJoystickButton(joystick, (Uint8)7, SDL_RELEASED);
+ }
+
+ if (joystick->hwdata->curpad.start)
+ {
+ if (!joystick->buttons[8])
+ SDL_PrivateJoystickButton(joystick, (Uint8)8, SDL_PRESSED);
+ }
+ else
+ {
+ if (joystick->buttons[8])
+ SDL_PrivateJoystickButton(joystick, (Uint8)8, SDL_RELEASED);
+ }
+
+ if (joystick->hwdata->curpad.select)
+ {
+ if (!joystick->buttons[9])
+ SDL_PrivateJoystickButton(joystick, (Uint8)9, SDL_PRESSED);
+ }
+ else
+ {
+ if (joystick->buttons[9])
+ SDL_PrivateJoystickButton(joystick, (Uint8)9, SDL_RELEASED);
+ }
+
+ if (joystick->hwdata->curpad.lt > 200)
+ {
+ if (!joystick->buttons[10])
+ SDL_PrivateJoystickButton(joystick, (Uint8)10, SDL_PRESSED);
+ }
+ else
+ {
+ if (joystick->buttons[10])
+ SDL_PrivateJoystickButton(joystick, (Uint8)10, SDL_RELEASED);
+ }
+
+ if (joystick->hwdata->curpad.rt > 200)
+ {
+ if (!joystick->buttons[11])
+ SDL_PrivateJoystickButton(joystick, (Uint8)11, SDL_PRESSED);
+ }
+ else
+ {
+ if (joystick->buttons[11])
+ SDL_PrivateJoystickButton(joystick, (Uint8)11, SDL_RELEASED);
+ }
+
+
+ // do the HATS baby
+
+ hat = SDL_HAT_CENTERED;
+
+ if (joystick->hwdata->curpad.down)
+ hat|=SDL_HAT_DOWN;
+ if (joystick->hwdata->curpad.up)
+ hat|=SDL_HAT_UP;
+ if (joystick->hwdata->curpad.left)
+ hat|=SDL_HAT_LEFT;
+ if (joystick->hwdata->curpad.right)
+ hat|=SDL_HAT_RIGHT;
+
+
+ changed = hat^prev_buttons[joystick->index];
+
+ if ( changed ) {
+ SDL_PrivateJoystickHat(joystick, 0, hat);
+ }
+
+ prev_buttons[joystick->index] = hat;
+
+ // Axis - LStick
+
+ if ((joystick->hwdata->curpad.s1_x <= -10000) ||
+ (joystick->hwdata->curpad.s1_x >= 10000))
+ {
+ if (joystick->hwdata->curpad.s1_x < 0)
+ joystick->hwdata->curpad.s1_x++;
+ nX = ((Sint16)joystick->hwdata->curpad.s1_x);
+ }
+ else
+ nX = 0;
+
+ if ( nX != joystick->axes[0] )
+ SDL_PrivateJoystickAxis(joystick, (Uint8)0, (Sint16)nX);
+
+
+ if ((joystick->hwdata->curpad.s1_y <= -10000) ||
+ (joystick->hwdata->curpad.s1_y >= 10000))
+ {
+ if (joystick->hwdata->curpad.s1_y < 0)
+ joystick->hwdata->curpad.s1_y++;
+ nY = -((Sint16)(joystick->hwdata->curpad.s1_y));
+ }
+ else
+ nY = 0;
+
+ if ( nY != joystick->axes[1] )
+ SDL_PrivateJoystickAxis(joystick, (Uint8)1, (Sint16)nY);
+
+
+ // Axis - RStick
+
+ if ((joystick->hwdata->curpad.s2_x <= -10000) ||
+ (joystick->hwdata->curpad.s2_x >= 10000))
+ {
+ if (joystick->hwdata->curpad.s2_x < 0)
+ joystick->hwdata->curpad.s2_x++;
+ nXR = ((Sint16)joystick->hwdata->curpad.s2_x);
+ }
+ else
+ nXR = 0;
+
+ if ( nXR != joystick->axes[2] )
+ SDL_PrivateJoystickAxis(joystick, (Uint8)2, (Sint16)nXR);
+
+
+ if ((joystick->hwdata->curpad.s2_y <= -10000) ||
+ (joystick->hwdata->curpad.s2_y >= 10000))
+ {
+ if (joystick->hwdata->curpad.s2_y < 0)
+ joystick->hwdata->curpad.s2_y++;
+ nYR = -((Sint16)joystick->hwdata->curpad.s2_y);
+ }
+ else
+ nYR = 0;
+
+ if ( nYR != joystick->axes[3] )
+ SDL_PrivateJoystickAxis(joystick, (Uint8)3, (Sint16)nYR);
+
+
+ joystick->hwdata->oldpad = joystick->hwdata->curpad;
+}
+
+void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
+{
+ if (joystick->hwdata != NULL) {
+ /* free system specific hardware data */
+ SDL_free(joystick->hwdata);
+ joystick->hwdata = NULL;
+ }
+
+ return;
+}
+
+void SDL_SYS_JoystickQuit(void)
+{
+
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.