Mercurial > sdl-ios-xcode
changeset 173:83018110dce8
Added initial support for EPOC/Symbian OS (thanks Hannu!)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 11 Sep 2001 20:38:49 +0000 |
parents | 37e3ca9254c7 |
children | da9a97f693a8 |
files | README.Epoc docs.html include/SDL_byteorder.h include/SDL_main.h include/SDL_types.h include/begin_code.h src/main/Makefile.am src/main/epoc/SDL_main.cpp src/thread/Makefile.am src/thread/epoc/SDL_sysmutex.cpp src/thread/epoc/SDL_syssem.cpp src/thread/epoc/SDL_systhread.cpp src/thread/epoc/SDL_systhread_c.h src/timer/Makefile.am src/timer/epoc/SDL_systimer.cpp src/video/Makefile.am src/video/SDL_sysvideo.h src/video/SDL_video.c src/video/epoc/SDL_epocevents.cpp src/video/epoc/SDL_epocevents_c.h src/video/epoc/SDL_epocvideo.cpp src/video/epoc/SDL_epocvideo.h |
diffstat | 22 files changed, 2103 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.Epoc Tue Sep 11 20:38:49 2001 +0000 @@ -0,0 +1,87 @@ +31.8.2001 HJV + +SDL for EPOC/Symbian OS +======================= + +This is an Epoc port of SDL (1.2.0). It is not yet complete, but good enough for starting to port all those wonderful SDL based demos, games and other programs to Epoc! I have tested a bunch of demos and test programs in Nokia 9210 Communicator, which is a fancy device with combined PDA/GSM phone features, Symbian OS (Crystal), a full keyboard and a color screen (640x200x12bit). + +Btw. Also SDLDoom works over SDL Epoc port now (CDoom)! + + +How to install to device +======================== + +Extract binary packets of the demo and test programs and copy the files to N9210. + + +How to use +========== + +Run exe's from the File manager. The Caps lock key enables or disables the virtual cursor. +The Esc key quits demo programs. +Function keys are mapped as follows: +- F1=chr+q, F2=chr+w,..., F8=chr+i, +- F9=chr+a,..., F12=chr+d. + +In Crystal, Exe programs do not appear in task list nor in Extras :-( + + +How to build +============ + +Building SDL, SDL_IMAGE and tests & demos: +- Build files are in "\sdl\epoc\" and "\sdl_image\epoc\" directories +- Building as usual: "bldmake bldfiles" "abld build wins udeb" "abld build armi urel" +- Test and demos programs are build: "abld test build wins udeb" "abld test build armi urel" + + +Building and sources +==================== +Information about the Epoc implementation: +- Made over SDL 1.2.0 +- Ported sources: SDL, SDL_image, xflame, fire, warp, newvox, graywin, testalpha, SDLDoom(CDoom) +- Test programs do not have any major changes: usually only screen size and depth is + changed for 9210, if needed +- Like in all the other platform implementations, the Epoc specific code is in "Epoc" subdirectories. All build files for Epoc are in the directory \sdl\epoc\. Adding a new OS support requires always some changes also in generic files (search for "#ifdef __SYMBIAN32__"). +- Currently, two resolutions and bit depths are supported: 320x200 and 640x200 with 8 or 12 bit color. +- I addition, two faked resolutions are supported: 640x400, 640x480. These are implemented by shrinking the screen vertically i.e. only every second scanline is drawn. This can be used for testing and for non-resource intensive programs. Thought, using faked resolutions is a waste of memory and cpu power! + +Change history +============== + +31.8.2001 Alpha 0.2: +- Now you should build ARMI binaries instead of THUMB. It runs faster. +- sdl_main.cpp: removed check for existing instance of sdlprogram +- sdl_error.h: Added debug macros under conditional compilation in Epoc +- sdl_epocevents.cpp: Added focus lost&gained event handling, added modifier handling, added a lot more key event handling (function keys and others). Function keys are mapped as follows: + F1=chr+q, F2=chr+w,..., F8=chr+i, F9=chr+a,..., F12=chr+d. +- sdl_epocvideo.h: Added EPOC_ScreenOffset variable. Added EPOC_IsWindowFocused variable (but not used for anything yet!). Added RedrawWindowL() function. +- sdl_epocvideo.cpp: Added debugging functions: Debug_AvailMem2() and Debug_AvailMem(). + Changed window to have white background. Centralize game screen if it is not full size. + Added RedrawWindowL() function. Force other windows to redraw if SDL window lost focus. This cleans up possible game graphics from screen. Redraw after getting focus again. + + +Todo +==== + +This Epoc port is (of course;-) not thoroughly tested. For testing, I have compiled and run a couple of test programs and demos in N9210. Still, e.g. thread related functions have not been tested at all. + +Known bugs and unimplemented features: +- No sound +- No console output screen. Printing to stdout do not have any effect. +- Epoc do not allow static/global variables in DLL libraries. So I could only use static linking with SDL. +- Some test programs may take so much cpu in 9210 that e.g. SMS sending and receiving is not possible at a same time. Also screen may look awkward if there appear visible notes, dialogs etc. when an sdl program is active. SDL program runs in the lowest possible priority for minimum interference in the system. Unfortunately, this is always not enough. Perhaps some Delay() commands are needed. + +P.s. I have ported also the SDL version of MirrorMagic puzzle game to Epoc. I will put the sources and binaries available as soon as I bother to clean the ported sources a bit... + + +Open Source & "bazaar" style software development +================================================= + +You can take part in this porting project. This is Open Source software and you are very welcome to try it, test it, improve the code and implement the missing pieces. If you have any fix suggestions, improvements, code excerpts etc., contact me by email. Please start the mail subject with a string "EPOC SDL:". + +Cheers, +Hannu + +Mail:hannu.j.viitala@mbnet.fi +Homepage of SDL for Epoc: www.mbnet.fi/~haviital
--- a/docs.html Tue Sep 11 19:00:18 2001 +0000 +++ b/docs.html Tue Sep 11 20:38:49 2001 +0000 @@ -16,6 +16,8 @@ Major changes since SDL 1.0.0: </H2> <UL> + <LI> 1.2.3: Added initial support for EPOC/Symbian OS (thanks Hannu!) + <LI> 1.2.3: Improved MacOS X international keyboard handling <LI> 1.2.3: Added support for DirectFB video on Linux (thanks Denis!) <LI> 1.2.3: Fixed IDE and SCSI CD-ROM detection on BeOS (thanks Caz!) <LI> 1.2.3: Fixed the system dependent SDL_WINDOWID hack on Windows
--- a/include/SDL_byteorder.h Tue Sep 11 19:00:18 2001 +0000 +++ b/include/SDL_byteorder.h Tue Sep 11 20:38:49 2001 +0000 @@ -43,6 +43,7 @@ (defined(__alpha__) || defined(__alpha)) || \ defined(__arm__) || \ (defined(__mips__) && defined(__MIPSEL__)) || \ + defined(__SYMBIAN32__) || \ defined(__LITTLE_ENDIAN__) #define SDL_BYTEORDER SDL_LIL_ENDIAN #else
--- a/include/SDL_main.h Tue Sep 11 19:00:18 2001 +0000 +++ b/include/SDL_main.h Tue Sep 11 20:38:49 2001 +0000 @@ -31,7 +31,7 @@ /* Redefine main() on Win32 and MacOS so that it is called by winmain.c */ #if defined(WIN32) || (defined(__MWERKS__) && !defined(__BEOS__)) || \ - defined(macintosh) || defined(__APPLE__) + defined(macintosh) || defined(__APPLE__) || defined(__SYMBIAN32__) #ifdef __cplusplus #define C_LINKAGE "C"
--- a/include/SDL_types.h Tue Sep 11 19:00:18 2001 +0000 +++ b/include/SDL_types.h Tue Sep 11 20:38:49 2001 +0000 @@ -54,6 +54,11 @@ #endif #endif /* !__STRICT_ANSI__ */ +/* The 64-bit type isn't available on EPOC/Symbian OS */ +#ifdef __SYMBIAN32__ +#undef SDL_HAS_64BIT_TYPE +#endif + /* The 64-bit datatype isn't supported on all platforms */ #ifdef SDL_HAS_64BIT_TYPE typedef unsigned SDL_HAS_64BIT_TYPE Uint64;
--- a/include/begin_code.h Tue Sep 11 19:00:18 2001 +0000 +++ b/include/begin_code.h Tue Sep 11 20:38:49 2001 +0000 @@ -48,6 +48,12 @@ # endif #endif +/* Removed DECLSPEC on Symbian OS because SDL cannot be a DLL in EPOC */ +#ifdef __SYMBIAN32__ +#undef DECLSPEC +#define DECLSPEC +#endif // __SYMBIAN32__ + /* Force structure packing at 4 byte alignment. This is necessary if the header is included in code which has structure packing set to an alternate value, say for loading structures from disk.
--- a/src/main/Makefile.am Tue Sep 11 19:00:18 2001 +0000 +++ b/src/main/Makefile.am Tue Sep 11 20:38:49 2001 +0000 @@ -6,8 +6,12 @@ SUBDIRS = macosx -ARCH_SUBDIRS = $(srcdir)/beos $(srcdir)/linux \ - $(srcdir)/macos $(srcdir)/macosx $(srcdir)/win32 +ARCH_SUBDIRS = $(srcdir)/beos \ + $(srcdir)/epoc \ + $(srcdir)/linux \ + $(srcdir)/macos \ + $(srcdir)/macosx \ + $(srcdir)/win32 # Build a separate library containing the main() entry point. lib_LIBRARIES = libSDLmain.a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/epoc/SDL_main.cpp Tue Sep 11 20:38:49 2001 +0000 @@ -0,0 +1,129 @@ +/* + 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" + +#ifndef EXPORT_C +# ifdef __VC32__ +# define IMPORT_C __declspec(dllexport) +# define EXPORT_C __declspec(dllexport) +# endif +# ifdef __GCC32__ +# define IMPORT_C +# define EXPORT_C __declspec(dllexport) +# endif +#endif + +#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 */ + +GLDEF_C TInt E32Main() + { + /* Get the clean-up stack */ + CTrapCleanup* cleanup = CTrapCleanup::New(); + + #if defined(__WINS__) + /* arrange for access to Win32 stdin/stdout/stderr */ + RWin32Stream::StartServer(); + #endif + + /* Arrange for multi-threaded operation */ + SpawnPosixServerThread(); + + /* Get args and environment */ + int argc=0; + char** argv=0; + char** envp=0; + __crt0(argc,argv,envp); + + #if defined(__WINS__) + /* Cause the graphical Window Server to come into existence */ + RSemaphore sem; + sem.CreateGlobal(_L("WsExeSem"),0); + RegisterWsExe(sem.FullName()); + #endif + + + /* Start the application! */ + + /* Create stdlib */ + _REENT; + + /* Set process and thread priority */ + RThread currentThread; + + currentThread.Rename(_L("SdlProgram")); + 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! */ + + /* Free resources and return */ + CloseSTDLIB(); + delete cleanup; + return(KErrNone); + } + +/* Epoc dll entry point */ +#if defined(__WINS__) +GLDEF_C TInt E32Dll(TDllReason) + { + return(KErrNone); + } + +EXPORT_C TInt WinsMain(TAny *) + { + E32Main(); + return KErrNone; + } +#endif
--- a/src/thread/Makefile.am Tue Sep 11 19:00:18 2001 +0000 +++ b/src/thread/Makefile.am Tue Sep 11 20:38:49 2001 +0000 @@ -3,8 +3,13 @@ noinst_LTLIBRARIES = libthread.la -ARCH_SUBDIRS = $(srcdir)/generic $(srcdir)/amigaos $(srcdir)/beos \ - $(srcdir)/irix $(srcdir)/linux $(srcdir)/win32 +ARCH_SUBDIRS = $(srcdir)/generic \ + $(srcdir)/amigaos \ + $(srcdir)/beos \ + $(srcdir)/epoc \ + $(srcdir)/irix \ + $(srcdir)/linux \ + $(srcdir)/win32 # Older versions of Linux require an asm clone() implementation if USE_CLONE
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thread/epoc/SDL_sysmutex.cpp Tue Sep 11 20:38:49 2001 +0000 @@ -0,0 +1,112 @@ +/* + 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$"; +#endif + +/* Mutex functions using the Win32 API */ + +//#include <stdio.h> +//#include <stdlib.h> + +#include<e32std.h> + +#include "SDL_error.h" +#include "SDL_mutex.h" + + + +struct SDL_mutex + { + TInt handle; + }; + +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); + } + +/* 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(); + return(mutex); +} + +/* Free the mutex */ +void SDL_DestroyMutex(SDL_mutex *mutex) +{ + if ( mutex ) + { + RMutex rmutex; + rmutex.SetHandle(mutex->handle); + rmutex.Signal(); + rmutex.Close(); + 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); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thread/epoc/SDL_syssem.cpp Tue Sep 11 20:38:49 2001 +0000 @@ -0,0 +1,199 @@ +/* + 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$"; +#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*); +extern TInt NewThread(const TDesC& aName, TAny* aPtr1, TAny* aPtr2); + +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); + sema.Signal(sema.Count()); + sema.Close(); + delete sem; + sem = NULL; + } +} + + + 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; + } + + + + +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; + } + + + 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; +} + +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; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thread/epoc/SDL_systhread.cpp Tue Sep 11 20:38:49 2001 +0000 @@ -0,0 +1,127 @@ +/* + 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 <stdlib.h> +//#include <stdio.h> + + +extern "C" { +#undef NULL +#include "SDL_error.h" +#include "SDL_thread.h" +#include "SDL_systhread.h" + }; + +#include <e32std.h> + + +static int object_count; + +int RunThread(TAny* data) +{ + SDL_RunThread(data); + return(0); +} + + +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; + + 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; + TThreadId id = current.Id(); + return id; +} + +void SDL_SYS_WaitThread(SDL_Thread *thread) +{ + RUndertaker taker; + taker.Create(); + TRequestStatus status; + taker.Logon(status, thread->handle); + User::WaitForRequest(status); + taker.Close(); +} + +/* 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(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/thread/epoc/SDL_systhread_c.h Tue Sep 11 20:38:49 2001 +0000 @@ -0,0 +1,30 @@ +/* + 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; +
--- a/src/timer/Makefile.am Tue Sep 11 19:00:18 2001 +0000 +++ b/src/timer/Makefile.am Tue Sep 11 20:38:49 2001 +0000 @@ -3,8 +3,12 @@ noinst_LTLIBRARIES = libtimer.la -ARCH_SUBDIRS = $(srcdir)/amigaos $(srcdir)/beos $(srcdir)/linux \ - $(srcdir)/macos $(srcdir)/win32 +ARCH_SUBDIRS = $(srcdir)/amigaos \ + $(srcdir)/beos \ + $(srcdir)/epoc \ + $(srcdir)/linux \ + $(srcdir)/macos \ + $(srcdir)/win32 # Include the architecture-independent sources COMMON_SRCS = SDL_timer.c SDL_timer_c.h SDL_systimer.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/timer/epoc/SDL_systimer.cpp Tue Sep 11 20:38:49 2001 +0000 @@ -0,0 +1,111 @@ +/* + 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) +*/ + +#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) +{ + Uint32 ms; + + 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) +{ + 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"
--- a/src/video/Makefile.am Tue Sep 11 19:00:18 2001 +0000 +++ b/src/video/Makefile.am Tue Sep 11 20:38:49 2001 +0000 @@ -8,7 +8,7 @@ DIST_SUBDIRS = dummy x11 dga nanox fbcon directfb vgl svga ggi aalib \ wincommon windib windx5 \ maccommon macdsp macrom quartz \ - bwindow ps2gs photon cybergfx + bwindow ps2gs photon cybergfx epoc DRIVERS = @VIDEO_DRIVERS@
--- a/src/video/SDL_sysvideo.h Tue Sep 11 19:00:18 2001 +0000 +++ b/src/video/SDL_sysvideo.h Tue Sep 11 20:38:49 2001 +0000 @@ -364,12 +364,6 @@ #ifdef ENABLE_BWINDOW extern VideoBootStrap BWINDOW_bootstrap; #endif -#ifdef ENABLE_DUMMYVIDEO -extern VideoBootStrap DUMMY_bootstrap; -#endif -#ifdef ENABLE_PHOTON -extern VideoBootStrap ph_bootstrap; -#endif /* MacOS X gets the proper defines from configure */ #if defined(macintosh) && !defined(MACOSX) #define ENABLE_TOOLBOX @@ -389,6 +383,15 @@ #ifdef ENABLE_CYBERGRAPHICS extern VideoBootStrap CGX_bootstrap; #endif +#ifdef ENABLE_PHOTON +extern VideoBootStrap ph_bootstrap; +#endif +#ifdef ENABLE_EPOC +extern VideoBootStrap EPOC_bootstrap; +#endif +#ifdef ENABLE_DUMMYVIDEO +extern VideoBootStrap DUMMY_bootstrap; +#endif /* This is the current video device */ extern SDL_VideoDevice *current_video;
--- a/src/video/SDL_video.c Tue Sep 11 19:00:18 2001 +0000 +++ b/src/video/SDL_video.c Tue Sep 11 20:38:49 2001 +0000 @@ -96,14 +96,18 @@ #ifdef ENABLE_CYBERGRAPHICS &CGX_bootstrap, #endif +#ifdef ENABLE_PHOTON + &ph_bootstrap, +#endif +#ifdef ENABLE_EPOC + &EPOC_bootstrap, +#endif #ifdef ENABLE_DUMMYVIDEO &DUMMY_bootstrap, #endif -#ifdef ENABLE_PHOTON - &ph_bootstrap, -#endif NULL }; + SDL_VideoDevice *current_video = NULL; /* Various local functions */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/epoc/SDL_epocevents.cpp Tue Sep 11 20:38:49 2001 +0000 @@ -0,0 +1,418 @@ +/* + 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_epocevents.cpp + Handle the event stream, converting Epoc events into SDL events + + Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi) +*/ + + +#include <stdio.h> +#undef NULL + +extern "C" { +#include "SDL_error.h" +#include "SDL_video.h" +#include "SDL_keysym.h" +#include "SDL_keyboard.h" +#include "SDL_events_c.h" +#include "SDL_timer.h" +}; /* extern "C" */ + +#include "SDL_epocvideo.h" +#include "SDL_epocevents_c.h" + +#include <hal.h> + +extern "C" { +/* The translation tables from a console scancode to a SDL keysym */ +static SDLKey keymap[MAX_SCANCODE]; +static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym); +}; /* extern "C" */ + +TBool isCursorVisible = ETrue; + +int EPOC_HandleWsEvent(_THIS, const TWsEvent& aWsEvent) +{ + int posted = 0; + SDL_keysym keysym; + + + switch (aWsEvent.Type()) { + + case EEventPointer: /* Mouse pointer events */ + { + const TPointerEvent* pointerEvent = aWsEvent.Pointer(); + TPoint mousePos = pointerEvent->iPosition; + + //SDL_TRACE1("SDL: EPOC_HandleWsEvent, pointerEvent->iType=%d", pointerEvent->iType); //!! + + if (Private->EPOC_ShrinkedHeight) { + mousePos.iY <<= 1; /* Scale y coordinate to shrinked screen height */ + } + posted += SDL_PrivateMouseMotion(0, 0, mousePos.iX, mousePos.iY); /* Absolute position on screen */ + if (pointerEvent->iType==TPointerEvent::EButton1Down) { + posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, 0, 0); + } + else if (pointerEvent->iType==TPointerEvent::EButton1Up) { + posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, 0, 0); + } + else if (pointerEvent->iType==TPointerEvent::EButton2Down) { + posted += SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, 0, 0); + } + else if (pointerEvent->iType==TPointerEvent::EButton2Up) { + posted += SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, 0, 0); + } + //!!posted += SDL_PrivateKeyboard(SDL_PRESSED, TranslateKey(aWsEvent.Key()->iScanCode, &keysym)); + break; + } + + case EEventKeyDown: /* Key events */ + { + (void*)TranslateKey(aWsEvent.Key()->iScanCode, &keysym); + + /* Special handling */ + switch((int)keysym.sym) { + case SDLK_CAPSLOCK: + if (!isCursorVisible) { + /* Enable virtual cursor */ + HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible); + } + else { + /* Disable virtual cursor */ + HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible); + } + isCursorVisible = !isCursorVisible; + break; + } + + posted += SDL_PrivateKeyboard(SDL_PRESSED, &keysym); + break; + } + + case EEventKeyUp: /* Key events */ + { + posted += SDL_PrivateKeyboard(SDL_RELEASED, TranslateKey(aWsEvent.Key()->iScanCode, &keysym)); + break; + } + + case EEventFocusGained: /* SDL window got focus */ + { + //Private->EPOC_IsWindowFocused = ETrue; + /* Draw window background and screen buffer */ + RedrawWindowL(_this); + break; + } + + case EEventFocusLost: /* SDL window lost focus */ + { + //Private->EPOC_IsWindowFocused = EFalse; + + // Wait and eat events until focus is gained again + /* + while (ETrue) { + Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus); + User::WaitForRequest(Private->EPOC_WsEventStatus); + Private->EPOC_WsSession.GetEvent(Private->EPOC_WsEvent); + TInt eventType = Private->EPOC_WsEvent.Type(); + Private->EPOC_WsEventStatus = KRequestPending; + //Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus); + if (eventType == EEventFocusGained) { + RedrawWindowL(_this); + break; + } + } + */ + break; + } + + case EEventModifiersChanged: + { + TModifiersChangedEvent* modEvent = aWsEvent.ModifiersChanged(); + TUint modstate = KMOD_NONE; + if (modEvent->iModifiers == EModifierLeftShift) + modstate |= KMOD_LSHIFT; + if (modEvent->iModifiers == EModifierRightShift) + modstate |= KMOD_RSHIFT; + if (modEvent->iModifiers == EModifierLeftCtrl) + modstate |= KMOD_LCTRL; + if (modEvent->iModifiers == EModifierRightCtrl) + modstate |= KMOD_RCTRL; + if (modEvent->iModifiers == EModifierLeftAlt) + modstate |= KMOD_LALT; + if (modEvent->iModifiers == EModifierRightAlt) + modstate |= KMOD_RALT; + if (modEvent->iModifiers == EModifierLeftFunc) + modstate |= KMOD_LMETA; + if (modEvent->iModifiers == EModifierRightFunc) + modstate |= KMOD_RMETA; + if (modEvent->iModifiers == EModifierCapsLock) + modstate |= KMOD_CAPS; + SDL_SetModState(STATIC_CAST(SDLMod,(modstate | KMOD_LSHIFT))); + break; + } + default: + break; + } + + return posted; +} + +extern "C" { + +void EPOC_PumpEvents(_THIS) +{ + int posted = 0; // !! Do we need this? + //Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus); + while (Private->EPOC_WsEventStatus != KRequestPending) { + + Private->EPOC_WsSession.GetEvent(Private->EPOC_WsEvent); + posted = EPOC_HandleWsEvent(_this, Private->EPOC_WsEvent); + Private->EPOC_WsEventStatus = KRequestPending; + Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus); + } +} + + +void EPOC_InitOSKeymap(_THIS) +{ + int i; + + /* Initialize the key translation table */ + for ( i=0; i<SDL_TABLESIZE(keymap); ++i ) + keymap[i] = SDLK_UNKNOWN; + + + /* Numbers */ + for ( i = 0; i<32; ++i ){ + keymap[' ' + i] = (SDLKey)(SDLK_SPACE+i); + } + /* e.g. Alphabet keys */ + for ( i = 0; i<32; ++i ){ + keymap['A' + i] = (SDLKey)(SDLK_a+i); + } + + keymap[EStdKeyBackspace] = SDLK_BACKSPACE; + keymap[EStdKeyTab] = SDLK_TAB; + keymap[EStdKeyEnter] = SDLK_RETURN; + keymap[EStdKeyEscape] = SDLK_ESCAPE; + keymap[EStdKeySpace] = SDLK_SPACE; + keymap[EStdKeyPause] = SDLK_PAUSE; + keymap[EStdKeyHome] = SDLK_HOME; + keymap[EStdKeyEnd] = SDLK_END; + keymap[EStdKeyPageUp] = SDLK_PAGEUP; + keymap[EStdKeyPageDown] = SDLK_PAGEDOWN; + keymap[EStdKeyDelete] = SDLK_DELETE; + keymap[EStdKeyUpArrow] = SDLK_UP; + keymap[EStdKeyDownArrow] = SDLK_DOWN; + keymap[EStdKeyLeftArrow] = SDLK_LEFT; + keymap[EStdKeyRightArrow] = SDLK_RIGHT; + keymap[EStdKeyCapsLock] = SDLK_CAPSLOCK; + keymap[EStdKeyLeftShift] = SDLK_LSHIFT; + keymap[EStdKeyRightShift] = SDLK_RSHIFT; + keymap[EStdKeyLeftAlt] = SDLK_LALT; + keymap[EStdKeyRightAlt] = SDLK_RALT; + keymap[EStdKeyLeftCtrl] = SDLK_LCTRL; + keymap[EStdKeyRightCtrl] = SDLK_RCTRL; + keymap[EStdKeyLeftFunc] = SDLK_LMETA; + keymap[EStdKeyRightFunc] = SDLK_RMETA; + keymap[EStdKeyInsert] = SDLK_INSERT; + keymap[EStdKeyComma] = SDLK_COMMA; + keymap[EStdKeyFullStop] = SDLK_PERIOD; + keymap[EStdKeyForwardSlash] = SDLK_SLASH; + keymap[EStdKeyBackSlash] = SDLK_BACKSLASH; + keymap[EStdKeySemiColon] = SDLK_SEMICOLON; + keymap[EStdKeySingleQuote] = SDLK_QUOTE; + keymap[EStdKeyHash] = SDLK_HASH; + keymap[EStdKeySquareBracketLeft] = SDLK_LEFTBRACKET; + keymap[EStdKeySquareBracketRight] = SDLK_RIGHTBRACKET; + keymap[EStdKeyMinus] = SDLK_MINUS; + keymap[EStdKeyEquals] = SDLK_EQUALS; + + keymap[EStdKeyF1] = SDLK_F1; /* chr + q */ + keymap[EStdKeyF2] = SDLK_F2; /* chr + w */ + keymap[EStdKeyF3] = SDLK_F3; /* chr + e */ + keymap[EStdKeyF4] = SDLK_F4; /* chr + r */ + keymap[EStdKeyF5] = SDLK_F5; /* chr + t */ + keymap[EStdKeyF6] = SDLK_F6; /* chr + y */ + keymap[EStdKeyF7] = SDLK_F7; /* chr + i */ + keymap[EStdKeyF8] = SDLK_F8; /* chr + o */ + + keymap[EStdKeyF9] = SDLK_F9; /* chr + a */ + keymap[EStdKeyF10] = SDLK_F10; /* chr + s */ + keymap[EStdKeyF11] = SDLK_F11; /* chr + d */ + keymap[EStdKeyF12] = SDLK_F12; /* chr + f */ + + /* !!TODO + EStdKeyNumLock=0x1b, + EStdKeyScrollLock=0x1c, + + EStdKeyNkpForwardSlash=0x84, + EStdKeyNkpAsterisk=0x85, + EStdKeyNkpMinus=0x86, + EStdKeyNkpPlus=0x87, + EStdKeyNkpEnter=0x88, + EStdKeyNkp1=0x89, + EStdKeyNkp2=0x8a, + EStdKeyNkp3=0x8b, + EStdKeyNkp4=0x8c, + EStdKeyNkp5=0x8d, + EStdKeyNkp6=0x8e, + EStdKeyNkp7=0x8f, + EStdKeyNkp8=0x90, + EStdKeyNkp9=0x91, + EStdKeyNkp0=0x92, + EStdKeyNkpFullStop=0x93, + EStdKeyMenu=0x94, + EStdKeyBacklightOn=0x95, + EStdKeyBacklightOff=0x96, + EStdKeyBacklightToggle=0x97, + EStdKeyIncContrast=0x98, + EStdKeyDecContrast=0x99, + EStdKeySliderDown=0x9a, + EStdKeySliderUp=0x9b, + EStdKeyDictaphonePlay=0x9c, + EStdKeyDictaphoneStop=0x9d, + EStdKeyDictaphoneRecord=0x9e, + EStdKeyHelp=0x9f, + EStdKeyOff=0xa0, + EStdKeyDial=0xa1, + EStdKeyIncVolume=0xa2, + EStdKeyDecVolume=0xa3, + EStdKeyDevice0=0xa4, + EStdKeyDevice1=0xa5, + EStdKeyDevice2=0xa6, + EStdKeyDevice3=0xa7, + EStdKeyDevice4=0xa8, + EStdKeyDevice5=0xa9, + EStdKeyDevice6=0xaa, + EStdKeyDevice7=0xab, + EStdKeyDevice8=0xac, + EStdKeyDevice9=0xad, + EStdKeyDeviceA=0xae, + EStdKeyDeviceB=0xaf, + EStdKeyDeviceC=0xb0, + EStdKeyDeviceD=0xb1, + EStdKeyDeviceE=0xb2, + EStdKeyDeviceF=0xb3, + EStdKeyApplication0=0xb4, + EStdKeyApplication1=0xb5, + EStdKeyApplication2=0xb6, + EStdKeyApplication3=0xb7, + EStdKeyApplication4=0xb8, + EStdKeyApplication5=0xb9, + EStdKeyApplication6=0xba, + EStdKeyApplication7=0xbb, + EStdKeyApplication8=0xbc, + EStdKeyApplication9=0xbd, + EStdKeyApplicationA=0xbe, + EStdKeyApplicationB=0xbf, + EStdKeyApplicationC=0xc0, + EStdKeyApplicationD=0xc1, + EStdKeyApplicationE=0xc2, + EStdKeyApplicationF=0xc3, + EStdKeyYes=0xc4, + EStdKeyNo=0xc5, + EStdKeyIncBrightness=0xc6, + EStdKeyDecBrightness=0xc7, + EStdKeyCaseOpen=0xc8, + EStdKeyCaseClose=0xc9 + */ + +} + + + +static SDL_keysym *TranslateKey(int scancode, SDL_keysym *keysym) +{ + char debug[256]; + //SDL_TRACE1("SDL: TranslateKey, scancode=%d", scancode); //!! + + /* Set the keysym information */ + + keysym->scancode = scancode; + + if ((scancode >= MAX_SCANCODE) && + ((scancode - ENonCharacterKeyBase + 0x0081) >= MAX_SCANCODE)) { + SDL_SetError("Too big scancode"); + keysym->scancode = SDLK_UNKNOWN; + keysym->mod = KMOD_NONE; + return keysym; + } + + keysym->mod = SDL_GetModState(); //!!Is this right?? + + /* Handle function keys: F1, F2, F3 ... */ + if (keysym->mod & KMOD_META) { + if (scancode >= 'A' && scancode < ('A' + 24)) { /* first 32 alphapet keys */ + switch(scancode) { + case 'Q': scancode = EStdKeyF1; break; + case 'W': scancode = EStdKeyF2; break; + case 'E': scancode = EStdKeyF3; break; + case 'R': scancode = EStdKeyF4; break; + case 'T': scancode = EStdKeyF5; break; + case 'Y': scancode = EStdKeyF6; break; + case 'U': scancode = EStdKeyF7; break; + case 'I': scancode = EStdKeyF8; break; + case 'A': scancode = EStdKeyF9; break; + case 'S': scancode = EStdKeyF10; break; + case 'D': scancode = EStdKeyF11; break; + case 'F': scancode = EStdKeyF12; break; + } + keysym->sym = keymap[scancode]; + } + } + + if (scancode >= ENonCharacterKeyBase) { + // Non character keys + keysym->sym = keymap[scancode - + ENonCharacterKeyBase + 0x0081]; // !!hard coded + } else { + keysym->sym = keymap[scancode]; + } + + + /* If UNICODE is on, get the UNICODE value for the key */ + keysym->unicode = 0; + +#if 0 // !!TODO:unicode + + if ( SDL_TranslateUNICODE ) + { + /* Populate the unicode field with the ASCII value */ + keysym->unicode = scancode; + } +#endif + + //!! + //sprintf(debug, "SDL: TranslateKey: keysym->scancode=%d, keysym->sym=%d, keysym->mod=%d", + // keysym->scancode, keysym->sym, keysym->mod); + //SDL_TRACE(debug); //!! + + return(keysym); +} + +}; /* extern "C" */ + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/epoc/SDL_epocevents_c.h Tue Sep 11 20:38:49 2001 +0000 @@ -0,0 +1,50 @@ +/* + 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_epocevents_c.h + Handle the event stream, converting Epoc events into SDL events + + Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi) +*/ + + +#ifdef SAVE_RCSID +static char rcsid = + "@(#) $Id$"; +#endif + +extern "C" { +#include "SDL_sysvideo.h" +}; + +#define MAX_SCANCODE 255 + +/* Variables and functions exported by SDL_sysevents.c to other parts + of the native video subsystem (SDL_sysvideo.c) +*/ + +extern "C" { +extern void EPOC_InitOSKeymap(_THIS); +extern void EPOC_PumpEvents(_THIS); +}; +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/epoc/SDL_epocvideo.cpp Tue Sep 11 20:38:49 2001 +0000 @@ -0,0 +1,700 @@ +/* + 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_epocvideo.cpp + Epoc based SDL video driver implementation + + Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi) +*/ + + + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +extern "C" { +#include "SDL_error.h" +#include "SDL_timer.h" +#include "SDL_video.h" +#undef NULL +#include "SDL_pixels_c.h" +}; + +#include "SDL_epocvideo.h" +#include "SDL_epocevents_c.h" + +#include <hal.h> +#include <coedef.h> + +/* For debugging */ + +void RDebug_Print_b(char* error_str, void* param) + { + TBuf8<128> error8((TUint8*)error_str); + TBuf<128> error; + error.Copy(error8); + if (param) //!! Do not work if the parameter is really 0!! + RDebug::Print(error, param); + else + RDebug::Print(error); + } + +extern "C" void RDebug_Print(char* error_str, void* param) + { + RDebug_Print_b(error_str, param); + } + + +int Debug_AvailMem2() + { + //User::CompressAllHeaps(); + TMemoryInfoV1Buf membuf; + User::LeaveIfError(UserHal::MemoryInfo(membuf)); + TMemoryInfoV1 minfo = membuf(); + return(minfo.iFreeRamInBytes); + } + +extern "C" int Debug_AvailMem() + { + return(Debug_AvailMem2()); + } + + +extern "C" { + +/* Initialization/Query functions */ + +static int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat); +static SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); +static SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); +static int EPOC_SetColors(_THIS, int firstcolor, int ncolors, + SDL_Color *colors); +static void EPOC_VideoQuit(_THIS); + +/* Hardware surface functions */ + +static int EPOC_AllocHWSurface(_THIS, SDL_Surface *surface); +static int EPOC_LockHWSurface(_THIS, SDL_Surface *surface); +static int EPOC_FlipHWSurface(_THIS, SDL_Surface *surface); +static void EPOC_UnlockHWSurface(_THIS, SDL_Surface *surface); +static void EPOC_FreeHWSurface(_THIS, SDL_Surface *surface); +static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); + +static int EPOC_Available(void); +static SDL_VideoDevice *EPOC_CreateDevice(int devindex); + +/* Mouse functions */ + +static WMcursor *EPOC_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y); +static void EPOC_FreeWMCursor(_THIS, WMcursor *cursor); +static int EPOC_ShowWMCursor(_THIS, WMcursor *cursor); + + + +/* !! Table for fast conversion from 8 bit to 12 bit */ +static TUint16 EPOC_HWPalette_256_to_4k[256]; + +VideoBootStrap EPOC_bootstrap = { + "epoc", "EPOC system", + EPOC_Available, EPOC_CreateDevice +}; + +const TUint32 WindowClientHandle = 9210; //!! + +/* Epoc video driver bootstrap functions */ + +static int EPOC_Available(void) +{ + return 1; /* Always available */ +} + +static void EPOC_DeleteDevice(SDL_VideoDevice *device) +{ + free(device->hidden); + free(device); +} + +static SDL_VideoDevice *EPOC_CreateDevice(int devindex) +{ + SDL_VideoDevice *device; + + /* Allocate all variables that we free on delete */ + device = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); + if ( device ) { + memset(device, 0, (sizeof *device)); + device->hidden = (struct SDL_PrivateVideoData *) + malloc((sizeof *device->hidden)); + } + if ( (device == NULL) || (device->hidden == NULL) ) { + SDL_OutOfMemory(); + if ( device ) { + free(device); + } + return(0); + } + memset(device->hidden, 0, (sizeof *device->hidden)); + + /* Set the function pointers */ + device->VideoInit = EPOC_VideoInit; + device->ListModes = EPOC_ListModes; + device->SetVideoMode = EPOC_SetVideoMode; + device->SetColors = EPOC_SetColors; + device->UpdateRects = NULL; + device->VideoQuit = EPOC_VideoQuit; + device->AllocHWSurface = EPOC_AllocHWSurface; + device->CheckHWBlit = NULL; + device->FillHWRect = NULL; + device->SetHWColorKey = NULL; + device->SetHWAlpha = NULL; + device->LockHWSurface = EPOC_LockHWSurface; + device->UnlockHWSurface = EPOC_UnlockHWSurface; + device->FlipHWSurface = EPOC_FlipHWSurface; + device->FreeHWSurface = EPOC_FreeHWSurface; + device->SetIcon = NULL; + device->SetCaption = NULL; + device->GetWMInfo = NULL; + device->FreeWMCursor = EPOC_FreeWMCursor; + device->CreateWMCursor = EPOC_CreateWMCursor; + device->ShowWMCursor = EPOC_ShowWMCursor; + device->WarpWMCursor = NULL; + device->InitOSKeymap = EPOC_InitOSKeymap; + device->PumpEvents = EPOC_PumpEvents; + device->free = EPOC_DeleteDevice; + + return device; +} + + +int GetBpp(TDisplayMode displaymode) +{ + TInt numColors = TDisplayModeUtils::NumDisplayModeColors(displaymode); + TInt bitsPerPixel = 1; + for (TInt32 i = 2; i < numColors; i <<= 1, bitsPerPixel++); + return bitsPerPixel; +} + +void ConstructWindowL(_THIS) +{ + TInt error; + + error = Private->EPOC_WsSession.Connect(); + User::LeaveIfError(error); + Private->EPOC_WsScreen=new(ELeave) CWsScreenDevice(Private->EPOC_WsSession); + User::LeaveIfError(Private->EPOC_WsScreen->Construct()); + User::LeaveIfError(Private->EPOC_WsScreen->CreateContext(Private->EPOC_WindowGc)); + + Private->EPOC_WsWindowGroup=RWindowGroup(Private->EPOC_WsSession); + User::LeaveIfError(Private->EPOC_WsWindowGroup.Construct(WindowClientHandle)); + Private->EPOC_WsWindowGroup.SetOrdinalPosition(0); + + //!! + TBuf<32> winGroupName; + winGroupName.Append(0); + winGroupName.Append(0); + winGroupName.Append(0);// uid + winGroupName.Append(0); + winGroupName.Append(_L("SDL")); // caption + winGroupName.Append(0); + winGroupName.Append(0); //doc name + Private->EPOC_WsWindowGroup.SetName(winGroupName); //!! + + Private->EPOC_WsWindow=RWindow(Private->EPOC_WsSession); + User::LeaveIfError(Private->EPOC_WsWindow.Construct(Private->EPOC_WsWindowGroup,WindowClientHandle)); + Private->EPOC_WsWindow.SetBackgroundColor(KRgbWhite); + Private->EPOC_WsWindow.Activate(); + Private->EPOC_WsWindow.SetSize(Private->EPOC_WsScreen->SizeInPixels()); + Private->EPOC_WsWindow.SetVisible(ETrue); + + Private->EPOC_WsWindowGroupID = Private->EPOC_WsWindowGroup.Identifier(); + Private->EPOC_IsWindowFocused = EFalse; +} + + +int EPOC_VideoInit(_THIS, SDL_PixelFormat *vformat) +{ + // !!TODO:handle leave functions! + + int i; + + /* Initialize all variables that we clean on shutdown */ + + for ( i=0; i<SDL_NUMMODES; ++i ) { + Private->SDL_modelist[i] = (SDL_Rect *)malloc(sizeof(SDL_Rect)); + Private->SDL_modelist[i]->x = Private->SDL_modelist[i]->y = 0; + } + /* Modes sorted largest to smallest !!TODO:sorting order??*/ + Private->SDL_modelist[0]->w = 640; Private->SDL_modelist[0]->h = 200; + Private->SDL_modelist[1]->w = 320; Private->SDL_modelist[1]->h = 200; + Private->SDL_modelist[2]->w = 640; Private->SDL_modelist[2]->h = 400; + Private->SDL_modelist[3]->w = 640; Private->SDL_modelist[3]->h = 480; + Private->SDL_modelist[4] = NULL; + + /* Construct Epoc window */ + + ConstructWindowL(_this); + + /* Initialise Epoc frame buffer */ + + TDisplayMode displayMode = Private->EPOC_WsScreen->DisplayMode(); + + #ifndef __WINS__ + + TScreenInfoV01 screenInfo; + TPckg<TScreenInfoV01> sInfo(screenInfo); + UserSvr::ScreenInfo(sInfo); + + Private->EPOC_ScreenSize = screenInfo.iScreenSize; + Private->EPOC_DisplayMode = displayMode; + Private->EPOC_HasFrameBuffer = screenInfo.iScreenAddressValid; + Private->EPOC_FrameBuffer = Private->EPOC_HasFrameBuffer ? (TUint8*) screenInfo.iScreenAddress : NULL; + Private->EPOC_BytesPerPixel = ((GetBpp(displayMode)-1) / 8) + 1; + Private->EPOC_BytesPerScanLine = screenInfo.iScreenSize.iWidth * Private->EPOC_BytesPerPixel; + + /* It seems that in SA1100 machines for 8bpp displays there is a 512 palette table at the + * beginning of the frame buffer. E.g. Series 7 and Netbook. + * In 12 bpp machines the table has 16 entries. + */ + if (Private->EPOC_HasFrameBuffer && GetBpp(displayMode) == 8) + Private->EPOC_FrameBuffer += 512; + if (Private->EPOC_HasFrameBuffer && GetBpp(displayMode) == 12) + Private->EPOC_FrameBuffer += 16 * 2; + + #else /* defined __WINS__ */ + + /* Create bitmap, device and context for screen drawing */ + Private->EPOC_ScreenSize = Private->EPOC_WsScreen->SizeInPixels(); + + Private->EPOC_Bitmap = new (ELeave) CWsBitmap(Private->EPOC_WsSession); + Private->EPOC_Bitmap->Create(Private->EPOC_ScreenSize, displayMode); + + Private->EPOC_DisplayMode = displayMode; + Private->EPOC_HasFrameBuffer = ETrue; + Private->EPOC_FrameBuffer = NULL; /* Private->EPOC_Bitmap->DataAddress() can change any time */ + Private->EPOC_BytesPerPixel = ((GetBpp(displayMode)-1) / 8) + 1; + Private->EPOC_BytesPerScanLine = Private->EPOC_WsScreen->SizeInPixels().iWidth * Private->EPOC_BytesPerPixel; + + #endif /* __WINS__ */ + + /* The "best" video format should be returned to caller. */ + + vformat->BitsPerPixel = /*!!GetBpp(displayMode) */ 8; + vformat->BytesPerPixel = /*!!Private->EPOC_BytesPerPixel*/ 1; + + /* Activate events for me */ + + Private->EPOC_WsEventStatus = KRequestPending; + Private->EPOC_WsSession.EventReady(&Private->EPOC_WsEventStatus); + Private->EPOC_RedrawEventStatus = KRequestPending; + Private->EPOC_WsSession.RedrawReady(&Private->EPOC_RedrawEventStatus); + Private->EPOC_WsWindow.PointerFilter(EPointerFilterDrag, 0); + + Private->EPOC_ScreenOffset = 0; + + //!! TODO: error handling + //if (ret != KErrNone) + // return(-1); + //else + return(0); +} + + +SDL_Rect **EPOC_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) +{ + if (format->BitsPerPixel == 12 || format->BitsPerPixel == 8) + return Private->SDL_modelist; + return NULL; +} + +int EPOC_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) +{ + for(int i = firstcolor; i < ncolors; i++) { + // 4k value: 000rgb + TUint16 color4K = 0; + color4K |= (colors[i].r & 0x0000f0) << 4; + color4K |= (colors[i].g & 0x0000f0); + color4K |= (colors[i].b & 0x0000f0) >> 4; + EPOC_HWPalette_256_to_4k[i] = color4K; + } + return(0); +} + + +SDL_Surface *EPOC_SetVideoMode(_THIS, SDL_Surface *current, + int width, int height, int bpp, Uint32 flags) +{ + /* Check parameters */ + if (!((width == 640 && height == 200 && bpp == 12) || + (width == 640 && height == 400 && bpp == 12) || + (width == 640 && height == 480 && bpp == 12) || + (width == 320 && height == 200 && bpp == 12) || + (width == 640 && height == 200 && bpp == 8) || + (width == 640 && height == 400 && bpp == 8) || + (width == 640 && height == 480 && bpp == 8) || + (width == 320 && height == 200 && bpp == 8))) { + SDL_SetError("Requested video mode is not supported"); + return NULL; + } + + if (current && current->pixels) { + free(current->pixels); + current->pixels = NULL; + } + if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { + return(NULL); + } + + /* Set up the new mode framebuffer */ + if (bpp == 8) + current->flags = (SDL_FULLSCREEN|SDL_SWSURFACE|SDL_PREALLOC|SDL_HWPALETTE); + else // 12 bpp + current->flags = (SDL_FULLSCREEN|SDL_SWSURFACE|SDL_PREALLOC); + current->w = width; + current->h = height; + int numBytesPerPixel = ((bpp-1)>>3) + 1; + current->pitch = numBytesPerPixel * width; // Number of bytes in scanline + current->pixels = malloc(width * height * numBytesPerPixel); + memset(current->pixels, 0, width * height * numBytesPerPixel); + + /* Set the blit function */ + _this->UpdateRects = EPOC_DirectUpdate; + + /* Must buffer height be shrinked to screen by 2 ? */ + if (current->h >= 400) + Private->EPOC_ShrinkedHeight = ETrue; + + /* Centralize game window on device screen */ + Private->EPOC_ScreenOffset = (Private->EPOC_ScreenSize.iWidth - current->w) / 2; + + /* We're done */ + return(current); +} + +void RedrawWindowL(_THIS) +{ + SDL_Rect fullScreen; + fullScreen.x = 0; + fullScreen.y = 0; + fullScreen.w = _this->screen->w; + fullScreen.h = _this->screen->h; + +#ifdef __WINS__ + TBitmapUtil lock(Private->EPOC_Bitmap); + lock.Begin(TPoint(0,0)); // Lock bitmap heap + Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow); +#endif + + if (fullScreen.w < Private->EPOC_ScreenSize.iWidth + && fullScreen.w < Private->EPOC_ScreenSize.iWidth) { + /* Draw blue stripes background */ +#ifdef __WINS__ + TUint16* screenBuffer = (TUint16*)Private->EPOC_Bitmap->DataAddress(); +#else + TUint16* screenBuffer = (TUint16*)Private->EPOC_FrameBuffer; +#endif + for (int y=0; y < Private->EPOC_ScreenSize.iHeight; y++) { + for (int x=0; x < Private->EPOC_ScreenSize.iWidth; x++) { + TUint16 color = ((x+y)>>1) & 0xf; /* Draw pattern */ + *screenBuffer++ = color; + } + } + } + + + /* Tell the system that something has been drawn */ + TRect rect = TRect(Private->EPOC_WsWindow.Size()); + Private->EPOC_WsWindow.Invalidate(rect); + +#ifdef __WINS__ + Private->EPOC_WsWindow.BeginRedraw(rect); + Private->EPOC_WindowGc->BitBlt(TPoint(), Private->EPOC_Bitmap); + Private->EPOC_WsWindow.EndRedraw(); + Private->EPOC_WindowGc->Deactivate(); + lock.End(); // Unlock bitmap heap + Private->EPOC_WsSession.Flush(); +#endif + + /* Draw current buffer */ + EPOC_DirectUpdate(_this, 1, &fullScreen); +} + + +/* We don't actually allow hardware surfaces other than the main one */ +static int EPOC_AllocHWSurface(_THIS, SDL_Surface *surface) +{ + return(-1); +} +static void EPOC_FreeHWSurface(_THIS, SDL_Surface *surface) +{ + return; +} + +static int EPOC_LockHWSurface(_THIS, SDL_Surface *surface) +{ + return(0); +} +static void EPOC_UnlockHWSurface(_THIS, SDL_Surface *surface) +{ + return; +} + +static int EPOC_FlipHWSurface(_THIS, SDL_Surface *surface) +{ + return(0); +} + +static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) +{ + TInt focusWindowGroupId = Private->EPOC_WsSession.GetFocusWindowGroup(); + if (focusWindowGroupId != Private->EPOC_WsWindowGroupID) { + + /* Force focus window to redraw again for cleaning away SDL screen graphics */ + + + TInt pos = Private->EPOC_WsWindowGroup.OrdinalPosition(); + Private->EPOC_WsWindowGroup.SetOrdinalPosition(0, KMaxTInt); + TRect rect = TRect(Private->EPOC_WsWindow.Size()); + Private->EPOC_WsWindow.Invalidate(rect); + Private->EPOC_WsWindowGroup.SetOrdinalPosition(pos, ECoeWinPriorityNormal); + + /* If this is not the topmost window, wait here! Sleep for 1 second to give cpu to + multitasking and poll for being the topmost window. + */ + while (Private->EPOC_WsSession.GetFocusWindowGroup() != Private->EPOC_WsWindowGroupID) + SDL_Delay(1000); + + RedrawWindowL(_this); + } + + TInt i; + TInt sourceNumBytesPerPixel = ((_this->screen->format->BitsPerPixel-1)>>3) + 1; + TInt targetNumBytesPerPixel = Private->EPOC_BytesPerPixel; + TInt fixedOffset = Private->EPOC_ScreenOffset; + TInt screenW = _this->screen->w; + TInt screenH = _this->screen->h; + TInt sourceScanlineLength = screenW; + if (Private->EPOC_ShrinkedHeight) { /* simulate 400 pixel height in 200 pixel screen */ + sourceScanlineLength <<= 1; + screenH >>= 1; + } + TInt targetScanlineLength = Private->EPOC_ScreenSize.iWidth; +#ifdef __WINS__ + TBitmapUtil lock(Private->EPOC_Bitmap); + lock.Begin(TPoint(0,0)); // Lock bitmap heap + Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow); + TUint16* screenBuffer = (TUint16*)Private->EPOC_Bitmap->DataAddress(); +#else + TUint16* screenBuffer = (TUint16*)Private->EPOC_FrameBuffer; +#endif + + + /* Render the rectangles in the list */ + + for ( i=0; i < numrects; ++i ) { + SDL_Rect rect2; + const SDL_Rect& currentRect = rects[i]; + rect2.x = currentRect.x; + rect2.y = currentRect.y; + rect2.w = currentRect.w; + rect2.h = currentRect.h; + + if (rect2.w <= 0 || rect2.h <= 0) /* sanity check */ + continue; + + if (Private->EPOC_ShrinkedHeight) { /* simulate 400 pixel height in 200 pixel screen */ + rect2.y >>= 1; + if (!(rect2.h >>= 1)) + rect2.h = 1; // always at least 1 pixel height! + } + + /* All variables are measured in pixels */ + + /* Check rects validity, i.e. upper and lower bounds */ + TInt maxX = Min(screenW - 1, rect2.x + rect2.w - 1); + TInt maxY = Min(screenH - 1, rect2.y + rect2.h - 1); + if (maxX < 0 || maxY < 0) /* sanity check */ + continue; + maxY = Min(maxY, 199); + + TInt sourceRectWidth = maxX - rect2.x + 1; + TInt sourceRectWidthInBytes = sourceRectWidth * sourceNumBytesPerPixel; + TInt sourceRectHeight = maxY - rect2.y + 1; + TInt sourceStartOffset = rect2.x + rect2.y * sourceScanlineLength; + TInt targetStartOffset = fixedOffset + rect2.x + rect2.y * targetScanlineLength; + + // !! Nokia9210 native mode: 12 bpp --> 12 bpp + if (_this->screen->format->BitsPerPixel == 12) { + TUint16* bitmapLine = (TUint16*)_this->screen->pixels + sourceStartOffset; + TUint16* screenMemory = screenBuffer + targetStartOffset; + for(TInt y = 0 ; y < sourceRectHeight ; y++) { + __ASSERT_DEBUG(screenMemory < (screenBuffer + + Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight), + User::Panic(_L("SDL"), KErrCorrupt)); + __ASSERT_DEBUG(screenMemory >= screenBuffer, + User::Panic(_L("SDL"), KErrCorrupt)); + __ASSERT_DEBUG(bitmapLine < ((TUint16*)_this->screen->pixels + + + (_this->screen->w * _this->screen->h)), + User::Panic(_L("SDL"), KErrCorrupt)); + __ASSERT_DEBUG(bitmapLine >= (TUint16*)_this->screen->pixels, + User::Panic(_L("SDL"), KErrCorrupt)); + Mem::Copy(screenMemory, bitmapLine, sourceRectWidthInBytes); + bitmapLine += sourceScanlineLength; + screenMemory += targetScanlineLength; + } + } + // !! 256 color paletted mode: 8 bpp --> 12 bpp + else { + TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset; + TUint16* screenMemory = screenBuffer + targetStartOffset; + for(TInt y = 0 ; y < sourceRectHeight ; y++) { + TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */ + TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */ + /* Convert each pixel from 256 palette to 4k color values */ + for(TInt x = 0 ; x < sourceRectWidth ; x++) { + __ASSERT_DEBUG(screenMemoryLinePos < (screenBuffer + + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)), + User::Panic(_L("SDL"), KErrCorrupt)); + __ASSERT_DEBUG(screenMemoryLinePos >= screenBuffer, + User::Panic(_L("SDL"), KErrCorrupt)); + __ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels + + + (_this->screen->w * _this->screen->h)), + User::Panic(_L("SDL"), KErrCorrupt)); + __ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels, + User::Panic(_L("SDL"), KErrCorrupt)); + *screenMemoryLinePos = EPOC_HWPalette_256_to_4k[*bitmapPos]; + bitmapPos++; + screenMemoryLinePos++; + } + bitmapLine += sourceScanlineLength; + screenMemory += targetScanlineLength; + } + } + + } + +#ifdef __WINS__ + + TRect rect = TRect(Private->EPOC_WsWindow.Size()); + Private->EPOC_WsWindow.Invalidate(rect); + Private->EPOC_WsWindow.BeginRedraw(rect); + Private->EPOC_WindowGc->BitBlt(TPoint(), Private->EPOC_Bitmap); + Private->EPOC_WsWindow.EndRedraw(); + Private->EPOC_WindowGc->Deactivate(); + lock.End(); // Unlock bitmap heap + Private->EPOC_WsSession.Flush(); + +#endif + + /* Update virtual cursor */ + //!!Private->EPOC_WsSession.SetPointerCursorPosition(Private->EPOC_WsSession.PointerCursorPosition()); + + return; +} + + +/* Note: If we are terminated, this could be called in the middle of + another SDL video routine -- notably UpdateRects. +*/ +void EPOC_VideoQuit(_THIS) +{ + int i; + + /* Free video mode lists */ + for ( i=0; i<SDL_NUMMODES; ++i ) { + if ( Private->SDL_modelist[i] != NULL ) { + free(Private->SDL_modelist[i]); + Private->SDL_modelist[i] = NULL; + } + } + + if ( _this->screen && (_this->screen->flags & SDL_HWSURFACE) ) { + /* Direct screen access, no memory buffer */ + _this->screen->pixels = NULL; + } + + if (_this->screen && _this->screen->pixels) { + free(_this->screen->pixels); + _this->screen->pixels = NULL; + } + + /* Free Epoc resources */ + + /* Disable events for me */ + if (Private->EPOC_WsEventStatus != KRequestPending) + Private->EPOC_WsSession.EventReadyCancel(); + if (Private->EPOC_RedrawEventStatus != KRequestPending) + Private->EPOC_WsSession.RedrawReadyCancel(); + + #ifdef __WINS__ + delete Private->EPOC_Bitmap; + Private->EPOC_Bitmap = NULL; + #endif + + if (Private->EPOC_WsWindow.WsHandle()) + Private->EPOC_WsWindow.Close(); + + if (Private->EPOC_WsWindowGroup.WsHandle()) + Private->EPOC_WsWindowGroup.Close(); + + delete Private->EPOC_WindowGc; + Private->EPOC_WindowGc = NULL; + + delete Private->EPOC_WsScreen; + Private->EPOC_WsScreen = NULL; + + if (Private->EPOC_WsSession.WsHandle()) + Private->EPOC_WsSession.Close(); +} + + +WMcursor *EPOC_CreateWMCursor(_THIS, Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y) +{ + return (WMcursor *) 9210; // it's ok to return something unuseful but true +} + +void EPOC_FreeWMCursor(_THIS, WMcursor *cursor) +{ + /* Disable virtual cursor */ + HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible); + Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNone); +} + +int EPOC_ShowWMCursor(_THIS, WMcursor *cursor) +{ + + if (cursor == (WMcursor *)9210) { + /* Enable virtual cursor */ + HAL::Set(HAL::EMouseState, HAL::EMouseState_Visible); + Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNormal); + } + else { + /* Disable virtual cursor */ + HAL::Set(HAL::EMouseState, HAL::EMouseState_Invisible); + Private->EPOC_WsSession.SetPointerCursorMode(EPointerCursorNone); + } + + return(1); +} + +}; // extern "C" +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/video/epoc/SDL_epocvideo.h Tue Sep 11 20:38:49 2001 +0000 @@ -0,0 +1,89 @@ +/* + 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_epocvideo.h + Epoc based SDL video driver implementation + + Epoc version by Hannu Viitala (hannu.j.viitala@mbnet.fi) +*/ + +#ifndef _SDL_epocvideo_h +#define _SDL_epocvideo_h + +extern "C" { +#include "SDL_mouse.h" +#include "SDL_sysvideo.h" +}; + +#include <e32std.h> +#include <bitdev.h> +#include <w32std.h> + +/* Hidden "this" pointer for the video functions */ +#define _THIS SDL_VideoDevice *_this +#define Private _this->hidden + +#define SDL_NUMMODES 4 + +/* Private display data */ +struct SDL_PrivateVideoData { + + SDL_Rect *SDL_modelist[SDL_NUMMODES+1]; + + /* Epoc window server info */ + + RWsSession EPOC_WsSession; + RWindowGroup EPOC_WsWindowGroup; + TInt EPOC_WsWindowGroupID; + RWindow EPOC_WsWindow; + CWsScreenDevice* EPOC_WsScreen; + CWindowGc* EPOC_WindowGc; + TRequestStatus EPOC_WsEventStatus; + TRequestStatus EPOC_RedrawEventStatus; + TWsEvent EPOC_WsEvent; + TWsRedrawEvent EPOC_RedrawEvent; + #ifdef __WINS__ + CWsBitmap* EPOC_Bitmap; + #endif + TBool EPOC_IsWindowFocused; //!!Not used for anything yet! + + /* Screen hardware frame buffer info */ + + TBool EPOC_HasFrameBuffer; + TInt EPOC_BytesPerPixel; + TInt EPOC_BytesPerScanLine; + TDisplayMode EPOC_DisplayMode; + TSize EPOC_ScreenSize; + TUint8* EPOC_FrameBuffer; /* if NULL in HW we can't do direct screen access */ + TInt EPOC_ScreenOffset; + + /* Simulate double screen height */ + TBool EPOC_ShrinkedHeight; +}; + +extern "C" { +extern void RedrawWindowL(_THIS); +}; + + +#endif /* _SDL_epocvideo_h */