  			result = FALSE;
  		}
  		ExitRequested = FALSE;
-Index: src/uqm/battle.c
-===================================================================
---- src/uqm/battle.c	(revision 3779)
-+++ src/uqm/battle.c	(working copy)
-@@ -16,6 +16,10 @@
-  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-  */
- 
-+#ifdef ANDROID
-+#include <android/log.h>
-+#endif
-+
- #include "battle.h"
- 
- #include "battlecontrols.h"
-@@ -44,6 +48,8 @@
- #include "libs/graphics/gfx_common.h"
- #include "libs/log.h"
- #include "libs/mathlib.h"
-+#include "globdata.h"
-+#include "libs/input/sdl/vcontrol.h"
- 
- 
- BYTE battle_counter[NUM_SIDES];
-@@ -138,7 +144,8 @@
- frameInputHuman (HumanInputContext *context, STARSHIP *StarShipPtr)
- {
- 	(void) StarShipPtr;
--	return CurrentInputToBattleInput (context->playerNr);
-+
-+	return CurrentInputToBattleInput (context->playerNr, StarShipPtr ? StarShipPtr->ShipFacing : -1);
- }
- 
- static void
-@@ -208,8 +215,11 @@
- 						StarShipPtr->ship_input_state |= SPECIAL;
- 
- 					if (CanRunAway && cur_player == 0 &&
--							(InputState & BATTLE_ESCAPE))
-+							((InputState & BATTLE_ESCAPE) || EmergencyEscapeWarpUnitActivatedFromMenu))
-+					{
-+						EmergencyEscapeWarpUnitActivatedFromMenu = FALSE;
- 						DoRunAway (StarShipPtr);
-+					}
- 				}
- 			}
- 
-@@ -397,6 +407,10 @@
- {
- 	SIZE num_ships;
- 
-+	TFB_SetOnScreenKeyboard_Melee ();
-+	if (PlayerControl[1] & HUMAN_CONTROL) {
-+		TFB_SetOnScreenKeyboard_TwoPlayersMelee ();
-+	}
- 
- #if !(DEMO_MODE || CREATE_JOURNAL)
- 	if (LOBYTE (GLOBAL (CurrentActivity)) != SUPER_MELEE) {
-@@ -506,7 +520,7 @@
- 	UninitShips ();
- 	FreeBattleSong ();
- 
--	
-+	TFB_SetOnScreenKeyboard_Menu ();
- 	return (BOOLEAN) (num_ships < 0);
- }
- 
-Index: src/uqm/globdata.c
-===================================================================
---- src/uqm/globdata.c	(revision 3779)
-+++ src/uqm/globdata.c	(working copy)
-@@ -131,7 +131,7 @@
- 		OldContext = SetContext (RadarContext);
- 		SetContextFGFrame (Screen);
- 		r.corner.x = RADAR_X;
--		r.corner.y = RADAR_Y;
-+		r.corner.y = RADAR_Y_LIFTED_UP;
- 		r.extent.width = RADAR_WIDTH;
- 		r.extent.height = RADAR_HEIGHT;
- 		SetContextClipRect (&r);
-Index: src/uqm/shipyard.c
-===================================================================
---- src/uqm/shipyard.c	(revision 3779)
-+++ src/uqm/shipyard.c	(working copy)
-@@ -201,9 +201,9 @@
- 	OldContext = SetContext (StatusContext);
- 	GetContextClipRect (&r);
- 	s.origin.x = RADAR_X - r.corner.x;
--	s.origin.y = RADAR_Y - r.corner.y;
-+	s.origin.y = RADAR_Y_LIFTED_UP - r.corner.y;
- 	r.corner.x = s.origin.x - 1;
--	r.corner.y = s.origin.y - 11;
-+	r.corner.y = s.origin.y - 1;
- 	r.extent.width = RADAR_WIDTH + 2;
- 	r.extent.height = 11;
- 	BatchGraphics ();
-@@ -227,10 +227,6 @@
- 		NewRaceItem = GetIndexFromStarShip (&GLOBAL (avail_race_q),
- 				hStarShip);
- 
--		// Draw the ship name, above the ship image.
--		s.frame = SetAbsFrameIndex (pMS->ModuleFrame, 3 + NewRaceItem);
--		DrawStamp (&s);
--
- 		// Draw the ship image.
- 		FleetPtr = LockFleetInfo (&GLOBAL (avail_race_q), hStarShip);
- 		s.frame = FleetPtr->melee_icon;
-@@ -241,6 +237,12 @@
- 		s.origin.y += (RADAR_HEIGHT >> 1);
- 		DrawStamp (&s);
- 
-+		// Draw the ship name, above the ship image.
-+		s.origin.x -= (RADAR_WIDTH >> 1);
-+		s.origin.y -= (RADAR_HEIGHT >> 2);
-+		s.frame = SetAbsFrameIndex (pMS->ModuleFrame, 3 + NewRaceItem);
-+		DrawStamp (&s);
-+
- 		// Print the ship cost.
- 		t.align = ALIGN_RIGHT;
- 		t.CharCount = (COUNT)~0;
-Index: src/uqm/outfit.c
-===================================================================
---- src/uqm/outfit.c	(revision 3779)
-+++ src/uqm/outfit.c	(working copy)
-@@ -55,7 +55,7 @@
- 	OldContext = SetContext (StatusContext);
- 	GetContextClipRect (&r);
- 	s.origin.x = RADAR_X - r.corner.x;
--	s.origin.y = RADAR_Y - r.corner.y;
-+	s.origin.y = RADAR_Y_LIFTED_UP - r.corner.y + 10;
- 	r.corner.x = s.origin.x - 1;
- 	r.corner.y = s.origin.y - 11;
- 	r.extent.width = RADAR_WIDTH + 2;
-Index: src/uqm/starcon.c
-===================================================================
---- src/uqm/starcon.c	(revision 3779)
-+++ src/uqm/starcon.c	(working copy)
-@@ -218,6 +218,7 @@
- 		InitGameClock ();
- 		AddInitialGameEvents();
- 
-+		TFB_SetOnScreenKeyboard_Melee ();
- 		do
- 		{
- #ifdef DEBUG
 Index: src/uqm/status.c
 ===================================================================
 --- src/uqm/status.c	(revision 3779)

 
 #include "md5.h"
 
Index: src/libs/input/sdl/input.c
===================================================================
--- src/libs/input/sdl/input.c	(revision 3779)
+++ src/libs/input/sdl/input.c	(working copy)
@@ -86,6 +86,7 @@
 	"weapon",
 	"special",
 	"escape",
+	"thrust",
 	NULL
 };
 
@@ -186,7 +187,7 @@
 		   directory. */
 		LoadResourceIndex (contentDir, "uqm.key", "keys.");
 	}
-
+	
 	register_flight_controls ();
 
 	return;
Index: src/libs/input/sdl/vcontrol.c
===================================================================
--- src/libs/input/sdl/vcontrol.c	(revision 3779)
+++ src/libs/input/sdl/vcontrol.c	(working copy)
@@ -46,6 +46,7 @@
 typedef struct vcontrol_joystick_axis {
 	keybinding *neg, *pos;
 	int polarity;
+	int value;
 } axis_type;
 
 typedef struct vcontrol_joystick_hat {
@@ -66,7 +67,7 @@
 
 #endif /* HAVE_JOYSTICK */
 
-static unsigned int joycount;
+static unsigned int joycount = 0;
 static unsigned int num_sdl_keys = 0;
 static keybinding **bindings = NULL;
 
@@ -141,6 +142,7 @@
 		for (j = 0; j < axes; j++)
 		{
 			x->axes[j].neg = x->axes[j].pos = NULL;
+			x->axes[j].polarity = x->axes[j].value = 0;
 		}
 		for (j = 0; j < hats; j++)
 		{
@@ -818,6 +820,7 @@
 	int t;
 	if (!joysticks[port].stick)
 		return;
+	joysticks[port].axes[axis].value = value;
 	t = joysticks[port].threshold;
 	if (value > t)
 	{
@@ -894,6 +897,25 @@
 #endif /* HAVE_JOYSTICK */
 }
 
+int
+VControl_GetJoyAxis(int port, int axis)
+{
+#ifdef HAVE_JOYSTICK
+	if( joycount <= port )
+		return 0;
+	if (!joysticks[port].stick || joysticks[port].numaxes <= axis )
+		return 0;
+	return joysticks[port].axes[axis].value;
+#else
+	return 0;
+#endif /* HAVE_JOYSTICK */
+};
+
+int VControl_GetJoysticksAmount()
+{
+	return joycount;
+};
+
 void
 VControl_ResetInput (void)
 {
Index: src/libs/input/sdl/vcontrol.h
===================================================================
--- src/libs/input/sdl/vcontrol.h	(revision 3779)
+++ src/libs/input/sdl/vcontrol.h	(working copy)
@@ -76,6 +76,9 @@
 void VControl_ProcessJoyAxis (int port, int axis, int value);
 void VControl_ProcessJoyHat (int port, int which, Uint8 value);
 
+int VControl_GetJoyAxis(int port, int axis);
+int VControl_GetJoysticksAmount();
+
 /* Force the input into the blank state.  For preventing "sticky" keys. */
 void VControl_ResetInput (void);
 
Index: src/libs/input/input_common.h
===================================================================
--- src/libs/input/input_common.h	(revision 3779)
+++ src/libs/input/input_common.h	(working copy)
@@ -31,7 +31,7 @@
 extern int TFB_InitInput (int driver, int flags);
 extern void TFB_UninitInput (void);
 
-#define MAX_FLIGHT_ALTERNATES  2
+#define MAX_FLIGHT_ALTERNATES  3
 
 extern void TFB_SetInputVectors (volatile int menu[], int num_menu,
 		volatile int flight[], int num_templ, int num_flight);
Index: src/libs/resource/filecntl.c
===================================================================
--- src/libs/resource/filecntl.c	(revision 3779)

 	getBoolConfigValue (&options->keepAspectRatio, "config.keepaspectratio");
 	getGammaConfigValue (&options->gamma, "config.gamma");
 
Index: src/libs/graphics/gfx_common.h
===================================================================
--- src/libs/graphics/gfx_common.h	(revision 3779)
+++ src/libs/graphics/gfx_common.h	(working copy)
@@ -107,4 +107,10 @@
 extern int ScreenColorDepth;
 extern int GraphicsDriver;
 
+void TFB_SetOnScreenKeyboard_Hidden (void);
+void TFB_SetOnScreenKeyboard_Menu (void);
+void TFB_SetOnScreenKeyboard_Starmap (void);
+void TFB_SetOnScreenKeyboard_Melee (void);
+void TFB_SetOnScreenKeyboard_TwoPlayersMelee (void);
+
 #endif
Index: src/libs/graphics/sdl/pure.c
===================================================================
--- src/libs/graphics/sdl/pure.c	(revision 3779)
+++ src/libs/graphics/sdl/pure.c	(working copy)
@@ -104,6 +104,7 @@
 {
 	int i, videomode_flags;
 	SDL_PixelFormat conv_fmt;
+	int BPP = 32;
 	
 	GraphicsDriver = driver;
 
@@ -128,6 +129,14 @@
 					"under pure SDL, using 640x480", width, height);
 	}
 
+#ifdef ANDROID
+	videomode_flags = SDL_SWSURFACE;
+	ScreenWidthActual = 320;
+	ScreenHeightActual = 240;
+	graphics_backend = &pure_unscaled_backend;
+	BPP = 16;
+#endif
+
 	videomode_flags |= SDL_ANYFORMAT;
 	if (flags & TFB_GFXFLAGS_FULLSCREEN)
 		videomode_flags |= SDL_FULLSCREEN;
@@ -135,7 +144,7 @@
 	/* We'll ask for a 32bpp frame, but it doesn't really matter, because we've set
 	   SDL_ANYFORMAT */
 	SDL_Video = SDL_SetVideoMode (ScreenWidthActual, ScreenHeightActual, 
-		32, videomode_flags);
+		BPP, videomode_flags);
 
 	if (SDL_Video == NULL)
 	{
Index: src/libs/graphics/sdl/sdl_common.c
===================================================================
--- src/libs/graphics/sdl/sdl_common.c	(revision 3779)
+++ src/libs/graphics/sdl/sdl_common.c	(working copy)
@@ -34,7 +34,11 @@
 #include "libs/memlib.h"
 #include "libs/vidlib.h"
 #include SDL_INCLUDE(SDL_thread.h)
+#ifdef ANDROID
+#include <SDL/SDL_screenkeyboard.h>
+#endif
 
+
 SDL_Surface *SDL_Video;
 SDL_Surface *SDL_Screen;
 SDL_Surface *TransitionScreen;
@@ -172,6 +176,8 @@
 
 	TFB_DrawCanvas_Initialize ();
 
+	TFB_InitOnScreenKeyboard ();
+
 	return 0;
 }
 
@@ -397,3 +403,155 @@
 	SDL_FreeSurface (*screen);
 	*screen = NULL;
 }
+
+#ifdef ANDROID
+
+static SDL_Rect SDL_LeftJoystickRect, SDL_RightJoystickRect, SDL_TextInputRect;
+
+void
+TFB_InitOnScreenKeyboard (void)
+{
+	SDL_ANDROID_GetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD, &SDL_LeftJoystickRect);
+	SDL_ANDROID_GetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2, &SDL_RightJoystickRect);
+	SDL_ANDROID_GetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT, &SDL_TextInputRect);
+
+	/* TFB_SetOnScreenKeyboard_Hidden (); */
+	TFB_SetOnScreenKeyboard_Menu ();
+}
+
+void
+TFB_SetOnScreenKeyboard_Hidden (void)
+{
+	if (SDL_ANDROID_GetScreenKeyboardRedefinedByUser())
+		return;
+	SDL_Rect b;
+	b.w = b.h = b.x = b.y = 0;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, &b);
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_1, &b);
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, &b);
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_3, &b);
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_4, &b);
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_5, &b);
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD, &b);
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2, &b);
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT, &b);
+}
+
+void
+TFB_SetOnScreenKeyboard_Menu (void)
+{
+	if (SDL_ANDROID_GetScreenKeyboardRedefinedByUser())
+		return;
+	TFB_SetOnScreenKeyboard_Hidden();
+	SDL_Rect b;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD, &SDL_LeftJoystickRect);
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_TEXT, &SDL_TextInputRect);
+	b.w = SDL_RightJoystickRect.w / 2;
+	b.h = SDL_RightJoystickRect.h / 2;
+	b.x = SDL_RightJoystickRect.x + b.w;
+	b.y = SDL_RightJoystickRect.y + SDL_RightJoystickRect.h - b.h;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, &b);
+	b.x = SDL_RightJoystickRect.x;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_1, &b);
+}
+
+void
+TFB_SetOnScreenKeyboard_Starmap (void)
+{
+	if (SDL_ANDROID_GetScreenKeyboardRedefinedByUser())
+		return;
+	TFB_SetOnScreenKeyboard_Menu();
+	SDL_Rect b;
+	b.h = SDL_RightJoystickRect.h / 2;
+	b.w = SDL_RightJoystickRect.w / 2;
+	b.x = SDL_RightJoystickRect.x - b.w;
+	b.y = SDL_RightJoystickRect.y + SDL_RightJoystickRect.h - b.h;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_3, &b);
+	b.x -= b.w;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_4, &b);
+}
+
+void
+TFB_SetOnScreenKeyboard_Melee (void)
+{
+	if (SDL_ANDROID_GetScreenKeyboardRedefinedByUser())
+		return;
+	/* Make the on-screen buttons slightly overlap, so we can hit them with one finger */
+	TFB_SetOnScreenKeyboard_Hidden();
+	SDL_Rect b;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD, &SDL_LeftJoystickRect);
+	b.w = SDL_RightJoystickRect.w * 3 / 5;
+	b.h = SDL_RightJoystickRect.h * 3 / 5;
+	b.x = SDL_RightJoystickRect.x + SDL_RightJoystickRect.w - b.w;
+	b.y = SDL_RightJoystickRect.y + SDL_RightJoystickRect.h - b.h; //SDL_RightJoystickRect.y;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_0, &b);
+	b.x = SDL_RightJoystickRect.x;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_1, &b);
+	// Throttle button is replaced by tapping joystick
+	/*
+	b.w = SDL_RightJoystickRect.w;
+	b.y = SDL_RightJoystickRect.y + SDL_RightJoystickRect.h - b.h;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_2, &b);
+	*/
+}
+
+void
+TFB_SetOnScreenKeyboard_TwoPlayersMelee (void)
+{
+	if (SDL_ANDROID_GetScreenKeyboardRedefinedByUser())
+		return;
+	/* Mirror the buttons */
+	TFB_SetOnScreenKeyboard_Melee();
+	SDL_Rect b = SDL_RightJoystickRect;
+	b.y = 0;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_DPAD2, &b);
+	b.w = SDL_RightJoystickRect.w * 3 / 5;
+	b.h = SDL_RightJoystickRect.h * 3 / 5;
+	b.x = 0;
+	b.y = 0; // SDL_RightJoystickRect.h - b.h;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_3, &b);
+	b.x = SDL_RightJoystickRect.w - b.w;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_4, &b);
+	// Throttle button is replaced by tapping joystick
+	/*
+	b.w = SDL_RightJoystickRect.w;
+	b.x = 0;
+	b.y = 0;
+	SDL_ANDROID_SetScreenKeyboardButtonPos(SDL_ANDROID_SCREENKEYBOARD_BUTTON_5, &b);
+	*/
+}
+
+#else
+
+/* Stubs */
+void
+TFB_InitOnScreenKeyboard (void)
+{
+}
+
+void
+TFB_SetOnScreenKeyboard_Hidden (void)
+{
+}
+
+void
+TFB_SetOnScreenKeyboard_Menu (void)
+{
+}
+
+void
+TFB_SetOnScreenKeyboard_Starmap (void)
+{
+}
+
+void
+TFB_SetOnScreenKeyboard_Melee (void)
+{
+}
+
+void
+TFB_SetOnScreenKeyboard_TwoPlayersMelee (void)
+{
+}
+
+#endif
Index: src/libs/graphics/sdl/sdl_common.h
===================================================================
--- src/libs/graphics/sdl/sdl_common.h	(revision 3779)
+++ src/libs/graphics/sdl/sdl_common.h	(working copy)
@@ -52,4 +52,6 @@
 int ReInit_Screen (SDL_Surface **screen, SDL_Surface *templat, int w, int h);
 void UnInit_Screen (SDL_Surface **screen);
 
+void TFB_InitOnScreenKeyboard (void);
+
 #endif
Index: src/libs/strings/getstr.c
===================================================================
--- src/libs/strings/getstr.c	(revision 3779)
+++ src/libs/strings/getstr.c	(working copy)
@@ -72,7 +72,7 @@
 // returns FALSE if and only if the buffer needs to be enlarged but
 // memory allocation failed.
 static BOOLEAN
-ensureBufSize (char **buf, size_t *curSize, size_t minSize, size_t increment)
+ensureBufSize (char **buf, DWORD *curSize, DWORD minSize, DWORD increment)
 {
 	char *newBuf;
 	size_t newSize;
Index: src/libs/input/input_common.h
===================================================================
--- src/libs/input/input_common.h	(revision 3779)
+++ src/libs/input/input_common.h	(working copy)
@@ -31,7 +31,7 @@
 extern int TFB_InitInput (int driver, int flags);
 extern void TFB_UninitInput (void);
 
-#define MAX_FLIGHT_ALTERNATES  2
+#define MAX_FLIGHT_ALTERNATES  3
 
 extern void TFB_SetInputVectors (volatile int menu[], int num_menu,
 		volatile int flight[], int num_templ, int num_flight);
Index: src/libs/input/sdl/vcontrol.h
===================================================================
--- src/libs/input/sdl/vcontrol.h	(revision 3779)
+++ src/libs/input/sdl/vcontrol.h	(working copy)
@@ -76,6 +76,9 @@
 void VControl_ProcessJoyAxis (int port, int axis, int value);
 void VControl_ProcessJoyHat (int port, int which, Uint8 value);
 
+int VControl_GetJoyAxis(int port, int axis);
+int VControl_GetJoysticksAmount();
+
 /* Force the input into the blank state.  For preventing "sticky" keys. */
 void VControl_ResetInput (void);
 
Index: src/libs/input/sdl/input.c
===================================================================
--- src/libs/input/sdl/input.c	(revision 3779)
+++ src/libs/input/sdl/input.c	(working copy)
@@ -86,6 +86,7 @@
 	"weapon",
 	"special",
 	"escape",
+	"thrust",
 	NULL
 };
 
@@ -186,7 +187,7 @@
 		   directory. */
 		LoadResourceIndex (contentDir, "uqm.key", "keys.");
 	}
-
+	
 	register_flight_controls ();
 
 	return;
Index: src/libs/input/sdl/vcontrol.c
===================================================================
--- src/libs/input/sdl/vcontrol.c	(revision 3779)
+++ src/libs/input/sdl/vcontrol.c	(working copy)
@@ -46,6 +46,7 @@
 typedef struct vcontrol_joystick_axis {
 	keybinding *neg, *pos;
 	int polarity;
+	int value;
 } axis_type;
 
 typedef struct vcontrol_joystick_hat {
@@ -66,7 +67,7 @@
 
 #endif /* HAVE_JOYSTICK */
 
-static unsigned int joycount;
+static unsigned int joycount = 0;
 static unsigned int num_sdl_keys = 0;
 static keybinding **bindings = NULL;
 
@@ -141,6 +142,7 @@
 		for (j = 0; j < axes; j++)
 		{
 			x->axes[j].neg = x->axes[j].pos = NULL;
+			x->axes[j].polarity = x->axes[j].value = 0;
 		}
 		for (j = 0; j < hats; j++)
 		{
@@ -818,6 +820,7 @@
 	int t;
 	if (!joysticks[port].stick)
 		return;
+	joysticks[port].axes[axis].value = value;
 	t = joysticks[port].threshold;
 	if (value > t)
 	{
@@ -894,6 +897,25 @@
 #endif /* HAVE_JOYSTICK */
 }
 
+int
+VControl_GetJoyAxis(int port, int axis)
+{
+#ifdef HAVE_JOYSTICK
+	if( joycount <= port )
+		return 0;
+	if (!joysticks[port].stick || joysticks[port].numaxes <= axis )
+		return 0;
+	return joysticks[port].axes[axis].value;
+#else
+	return 0;
+#endif /* HAVE_JOYSTICK */
+};
+
+int VControl_GetJoysticksAmount()
+{
+	return joycount;
+};
+
 void
 VControl_ResetInput (void)
 {
Index: src/libs/log/msgbox_stub.c
===================================================================
--- src/libs/log/msgbox_stub.c	(revision 3779)
+++ src/libs/log/msgbox_stub.c	(working copy)
@@ -16,6 +16,9 @@
 
 #include "msgbox.h"
 #include "loginternal.h"
+#ifdef ANDROID
+#include <android/log.h>
+#endif
 
 void
 log_displayBox (const /*UTF-8*/char *title, int isError,
@@ -26,6 +29,9 @@
 	// So just inform the user of our predicament
 	fprintf (streamOut, "Do not know how to display %s box\n",
 			isError ? "an error" : "a");
+#ifdef ANDROID
+	__android_log_print( isError ? ANDROID_LOG_FATAL : ANDROID_LOG_INFO, "Ur-Quan Masters", "%s: %s", title, msg );
+#endif
 	
 	// Suppress the compiler warnings in any case.
 	(void)title;
Index: src/libs/log/uqmlog.c
===================================================================
--- src/libs/log/uqmlog.c	(revision 3779)
+++ src/libs/log/uqmlog.c	(working copy)
@@ -23,6 +23,9 @@
 #include <stdlib.h>
 #include <signal.h>
 #include <errno.h>
+#ifdef ANDROID
+#include <android/log.h>
+#endif
 #include "libs/threadlib.h"
 
 #ifndef MAX_LOG_ENTRY_SIZE
@@ -191,6 +194,9 @@
 	if ((int)level <= maxStreamLevel)
 	{
 		fprintf (streamOut, "%s\n", full_msg);
+#ifdef ANDROID
+	__android_log_print( ANDROID_LOG_INFO, "Ur-Quan Masters", "%s", full_msg );
+#endif
 	}
 
 	if ((int)level <= maxLevel)
@@ -227,6 +233,9 @@
 	if ((int)level <= maxStreamLevel)
 	{
 		fprintf (streamOut, "%s\n", full_msg);
+#ifdef ANDROID
+	__android_log_print( ANDROID_LOG_INFO, "Ur-Quan Masters", "%s", full_msg );
+#endif
 	}
 
 	if ((int)level <= maxLevel)
Index: src/libs/log/msgbox_win.c
===================================================================
--- src/libs/log/msgbox_win.c	(revision 3779)
+++ src/libs/log/msgbox_win.c	(working copy)
@@ -14,6 +14,7 @@
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#ifndef ANDROID
 #include "msgbox.h"
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
@@ -64,4 +65,4 @@
 	free (swTitle);
 	free (swMsg);
 }
-
+#endif
Index: src/libs/uio/io.c
===================================================================
--- src/libs/uio/io.c	(revision 3779)
