Permalink
Browse files

- fixed endian issue with video

- start of audio and thread code. still doesnt work yet
  • Loading branch information...
1 parent c82dca3 commit fe239a1a37b3500708b6ffdb44eb888f3f3c2b5a @lantus lantus committed Oct 6, 2011
View
@@ -1,6 +1,6 @@
# Makefile to build the SDL library
-INCLUDE = -I./include -I./src/video
+INCLUDE = -I./include -I./src/video -I./src/audio
CFLAGS = -g -O2 $(INCLUDE)
CC = xenon-gcc
AR = xenon-ar
@@ -24,13 +24,12 @@ SOURCES = \
src/timer/*.c \
src/timer/xenon/*.c \
src/video/*.c \
- src/audio/dummy/*.c \
+ src/audio/xenon/*.c \
src/video/xenon/*.c \
src/video/xenon/*.s \
src/joystick/dummy/*.c \
src/cdrom/dummy/*.c \
src/thread/generic/*.c \
- src/timer/dummy/*.c \
src/loadso/dummy/*.c \
OBJECTS = $(shell echo $(SOURCES) | sed -e 's,\.c,\.o,g' -e 's,\.s,\.o,g')
View
@@ -25,22 +25,34 @@
#include <stdarg.h>
#include <xetypes.h>
+#include <xenos/xe.h>
+#include <xenos/xenos.h>
+#include <xenos/edram.h>
+#include <xenos/xenos.h>
+#include <usb/usbmain.h>
+#include <console/console.h>
+#include <xenon_smc/xenon_smc.h>
+#include <xenon_soc/xenon_power.h>
+
typedef unsigned int size_t;
#define HAVE_MMAP 0
#define SDL_BYTEORDER SDL_BIG_ENDIAN
-#define SDL_AUDIO_DRIVER_DUMMY 1
#define SDL_CDROM_DISABLED 1
#define SDL_JOYSTICK_DISABLED 1
#define SDL_LOADSO_DISABLED 1
-#define SDL_THREADS_DISABLED 1
+#define SDL_THREADS_XENON 1
+#define SDL_AUDIO_DRIVER_XENON 1
#define SDL_VIDEO_DRIVER_XENON 1
+#define DEBUG_THREADS 1
+#define SDL_THREADS_DISABLED 1
#define HAVE_MALLOC 1
#define HAVE_MEMCPY 1
#define HAVE_MEMSET 1
#define HAVE_FREE 1
#define HAVE_CALLOC 1
#define HAVE_REALLOC 1
+#define HAVE_STDIO_H 1
#endif /* _SDL_config_xenon_h */
View
@@ -149,6 +149,13 @@ int SDL_InitSubSystem(Uint32 flags)
int SDL_Init(Uint32 flags)
{
+ // ill just dump these here...
+ xenon_make_it_faster(XENON_SPEED_FULL);
+ xenos_init(VIDEO_MODE_AUTO);
+ console_init();
+ usb_init();
+ usb_do_poll();
+
#if !SDL_THREADS_DISABLED && SDL_THREAD_PTH
if (!pth_init()) {
return -1;
@@ -157,7 +164,7 @@ int SDL_Init(Uint32 flags)
/* Clear the error message */
SDL_ClearError();
-
+
/* Initialize the desired subsystems */
if ( SDL_InitSubSystem(flags) < 0 ) {
return(-1);
View
@@ -113,6 +113,9 @@ static AudioBootStrap *bootstrap[] = {
#if SDL_AUDIO_DRIVER_EPOCAUDIO
&EPOCAudio_bootstrap,
#endif
+#if SDL_AUDIO_DRIVER_XENON
+ &XENONAudio_bootstrap,
+#endif
NULL
};
SDL_AudioDevice *current_audio = NULL;
View
@@ -177,6 +177,9 @@ extern AudioBootStrap DART_bootstrap;
#if SDL_AUDIO_DRIVER_EPOCAUDIO
extern AudioBootStrap EPOCAudio_bootstrap;
#endif
+#if SDL_AUDIO_DRIVER_XENON
+extern AudioBootStrap XENONAudio_bootstrap;
+#endif
/* This is the current audio device */
extern SDL_AudioDevice *current_audio;
@@ -0,0 +1,210 @@
+/*
+ SDL - Simple DirectMedia Layer
+ Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ Sam Lantinga
+ slouken@libsdl.org
+*/
+
+#include <stdio.h>
+
+#include "SDL_types.h"
+#include "SDL_error.h"
+#include "SDL_timer.h"
+#include "SDL_audio.h"
+#include "SDL_audio_c.h"
+#include "SDL_xenonaudio.h"
+
+/* Audio driver functions */
+static int XENON_OpenAudio(_THIS, SDL_AudioSpec *spec);
+static void XENON_WaitAudio_BusyWait(_THIS);
+static void XENON_PlayAudio(_THIS);
+static Uint8 *XENON_GetAudioBuf(_THIS);
+static void XENON_WaitDone(_THIS);
+static void XENON_CloseAudio(_THIS);
+static void XENON_ThreadInit(_THIS);
+
+/* Audio driver bootstrap functions */
+
+static int Audio_Available(void)
+{
+ // Audio is always available on Xenon
+ return(1);
+}
+
+
+static void XENON_Unload(void)
+{
+ // do nothing
+}
+static int XENON_Load(void)
+{
+ return 1;
+}
+
+static void Audio_DeleteDevice(SDL_AudioDevice *device)
+{
+ if (device->hidden)
+ {
+ free(device->hidden);
+ device->hidden = NULL;
+ }
+}
+
+static SDL_AudioDevice *Audio_CreateDevice(int devindex)
+{
+ SDL_AudioDevice *this;
+
+ if ( XENON_Load() < 0 ) {
+ return(NULL);
+ }
+
+ /* Initialize all variables that we clean on shutdown */
+ this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
+ if ( this ) {
+ memset(this, 0, (sizeof *this));
+ this->hidden = (struct SDL_PrivateAudioData *)
+ malloc((sizeof *this->hidden));
+ }
+ if ( (this == NULL) || (this->hidden == NULL) ) {
+ SDL_OutOfMemory();
+ if ( this ) {
+ free(this);
+ }
+ return(0);
+ }
+ memset(this->hidden, 0, (sizeof *this->hidden));
+
+ /* Set the function pointers */
+
+ this->OpenAudio = XENON_OpenAudio;
+ this->WaitAudio = XENON_WaitAudio_BusyWait;
+ this->PlayAudio = XENON_PlayAudio;
+ this->GetAudioBuf = XENON_GetAudioBuf;
+ this->CloseAudio = XENON_CloseAudio;
+
+ this->free = Audio_DeleteDevice;
+
+ /* Open the audio device */
+
+ xenon_sound_init();
+
+ return this;
+}
+
+AudioBootStrap XENONAudio_bootstrap = {
+ "XENON Audio", "XENON Audio SDL Driver",
+ Audio_Available, Audio_CreateDevice
+};
+
+
+static void XENON_ThreadInit(_THIS)
+{
+
+}
+
+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);
+
+ currentBuffer++;
+ currentBuffer %= (NUM_BUFFERS);
+}
+
+static Uint8 *XENON_GetAudioBuf(_THIS)
+{
+ return(locked_buf);
+}
+
+static void XENON_WaitDone(_THIS)
+{
+ Uint8 *stream;
+
+ /* Wait for the playing chunk to finish */
+ stream = this->GetAudioBuf(this);
+ if ( stream != NULL ) {
+ memset(stream, silence, mixlen);
+ this->PlayAudio(this);
+ }
+ this->WaitAudio(this);
+
+
+
+}
+
+static void XENON_CloseAudio(_THIS)
+{
+
+ if (locked_buf)
+ {
+ free(locked_buf);
+ locked_buf = NULL;
+ }
+
+ if (pAudioBuffers)
+ {
+ free(pAudioBuffers);
+ pAudioBuffers = NULL;
+ }
+}
+
+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);
+ }
+
+ /* Update the fragment size as size in bytes */
+ SDL_CalculateAudioSpec(spec);
+
+ locked_buf = (unsigned char *)malloc(spec->size);
+
+ /* Create the audio buffer to which we write */
+ NUM_BUFFERS = -1;
+
+ if ( NUM_BUFFERS < 0 )
+ NUM_BUFFERS = 4;
+
+ pAudioBuffers = (unsigned char *)malloc(spec->size*NUM_BUFFERS);
+ playing = 0;
+ mixlen = spec->size;
+
+ return(0);
+}
@@ -0,0 +1,55 @@
+/*
+ SDL - Simple DirectMedia Layer
+ Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+ Sam Lantinga
+ slouken@libsdl.org
+*/
+
+#ifndef _SDL_xenonaudio_h
+#define _SDL_xenonaudio_h
+
+#include <xenon_sound/sound.h>
+
+#include "SDL_sysaudio.h"
+
+/* Hidden "this" pointer for the video functions */
+#define _THIS SDL_AudioDevice *this
+
+struct SDL_PrivateAudioData {
+ int NUM_BUFFERS;
+ int mixlen, silence;
+ int currentBuffer;
+ long playing;
+ Uint8 *locked_buf;
+ unsigned char* pAudioBuffers;
+};
+
+#define sound (this->hidden->sound)
+#define masterVoice (this->hidden->masterVoice)
+#define mixbuf (this->hidden->mixbuf)
+#define NUM_BUFFERS (this->hidden->NUM_BUFFERS)
+#define mixlen (this->hidden->mixlen)
+#define silence (this->hidden->silence)
+#define playing (this->hidden->playing)
+#define locked_buf (this->hidden->locked_buf)
+#define audio_event (this->hidden->audio_event)
+#define pAudioBuffers (this->hidden->pAudioBuffers)
+#define currentBuffer (this->hidden->currentBuffer)
+
+#endif /* _SDL_xenonaudio_h */
+
View
@@ -215,6 +215,7 @@ DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *
thread_args *args;
int ret;
+ printf("SDL_CreateThread();\n");
/* Allocate memory for the thread info structure */
thread = (SDL_Thread *)SDL_malloc(sizeof(*thread));
if ( thread == NULL ) {
@@ -235,6 +236,9 @@ DECLSPEC SDL_Thread * SDLCALL SDL_CreateThread(int (SDLCALL *fn)(void *), void *
args->data = data;
args->info = thread;
args->wait = SDL_CreateSemaphore(0);
+
+ printf("SDL_CreateSemaphore(0);\n");
+
if ( args->wait == NULL ) {
SDL_free(thread);
SDL_free(args);
@@ -43,6 +43,8 @@
#include "win32/SDL_systhread_c.h"
#elif SDL_THREAD_SYMBIAN
#include "symbian/SDL_systhread_c.h"
+#elif SDL_THREADS_XENON
+#include "xenon/SDL_systhread_c.h"
#else
#error Need thread implementation for this platform
#include "generic/SDL_systhread_c.h"
Oops, something went wrong.

0 comments on commit fe239a1

Please sign in to comment.