comparison src/joystick/riscos/SDL_sysjoystick.c @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents 92947e3a18db
children 4da1ee79c9af
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
39 39
40 #include "kernel.h" 40 #include "kernel.h"
41 41
42 #define JOYSTICK_READ 0x43F40 42 #define JOYSTICK_READ 0x43F40
43 43
44 struct joystick_hwdata 44 struct joystick_hwdata
45 { 45 {
46 int joystate; 46 int joystate;
47 }; 47 };
48 48
49 49
50 /* Function to scan the system for joysticks. 50 /* Function to scan the system for joysticks.
51 * This function should set SDL_numjoysticks to the number of available 51 * This function should set SDL_numjoysticks to the number of available
52 * joysticks. Joystick 0 should be the system default joystick. 52 * joysticks. Joystick 0 should be the system default joystick.
53 * It should return number of joysticks, or -1 on an unrecoverable fatal error. 53 * It should return number of joysticks, or -1 on an unrecoverable fatal error.
54 */ 54 */
55 int SDL_SYS_JoystickInit(void) 55 int
56 SDL_SYS_JoystickInit (void)
56 { 57 {
57 _kernel_swi_regs regs; 58 _kernel_swi_regs regs;
58 59
59 /* Try to read joystick 0 */ 60 /* Try to read joystick 0 */
60 regs.r[0] = 0; 61 regs.r[0] = 0;
61 if (_kernel_swi(JOYSTICK_READ, &regs, &regs) == NULL) 62 if (_kernel_swi (JOYSTICK_READ, &regs, &regs) == NULL) {
62 { 63 /* Switch works so assume we've got a joystick */
63 /* Switch works so assume we've got a joystick */ 64 return 1;
64 return 1; 65 }
65 } 66 /* Switch fails so it looks like there's no joystick here */
66 /* Switch fails so it looks like there's no joystick here */
67 67
68 return(0); 68 return (0);
69 } 69 }
70 70
71 /* Function to get the device-dependent name of a joystick */ 71 /* Function to get the device-dependent name of a joystick */
72 const char *SDL_SYS_JoystickName(int index) 72 const char *
73 SDL_SYS_JoystickName (int index)
73 { 74 {
74 if (index == 0) 75 if (index == 0) {
75 { 76 return "RISC OS Joystick 0";
76 return "RISC OS Joystick 0"; 77 }
77 }
78 78
79 SDL_SetError("No joystick available with that index"); 79 SDL_SetError ("No joystick available with that index");
80 return(NULL); 80 return (NULL);
81 } 81 }
82 82
83 /* Function to open a joystick for use. 83 /* Function to open a joystick for use.
84 The joystick to open is specified by the index field of the joystick. 84 The joystick to open is specified by the index field of the joystick.
85 This should fill the nbuttons and naxes fields of the joystick structure. 85 This should fill the nbuttons and naxes fields of the joystick structure.
86 It returns 0, or -1 if there is an error. 86 It returns 0, or -1 if there is an error.
87 */ 87 */
88 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) 88 int
89 SDL_SYS_JoystickOpen (SDL_Joystick * joystick)
89 { 90 {
90 _kernel_swi_regs regs; 91 _kernel_swi_regs regs;
91 92
92 if(!(joystick->hwdata=SDL_malloc(sizeof(struct joystick_hwdata)))) 93 if (!(joystick->hwdata = SDL_malloc (sizeof (struct joystick_hwdata))))
93 return -1; 94 return -1;
94 95
95 regs.r[0] = joystick->index; 96 regs.r[0] = joystick->index;
96 97
97 /* Don't know how to get exact count of buttons so assume max of 4 for now */ 98 /* Don't know how to get exact count of buttons so assume max of 4 for now */
98 joystick->nbuttons=4; 99 joystick->nbuttons = 4;
99 100
100 joystick->nhats=0; 101 joystick->nhats = 0;
101 joystick->nballs=0; 102 joystick->nballs = 0;
102 joystick->naxes=2; 103 joystick->naxes = 2;
103 joystick->hwdata->joystate=0; 104 joystick->hwdata->joystate = 0;
104 105
105 return 0; 106 return 0;
106 107
107 } 108 }
108 109
109 /* Function to update the state of a joystick - called as a device poll. 110 /* Function to update the state of a joystick - called as a device poll.
110 * This function shouldn't update the joystick structure directly, 111 * This function shouldn't update the joystick structure directly,
111 * but instead should call SDL_PrivateJoystick*() to deliver events 112 * but instead should call SDL_PrivateJoystick*() to deliver events
112 * and update joystick device state. 113 * and update joystick device state.
113 */ 114 */
114 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) 115 void
116 SDL_SYS_JoystickUpdate (SDL_Joystick * joystick)
115 { 117 {
116 _kernel_swi_regs regs; 118 _kernel_swi_regs regs;
117 regs.r[0] = joystick->index; 119 regs.r[0] = joystick->index;
118 120
119 if (_kernel_swi(JOYSTICK_READ, &regs, &regs) == NULL) 121 if (_kernel_swi (JOYSTICK_READ, &regs, &regs) == NULL) {
120 { 122 int newstate = regs.r[0];
121 int newstate = regs.r[0]; 123 int oldstate = joystick->hwdata->joystate;
122 int oldstate = joystick->hwdata->joystate; 124 if (newstate != oldstate) {
123 if (newstate != oldstate) 125 if ((newstate & 0xFF) != (oldstate & 0xFF)) {
124 { 126 int y = regs.r[0] & 0xFF;
125 if ((newstate & 0xFF) != (oldstate & 0xFF)) 127 /* Convert to signed values */
126 { 128 if (y >= 128)
127 int y = regs.r[0] & 0xFF; 129 y -= 256;
128 /* Convert to signed values */ 130 SDL_PrivateJoystickAxis (joystick, 1, -y * 256); /* Up and down opposite to result in SDL */
129 if (y >= 128) y -= 256; 131 }
130 SDL_PrivateJoystickAxis(joystick,1,-y * 256); /* Up and down opposite to result in SDL */ 132 if ((newstate & 0xFF00) != (oldstate & 0xFF00)) {
131 } 133 int x = (regs.r[0] & 0xFF00) >> 8;
132 if ((newstate & 0xFF00) != (oldstate & 0xFF00)) 134 if (x >= 128)
133 { 135 x -= 256;
134 int x = (regs.r[0] & 0xFF00) >> 8; 136 SDL_PrivateJoystickAxis (joystick, 0, x * 256);
135 if (x >= 128) x -= 256; 137 }
136 SDL_PrivateJoystickAxis(joystick,0,x * 256);
137 }
138 138
139 if ((newstate & 0xFF0000) != (oldstate & 0xFF0000)) 139 if ((newstate & 0xFF0000) != (oldstate & 0xFF0000)) {
140 { 140 int buttons = (regs.r[0] & 0xFF0000) >> 16;
141 int buttons = (regs.r[0] & 0xFF0000) >> 16; 141 int oldbuttons = (oldstate & 0xFF0000) >> 16;
142 int oldbuttons = (oldstate & 0xFF0000) >> 16; 142 int i;
143 int i; 143 for (i = 0; i < joystick->nbuttons; i++) {
144 for (i = 0; i < joystick->nbuttons; i++) 144 if ((buttons & (1 << i)) != (oldbuttons & (1 << i))) {
145 { 145 if (buttons & (1 << i))
146 if ((buttons & (1<<i)) != (oldbuttons & (1<<i))) 146 SDL_PrivateJoystickButton (joystick, i,
147 { 147 SDL_PRESSED);
148 if (buttons & (1<<i)) SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED); 148 else
149 else SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED); 149 SDL_PrivateJoystickButton (joystick, i,
150 } 150 SDL_RELEASED);
151 } 151 }
152 } 152 }
153 joystick->hwdata->joystate = newstate; 153 }
154 } 154 joystick->hwdata->joystate = newstate;
155 } 155 }
156 }
156 157
157 return; 158 return;
158 } 159 }
159 160
160 /* Function to close a joystick after use */ 161 /* Function to close a joystick after use */
161 void SDL_SYS_JoystickClose(SDL_Joystick *joystick) 162 void
163 SDL_SYS_JoystickClose (SDL_Joystick * joystick)
162 { 164 {
163 if(joystick->hwdata) 165 if (joystick->hwdata)
164 SDL_free(joystick->hwdata); 166 SDL_free (joystick->hwdata);
165 return; 167 return;
166 } 168 }
167 169
168 /* Function to perform any system-specific joystick related cleanup */ 170 /* Function to perform any system-specific joystick related cleanup */
169 void SDL_SYS_JoystickQuit(void) 171 void
172 SDL_SYS_JoystickQuit (void)
170 { 173 {
171 SDL_numjoysticks=0; 174 SDL_numjoysticks = 0;
172 175
173 return; 176 return;
174 } 177 }
175 178
176 #endif /* SDL_JOYSTICK_RISCOS */ 179 #endif /* SDL_JOYSTICK_RISCOS */
180 /* vi: set ts=4 sw=4 expandtab: */