SDL port for Android SDK/NDK 1.6

Quickly share your Android Code Snippets here...

Re: SDL port for Android SDK/NDK 1.6

Postby T-1000 » Mon Nov 05, 2012 1:18 pm

Hi there. Itś been a long time without coding.
I am trying to use some code I have used some time ago and render using opengl but now the result is nothing viewable.
Can anyone please tell me what is wrong in thes code?

Code: Select all
void renderSprite(Csprite sprite, bool androidUseQuads = false)
{

    glEnable(GL_TEXTURE_2D);
    // position
    glTranslatef(sprite.x, sprite.y, sprite.z);
    glBindTexture(GL_TEXTURE_2D, sprite.texture.id);

/* Start Transformations */
    glTranslatef((float)sprite.w / 2, (float)sprite.h / 2, 0);
   // rotation
    glRotatef(sprite.angleX, 1.0f, 0.0f, 0.0f);
    glRotatef(sprite.angleY, 0.0f, 1.0f, 0.0f);
    glRotatef(sprite.angleZ, 0.0f, 0.0f, 1.0f);
   // scale
    glScalef(sprite.scaleX, sprite.scaleY, sprite.scaleZ);

    glTranslatef((float)-1 * sprite.w / 2, (float)-1 *sprite.h / 2, 0);
/* End Transformations */


    // calculate mapping vertexes
    float minX = (float)sprite.srcX / (float)sprite.texture.w * sprite.texture.p2w;
    float maxX = ((float)sprite.srcX + (float)sprite.w) / (float)sprite.texture.w * sprite.texture.p2w;
    float minY = (float)sprite.srcY / (float)sprite.texture.h * sprite.texture.p2h;
    float maxY = ((float)sprite.srcY + (float)sprite.h) / (float)sprite.texture.h * sprite.texture.p2h;

    float tmp;
    if(sprite.flipX)
    {
   tmp = minX;
   minX = maxX;
   maxX = tmp;
    }
    if(sprite.flipY)
    {
   tmp = minY;
   minY = maxY;
   maxY = tmp;
    }

/* The following piece of code is deprecated ¿? */
#if 0
    {
   int rect[4] = {sprite.srcX, sprite.srcY + sprite.h, sprite.w, -sprite.h};
   glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, rect);
   float spriteX = sprite.x;
   float spriteY = SCREEN_HEIGHT - sprite.y - sprite.h;
   float spriteW = sprite.w * sprite.scaleX;
   float spriteH = sprite.h * sprite.scaleY;
   spriteX = spriteX + (sprite.w / 2 - spriteW / 2);
   spriteY = spriteY + (sprite.h / 2 - spriteH / 2);
   glDrawTexiOES(spriteX, spriteY, 0, spriteW, spriteH);
    }
#endif

   glEnableClientState(GL_VERTEX_ARRAY);
        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        GLfloat vertices[] = { 0.0f, 0.0f, 0.0f,  sprite.w, 0.0f, 0.0f,
                               sprite.w, sprite.h, 0.0f,  0.0f, sprite.h, 0.0f };
        GLfloat texcoords[] = { minX, minY,  maxX, minY,  maxX, maxY,  minX, maxY };
        glVertexPointer(3, GL_FLOAT, 0, vertices);
        glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
        glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
        glDisableClientState(GL_VERTEX_ARRAY);

    glLoadIdentity();
}



Here is the initialization:

Code: Select all
#define SCREEN_WIDTH  800
#define SCREEN_HEIGHT 480
#define SCREEN_BPP     16

#define TRUE  1
#define FALSE 0

SDL_Surface *screen;

int initGL(void)
{
    glClearColor(0, 0, 0, 0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_ALPHA_TEST);
    glEnable(GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);

    glAlphaFunc(GL_GREATER, 0.01);
#ifndef ANDROID
#define glOrthof glOrtho
#endif
    glOrthof(0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, -1, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
   
    if(glGetError() != GL_NO_ERROR)
   return(FALSE);
    else
   return(TRUE);
}

void initSDL()
{
    int videoFlags;
    const SDL_VideoInfo *videoInfo;

    if(SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ) < 0)
    {
        fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError());
   exit(-1);
    }

    videoInfo = SDL_GetVideoInfo( );
    if(!videoInfo)
    {
        fprintf(stderr, "Video query failed: %s\n",  SDL_GetError());
        exit(-1);
    }

    videoFlags  = SDL_OPENGL;          /* Enable OpenGL in SDL */
    videoFlags |= SDL_GL_DOUBLEBUFFER; /* Enable double buffering */

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, videoFlags);
    if (!screen)
    {
        fprintf(stderr, "Video mode set failed: %s\n", SDL_GetError());
        exit(-1);
    }

    Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048);

    SDL_WM_SetCaption( "Dragon Memory", "Dragon Memory");
    SDL_WM_SetIcon(IMG_Load(DATADIR "/gfx/icon.p"), NULL);
}



Any help ir appreciated :)
Thanks
T-1000
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Nov 12, 2010 12:10 pm

Top

Re: SDL port for Android SDK/NDK 1.6

Postby awulms » Sun Nov 11, 2012 12:08 pm

Hi

I'm porting openMSX (an emulator for the MSX home computer system from the 80's and 90's) to Android. The emulator relies heavily on SDL.

Thanks to your excellent SDL port for Android, I have managed to get it working. The emulator meanwhile starts on Android.

I'm currently however fighting with the keyboard. I use the keyboard in the 'emulate hardware' mode (with setting CompatibilityHacksTextInputEmulatesHwKeyboard=y).

It works partially but not entirely.

At the moment I'm debugging it. For that purpose, I made a small test program, derived from the ballfield demo app. I have added some debug lines to this test app.

When I enter a lowercase a, I get following in the log output, which is as expected:
I/Ballfield(26499): SDL key event: evt DOWN state PRESSED key 97 key name a scancode 97 mod 0 unicode 97
I/Ballfield(26499): SDL key event: evt UP state RELEASED key 97 key name a scancode 97 mod 0 unicode 97

However, when I enter an uppercase A, I get following strange result:
I/Ballfield(26499): SDL key event: evt DOWN state PRESSED key 282 key name f1 scancode 26 mod 0 unicode 282
I/Ballfield(26499): SDL key event: evt DOWN state PRESSED key 97 key name a scancode 97 mod 0 unicode 97
I/Ballfield(26499): SDL key event: evt UP state RELEASED key 97 key name a scancode 97 mod 0 unicode 97
I/Ballfield(26499): SDL key event: evt UP state RELEASED key 282 key name f1 scancode 26 mod 0 unicode 282

I would expect to see "press SHIFT, press a, release a, release SHIFT" but instead I get "press F1, press a, release a, release F1"

It seems like something is going wrong with the mapping of the virtual keyboard events to SDL events.
Where can I find the code that performs this mapping so that I can fix it?

PS: I'm testing on a samsung galaxy nexus with android 4.1

Kind regards,
Alex
awulms
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Nov 11, 2012 11:48 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Sun Nov 11, 2012 10:02 pm

I would expect to see "press SHIFT, press a, release a, release SHIFT" but instead I get "press F1, press a, release a, release F1"

Thanks for bugreport, I've fixed that, the key mapping is inside file project/jni/sdl-1.2/src/video/android/keymap.c.
You'll have to deinstall and re-install your app to make it work, or use ResetSdlConfigForThisVersion=y parameter inside AndroidAppSettings.cfg, because old keymap is saved inside SDL config.

I am trying to use some code I have used some time ago and render using opengl but now the result is nothing viewable.

You've posted just a part of your code, so I cannot tell what's exactly wrong (what is CSprite, for example?).
When you're using OpenGL, SDL will not resize your graphics to fit the screen, so you have to use the actual device screen size, as returned by SDL_GetVideoInfo(), you cannot just #define it.
I've updated OpenGL test application, please look at project/jni/application/test-opengl/sdl_hello.cpp , that code works and should be simple enough to copy-paste.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby T-1000 » Wed Nov 14, 2012 11:52 pm

Thanks a lot for your help. I was taking a look at test-opengl and helped me a lot.
T-1000
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Nov 12, 2010 12:10 pm

Re: SDL port for Android SDK/NDK 1.6

Postby T-1000 » Tue Nov 20, 2012 4:52 pm

My application y now updated in Play Store and running fine.
https://play.google.com/store/apps/deta ... ech.memory
One question is (sorry for my bad ennglish...)
How can I avoid the advertisements to be displayed when, in the first run o the application,the data is being decompressed?
I don't know how my program can control that screen.
T-1000
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Nov 12, 2010 12:10 pm

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Tue Nov 20, 2012 6:53 pm

Remove lines 144-145 from file project/java/MainActivity.java:
Code: Select all
            _videoLayout.addView(_ad.getView());
            _ad.getView().setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.RIGHT));
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Top

Re: SDL port for Android SDK/NDK 1.6

Postby awulms » Sat Nov 24, 2012 9:40 am

Thanks for the fix to key mapping. The situation has improved. I have meanwhile noticed a few more issues, especially with unicode handling. I will see if I can fix it and provide a patch.

Cheers,
Alex
awulms
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Nov 11, 2012 11:48 am

Re: SDL port for Android SDK/NDK 1.6

Postby awulms » Sat Nov 24, 2012 11:12 pm

Hi,

I completely forgot to mention it previously but the file project/jni/xml2/trio.c by default does not compile on my linux machine. I use Android NDK r8b. Compiling the file gives some issues with the Locale support.

I have made following patch for trio.c in order to work around the compilation issue. Maybe you want to include it in the git repository:
Code: Select all
From 1ab39fec631545c4d0639dd3b16c4bb10e3fd0c8 Mon Sep 17 00:00:00 2001
From: Alex Wulms <awulms@nospam.thevoid>
Date: Sat, 24 Nov 2012 22:55:31 +0100
Subject: [PATCH] Locale support (used in xlm2/trio.c) does not work with
android-ndk-r8b

---
project/jni/xml2/trio.c |    7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/project/jni/xml2/trio.c b/project/jni/xml2/trio.c
index 1698e70..9d1f185 100644
--- a/project/jni/xml2/trio.c
+++ b/project/jni/xml2/trio.c
@@ -137,8 +137,11 @@ typedef unsigned long trio_flags_t;
#if defined(TRIO_PLATFORM_UNIX)
# include <unistd.h>
# include <signal.h>
-# include <locale.h>
-# define USE_LOCALE
+/* locale implementation on Android is broken, at least with NDK 8b */
+# if !defined ANDROID
+#  include <locale.h>
+#  define USE_LOCALE
+# endif
#endif /* TRIO_PLATFORM_UNIX */
#if defined(TRIO_PLATFORM_VMS)
# include <unistd.h>
--
1.7.10.4



Kind regards,
Alex
awulms
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Nov 11, 2012 11:48 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Sun Nov 25, 2012 1:02 pm

Merget that, thanks.
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby awulms » Fri Dec 07, 2012 10:34 pm

Hi,

I have another patch. This time for the build system. In openMSX emulator we have an on-screen-display menu that users can open to change settings or insert rom images or disk images into the emulated machine. For the android port, we want to bind that menu to the Android menu button. However, as you probably know, there is no longer a physical menu button on android 3 and 4 devices. Though, Android 3 and 4 renders a virtual menu button when targetting API 10 or lower (e.g. any Android before 3).

Your manifest file by default targets android 15, which means that the menu button is not present on android 3&4.

The patch I have made is for the changeAppSettings.sh script. It checks if the menu button is bound to an event. If yes, then it will target SDK 10 so that the menu button is rendered on modern android devices. Otherwise it targets SDK 15 so that the button is suppressed.

Can you accept this patch?

Here it is:
Code: Select all
diff --git a/changeAppSettings.sh b/changeAppSettings.sh
index 8f22ee9..10b0135 100755
--- a/changeAppSettings.sh
+++ b/changeAppSettings.sh
@@ -897,11 +897,24 @@ for F in *.java; do
done
cd ../..

+set $RedefinedKeys
+if [ -z "$5" -o "$5" = "NO_REMAP"  ]; then
+       # MENU key is not bound to an event, target latest Android API so that
+       # on Android 3.0 and above, the menu button does not get rendered
+       TargetSdkVersion=15
+else
+       # MENU key is bound to an event. Target Android 2.3 or older so
+       # that Android 3.0 and above render the menu button for backward
+       # compatibility reasons
+       TargetSdkVersion=10
+fi
+
echo Patching project/AndroidManifest.xml
cat project/AndroidManifestTemplate.xml | \
        sed "s/package=.*/package=\"$AppFullName\"/" | \
        sed "s/android:screenOrientation=.*/android:screenOrientation=\"$ScreenOrientation1\"/" | \
        sed "s^android:versionCode=.*^android:versionCode=\"$AppVersionCode\"^" | \
+       sed "s/android:targetSdkVersion=\"[0-9]*\"/android:targetSdkVersion=\"$TargetSdkVersion\"/"  | \
        sed "s^android:versionName=.*^android:versionName=\"$AppVersionName\"^" > \
        project/AndroidManifest.xml
if [ "$AdmobPublisherId" = "n" -o -z "$AdmobPublisherId" ] ; then

awulms
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Nov 11, 2012 11:48 am

Re: SDL port for Android SDK/NDK 1.6

Postby pelya » Sat Dec 08, 2012 1:50 am

Well, targeting older API level is hacky, and you will lose support for middle/right mouse button for Bluetooth mouse, and stylus support on Galaxy Note. Also, I don't want to disable Menu button for my other ports, most of them use it as a non-mandatory hotkey.
If your app cannot live without an extra button, you probably need to use some on-screen buttons, provided by SDL - for example set AppTouchscreenKeyboardKeysAmount=3 and RedefinedKeysScreenKb="SLASH BACKSPACE TAB" - that will enable three on-screen buttons, that will send you the keycodes you've specified.
If you absolutely don't want to lose any screen space for on-screen buttons, you may try to use multitouch gestures instead - specify RedefinedKeysScreenKb="A B C D E F LCTRL LALT LSHIFT TAB" will bind pinch-zoom in/out gestures to Ctrl and Alt, and rotate left/right to Shift and Tab.
If you have AppUsesMouse=y and AppNeedsTwoButtonMouse=y, touching the screen with two fingers will send you a right mouse button event, which you may also use for menu invocation (but you'll need to modify OpenMSX code).
pelya
Master Developer
Master Developer
 
Posts: 323
Joined: Mon Nov 23, 2009 11:31 am

Re: SDL port for Android SDK/NDK 1.6

Postby awulms » Sat Dec 08, 2012 5:50 pm

Thanks for the clarification. Originally I had bound the menu to the back button but the pilot testers found it confusing. That is why I investigated binding it to the menu button. I'll keep it bound to the back button for now.
awulms
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Nov 11, 2012 11:48 am

Re: SDL port for Android SDK/NDK 1.6

Postby awulms » Sat Dec 15, 2012 3:40 pm

Is it possible to add a default audio buffer size option to the AndroidAppSettings.cfg file? On all devices we tried so far (with openMSX), the SDL setting 'audio buffer size' had to be changed from "very small" to "small" to not get choppy sound. It would be great if we can make this the default, so that people have good sound right away.

Please note that I have tried parameter CompatibilityHacksPreventAudioChopping with value y and n, but it makes no difference. In either case, using 'very small' audio buffer gives choppy sound while 'small' gives a perfect sound and a still acceptable lag.
awulms
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Nov 11, 2012 11:48 am

Re: SDL port for Android SDK/NDK 1.6

Postby awulms » Sun Dec 16, 2012 11:16 am

One of the openMSX beta testers has reported that openMSX crashes on a device with build fingerprint 'samsung/GT-I5800/GT-I5800/GT-I5800:2.1-update1/ECLAIR/XWJG6:user/release-keys' in libsdl.

adb logcat shows following related output:
Code: Select all
I/libSDL  (18584): Changing curdir to "/sdcard/Android/data/org.openmsx.android.openmsx/files"
I/libSDL  (18584): Calling SDL_main("sdl")
I/libSDL  (18584): param 0 = "sdl"
I/openMSX (18584): Redirecting stdout to openmsx_system/openmsx.stdout and stderr to openmsx_system/openmsx.stderr
D/openMSX (18584): MMX:  0
D/openMSX (18584): SSE:  0
D/openMSX (18584): SSE2: 0
I/openMSX (18584): System data dir: /sdcard/Android/data/org.openmsx.android.openmsx/files/openmsx_system
I/libSDL  (18584): ANDROIDAUD_OpenAudio(): app requested audio bytespersample 2 freq 44100 channels 2 samples 1024
I/AudioPolicyManager( 1962): setOutputDevice() output 1 device 2 delayMs 0
I/AudioPolicyManager( 1962): setOutputDevice() setting same device 2 for output 1
I/libSDL  (18584): ANDROIDAUD_OpenAudio(): app opened audio bytespersample 2 freq 44100 channels 2 bufsize 4096
D/AudioHardwareALSA( 1962): codecOn
D/openMSX (18584): LocalFile: /sdcard/openMSX/share/softwaredb.xml
I/DEBUG   (17482): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG   (17482): Build fingerprint: 'samsung/GT-I5800/GT-I5800/GT-I5800:2.1-update1/ECLAIR/XWJG6:user/release-keys'
I/DEBUG   (17482): pid: 18584, tid: 18593  >>> org.openmsx.android.openmsx <<<
I/DEBUG   (17482): signal 4 (SIGILL), fault addr 81800000
I/DEBUG   (17482):  r0 825fb682  r1 48a7c3d4  r2 825fb684  r3 81800000
I/DEBUG   (17482):  r4 0028ee10  r5 81848c54  r6 825fb682  r7 82748de0
I/DEBUG   (17482):  r8 0028ecc4  r9 826f8e9c  10 82748de0  fp 48a7c6b4
I/DEBUG   (17482):  ip 81848da8  sp 48a7c3c8  lr 81839820  pc 81800000  cpsr a0000010
I/AudioHardwareALSA( 1962): Initialized ALSA PLAYBACK device AndroidPlayback_Speaker_normal
D/AudioHardwareALSA( 1962): Set PLAYBACK PCM format to S16_LE (Signed 16 bit Little Endian)
D/AudioHardwareALSA( 1962): Using 2 channels for PLAYBACK.
D/AudioHardwareALSA( 1962): Set PLAYBACK sample rate to 44100 HZ
D/AudioHardwareALSA( 1962): Buffer size: 1024
D/AudioHardwareALSA( 1962): Latency: 23219
W/AudioFlinger( 1962): write blocked for 439 msecs, 410 delayed writes, thread 0x26138
I/DEBUG   (17482):          #00  pc 00000000  /data/data/org.openmsx.android.openmsx/lib/libsdl-1.2.so
I/DEBUG   (17482):          #01  pc 0003981c  /data/data/org.openmsx.android.openmsx/lib/libsdl-1.2.so
I/DEBUG   (17482):          #02  pc 0003a3d4  /data/data/org.openmsx.android.openmsx/lib/libsdl-1.2.so
I/DEBUG   (17482):


And then some more details about what is on the data stack during the crash.

I have looked-up the source code lines for the three mentioned addresses with gdb, but it does not seem to be useful. Here is the output from gdb
Code: Select all
(gdb) list *0x3a3d4
0x3a3d4 is in __gnu_Unwind_RaiseException (/usr/local/google/home/andrewhsieh/ndk-andrewhsieh/src/build/../gcc/gcc-4.6/libgcc/../gcc/config/arm/unwind-arm.c:826).
821     in /usr/local/google/home/andrewhsieh/ndk-andrewhsieh/src/build/../gcc/gcc-4.6/libgcc/../gcc/config/arm/unwind-arm.c

(gdb) list *0x3981c
0x3981c is in get_eit_entry (/usr/local/google/home/andrewhsieh/ndk-andrewhsieh/src/build/../gcc/gcc-4.6/libgcc/../gcc/config/arm/unwind-arm.c:603).
598     in /usr/local/google/home/andrewhsieh/ndk-andrewhsieh/src/build/../gcc/gcc-4.6/libgcc/../gcc/config/arm/unwind-arm.c

(gdb) list *0x0
No source file for address 0x0.


Any idea what could go wrong? The latest trace messages in the adb logcat are about the audio. Though, it might be misleading, because audio runs in a separate thread so the audio messages might simply be interlaced with the crash messages. I'm not sure about it.

Have you heard about any issues with the Samsung i5800 among your users? Myself, I found one topic here about a libgdx issue with Samsung i5800. Might it be related? The person who posted that message believes that it might be related to opengl and I have understood that you use openGL (or GL ES) for the onscreen controls so there might be a link.

Any help or hints on how to further troubleshoot this are welcome. My beta tester is willing to further assist with the debugging.
awulms
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Nov 11, 2012 11:48 am

Re: SDL port for Android SDK/NDK 1.6

Postby awulms » Mon Dec 17, 2012 5:17 pm

As promised a while ago, here is a small patch for the key mappings. The patch has been tested with standard virtual Android keyboard on Samsung galaxy nexus with Android 4.2 and the patch has also been tested with the "hackers keyboard" app, mentioned in the readme in the git repository.

With this patch, the keyboard behaves more like the keyboard on PC under linux, windows and Mac
Code: Select all
diff --git a/project/jni/sdl-1.2/src/video/android/keymap.c b/project/jni/sdl-1.2/src/video/android/keymap.c
index 4427eb3..df88bd7 100644
--- a/project/jni/sdl-1.2/src/video/android/keymap.c
+++ b/project/jni/sdl-1.2/src/video/android/keymap.c
@@ -42,8 +42,8 @@ void SDL_android_init_keymap(SDLKey *SDL_android_keymap)
   keymap[KEYCODE_7] = SDL_KEY(7);
   keymap[KEYCODE_8] = SDL_KEY(8);
   keymap[KEYCODE_9] = SDL_KEY(9);
-  keymap[KEYCODE_STAR] = SDL_KEY(KP_DIVIDE);
-  keymap[KEYCODE_POUND] = SDL_KEY(KP_MULTIPLY);
+  keymap[KEYCODE_STAR] = SDL_KEY(KP_MULTIPLY);
+  keymap[KEYCODE_POUND] = SDL_KEY(HASH);

   keymap[KEYCODE_DPAD_UP] = SDL_KEY(UP);
   keymap[KEYCODE_DPAD_DOWN] = SDL_KEY(DOWN);
@@ -52,10 +52,10 @@ void SDL_android_init_keymap(SDLKey *SDL_android_keymap)

   keymap[KEYCODE_SOFT_LEFT] = SDL_KEY(KP_4);
   keymap[KEYCODE_SOFT_RIGHT] = SDL_KEY(KP_6);
-  keymap[KEYCODE_ENTER] = SDL_KEY(RETURN); //SDL_KEY(KP_ENTER);
+  keymap[KEYCODE_ENTER] = SDL_KEY(RETURN);


-  keymap[KEYCODE_CLEAR] = SDL_KEY(BACKSPACE);
+  keymap[KEYCODE_CLEAR] = SDL_KEY(CLEAR);
   keymap[KEYCODE_A] = SDL_KEY(A);
   keymap[KEYCODE_B] = SDL_KEY(B);
   keymap[KEYCODE_C] = SDL_KEY(C);
@@ -86,10 +86,10 @@ void SDL_android_init_keymap(SDLKey *SDL_android_keymap)
   keymap[KEYCODE_PERIOD] = SDL_KEY(PERIOD);
   keymap[KEYCODE_TAB] = SDL_KEY(TAB);
   keymap[KEYCODE_SPACE] = SDL_KEY(SPACE);
-  keymap[KEYCODE_DEL] = SDL_KEY(DELETE);
+  keymap[KEYCODE_DEL] = SDL_KEY(BACKSPACE);
   keymap[KEYCODE_GRAVE] = SDL_KEY(GRAVE);
-  keymap[KEYCODE_MINUS] = SDL_KEY(KP_MINUS);
-  keymap[KEYCODE_PLUS] = SDL_KEY(KP_PLUS);
+  keymap[KEYCODE_MINUS] = SDL_KEY(MINUS);
+  keymap[KEYCODE_PLUS] = SDL_KEY(PLUS);
   keymap[KEYCODE_EQUALS] = SDL_KEY(EQUALS);
   keymap[KEYCODE_LEFT_BRACKET] = SDL_KEY(LEFTBRACKET);
   keymap[KEYCODE_RIGHT_BRACKET] = SDL_KEY(RIGHTBRACKET);
@@ -97,7 +97,7 @@ void SDL_android_init_keymap(SDLKey *SDL_android_keymap)
   keymap[KEYCODE_SEMICOLON] = SDL_KEY(SEMICOLON);
   keymap[KEYCODE_APOSTROPHE] = SDL_KEY(APOSTROPHE);
   keymap[KEYCODE_SLASH] = SDL_KEY(SLASH);
-  keymap[KEYCODE_AT] = SDL_KEY(KP_PERIOD);
+  keymap[KEYCODE_AT] = SDL_KEY(AT);

   keymap[KEYCODE_MEDIA_PLAY_PAUSE] = SDL_KEY(KP_2);
   keymap[KEYCODE_MEDIA_STOP] = SDL_KEY(HELP);


Furthermore, I have noticed that the unicode support in the Android port of SDL is currently broken. That is to say, it behaves completely differently then on other platforms. For openMSX I need good unicode support. At the moment I have worked-around it in openMSX itself with a dirty hack (see InputEvents.cc in sourceforge for the details).
I'll study better how the keyboard support in the SDL Android port works and then I'll fix the unicode support and provide you with a patch.
awulms
Junior Developer
Junior Developer
 
Posts: 13
Joined: Sun Nov 11, 2012 11:48 am

Top
PreviousNext

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 8 guests