Commit 10ab421d authored by Ryan C. Gordon's avatar Ryan C. Gordon

Added S60 port.

--HG--
branch : SDL-1.2
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/branches/SDL-1.2%402375
parent 6fb707a2
==============================================================================
Using the Simple DirectMedia Layer with S60 3.x / Symbian 9.x
==============================================================================
These instuctions are for people developing for S60 3.x. S60 3.x
uses Symbian OS so you need S60 SDK.
extract "symbian.zip" into this folder.
go to symbian folder
bldmake bldfiles
abld build
That produces WINSCW and ARMV5 versions of sdl.dll runtime library
and sdl.lib for development.
Eaudiolib.lib and dll are generated as well, and must be delivered
along SDL as it uses it for audio.
There are certain problems with GCC compiler when building for
target, it may compile or binaries are buggy - please use RVCT
compiler as it works and produces far more effient code.
Its likely that SDL application should be integrated into S60
work and behave well there. So there is CSDL class (sdlepocapi.h)
to make this easy. If you do porting from other system, then
implement a S60 application and use CSDL class, they you may
not need to modify original SDL code at all!
...@@ -46,6 +46,9 @@ SDL 1.2.12 is a minor bug fix release. ...@@ -46,6 +46,9 @@ SDL 1.2.12 is a minor bug fix release.
<P> <P>
Support for Nokia 9210 "EPOC" driver has been removed from the main SDL code. Support for Nokia 9210 "EPOC" driver has been removed from the main SDL code.
</P> </P>
<P>
Unofficial support for the S60/SymbianOS platform has been added.
</P>
</BLOCKQUOTE> </BLOCKQUOTE>
<H3> Unix Notes </H3> <H3> Unix Notes </H3>
......
...@@ -32,6 +32,8 @@ ...@@ -32,6 +32,8 @@
#include "SDL_config_macos.h" #include "SDL_config_macos.h"
#elif defined(__MACOSX__) #elif defined(__MACOSX__)
#include "SDL_config_macosx.h" #include "SDL_config_macosx.h"
#elif defined(__SYMBIAN32__)
#include "SDL_config_symbian.h" /* must be before win32! */
#elif defined(__WIN32__) #elif defined(__WIN32__)
#include "SDL_config_win32.h" #include "SDL_config_win32.h"
#elif defined(__OS2__) #elif defined(__OS2__)
......
...@@ -224,7 +224,6 @@ ...@@ -224,7 +224,6 @@
/* Enable various threading systems */ /* Enable various threading systems */
#undef SDL_THREAD_BEOS #undef SDL_THREAD_BEOS
#undef SDL_THREAD_DC #undef SDL_THREAD_DC
#undef SDL_THREAD_EPOC
#undef SDL_THREAD_OS2 #undef SDL_THREAD_OS2
#undef SDL_THREAD_PTH #undef SDL_THREAD_PTH
#undef SDL_THREAD_PTHREAD #undef SDL_THREAD_PTHREAD
...@@ -237,7 +236,6 @@ ...@@ -237,7 +236,6 @@
#undef SDL_TIMER_BEOS #undef SDL_TIMER_BEOS
#undef SDL_TIMER_DC #undef SDL_TIMER_DC
#undef SDL_TIMER_DUMMY #undef SDL_TIMER_DUMMY
#undef SDL_TIMER_EPOC
#undef SDL_TIMER_MACOS #undef SDL_TIMER_MACOS
#undef SDL_TIMER_MINT #undef SDL_TIMER_MINT
#undef SDL_TIMER_OS2 #undef SDL_TIMER_OS2
...@@ -255,7 +253,6 @@ ...@@ -255,7 +253,6 @@
#undef SDL_VIDEO_DRIVER_DIRECTFB #undef SDL_VIDEO_DRIVER_DIRECTFB
#undef SDL_VIDEO_DRIVER_DRAWSPROCKET #undef SDL_VIDEO_DRIVER_DRAWSPROCKET
#undef SDL_VIDEO_DRIVER_DUMMY #undef SDL_VIDEO_DRIVER_DUMMY
#undef SDL_VIDEO_DRIVER_EPOC
#undef SDL_VIDEO_DRIVER_FBCON #undef SDL_VIDEO_DRIVER_FBCON
#undef SDL_VIDEO_DRIVER_GAPI #undef SDL_VIDEO_DRIVER_GAPI
#undef SDL_VIDEO_DRIVER_GEM #undef SDL_VIDEO_DRIVER_GEM
......
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
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 St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
*/
/*
Symbian version Markus Mertama
*/
#ifndef _SDL_CONFIG_SYMBIAN_H
#define _SDL_CONFIG_SYMBIAN_H
#include "SDL_platform.h"
/* This is the minimal configuration that can be used to build SDL */
#include <stdarg.h>
#include <stddef.h>
#ifdef __GCCE__
#define SYMBIAN32_GCCE
#endif
#ifndef _SIZE_T_DEFINED
typedef unsigned int size_t;
#endif
#ifndef _INTPTR_T_DECLARED
typedef unsigned int uintptr_t;
#endif
#ifndef _INT8_T_DECLARED
typedef signed char int8_t;
#endif
#ifndef _UINT8_T_DECLARED
typedef unsigned char uint8_t;
#endif
#ifndef _INT16_T_DECLARED
typedef signed short int16_t;
#endif
#ifndef _UINT16_T_DECLARED
typedef unsigned short uint16_t;
#endif
#ifndef _INT32_T_DECLARED
typedef signed int int32_t;
#endif
#ifndef _UINT32_T_DECLARED
typedef unsigned int uint32_t;
#endif
#ifndef _INT64_T_DECLARED
typedef signed long long int64_t;
#endif
#ifndef _UINT64_T_DECLARED
typedef unsigned long long uint64_t;
#endif
#define SDL_AUDIO_DRIVER_EPOCAUDIO 1
/* Enable the stub cdrom driver (src/cdrom/dummy/\*.c) */
#define SDL_CDROM_DISABLED 1
/* Enable the stub joystick driver (src/joystick/dummy/\*.c) */
#define SDL_JOYSTICK_DISABLED 1
/* Enable the stub shared object loader (src/loadso/dummy/\*.c) */
#define SDL_LOADSO_DISABLED 1
#define SDL_THREAD_SYMBIAN 1
#define SDL_VIDEO_DRIVER_EPOC 1
#define SDL_VIDEO_OPENGL 0
#define SDL_HAS_64BIT_TYPE 1
#define HAVE_LIBC 1
#define HAVE_STDIO_H 1
#define STDC_HEADERS 1
#define HAVE_STRING_H 1
#define HAVE_CTYPE_H 1
#define HAVE_MATH_H 1
#define HAVE_MALLOC 1
#define HAVE_CALLOC 1
#define HAVE_REALLOC 1
#define HAVE_FREE 1
//#define HAVE_ALLOCA 1
#define HAVE_QSORT 1
#define HAVE_ABS 1
#define HAVE_MEMSET 1
#define HAVE_MEMCPY 1
#define HAVE_MEMMOVE 1
#define HAVE_MEMCMP 1
#define HAVE_STRLEN 1
#define HAVE__STRUPR 1
#define HAVE_STRCHR 1
#define HAVE_STRRCHR 1
#define HAVE_STRSTR 1
#define HAVE_ITOA 1
#define HAVE_STRTOL 1
#define HAVE_STRTOUL 1
#define HAVE_STRTOLL 1
#define HAVE_STRTOD 1
#define HAVE_ATOI 1
#define HAVE_ATOF 1
#define HAVE_STRCMP 1
#define HAVE_STRNCMP 1
#define HAVE__STRICMP 1
#define HAVE__STRNICMP 1
#define HAVE_SSCANF 1
#define HAVE_STDARG_H 1
#define HAVE_STDDEF_H 1
#endif /* _SDL_CONFIG_SYMBIAN_H */
...@@ -91,7 +91,9 @@ typedef uint32_t Uint32; ...@@ -91,7 +91,9 @@ typedef uint32_t Uint32;
#ifdef SDL_HAS_64BIT_TYPE #ifdef SDL_HAS_64BIT_TYPE
typedef int64_t Sint64; typedef int64_t Sint64;
#ifndef SYMBIAN32_GCCE
typedef uint64_t Uint64; typedef uint64_t Uint64;
#endif
#else #else
/* This is really just a hack to prevent the compiler from complaining */ /* This is really just a hack to prevent the compiler from complaining */
typedef struct { typedef struct {
......
...@@ -45,7 +45,7 @@ struct SDL_Thread; ...@@ -45,7 +45,7 @@ struct SDL_Thread;
typedef struct SDL_Thread SDL_Thread; typedef struct SDL_Thread SDL_Thread;
/* Create a thread */ /* Create a thread */
#if (defined(__WIN32__) && !defined(HAVE_LIBC)) || defined(__OS2__) #if ((defined(__WIN32__) && !defined(HAVE_LIBC)) || defined(__OS2__)) && !defined(__SYMBIAN32__)
/* /*
We compile SDL into a DLL on OS/2. This means, that it's the DLL which We compile SDL into a DLL on OS/2. This means, that it's the DLL which
creates a new thread for the calling process with the SDL_CreateThread() creates a new thread for the calling process with the SDL_CreateThread()
......
...@@ -83,11 +83,15 @@ ...@@ -83,11 +83,15 @@
#endif #endif
#endif /* SDLCALL */ #endif /* SDLCALL */
/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */
#ifdef __SYMBIAN32__ #ifdef __SYMBIAN32__
#ifndef EKA2
#undef DECLSPEC #undef DECLSPEC
#define DECLSPEC #define DECLSPEC
#endif /* __SYMBIAN32__ */ #elif !defined(__WINS__)
#undef DECLSPEC
#define DECLSPEC __declspec(dllexport)
#endif //EKA2
#endif //__SYMBIAN32__
/* Force structure packing at 4 byte alignment. /* Force structure packing at 4 byte alignment.
This is necessary if the header is included in code which has structure This is necessary if the header is included in code which has structure
...@@ -116,7 +120,7 @@ ...@@ -116,7 +120,7 @@
#if defined(_MSC_VER) || defined(__BORLANDC__) || \ #if defined(_MSC_VER) || defined(__BORLANDC__) || \
defined(__DMC__) || defined(__SC__) || \ defined(__DMC__) || defined(__SC__) || \
defined(__WATCOMC__) || defined(__LCC__) || \ defined(__WATCOMC__) || defined(__LCC__) || \
defined(__DECC) defined(__DECC) || defined(__EABI__)
#ifndef __inline__ #ifndef __inline__
#define __inline__ __inline #define __inline__ __inline
#endif #endif
......
...@@ -323,7 +323,7 @@ unsigned _System LibMain(unsigned hmod, unsigned termination) ...@@ -323,7 +323,7 @@ unsigned _System LibMain(unsigned hmod, unsigned termination)
} }
#endif /* __WATCOMC__ */ #endif /* __WATCOMC__ */
#elif defined(__WIN32__) #elif defined(__WIN32__) && !defined(__SYMBIAN32__)
#if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL)) #if !defined(HAVE_LIBC) || (defined(__WATCOMC__) && defined(BUILD_DLL))
/* Need to include DllMain() on Watcom C for some reason.. */ /* Need to include DllMain() on Watcom C for some reason.. */
......
...@@ -106,6 +106,9 @@ static AudioBootStrap *bootstrap[] = { ...@@ -106,6 +106,9 @@ static AudioBootStrap *bootstrap[] = {
#endif #endif
#if SDL_AUDIO_DRIVER_DART #if SDL_AUDIO_DRIVER_DART
&DART_bootstrap, &DART_bootstrap,
#endif
#if SDL_AUDIO_DRIVER_EPOCAUDIO
&EPOCAudio_bootstrap,
#endif #endif
NULL NULL
}; };
...@@ -545,7 +548,7 @@ int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained) ...@@ -545,7 +548,7 @@ int SDL_OpenAudio(SDL_AudioSpec *desired, SDL_AudioSpec *obtained)
switch (audio->opened) { switch (audio->opened) {
case 1: case 1:
/* Start the audio thread */ /* Start the audio thread */
#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) && !defined(__SYMBIAN32__)
#undef SDL_CreateThread #undef SDL_CreateThread
audio->thread = SDL_CreateThread(SDL_RunAudio, audio, NULL, NULL); audio->thread = SDL_CreateThread(SDL_RunAudio, audio, NULL, NULL);
#else #else
......
...@@ -171,6 +171,9 @@ extern AudioBootStrap MMEAUDIO_bootstrap; ...@@ -171,6 +171,9 @@ extern AudioBootStrap MMEAUDIO_bootstrap;
#if SDL_AUDIO_DRIVER_DART #if SDL_AUDIO_DRIVER_DART
extern AudioBootStrap DART_bootstrap; extern AudioBootStrap DART_bootstrap;
#endif #endif
#if SDL_AUDIO_DRIVER_EPOCAUDIO
extern AudioBootStrap EPOCAudio_bootstrap;
#endif
/* This is the current audio device */ /* This is the current audio device */
extern SDL_AudioDevice *current_audio; extern SDL_AudioDevice *current_audio;
......
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 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@devolution.com
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id: SDL_epocaudio.h,v 1.1.2.2 2001/02/10 07:20:03 hercules Exp $";
#endif
#ifndef _SDL_EPOCAUDIO_H
#define _SDL_EPOCAUDIO_H
extern "C" {
#include "SDL_sysaudio.h"
}
#endif /* _SDL_EPOCAUDIO_H */
#include "streamplayer.h"
#include<mda/common/audio.h>
const TInt KMaxVolume(256);
LOCAL_C TInt GetSampleRate(TInt aRate)
{
switch(aRate)
{
case 8000: return TMdaAudioDataSettings::ESampleRate8000Hz;
case 11025: return TMdaAudioDataSettings::ESampleRate11025Hz;
case 12000: return TMdaAudioDataSettings::ESampleRate12000Hz;
case 16000: return TMdaAudioDataSettings::ESampleRate16000Hz;
case 22050: return TMdaAudioDataSettings::ESampleRate22050Hz;
case 24000: return TMdaAudioDataSettings::ESampleRate24000Hz;
case 32000: return TMdaAudioDataSettings::ESampleRate32000Hz;
case 44100: return TMdaAudioDataSettings::ESampleRate44100Hz;
case 48000: return TMdaAudioDataSettings::ESampleRate48000Hz;
case 96000: return TMdaAudioDataSettings::ESampleRate96000Hz;
case 64000: return TMdaAudioDataSettings::ESampleRate64000Hz;
}
return KErrNotFound;
}
LOCAL_C TInt GetChannels(TInt aChannels)
{
switch(aChannels)
{
case 1: return TMdaAudioDataSettings::EChannelsMono;
case 2: return TMdaAudioDataSettings::EChannelsStereo;
}
return KErrNotFound;
}
TInt CStreamPlayer::ClosestSupportedRate(TInt aRate)
{
if(aRate > 96000)
return 96000;
TInt rate = aRate;
while(GetSampleRate(rate) == KErrNotFound)
{
++rate;
}
return rate;
}
CStreamPlayer::CStreamPlayer(MStreamProvider& aProvider, MStreamObs& aObs) :
iProvider(aProvider), iObs(aObs), iVolume(KMaxVolume)
{
}
CStreamPlayer::~CStreamPlayer()
{
iState |= EDied;
if(iState & EInited)
Close();
User::After(100000); //wait buffer to be flushed
ASSERT(iPtr.Length() == 0);
delete iStream;
}
void CStreamPlayer::ConstructL()
{
iStream = CMdaAudioOutputStream::NewL(*this, EMdaPriorityMax);
iSilence.SetMax();
iSilence.FillZ();
}
TInt CStreamPlayer::OpenStream(TInt aRate, TInt aChannels, TUint32 aType)
{
Close();
iType = aType;
iRate = GetSampleRate(aRate);
if(iRate == KErrNotFound)
return KErrNotSupported;
iChannels = GetChannels(aChannels);
if(iChannels == KErrNotFound)
return KErrNotSupported;
Open();
return KErrNone;
}
TInt CStreamPlayer::MaxVolume() const
{
return KMaxVolume;
}
void CStreamPlayer::SetVolume(TInt aNew)
{
const TInt maxi = MaxVolume();
if(aNew > maxi)
return;
if(aNew < 0)
return;
iVolume = aNew;
iState |= EVolumeChange;
}
TInt CStreamPlayer::Volume() const
{
return iVolume;
}
void CStreamPlayer::Open()
{
TMdaAudioDataSettings audioSettings;
audioSettings.Query();
audioSettings.iCaps = TMdaAudioDataSettings::ERealTime |
TMdaAudioDataSettings::ESampleRateFixed;
audioSettings.iSampleRate = iRate;
audioSettings.iChannels = iChannels;
audioSettings.iFlags = TMdaAudioDataSettings::ENoNetworkRouting;
audioSettings.iVolume = 0;
iState &= ~EStopped;
iStream->Open(&audioSettings);
}
void CStreamPlayer::Stop()
{
if(iState & (EStarted | EInited))
{
Close();
iState |= EStopped;
}
}
void CStreamPlayer::Start()
{
if(iPtr.Length() == 0)
{
iState |= EStarted;
if(iState & EInited)
{
Request();
}
else if(iState & EStopped)
{
Open();
}
}
}
void CStreamPlayer::Close()
{
iState &= ~EInited;
iStream->Stop();
iState &= ~EStarted;
}
void CStreamPlayer::Request()
{
if(iState & EInited)
{
iPtr.Set(KNullDesC8);
if(iState & EVolumeChange)
{
const TReal newVol = iVolume;
const TReal newMax = MaxVolume();
const TInt maxVol = iStream->MaxVolume();
const TReal max = static_cast<TReal>(maxVol);
const TReal newvolume = (newVol * max) / newMax;
const TInt vol = static_cast<TReal>(newvolume);
iStream->SetVolume(vol);
iState &= ~EVolumeChange;
}
if(iState & EStarted)
{
iPtr.Set(iProvider.Data());
}
if(iPtr.Length() == 0)
{
iPtr.Set(iSilence);
}
TRAPD(err, iStream->WriteL(iPtr));
if(err != KErrNone)
{
iObs.Complete(MStreamObs::EWrite, err);
}
/* else
{
iProvider.Written(iPtr.Length());
}*/
}
}
void CStreamPlayer::SetCapsL()
{
iStream->SetDataTypeL(iType);
iStream->SetAudioPropertiesL(iRate, iChannels);
}
void CStreamPlayer::MaoscOpenComplete(TInt aError)
{
if(aError == KErrNone)
{
TRAPD(err, SetCapsL());
if(err == KErrNone)
{
iStream->SetPriority(EPriorityNormal, EMdaPriorityPreferenceTime);
iState |= EInited;
SetVolume(Volume());
if(iState & EStarted)
{
Request();
}
}
aError = err;
}
if(!(iState & EDied))
iObs.Complete(MStreamObs::EInit, aError);
}
void CStreamPlayer::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/)
{
iPtr.Set(KNullDesC8);
if(aError == KErrNone)
{
if(iState & EInited)
Request();
else
iStream->Stop();
}
else if(!(iState & EDied))
iObs.Complete(MStreamObs::EPlay, aError);
}
void CStreamPlayer::MaoscPlayComplete(TInt aError)
{
iPtr.Set(KNullDesC8);
iState &= ~EStarted;
if(!(iState & EDied))
iObs.Complete(MStreamObs::EClose, aError);
}
TBool CStreamPlayer::Playing() const
{
return (iState & EInited) && (iState & EStarted);
}
TBool CStreamPlayer::Closed() const
{
return !(iState & EInited) && !(iState & EDied);
}
/*
void CStreamPlayer::Request()
{
SetActive();
TRequestStatus* s = &iStatus;
User::RequestComplete(s, KErrNone);
}
// iTimer.After(0);
*/
#ifndef STREAMPLAYER_H
#define STREAMPLAYER_H
#include<MdaAudioOutputStream.h>
const TInt KSilenceBuffer = 256;
class MStreamObs
{
public:
enum
{
EInit,
EPlay,
EWrite,
EClose,
};
virtual void Complete(TInt aState, TInt aError) = 0;
};
class MStreamProvider
{
public:
virtual TPtrC8 Data() = 0;
};
NONSHARABLE_CLASS(CStreamPlayer) : public CBase, public MMdaAudioOutputStreamCallback
{
public:
CStreamPlayer(MStreamProvider& aProvider, MStreamObs& aObs);
~CStreamPlayer();
void ConstructL();
static TInt ClosestSupportedRate(TInt aRate);
TInt OpenStream(TInt aRate, TInt aChannels, TUint32 aType = KMMFFourCCCodePCM16);
void SetVolume(TInt aNew);
TInt Volume() const;
TInt MaxVolume() const;
void Stop();
void Start();
void Open();
void Close();
TBool Playing() const;
TBool Closed() const;
private:
void MaoscOpenComplete(TInt aError) ;
void MaoscBufferCopied(TInt aError, const TDesC8& aBuffer);
void MaoscPlayComplete(TInt aError);
private:
void Request();
void SetCapsL();
private:
MStreamProvider& iProvider;
MStreamObs& iObs;
TInt iVolume;
CMdaAudioOutputStream* iStream;
TInt iRate;
TInt iChannels;
TUint32 iType;
enum
{
ENone = 0,
EInited = 0x1,
EStarted = 0x2,
EStopped = 0x4,
EVolumeChange = 0x8,
EDied = 0x10
};
TInt iState;
TBuf8<KSilenceBuffer> iSilence;
TPtrC8 iPtr;
};
#endif
...@@ -169,7 +169,7 @@ static int SDL_StartEventThread(Uint32 flags) ...@@ -169,7 +169,7 @@ static int SDL_StartEventThread(Uint32 flags)
/* The event thread will handle timers too */ /* The event thread will handle timers too */
SDL_SetTimerThreaded(2); SDL_SetTimerThreaded(2);
#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) #if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) && !defined(__SYMBIAN32__)
#undef SDL_CreateThread #undef SDL_CreateThread
SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL); SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL);
#else #else
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "SDL_rwops.h" #include "SDL_rwops.h"
#if defined(__WIN32__) #if defined(__WIN32__) && !defined(__SYMBIAN32__)
/* Functions to read/write Win32 API file pointers */ /* Functions to read/write Win32 API file pointers */
/* Will not use it on WinCE because stdio is buffered, it means /* Will not use it on WinCE because stdio is buffered, it means
...@@ -372,7 +372,7 @@ SDL_RWops *SDL_RWFromFile(const char *file, const char *mode) ...@@ -372,7 +372,7 @@ SDL_RWops *SDL_RWFromFile(const char *file, const char *mode)
return NULL; return NULL;
} }
#if defined(__WIN32__) #if defined(__WIN32__) && !defined(__SYMBIAN32__)
rwops = SDL_AllocRW(); rwops = SDL_AllocRW();
if (!rwops) if (!rwops)
return NULL; /* SDL_SetError already setup by SDL_AllocRW() */ return NULL; /* SDL_SetError already setup by SDL_AllocRW() */
......
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 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@devolution.com
*/
/*
SDL_main.cpp
The Epoc executable startup functions
Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi)
*/
#include <e32std.h>
#include <e32def.h>
#include <e32svr.h>
#include <e32base.h>
#include <estlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <w32std.h>
#include <apgtask.h>
#include "SDL_error.h"
#if defined(__WINS__)
#include <estw32.h>
IMPORT_C void RegisterWsExe(const TDesC &aName);
#endif
/* The prototype for the application's main() function */
#define main SDL_main
extern "C" int main (int argc, char *argv[], char *envp[]);
extern "C" void exit (int ret);
/* Epoc main function */
#ifdef __WINS__
void GetCmdLine(int& aArgc, char**& aArgv)
{
RChunk chunk;
if(chunk.OpenGlobal(RThread().Name(), ETrue) != KErrNone)
return;
TUint* ptr = (TUint*) chunk.Base();
if(ptr != NULL)
{
aArgc = (int) *(ptr); // count
aArgv = (char**) *(ptr + 1);
}
chunk.Close();
}
#endif
TInt E32Main()
{
/* Get the clean-up stack */
CTrapCleanup* cleanup = CTrapCleanup::New();
/* Arrange for multi-threaded operation */
SpawnPosixServerThread();
/* Get args and environment */
int argc=0;
char** argv=0;
char** envp=0;
#ifndef __WINS__
__crt0(argc,argv,envp);
#else
GetCmdLine(argc, argv);
#endif
/* Start the application! */
/* Create stdlib */
_REENT;
/* Set process and thread priority and name */
RThread currentThread;
RProcess thisProcess;
TParse exeName;
exeName.Set(thisProcess.FileName(), NULL, NULL);
currentThread.Rename(exeName.Name());
currentThread.SetProcessPriority(EPriorityLow);
currentThread.SetPriority(EPriorityMuchLess);
/* Call stdlib main */
int ret = main(argc, argv, envp); /* !! process exits here if there is "exit()" in main! */
/* Call exit */
//exit(ret); /* !! process exits here! */
//Markus: I do not understand above
//I commented it at let this function
//to return ret value - was it purpose
//that cleanup below is not called at all - why?
/* Free resources and return */
_cleanup(); //this is normally called at exit, I call it here, Markus
CloseSTDLIB();
delete cleanup;
#ifdef __WINS__
// User::Panic(_L("exit"), ret);
// RThread().Kill(ret); //Markus get rid of this thread
// RThread().RaiseException(EExcKill);
#endif
return ret;//Markus, or exit(ret); ??
//return(KErrNone);
}
#ifdef __WINS__
EXPORT_C TInt WinsMain()
{
return E32Main();
// return WinsMain(0, 0, 0);
}
#endif
/* Epoc dll entry point */
#if defined(__WINS__)
GLDEF_C TInt E32Dll(TDllReason)
{
return(KErrNone);
}
#endif
This diff is collapsed.
This diff is collapsed.
#include<eikstart.h>
#include<sdlmain.h>
#include<sdlepocapi.h>
GLREF_C TInt E32Main()
{
return SDLEnv::SetMain(SDL_main, CSDL::EEnableFocusStop | CSDL::EAllowImageResize,
NULL, SDLEnv::EParamQuery | SDLEnv::EVirtualMouse);
}
\ No newline at end of file
/*
vectorbuffer.cpp
yet another circle buffer
Markus Mertama
*/
#include"vectorbuffer.h"
void VectorPanic(TInt aErr, TInt aLine)
{
TBuf<64> b;
b.Format(_L("vector buffer at % d "), aLine);
User::Panic(b, aErr);
}
void TNodeBuffer::TNode::Terminator(TNodeBuffer::TNode* aNode)
{
Mem::Copy(iSucc, &aNode, sizeof(TNode*));
}
TInt TNodeBuffer::TNode::Size() const
{
return reinterpret_cast<const TUint8*>(iSucc) - Ptr();
}
const TUint8* TNodeBuffer::TNode::Ptr() const
{
return reinterpret_cast<const TUint8*>(this) + sizeof(TNode);
}
TNodeBuffer::TNode* TNodeBuffer::TNode::Empty(TUint8* aBuffer)
{
TNode* node = reinterpret_cast<TNode*>(aBuffer);
node->iSucc = node + 1;
return node;
}
TNodeBuffer::TNode* TNodeBuffer::TNode::New(TNode* aPred, const TDesC8& aData)
{
TNode* node = aPred->Size() == 0 ? aPred : aPred->iSucc;
TUint8* start = reinterpret_cast<TUint8*>(node) + sizeof(TNode);
node->iSucc = reinterpret_cast<TNode*>(start + aData.Size());
node->iSucc->iSucc = NULL; //terminator
__ASSERT_DEBUG(node->Size() == aData.Size(), VECPANIC(KErrCorrupt));
Mem::Copy(start, aData.Ptr(), aData.Size());
return node;
}
\ No newline at end of file
/*
vectorbuffer.cpp
yet another circle buffer
Markus Mertama
*/
#ifndef __VECTORBUFFER_H__
#define __VECTORBUFFER_H__
#include<e32std.h>
#define VLOG(x)
#define VECPANIC(x) VectorPanic(x, __LINE__)
void VectorPanic(TInt, TInt);
//int DEBUG_INT;
NONSHARABLE_CLASS(TNodeBuffer)
{
public:
protected:
NONSHARABLE_CLASS(TNode)
{
public:
static TNode* Empty(TUint8* iBuffer);
static TNode* New(TNode* aPrev, const TDesC8& aData);
const TUint8* Ptr() const;
TInt Size() const;
inline TNode* Succ();
static void SetSucc(TNode*& aNode);
void Terminator(TNode* aNode);
private:
TNode* iSucc;
};
};
inline TNodeBuffer::TNode* TNodeBuffer::TNode::Succ()
{
return iSucc;
}
template <TInt C>
NONSHARABLE_CLASS(TVectorBuffer) : public TNodeBuffer
{
public:
TVectorBuffer();
TInt Append(const TDesC8& aData);
// TInt AppendOverwrite(const TDesC8& aData);
TPtrC8 Shift();
TPtrC8 operator[](TInt aIndex) const;
TInt Size() const;
private:
TInt GetRoom(TInt aSize) const;
TInt Unreserved() const;
private:
TNode* iTop;
TNode* iBottom;
TInt iSize;
TUint8 iBuffer[C];
};
template <TInt C>
TVectorBuffer<C>::TVectorBuffer() : iSize(0)
{
Mem::FillZ(iBuffer, C);
iTop = TNode::Empty(iBuffer); //these points to buffer
iBottom = TNode::Empty(iBuffer);
}
template<TInt C >
TInt TVectorBuffer<C>::Unreserved() const
{
__ASSERT_DEBUG(iBottom < iBottom->Succ(), VECPANIC(KErrCorrupt));
const TInt bytesbetween =
reinterpret_cast<const TUint8*>(iBottom->Succ()) -
reinterpret_cast<const TUint8*>(iTop);
const TInt topsize = sizeof(TNode);
if(bytesbetween > 0) //bytesbetween is room between bottom and top
{ //therefore free room is subracted from free space
const TInt room = C - bytesbetween - topsize;
return room;
}
if(bytesbetween == 0)
{
if(Size() > 0)
return 0;
else
return C - topsize;
}
const TInt room = -bytesbetween - topsize; //free is space between pointers
return room;
}
template <TInt C>
TInt TVectorBuffer<C>::GetRoom(TInt aSize) const
{
const TInt bytesnew = sizeof(TNode) + aSize;
const TInt room = Unreserved() - bytesnew;
return room;
}
template <TInt C>
TInt TVectorBuffer<C>::Append(const TDesC8& aData) //ei ole ok!
{
const TInt len = aData.Length();
if(GetRoom(len) < 0)
{
return KErrOverflow;
}
if(iBottom->Succ()->Ptr() - iBuffer > (C - (len + TInt(sizeof(TNode)))))
{
VLOG("rc");
// RDebug::Print(_L("vector: append"));
TNode* p = TNode::Empty(iBuffer);
iBottom->Terminator(p);
iBottom = p;
return Append(aData);
// Append();
// iBottom = TNode::New(p, aData); //just append something into end
}
//DEBUG_INT++;
iBottom = TNode::New(iBottom, aData);
iSize += len;
return KErrNone;
}
/*
template <TInt C>
TInt TVectorBuffer<C>::AppendOverwrite(const TDesC8& aData) //ei ole ok!
{
while(Append(aData) == KErrOverflow)
{
if(iTop->Succ() == NULL)
{
return KErrUnderflow;
}
//Shift(); //data is lost
}
return KErrNone;
}
*/
template <TInt C>
TPtrC8 TVectorBuffer<C>::Shift()
{
__ASSERT_ALWAYS(iTop->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom
TNode* node = iTop;
iTop = iTop->Succ();
if(iTop > node)
{
// DEBUG_INT--;
iSize -= node->Size();
return TPtrC8(node->Ptr(), node->Size());
}
else
{
// RDebug::Print(_L("vector: shift"));
return Shift(); //this happens when buffer is terminated, and data lies in next
}
}
template <TInt C>
TInt TVectorBuffer<C>::Size() const
{
return iSize;
}
template <TInt C>
TPtrC8 TVectorBuffer<C>::operator[](TInt aIndex) const
{
TInt index = 0;
TNode* t = iTop->Size() > 0 ? iTop : iTop->Succ(); //eliminate terminator
while(index < aIndex)
{
TNode* nt = t->Succ();
if(nt < t)
{
nt = nt->Succ();
}
t = nt;
if(t->Size() > 0)
index++;
__ASSERT_ALWAYS(t->Succ() != NULL, VECPANIC(KErrUnderflow)); //can never pass-by bottom
}
return t->Ptr();
}
template <class T, TInt C>
NONSHARABLE_CLASS(TVector) : public TVectorBuffer<C * sizeof(T)>
{
public:
TVector();
TInt Append(const T& aData);
const T& Shift();
TInt Size() const;
const T& operator[](TInt aIndex) const;
};
template <class T, TInt C>
TVector<T, C>::TVector() : TVectorBuffer<C * sizeof(T)>()
{
}
template <class T, TInt C>
TInt TVector<T, C>::Append(const T& aData)
{
const TPckgC<T> data(aData);
return TVectorBuffer<C * sizeof(T)>::Append(data);
}
template <class T, TInt C>
const T& TVector<T, C>::Shift()
{
const TPtrC8 ptr = TVectorBuffer<C * sizeof(T)>::Shift();
return *(reinterpret_cast<const T*>(ptr.Ptr()));
}
template <class T, TInt C>
TInt TVector<T, C>::Size() const
{
return TVectorBuffer<C * sizeof(T)>::Size() / sizeof(T);
}
template <class T, TInt C>
const T& TVector<T, C>::operator[](TInt aIndex) const
{
const TPtrC8 ptr = TVectorBuffer<C * sizeof(T)>::operator[](aIndex);
return *(reinterpret_cast<const T*>(ptr.Ptr()));
}
#endif
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
#ifndef HAVE_GETENV #ifndef HAVE_GETENV
#if defined(__WIN32__) && !defined(_WIN32_WCE) #if defined(__WIN32__) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
......
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
#include "beos/SDL_systhread_c.h" #include "beos/SDL_systhread_c.h"
#elif SDL_THREAD_DC #elif SDL_THREAD_DC
#include "dc/SDL_systhread_c.h" #include "dc/SDL_systhread_c.h"
#elif SDL_THREAD_EPOC
#include "epoc/SDL_systhread_c.h"
#elif SDL_THREAD_OS2 #elif SDL_THREAD_OS2
#include "os2/SDL_systhread_c.h" #include "os2/SDL_systhread_c.h"
#elif SDL_THREAD_PTH #elif SDL_THREAD_PTH
...@@ -43,6 +41,8 @@ ...@@ -43,6 +41,8 @@
#include "irix/SDL_systhread_c.h" #include "irix/SDL_systhread_c.h"
#elif SDL_THREAD_WIN32 #elif SDL_THREAD_WIN32
#include "win32/SDL_systhread_c.h" #include "win32/SDL_systhread_c.h"
#elif SDL_THREAD_SYMBIAN
#include "symbian/SDL_systhread_c.h"
#else #else
#error Need thread implementation for this platform #error Need thread implementation for this platform
#include "generic/SDL_systhread_c.h" #include "generic/SDL_systhread_c.h"
......
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000 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@devolution.com
*/
/*
SDL_sysmutex.cpp
Epoc version by Markus Mertama (w@iki.fi)
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id: SDL_sysmutex.c,v 1.1.2.3 2000/06/22 15:25:23 hercules Exp $";
#endif
/* Mutex functions using the Win32 API */
//#include <stdio.h>
//#include <stdlib.h>
#include <e32std.h>
#include "epoc_sdl.h"
#include "SDL_error.h"
#include "SDL_mutex.h"
#ifdef EKA2 //???
struct SDL_mutex
{
TInt handle;
};
#else
struct _SDL_mutex
{
TInt handle;
};
#endif
extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*);
TInt NewMutex(const TDesC& aName, TAny* aPtr1, TAny*)
{
return ((RMutex*)aPtr1)->CreateGlobal(aName);
}
void DeleteMutex(TAny* aMutex)
{
SDL_DestroyMutex ((SDL_mutex*) aMutex);
}
/* Create a mutex */
SDL_mutex *SDL_CreateMutex(void)
{
RMutex rmutex;
TInt status = CreateUnique(NewMutex, &rmutex, NULL);
if(status != KErrNone)
{
SDL_SetError("Couldn't create mutex");
}
SDL_mutex* mutex = new /*(ELeave)*/ SDL_mutex;
mutex->handle = rmutex.Handle();
EpocSdlEnv::AppendCleanupItem(TSdlCleanupItem(DeleteMutex, mutex));
return(mutex);
}
/* Free the mutex */
void SDL_DestroyMutex(SDL_mutex *mutex)
{
if ( mutex )
{
RMutex rmutex;
rmutex.SetHandle(mutex->handle);
if(rmutex.IsHeld())
{
rmutex.Signal();
}
rmutex.Close();
EpocSdlEnv::RemoveCleanupItem(mutex);
delete(mutex);
mutex = NULL;
}
}
/* Lock the mutex */
int SDL_mutexP(SDL_mutex *mutex)
{
if ( mutex == NULL ) {
SDL_SetError("Passed a NULL mutex");
return -1;
}
RMutex rmutex;
rmutex.SetHandle(mutex->handle);
rmutex.Wait();
return(0);
}
/* Unlock the mutex */
int SDL_mutexV(SDL_mutex *mutex)
{
if ( mutex == NULL ) {
SDL_SetError("Passed a NULL mutex");
return -1;
}
RMutex rmutex;
rmutex.SetHandle(mutex->handle);
rmutex.Signal();
return(0);
}
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000 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@devolution.com
*/
/*
SDL_syssem.cpp
Epoc version by Markus Mertama (w@iki.fi)
*/
#ifdef SAVE_RCSID
static char rcsid =
"@(#) $Id: SDL_syssem.c,v 1.1.2.4 2000/06/22 15:24:48 hercules Exp $";
#endif
/* Semaphore functions using the Win32 API */
//#include <stdio.h>
//#include <stdlib.h>
#include <e32std.h>
#include "SDL_error.h"
#include "SDL_thread.h"
#define SDL_MUTEX_TIMEOUT -2
struct SDL_semaphore
{
TInt handle;
TInt count;
};
extern TInt CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny*, TAny*);
#ifndef EKA2
extern TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2);
#endif
TInt NewSema(const TDesC& aName, TAny* aPtr1, TAny* aPtr2)
{
TInt value = *((TInt*) aPtr2);
return ((RSemaphore*)aPtr1)->CreateGlobal(aName, value);
}
/* Create a semaphore */
SDL_sem *SDL_CreateSemaphore(Uint32 initial_value)
{
RSemaphore s;
TInt status = CreateUnique(NewSema, &s, &initial_value);
if(status != KErrNone)
{
SDL_SetError("Couldn't create semaphore");
}
SDL_semaphore* sem = new /*(ELeave)*/ SDL_semaphore;
sem->handle = s.Handle();
sem->count = initial_value;
return(sem);
}
/* Free the semaphore */
void SDL_DestroySemaphore(SDL_sem *sem)
{
if ( sem )
{
RSemaphore sema;
sema.SetHandle(sem->handle);
while(--sem->count)
sema.Signal();
sema.Close();
delete sem;
sem = NULL;
}
}
#ifndef EKA2
struct TInfo
{
TInfo(TInt aTime, TInt aHandle) :
iTime(aTime), iHandle(aHandle), iVal(0) {}
TInt iTime;
TInt iHandle;
TInt iVal;
};
TBool ThreadRun(TAny* aInfo)
{
TInfo* info = STATIC_CAST(TInfo*, aInfo);
User::After(info->iTime);
RSemaphore sema;
sema.SetHandle(info->iHandle);
sema.Signal();
info->iVal = SDL_MUTEX_TIMEOUT;
return 0;
}
#endif
void _WaitAll(SDL_sem *sem)
{
//since SemTryWait may changed the counter.
//this may not be atomic, but hopes it works.
RSemaphore sema;
sema.SetHandle(sem->handle);
sema.Wait();
while(sem->count < 0)
{
sema.Wait();
}
}
int SDL_SemWaitTimeout(SDL_sem *sem, Uint32 timeout)
{
if ( ! sem ) {
SDL_SetError("Passed a NULL sem");
return -1;
}
if ( timeout == SDL_MUTEX_MAXWAIT )
{
_WaitAll(sem);
return SDL_MUTEX_MAXWAIT;
}
#ifdef EKA2
RSemaphore sema;
sema.SetHandle(sem->handle);
if(KErrNone == sema.Wait(timeout))
return 0;
return -1;
#else
RThread thread;
TInfo* info = new (ELeave)TInfo(timeout, sem->handle);
TInt status = CreateUnique(NewThread, &thread, info);
if(status != KErrNone)
return status;
thread.Resume();
_WaitAll(sem);
if(thread.ExitType() == EExitPending)
{
thread.Kill(SDL_MUTEX_TIMEOUT);
}
thread.Close();
return info->iVal;
#endif
}
int SDL_SemTryWait(SDL_sem *sem)
{
if(sem->count > 0)
{
sem->count--;
}
return SDL_MUTEX_TIMEOUT;
}
int SDL_SemWait(SDL_sem *sem)
{
return SDL_SemWaitTimeout(sem, SDL_MUTEX_MAXWAIT);
}
/* Returns the current count of the semaphore */
Uint32 SDL_SemValue(SDL_sem *sem)
{
if ( ! sem ) {
SDL_SetError("Passed a NULL sem");
return 0;
}
return sem->count;
}
int SDL_SemPost(SDL_sem *sem)
{
if ( ! sem ) {
SDL_SetError("Passed a NULL sem");
return -1;
}
sem->count++;
RSemaphore sema;
sema.SetHandle(sem->handle);
sema.Signal();
return 0;
}
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000 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@devolution.com
*/
/*
SDL_systhread.cpp
Epoc thread management routines for SDL
Epoc version by Markus Mertama (w@iki.fi)
*/
#include "epoc_sdl.h"
//#include <stdlib.h>
//#include <stdio.h>
extern "C" {
#undef NULL
#include "SDL_error.h"
#include "SDL_thread.h"
#include "SDL_systhread.h"
#include "SDL_thread_c.h"
}
#include <e32std.h>
#include "epoc_sdl.h"
static int object_count;
int RunThread(TAny* data)
{
CTrapCleanup* cleanup = CTrapCleanup::New();
TRAPD(err, SDL_RunThread(data));
EpocSdlEnv::CleanupItems();
delete cleanup;
return(err);
}
TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2)
{
return ((RThread*)(aPtr1))->Create(aName,
RunThread,
KDefaultStackSize,
NULL,
aPtr2);
}
int CreateUnique(TInt (*aFunc)(const TDesC& aName, TAny*, TAny*), TAny* aPtr1, TAny* aPtr2)
{
TBuf<16> name;
TInt status = KErrNone;
do
{
object_count++;
name.Format(_L("SDL_%x"), object_count);
status = aFunc(name, aPtr1, aPtr2);
}
while(status == KErrAlreadyExists);
return status;
}
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
{
RThread rthread;
const TInt status = CreateUnique(NewThread, &rthread, args);
if (status != KErrNone)
{
delete(((RThread*)(thread->handle)));
thread->handle = NULL;
SDL_SetError("Not enough resources to create thread");
return(-1);
}
rthread.Resume();
thread->handle = rthread.Handle();
return(0);
}
void SDL_SYS_SetupThread(void)
{
return;
}
Uint32 SDL_ThreadID(void)
{
RThread current;
const TThreadId id = current.Id();
return id;
}
void SDL_SYS_WaitThread(SDL_Thread *thread)
{
SDL_TRACE1("Close thread", thread);
RThread t;
const TInt err = t.Open(thread->threadid);
if(err == KErrNone && t.ExitType() == EExitPending)
{
TRequestStatus status;
t.Logon(status);
User::WaitForRequest(status);
}
t.Close();
/* RUndertaker taker;
taker.Create();
TRequestStatus status;
taker.Logon(status, thread->handle);
User::WaitForRequest(status);
taker.Close();*/
SDL_TRACE1("Closed thread", thread);
}
/* WARNING: This function is really a last resort.
* Threads should be signaled and then exit by themselves.
* TerminateThread() doesn't perform stack and DLL cleanup.
*/
void SDL_SYS_KillThread(SDL_Thread *thread)
{
RThread rthread;
rthread.SetHandle(thread->handle);
rthread.Kill(0);
rthread.Close();
}
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000 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@devolution.com
*/
/*
SDL_systhread_c.h
Epoc version by Markus Mertama (w@iki.fi)
*/
typedef int SYS_ThreadHandle;
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 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@devolution.com
*/
/*
SDL_systimer.cpp
Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi)
Markus Mertama
*/
#include <e32std.h>
#include <e32hal.h>
extern "C" {
#include "SDL_error.h"
#include "SDL_thread.h"
#include "SDL_timer.h"
#include "SDL_timer_c.h"
static TUint start = 0;
static TInt tickPeriodMilliSeconds;
void SDL_StartTicks(void)
{
/* Set first ticks value */
start = User::TickCount();
TTimeIntervalMicroSeconds32 period;
TInt tmp = UserHal::TickPeriod(period);
tickPeriodMilliSeconds = period.Int() / 1000;
}
Uint32 SDL_GetTicks(void)
{
TUint deltaTics = User::TickCount() - start;
return(deltaTics * tickPeriodMilliSeconds);
}
void SDL_Delay(Uint32 ms)
{
User::After(TTimeIntervalMicroSeconds32(ms*1000));
}
/* Data to handle a single periodic alarm */
static int timer_alive = 0;
static SDL_Thread *timer = NULL;
static int RunTimer(void *unused)
{
while ( timer_alive )
{
if (SDL_timer_running)
{
SDL_ThreadedTimerCheck();
}
SDL_Delay(10);
}
return(0);
}
/* This is only called if the event thread is not running */
int SDL_SYS_TimerInit(void)
{
if(timer != NULL)
return (-1);
timer_alive = 1;
timer = SDL_CreateThread(RunTimer, NULL);
if ( timer == NULL )
return(-1);
return(SDL_SetTimerThreaded(1));
}
void SDL_SYS_TimerQuit(void)
{
timer_alive = 0;
if ( timer )
{
SDL_WaitThread(timer, NULL);
timer = NULL;
}
}
int SDL_SYS_StartTimer(void)
{
SDL_SetError("Internal logic error: Epoc uses threaded timer");
return(-1);
}
void SDL_SYS_StopTimer(void)
{
return;
}
} // extern "C"
This diff is collapsed.
This diff is collapsed.
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997, 1998, 1999, 2000, 2001 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@devolution.com
*/
#ifndef _SDL_epocvideo_h
#define _SDL_epocvideo_h
#ifndef EKA2
#include"SDL_epocvideo_org.h"
#else
#include"SDL_epocvideo2.h"
#endif
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment