diff src/joystick/amigaos/SDL_sysjoystick.c @ 1895:c121d94672cb

SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author Sam Lantinga <slouken@libsdl.org>
date Mon, 10 Jul 2006 21:04:37 +0000
parents 92947e3a18db
children
line wrap: on
line diff
--- a/src/joystick/amigaos/SDL_sysjoystick.c	Thu Jul 06 18:01:37 2006 +0000
+++ b/src/joystick/amigaos/SDL_sysjoystick.c	Mon Jul 10 21:04:37 2006 +0000
@@ -52,55 +52,52 @@
 
 
 /* Amiga specific datas */
-struct Library *LowLevelBase=NULL;
+struct Library *LowLevelBase = NULL;
 
-ULONG joybut[]=
-{
-	JPF_BUTTON_RED,
-	JPF_BUTTON_BLUE,
-	JPF_BUTTON_PLAY,
-	JPF_BUTTON_YELLOW,
-	JPF_BUTTON_GREEN,
-	JPF_BUTTON_FORWARD,
-	JPF_BUTTON_REVERSE,
+ULONG joybut[] = {
+    JPF_BUTTON_RED,
+    JPF_BUTTON_BLUE,
+    JPF_BUTTON_PLAY,
+    JPF_BUTTON_YELLOW,
+    JPF_BUTTON_GREEN,
+    JPF_BUTTON_FORWARD,
+    JPF_BUTTON_REVERSE,
 };
 
 struct joystick_hwdata
 {
-	ULONG joystate;
+    ULONG joystate;
 };
 
-int SDL_SYS_JoystickInit(void)
+int
+SDL_SYS_JoystickInit(void)
 {
-	if(!LowLevelBase)
-	{
-		if(LowLevelBase=OpenLibrary("lowlevel.library",37))
-			return 2;
-	}
-	else
-		return 2;
+    if (!LowLevelBase) {
+        if (LowLevelBase = OpenLibrary("lowlevel.library", 37))
+            return 2;
+    } else
+        return 2;
 
-	D(bug("%ld joysticks available.\n",SDL_numjoysticks));
+    D(bug("%ld joysticks available.\n", SDL_numjoysticks));
 
-	return 0;
+    return 0;
 }
 
 /* Function to get the device-dependent name of a joystick */
-const char *SDL_SYS_JoystickName(int index)
+const char *
+SDL_SYS_JoystickName(int index)
 {
-	if(index<2&&LowLevelBase)
-	{
-		switch(index)
-		{
-			case 0:
-				return "Port 1 Amiga Joystick/Joypad";
-			case 1:
-				return "Port 2 Amiga Joystick/Joypad";
-		}
-	}
+    if (index < 2 && LowLevelBase) {
+        switch (index) {
+        case 0:
+            return "Port 1 Amiga Joystick/Joypad";
+        case 1:
+            return "Port 2 Amiga Joystick/Joypad";
+        }
+    }
 
-	SDL_SetError("No joystick available with that index");
-	return(NULL);
+    SDL_SetError("No joystick available with that index");
+    return (NULL);
 }
 
 /* Function to open a joystick for use.
@@ -109,33 +106,33 @@
    It returns 0, or -1 if there is an error.
  */
 
-int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
+int
+SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
 {
-	ULONG temp,i;
-	D(bug("Opening joystick %ld\n",joystick->index));
+    ULONG temp, i;
+    D(bug("Opening joystick %ld\n", joystick->index));
 
-	if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata))))
-		return -1;
+    if (!(joystick->hwdata = SDL_malloc(sizeof(struct joystick_hwdata))))
+        return -1;
 
 /* This loop is to check if the controller is a joypad */
 
-	for(i=0;i<20;i++)
-	{
-		temp=ReadJoyPort(joystick->index^1); // fix to invert amiga joyports
-		WaitTOF();
-	}
+    for (i = 0; i < 20; i++) {
+        temp = ReadJoyPort(joystick->index ^ 1);        // fix to invert amiga joyports
+        WaitTOF();
+    }
 
-	if((temp&JP_TYPE_MASK)==JP_TYPE_GAMECTLR)
-		joystick->nbuttons=7;
-	else
-		joystick->nbuttons=3;
+    if ((temp & JP_TYPE_MASK) == JP_TYPE_GAMECTLR)
+        joystick->nbuttons = 7;
+    else
+        joystick->nbuttons = 3;
 
-	joystick->nhats=0;
-	joystick->nballs=0;
-	joystick->naxes=2;
-	joystick->hwdata->joystate=0L;
+    joystick->nhats = 0;
+    joystick->nballs = 0;
+    joystick->naxes = 2;
+    joystick->hwdata->joystate = 0L;
 
-	return 0;
+    return 0;
 }
 
 /* Function to update the state of a joystick - called as a device poll.
@@ -143,91 +140,80 @@
  * but instead should call SDL_PrivateJoystick*() to deliver events
  * and update joystick device state.
  */
-void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
+void
+SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
 {
-	ULONG data;
-	int i;
+    ULONG data;
+    int i;
 
-	if(joystick->index<2)
-	{
-		data=ReadJoyPort(joystick->index);
+    if (joystick->index < 2) {
+        data = ReadJoyPort(joystick->index);
 
-		if(data&JP_DIRECTION_MASK)
-		{
-			if(data&JPF_JOY_DOWN)
-			{
-				if(!(joystick->hwdata->joystate&JPF_JOY_DOWN))
-					SDL_PrivateJoystickAxis(joystick,0,127);
-			}
-			else if(data&JPF_JOY_UP)
-			{
-				if(!(joystick->hwdata->joystate&JPF_JOY_UP))
-					SDL_PrivateJoystickAxis(joystick,0,-127);
-			}
-			else if(joystick->hwdata->joystate&(JPF_JOY_UP|JPF_JOY_DOWN))
-				SDL_PrivateJoystickAxis(joystick,0,0);
+        if (data & JP_DIRECTION_MASK) {
+            if (data & JPF_JOY_DOWN) {
+                if (!(joystick->hwdata->joystate & JPF_JOY_DOWN))
+                    SDL_PrivateJoystickAxis(joystick, 0, 127);
+            } else if (data & JPF_JOY_UP) {
+                if (!(joystick->hwdata->joystate & JPF_JOY_UP))
+                    SDL_PrivateJoystickAxis(joystick, 0, -127);
+            } else if (joystick->hwdata->
+                       joystate & (JPF_JOY_UP | JPF_JOY_DOWN))
+                SDL_PrivateJoystickAxis(joystick, 0, 0);
 
-			if(data&JPF_JOY_LEFT)
-			{
-				if(!(joystick->hwdata->joystate&JPF_JOY_LEFT))
-					SDL_PrivateJoystickAxis(joystick,1,-127);
-			}
-			else if(data&JPF_JOY_RIGHT)
-			{
-				if(!(joystick->hwdata->joystate&JPF_JOY_RIGHT))
-					SDL_PrivateJoystickAxis(joystick,1,127);
-			}
-			else if(joystick->hwdata->joystate&(JPF_JOY_LEFT|JPF_JOY_RIGHT))
-				SDL_PrivateJoystickAxis(joystick,1,0);
-		}
-		else if(joystick->hwdata->joystate&(JPF_JOY_LEFT|JPF_JOY_RIGHT))
-		{
-				SDL_PrivateJoystickAxis(joystick,1,0);
-		}
-		else if(joystick->hwdata->joystate&(JPF_JOY_UP|JPF_JOY_DOWN))
-		{
-				SDL_PrivateJoystickAxis(joystick,0,0);
-		}
+            if (data & JPF_JOY_LEFT) {
+                if (!(joystick->hwdata->joystate & JPF_JOY_LEFT))
+                    SDL_PrivateJoystickAxis(joystick, 1, -127);
+            } else if (data & JPF_JOY_RIGHT) {
+                if (!(joystick->hwdata->joystate & JPF_JOY_RIGHT))
+                    SDL_PrivateJoystickAxis(joystick, 1, 127);
+            } else if (joystick->hwdata->
+                       joystate & (JPF_JOY_LEFT | JPF_JOY_RIGHT))
+                SDL_PrivateJoystickAxis(joystick, 1, 0);
+        } else if (joystick->hwdata->
+                   joystate & (JPF_JOY_LEFT | JPF_JOY_RIGHT)) {
+            SDL_PrivateJoystickAxis(joystick, 1, 0);
+        } else if (joystick->hwdata->joystate & (JPF_JOY_UP | JPF_JOY_DOWN)) {
+            SDL_PrivateJoystickAxis(joystick, 0, 0);
+        }
 
-		for(i=0;i<joystick->nbuttons;i++)
-		{
-			if( (data&joybut[i]) )
-			{
-				if(i==1)
-					data&=(~(joybut[2]));
+        for (i = 0; i < joystick->nbuttons; i++) {
+            if ((data & joybut[i])) {
+                if (i == 1)
+                    data &= (~(joybut[2]));
 
-				if(!(joystick->hwdata->joystate&joybut[i]))
-					SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
-			}
-			else if(joystick->hwdata->joystate&joybut[i])
-				SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
-		}
+                if (!(joystick->hwdata->joystate & joybut[i]))
+                    SDL_PrivateJoystickButton(joystick, i, SDL_PRESSED);
+            } else if (joystick->hwdata->joystate & joybut[i])
+                SDL_PrivateJoystickButton(joystick, i, SDL_RELEASED);
+        }
 
-		joystick->hwdata->joystate=data;
-	}
+        joystick->hwdata->joystate = data;
+    }
 
-	return;
+    return;
 }
 
 /* Function to close a joystick after use */
-void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
+void
+SDL_SYS_JoystickClose(SDL_Joystick * joystick)
 {
-	if(joystick->hwdata)
-		SDL_free(joystick->hwdata);
-	return;
+    if (joystick->hwdata)
+        SDL_free(joystick->hwdata);
+    return;
 }
 
 /* Function to perform any system-specific joystick related cleanup */
 
-void SDL_SYS_JoystickQuit(void)
+void
+SDL_SYS_JoystickQuit(void)
 {
-	if(LowLevelBase)
-	{
-		CloseLibrary(LowLevelBase);
-		LowLevelBase=NULL;
-		SDL_numjoysticks=0;
-	}
-	return;
+    if (LowLevelBase) {
+        CloseLibrary(LowLevelBase);
+        LowLevelBase = NULL;
+        SDL_numjoysticks = 0;
+    }
+    return;
 }
 
 #endif /* SDL_JOYSTICK_AMIGA */
+/* vi: set ts=4 sw=4 expandtab: */