src/joystick/amigaos/SDL_sysjoystick.c
author Sam Lantinga
Sat, 25 Feb 2006 15:01:44 +0000
changeset 1429 aff0170f9f1b
parent 1402 d910939febfa
child 1635 92947e3a18db
permissions -rw-r--r--
Date: Sat, 25 Feb 2006 14:26:19 +0100 (CET)
From: "Torsten Giebl"
Subject: [SDL] testpalette.diff

To get rid of Mousecursor Fullscreen problems on Mac OSX.
slouken@21
     1
/*
slouken@21
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@21
     4
slouken@21
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@21
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@21
     9
slouken@21
    10
    This library is distributed in the hope that it will be useful,
slouken@21
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@21
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@21
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@21
    18
slouken@21
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@21
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@21
    23
slouken@21
    24
/* This is the system specific header for the SDL joystick API */
slouken@21
    25
slouken@21
    26
#include <libraries/lowlevel.h>
slouken@255
    27
#if defined(__SASC) || defined(STORMC4_WOS)
slouken@21
    28
#include <proto/exec.h>
slouken@21
    29
#include <proto/lowlevel.h>
slouken@21
    30
#include <proto/graphics.h>
slouken@21
    31
#else
slouken@21
    32
#include <inline/exec.h>
slouken@21
    33
#include <inline/lowlevel.h>
slouken@21
    34
#include <inline/graphics.h>
slouken@21
    35
#endif
slouken@21
    36
#include "mydebug.h"
slouken@21
    37
slouken@21
    38
extern struct ExecBase *SysBase;
slouken@21
    39
extern struct GfxBase *GfxBase;
slouken@21
    40
slouken@21
    41
#include "SDL_joystick.h"
slouken@1361
    42
#include "../SDL_sysjoystick.h"
slouken@1361
    43
#include "../SDL_joystick_c.h"
slouken@21
    44
slouken@21
    45
/* Function to scan the system for joysticks.
slouken@21
    46
 * This function should set SDL_numjoysticks to the number of available
slouken@21
    47
 * joysticks.  Joystick 0 should be the system default joystick.
slouken@21
    48
 * It should return 0, or -1 on an unrecoverable fatal error.
slouken@21
    49
 */
slouken@21
    50
slouken@21
    51
slouken@21
    52
/* Amiga specific datas */
slouken@21
    53
struct Library *LowLevelBase=NULL;
slouken@21
    54
slouken@21
    55
ULONG joybut[]=
slouken@21
    56
{
slouken@21
    57
	JPF_BUTTON_RED,
slouken@21
    58
	JPF_BUTTON_BLUE,
slouken@21
    59
	JPF_BUTTON_PLAY,
slouken@21
    60
	JPF_BUTTON_YELLOW,
slouken@21
    61
	JPF_BUTTON_GREEN,
slouken@21
    62
	JPF_BUTTON_FORWARD,
slouken@21
    63
	JPF_BUTTON_REVERSE,
slouken@21
    64
};
slouken@21
    65
slouken@255
    66
struct joystick_hwdata
slouken@21
    67
{
slouken@21
    68
	ULONG joystate;
slouken@21
    69
};
slouken@21
    70
slouken@21
    71
int SDL_SYS_JoystickInit(void)
slouken@21
    72
{
slouken@21
    73
	if(!LowLevelBase)
slouken@21
    74
	{
slouken@21
    75
		if(LowLevelBase=OpenLibrary("lowlevel.library",37))
slouken@21
    76
			return 2;
slouken@21
    77
	}
slouken@21
    78
	else
slouken@21
    79
		return 2;
slouken@21
    80
slouken@21
    81
	D(bug("%ld joysticks available.\n",SDL_numjoysticks));
slouken@21
    82
slouken@21
    83
	return 0;
slouken@21
    84
}
slouken@21
    85
slouken@21
    86
/* Function to get the device-dependent name of a joystick */
slouken@21
    87
const char *SDL_SYS_JoystickName(int index)
slouken@21
    88
{
slouken@21
    89
	if(index<2&&LowLevelBase)
slouken@21
    90
	{
slouken@21
    91
		switch(index)
slouken@21
    92
		{
slouken@21
    93
			case 0:
slouken@21
    94
				return "Port 1 Amiga Joystick/Joypad";
slouken@21
    95
			case 1:
slouken@21
    96
				return "Port 2 Amiga Joystick/Joypad";
slouken@21
    97
		}
slouken@21
    98
	}
slouken@21
    99
slouken@21
   100
	SDL_SetError("No joystick available with that index");
slouken@21
   101
	return(NULL);
slouken@21
   102
}
slouken@21
   103
slouken@21
   104
/* Function to open a joystick for use.
slouken@21
   105
   The joystick to open is specified by the index field of the joystick.
slouken@21
   106
   This should fill the nbuttons and naxes fields of the joystick structure.
slouken@21
   107
   It returns 0, or -1 if there is an error.
slouken@21
   108
 */
slouken@21
   109
slouken@21
   110
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
slouken@21
   111
{
slouken@21
   112
	ULONG temp,i;
slouken@21
   113
	D(bug("Opening joystick %ld\n",joystick->index));
slouken@21
   114
slouken@1336
   115
	if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata))))
slouken@21
   116
		return -1;
slouken@21
   117
slouken@21
   118
/* This loop is to check if the controller is a joypad */
slouken@21
   119
slouken@21
   120
	for(i=0;i<20;i++)
slouken@21
   121
	{
slouken@255
   122
		temp=ReadJoyPort(joystick->index^1); // fix to invert amiga joyports
slouken@21
   123
		WaitTOF();
slouken@21
   124
	}
slouken@21
   125
slouken@21
   126
	if((temp&JP_TYPE_MASK)==JP_TYPE_GAMECTLR)
slouken@21
   127
		joystick->nbuttons=7;
slouken@21
   128
	else
slouken@21
   129
		joystick->nbuttons=3;
slouken@21
   130
slouken@21
   131
	joystick->nhats=0;
slouken@21
   132
	joystick->nballs=0;
slouken@21
   133
	joystick->naxes=2;
slouken@21
   134
	joystick->hwdata->joystate=0L;
slouken@21
   135
slouken@21
   136
	return 0;
slouken@21
   137
}
slouken@21
   138
slouken@21
   139
/* Function to update the state of a joystick - called as a device poll.
slouken@21
   140
 * This function shouldn't update the joystick structure directly,
slouken@21
   141
 * but instead should call SDL_PrivateJoystick*() to deliver events
slouken@21
   142
 * and update joystick device state.
slouken@21
   143
 */
slouken@21
   144
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
slouken@21
   145
{
slouken@255
   146
	ULONG data;
slouken@21
   147
	int i;
slouken@21
   148
slouken@21
   149
	if(joystick->index<2)
slouken@21
   150
	{
slouken@21
   151
		data=ReadJoyPort(joystick->index);
slouken@21
   152
slouken@21
   153
		if(data&JP_DIRECTION_MASK)
slouken@21
   154
		{
slouken@21
   155
			if(data&JPF_JOY_DOWN)
slouken@21
   156
			{
slouken@21
   157
				if(!(joystick->hwdata->joystate&JPF_JOY_DOWN))
slouken@21
   158
					SDL_PrivateJoystickAxis(joystick,0,127);
slouken@21
   159
			}
slouken@21
   160
			else if(data&JPF_JOY_UP)
slouken@21
   161
			{
slouken@21
   162
				if(!(joystick->hwdata->joystate&JPF_JOY_UP))
slouken@21
   163
					SDL_PrivateJoystickAxis(joystick,0,-127);
slouken@21
   164
			}
slouken@21
   165
			else if(joystick->hwdata->joystate&(JPF_JOY_UP|JPF_JOY_DOWN))
slouken@21
   166
				SDL_PrivateJoystickAxis(joystick,0,0);
slouken@21
   167
slouken@21
   168
			if(data&JPF_JOY_LEFT)
slouken@21
   169
			{
slouken@21
   170
				if(!(joystick->hwdata->joystate&JPF_JOY_LEFT))
slouken@21
   171
					SDL_PrivateJoystickAxis(joystick,1,-127);
slouken@21
   172
			}
slouken@21
   173
			else if(data&JPF_JOY_RIGHT)
slouken@21
   174
			{
slouken@21
   175
				if(!(joystick->hwdata->joystate&JPF_JOY_RIGHT))
slouken@21
   176
					SDL_PrivateJoystickAxis(joystick,1,127);
slouken@21
   177
			}
slouken@21
   178
			else if(joystick->hwdata->joystate&(JPF_JOY_LEFT|JPF_JOY_RIGHT))
slouken@21
   179
				SDL_PrivateJoystickAxis(joystick,1,0);
slouken@21
   180
		}
slouken@21
   181
		else if(joystick->hwdata->joystate&(JPF_JOY_LEFT|JPF_JOY_RIGHT))
slouken@21
   182
		{
slouken@21
   183
				SDL_PrivateJoystickAxis(joystick,1,0);
slouken@21
   184
		}
slouken@21
   185
		else if(joystick->hwdata->joystate&(JPF_JOY_UP|JPF_JOY_DOWN))
slouken@21
   186
		{
slouken@21
   187
				SDL_PrivateJoystickAxis(joystick,0,0);
slouken@21
   188
		}
slouken@21
   189
slouken@21
   190
		for(i=0;i<joystick->nbuttons;i++)
slouken@21
   191
		{
slouken@21
   192
			if( (data&joybut[i]) )
slouken@21
   193
			{
slouken@21
   194
				if(i==1)
slouken@21
   195
					data&=(~(joybut[2]));
slouken@21
   196
slouken@21
   197
				if(!(joystick->hwdata->joystate&joybut[i]))
slouken@21
   198
					SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
slouken@21
   199
			}
slouken@21
   200
			else if(joystick->hwdata->joystate&joybut[i])
slouken@21
   201
				SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
slouken@21
   202
		}
slouken@21
   203
slouken@21
   204
		joystick->hwdata->joystate=data;
slouken@21
   205
	}
slouken@21
   206
slouken@21
   207
	return;
slouken@21
   208
}
slouken@21
   209
slouken@21
   210
/* Function to close a joystick after use */
slouken@21
   211
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
slouken@21
   212
{
slouken@21
   213
	if(joystick->hwdata)
slouken@1336
   214
		SDL_free(joystick->hwdata);
slouken@21
   215
	return;
slouken@21
   216
}
slouken@21
   217
slouken@21
   218
/* Function to perform any system-specific joystick related cleanup */
slouken@21
   219
slouken@21
   220
void SDL_SYS_JoystickQuit(void)
slouken@21
   221
{
slouken@21
   222
	if(LowLevelBase)
slouken@21
   223
	{
slouken@21
   224
		CloseLibrary(LowLevelBase);
slouken@21
   225
		LowLevelBase=NULL;
slouken@21
   226
		SDL_numjoysticks=0;
slouken@21
   227
	}
slouken@21
   228
slouken@21
   229
	return;
slouken@21
   230
}
slouken@21
   231