annotate src/joystick/amigaos/SDL_sysjoystick.c @ 1361:19418e4422cb

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