annotate src/joystick/amigaos/SDL_sysjoystick.c @ 1336:3692456e7b0f

Use SDL_ prefixed versions of C library functions. FIXME: Change #include <stdlib.h> to #include "SDL_stdlib.h" Change #include <string.h> to #include "SDL_string.h" Make sure nothing else broke because of this...
author Sam Lantinga <slouken@libsdl.org>
date Tue, 07 Feb 2006 06:59:48 +0000
parents c9b51268668f
children 604d73db6802
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 <stdio.h> /* For the definition of NULL */
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include <libraries/lowlevel.h>
255
dcb5e869f8b5 Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
29 #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
30 #include <proto/exec.h>
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <proto/lowlevel.h>
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #include <proto/graphics.h>
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #else
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
34 #include <inline/exec.h>
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35 #include <inline/lowlevel.h>
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #include <inline/graphics.h>
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 #endif
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 #include "mydebug.h"
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 extern struct ExecBase *SysBase;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 extern struct GfxBase *GfxBase;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42 #include <stdlib.h>
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 #include "SDL_error.h"
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45 #include "SDL_joystick.h"
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 #include "SDL_sysjoystick.h"
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 #include "SDL_joystick_c.h"
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
49 /* 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
50 * 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
51 * 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
52 * 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
53 */
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
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 /* Amiga specific datas */
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 struct Library *LowLevelBase=NULL;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 ULONG joybut[]=
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 JPF_BUTTON_RED,
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62 JPF_BUTTON_BLUE,
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 JPF_BUTTON_PLAY,
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
64 JPF_BUTTON_YELLOW,
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
65 JPF_BUTTON_GREEN,
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66 JPF_BUTTON_FORWARD,
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 JPF_BUTTON_REVERSE,
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 };
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69
255
dcb5e869f8b5 Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
70 struct joystick_hwdata
21
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72 ULONG joystate;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73 };
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 int SDL_SYS_JoystickInit(void)
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77 if(!LowLevelBase)
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
78 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 if(LowLevelBase=OpenLibrary("lowlevel.library",37))
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80 return 2;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81 }
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 else
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 return 2;
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 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
86
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
87 return 0;
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
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
90 /* 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
91 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
92 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 if(index<2&&LowLevelBase)
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 switch(index)
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97 case 0:
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 return "Port 1 Amiga Joystick/Joypad";
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99 case 1:
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
100 return "Port 2 Amiga Joystick/Joypad";
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101 }
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 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
105 return(NULL);
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
106 }
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
108 /* 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
109 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
110 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
111 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
112 */
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
113
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
114 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
115 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
116 ULONG temp,i;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
117 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
118
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
119 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
120 return -1;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 /* 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
123
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 for(i=0;i<20;i++)
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
125 {
255
dcb5e869f8b5 Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
126 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
127 WaitTOF();
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 }
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
130 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
131 joystick->nbuttons=7;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 else
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133 joystick->nbuttons=3;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
134
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135 joystick->nhats=0;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
136 joystick->nballs=0;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
137 joystick->naxes=2;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138 joystick->hwdata->joystate=0L;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140 return 0;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
141 }
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
142
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 /* 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
144 * 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
145 * 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
146 * and update joystick device state.
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147 */
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
148 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
149 {
255
dcb5e869f8b5 Updated Amiga port by Gabriele Greco
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
150 ULONG data;
21
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151 int i;
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(joystick->index<2)
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 data=ReadJoyPort(joystick->index);
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(data&JP_DIRECTION_MASK)
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 if(data&JPF_JOY_DOWN)
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161 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
162 SDL_PrivateJoystickAxis(joystick,0,127);
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 }
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 else if(data&JPF_JOY_UP)
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
166 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
167 SDL_PrivateJoystickAxis(joystick,0,-127);
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
168 }
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169 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
170 SDL_PrivateJoystickAxis(joystick,0,0);
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
171
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 if(data&JPF_JOY_LEFT)
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
174 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
175 SDL_PrivateJoystickAxis(joystick,1,-127);
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
176 }
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
177 else if(data&JPF_JOY_RIGHT)
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
179 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
180 SDL_PrivateJoystickAxis(joystick,1,127);
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
181 }
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
182 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
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_LEFT|JPF_JOY_RIGHT))
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,1,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 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
190 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
191 SDL_PrivateJoystickAxis(joystick,0,0);
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
192 }
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 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
195 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
196 if( (data&joybut[i]) )
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
197 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198 if(i==1)
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
199 data&=(~(joybut[2]));
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
200
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
201 if(!(joystick->hwdata->joystate&joybut[i]))
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
202 SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
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 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
205 SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
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
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
208 joystick->hwdata->joystate=data;
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
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
211 return;
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
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
214 /* 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
215 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
216 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 if(joystick->hwdata)
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
218 SDL_free(joystick->hwdata);
21
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
219 return;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
220 }
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 /* 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
223
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
224 void SDL_SYS_JoystickQuit(void)
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
225 {
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
226 if(LowLevelBase)
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 CloseLibrary(LowLevelBase);
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
229 LowLevelBase=NULL;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
230 SDL_numjoysticks=0;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
231 }
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
232
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
233 return;
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
234 }
75a95f82bc1f Updated the Amiga OS port of SDL (thanks Gabriele)
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235