[AD] Nokia 770 support patch

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Hello all,

The patch which is attached fixes:
* problems with image distortion in 8-bit mode (because of improper alignment in 'ccolconv.c' which is important for ARM cpu)
* crash in FLI playing code
* addes ENTER key as fire button to allegro demo game (as Nokia 770 does not have SPACE or CTRL buttons)

Also it adds ALLEGRO_ARM define for selecting conditionally compiled code that should be run on ARM cpu.

One more notice for anyone who would like to try allegro on Nokia 770. It is important to use '-march=armv5te' optimization option, otherwise everything is *a lot* slower. For example 'clear_to_color()' function is *twice* faster with this optimization enabled.

The only thing remaining is to add proper fullscreen support and allegro will be ready to use on Nokia 770. At least I'm not aware of any other problems :) Also probably some functions written in ARM assembler would help to improve performance.

For more details see the following forum thread (unfortunately it is locked with no way to add a new post or edit the last one):
https://www.allegro.cc/forums/thread/561300

Index: demo/game.c
===================================================================
--- demo/game.c	(revision 5738)
+++ demo/game.c	(working copy)
@@ -224,7 +224,7 @@
 
    /* fire bullet? */
    if (!player_hit) {
-      if ((key[KEY_SPACE] || key[KEY_LCONTROL] || key[KEY_RCONTROL]) ||
+      if ((key[KEY_SPACE] || key[KEY_ENTER] || key[KEY_LCONTROL] || key[KEY_RCONTROL]) ||
           (joy[0].button[0].b) || (joy[0].button[1].b)) {
          if (prev_bullet_time + BULLET_DELAY < game_time) {
             bullet = add_bullet((player_x_pos >> SPEED_SHIFT) - 2, SCREEN_H - 64);
Index: src/misc/ccolconv.c
===================================================================
--- src/misc/ccolconv.c	(revision 5738)
+++ src/misc/ccolconv.c	(working copy)
@@ -103,6 +103,56 @@
    dest_feed = dest_rect->pitch - (width << 1);
    src = src_rect->data;
    dest = dest_rect->data;
+#ifdef ALLEGRO_ARM
+   /* ARM requires strict alignment for memory access. So this ARM branch of code 
+    * takes it into account. Combining data into 32-bit values when writing to
+    * memory really adds about 20% extra performance on Nokia 770. An interesting 
+    * thing is that this branch of code is not only correct, but also actually 
+    * a bit faster than the other one.
+    */
+#ifdef ALLEGRO_LITTLE_ENDIAN
+   #define FILL_DEST_DATA() \
+      dest_data = _colorconv_indexed_palette[src[0]]; \
+      dest_data |= _colorconv_indexed_palette[256 + src[1]]; \
+      src += 2;
+#else
+   #define FILL_DEST_DATA() \
+      dest_data = _colorconv_indexed_palette[256 + src[0]]; \
+      dest_data |= _colorconv_indexed_palette[src[1]]; \
+      src += 2;
+#endif
+
+   if (width <= 0) return;
+
+   y = src_rect->height;
+   if (width & 0x1) {
+      width >>= 1;
+      while (--y >= 0) {
+         if ((int)dest & 0x3) {
+            *(unsigned short *)(dest) = _colorconv_indexed_palette[*src++]; dest += 2;
+            x = width; while (--x >= 0) { FILL_DEST_DATA(); *(unsigned int *)dest = dest_data; dest += 4; }
+         } else {
+            x = width; while (--x >= 0) { FILL_DEST_DATA(); *(unsigned int *)dest = dest_data; dest += 4; }
+            *(unsigned short *)(dest) = _colorconv_indexed_palette[*src++]; dest += 2;
+         }
+         src += src_feed;
+         dest += dest_feed;
+      }
+   } else {
+      width >>= 1;
+      while (--y >= 0) {
+         if ((int)dest & 0x3) {
+            *(unsigned short *)(dest) = _colorconv_indexed_palette[*src++]; dest += 2;
+            x = width; while (--x > 0) { FILL_DEST_DATA(); *(unsigned int *)dest = dest_data; dest += 4; }
+            *(unsigned short *)(dest) = _colorconv_indexed_palette[*src++]; dest += 2;
+         } else {
+            x = width; while (--x >= 0) { FILL_DEST_DATA(); *(unsigned int *)dest = dest_data; dest += 4; }
+         }
+         src += src_feed;
+         dest += dest_feed;
+      }
+   }
+#else
    for (y = src_rect->height; y; y--) {
       for (x = width >> 2; x; x--) {
          src_data = *(unsigned int *)src;
@@ -148,6 +198,7 @@
       src += src_feed;
       dest += dest_feed;
    }
+#endif   
 }
 
 
Index: src/fli.c
===================================================================
--- src/fli.c	(revision 5738)
+++ src/fli.c	(working copy)
@@ -193,7 +193,7 @@
 #define READ_CHAR_NC(p)    (*(signed char *)(p)++)
 #endif
 
-#if (defined ALLEGRO_GCC) && (defined ALLEGRO_LITTLE_ENDIAN)
+#if (defined ALLEGRO_GCC) && (defined ALLEGRO_LITTLE_ENDIAN) && (!defined ALLEGRO_ARM)
 
 #if 0
 /* the "cast expression as lvalue" extension is deprecated in GCC 3.4 */
Index: include/allegro/internal/alconfig.h
===================================================================
--- include/allegro/internal/alconfig.h	(revision 5738)
+++ include/allegro/internal/alconfig.h	(working copy)
@@ -120,6 +120,10 @@
       #define ALLEGRO_AMD64
       #define _AL_SINCOS(x, s, c)  __asm__ ("fsincos" : "=t" (c), "=u" (s) : "0" (x))
    #endif
+   
+   #ifdef __arm__
+      #define ALLEGRO_ARM
+   #endif
 
    #ifndef AL_CONST
       #define AL_CONST     const



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/