annotate src/joystick/mint/SDL_sysjoystick.c @ 302:8a86bdf34f0f

Added Atari joystick support (thanks Patrice!)
author Sam Lantinga <slouken@libsdl.org>
date Thu, 07 Mar 2002 20:23:11 +0000
parents
children 9c6613983e85
rev   line source
302
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Library General Public License for more details.
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 #ifdef SAVE_RCSID
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 static char rcsid =
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 "@(#) $Id$";
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #endif
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 /*
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 * Atari Joystick/Joypad drivers
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 *
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 * Patrice Mandin
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 #include <stdlib.h>
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 #include <string.h>
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 #include <sys/cookie.h>
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 #include <mint/osbind.h>
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 #include "SDL_types.h"
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 #include "SDL_error.h"
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 #include "SDL_joystick.h"
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 #include "SDL_sysjoystick.h"
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 #include "SDL_joystick_c.h"
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 #include "../video/ataricommon/SDL_ikbdinterrupt_s.h"
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 /*--- Const ---*/
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 /* We can have:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 1 joystick on IKBD port 1 (port 0 is used by mouse)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 2 joypads on ports A,B
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 or 4 joysticks on joypads ports A,B
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 or 1 lightpen on joypad port A
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 or 2 analog paddles on joypads ports A,B
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 2 joysticks on parallel port
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 enum {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 IKBD_JOY1=0,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 PORTA_PAD,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 PORTB_PAD,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 PORTA_JOY0,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 PORTA_JOY1,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 PORTB_JOY0,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 PORTB_JOY1,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 PORTA_LP,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 PORTA_ANPAD,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 PORTB_ANPAD,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 #if 0
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 PARA_JOY0,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 PARA_JOY1,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 #endif
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 MAX_JOYSTICKS
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 };
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 enum {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 MCH_ST=0,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 MCH_STE,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 MCH_TT,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 MCH_F30
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 };
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 /* Joypad buttons
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 * Procontroller note:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 * L,R are connected to 4,6
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 * X,Y,Z are connected to 7,8,9
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 enum {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 JP_UP=0, JP_DOWN, JP_LEFT, JP_RIGHT,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 JP_KPMULT, JP_KP7, JP_KP4, JP_KP1,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 JP_KP0, JP_KP8, JP_KP5, JP_KP2,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 JP_KPNUM, JP_KP9, JP_KP6, JP_KP3,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 JP_PAUSE, JP_FIRE0, JP_UNDEF0, JP_FIRE1,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 JP_UNDEF1, JP_FIRE2, JP_UNDEF2, JP_OPTION
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 };
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 #define JP_NUM_BUTTONS 17
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 #define PORT_JS_RIGHT (1<<0)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 #define PORT_JS_LEFT (1<<1)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 #define PORT_JS_DOWN (1<<2)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 #define PORT_JS_UP (1<<3)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 #define PORT_JS_FIRE (1<<4)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 /*--- Types ---*/
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 typedef struct {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 SDL_bool enabled;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 unsigned char *name;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 Uint32 prevstate;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 } atarijoy_t;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 /*--- Variables ---*/
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 {SDL_FALSE,"IKBD joystick port 1",0},
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 {SDL_FALSE,"Joypad port A",0},
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 {SDL_FALSE,"Joypad port B",0},
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 {SDL_FALSE,"Joystick 0 port A",0},
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 {SDL_FALSE,"Joystick 1 port A",0},
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 {SDL_FALSE,"Joystick 0 port B",0},
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 {SDL_FALSE,"Joystick 1 port B",0},
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 {SDL_FALSE,"Lightpen port A",0},
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 {SDL_FALSE,"Analog paddle port A",0},
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 {SDL_FALSE,"Analog paddle port B",0}
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 #if 0
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 ,{SDL_FALSE,"Joystick 0 parallel port",0},
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 {SDL_FALSE,"Joystick 1 parallel port",0}
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 #endif
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 };
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 static const int jp_buttons[JP_NUM_BUTTONS]={
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 JP_KPMULT, JP_KP7, JP_KP4, JP_KP1,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 JP_KP0, JP_KP8, JP_KP5, JP_KP2,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 JP_KPNUM, JP_KP9, JP_KP6, JP_KP3,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 JP_PAUSE, JP_FIRE0, JP_FIRE1, JP_FIRE2,
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 JP_OPTION
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 };
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 static SDL_bool joypad_ports_enabled=SDL_FALSE;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 /* Updated joypad ports */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 static Uint16 jp_paddles[4];
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 static Uint16 jp_lightpens[2];
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 static Uint16 jp_directions;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 static Uint16 jp_fires;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 static Uint32 jp_joypads[2];
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 /*--- Functions prototypes ---*/
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 static int GetEnabledAtariJoystick(int index);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 static void UpdateJoypads(void);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 /*--- Functions ---*/
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 int SDL_SYS_JoystickInit(void)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 int i;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 unsigned long cookie_mch;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 const char *envr=getenv("SDL_JOYSTICK_ATARI");
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 const char *env_evt=getenv("SDL_ATARI_EVENTSDRIVER");
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 SDL_bool ikbd_enabled=SDL_FALSE;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 #define TEST_JOY_ENABLED(env,idstring,num) \
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 if (strstr(env,idstring"-off")) { \
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 atarijoysticks[num].enabled=SDL_FALSE; \
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 } \
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 if (strstr(env,idstring"-on")) { \
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 atarijoysticks[num].enabled=SDL_TRUE; \
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 /* Cookie _MCH present ? if not, assume ST machine */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 if (Getcookie(C__MCH, &cookie_mch) != C_FOUND) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 cookie_mch = MCH_ST << 16;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 /* Enable some default joysticks */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 ikbd_enabled=SDL_TRUE;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 if (env_evt) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 if (!strcmp(env_evt,"ikbd")) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 ikbd_enabled=SDL_FALSE;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 atarijoysticks[IKBD_JOY1].enabled=ikbd_enabled;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 atarijoysticks[PORTA_PAD].enabled=SDL_TRUE;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 atarijoysticks[PORTB_PAD].enabled=SDL_TRUE;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 /* Read environment for joysticks to enable */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 if (envr) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 /* IKBD on any Atari, maybe clones */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 if (env_evt) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 if (strcmp(env_evt,"ikbd")) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 /* Joypads ports only on STE and Falcon */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 if (!atarijoysticks[PORTA_PAD].enabled) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 if (!(atarijoysticks[PORTA_JOY0].enabled) && !(atarijoysticks[PORTA_JOY1].enabled)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 if (!atarijoysticks[PORTA_LP].enabled) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 if (!atarijoysticks[PORTB_PAD].enabled) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 #if 0
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 /* Parallel port on any Atari, maybe clones */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 TEST_JOY_ENABLED(envr, "para-joy1", PARA_JOY1);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 #endif
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 /* Need to update joypad ports ? */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 joypad_ports_enabled=SDL_FALSE;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 for (i=PORTA_PAD;i<=PORTB_ANPAD;i++) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 if (atarijoysticks[i].enabled) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 joypad_ports_enabled=SDL_TRUE;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 break;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 SDL_numjoysticks = 0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 for (i=0;i<MAX_JOYSTICKS;i++) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 if (atarijoysticks[i].enabled) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 ++SDL_numjoysticks;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 return(SDL_numjoysticks);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 static int GetEnabledAtariJoystick(int index)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 int i,j;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 /* Return the nth'index' enabled atari joystick */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 j=0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 for (i=0;i<MAX_JOYSTICKS;i++) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 if (atarijoysticks[i].enabled) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 if (j==index) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 break;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 } else {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 j++;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 if (i==MAX_JOYSTICKS)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 return -1;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 return i;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 const char *SDL_SYS_JoystickName(int index)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 int numjoystick;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 numjoystick=GetEnabledAtariJoystick(index);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 if (numjoystick==-1)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 return NULL;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 return(atarijoysticks[numjoystick].name);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 int numjoystick;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 numjoystick=GetEnabledAtariJoystick(joystick->index);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 if (numjoystick==-1)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 return -1;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 if ((numjoystick==PORTA_PAD) || (numjoystick==PORTB_PAD)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 joystick->nbuttons=JP_NUM_BUTTONS;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 } else if ((numjoystick==PORTA_LP) || (numjoystick==PORTA_ANPAD) ||
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 (numjoystick==PORTB_ANPAD)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 joystick->nbuttons=2;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 } else {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 joystick->nbuttons=1;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 joystick->naxes=2;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 joystick->nballs=0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 joystick->nhats=0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 return(0);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 int numjoystick;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 Uint32 curstate,prevstate;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 Sint16 curaxis;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 numjoystick=GetEnabledAtariJoystick(joystick->index);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 if (numjoystick==-1)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 return;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 prevstate = atarijoysticks[numjoystick].prevstate;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 if (joypad_ports_enabled) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 Supexec(UpdateJoypads);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 switch (numjoystick) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 case IKBD_JOY1:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 curstate = SDL_AtariIkbd_joystick & 0xff;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 if (curstate != prevstate) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 /* X axis */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 if ((curstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT)) != (prevstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT))) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 curaxis=0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 if (curstate & IKBD_JOY_LEFT) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 curaxis=-128;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 } else if (curstate & IKBD_JOY_RIGHT) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 curaxis=127;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 SDL_PrivateJoystickAxis(joystick,0,curaxis);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 /* Y axis */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 if ((curstate & (IKBD_JOY_UP|IKBD_JOY_DOWN)) != (prevstate & (IKBD_JOY_UP|IKBD_JOY_DOWN))) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 curaxis=0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 if (curstate & IKBD_JOY_UP) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 curaxis=-128;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 } else if (curstate & IKBD_JOY_DOWN) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 curaxis=127;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 SDL_PrivateJoystickAxis(joystick,1,curaxis);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 /* Button */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 if ((curstate & IKBD_JOY_FIRE) && !(prevstate & IKBD_JOY_FIRE)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356 SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 if (!(curstate & IKBD_JOY_FIRE) && (prevstate & IKBD_JOY_FIRE)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 atarijoysticks[IKBD_JOY1].prevstate = curstate;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 break;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 case PORTA_PAD:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 case PORTB_PAD:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 int numjoypad,i;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 numjoypad=0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 /* if (numjoystick==PORTA_PAD) numjoypad=0;*/
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 if (numjoystick==PORTB_PAD) numjoypad=1;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 curstate=jp_joypads[numjoypad];
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 if (curstate!=prevstate) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 /* X axis */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 if ((curstate & ((1<<JP_LEFT)|(1<<JP_RIGHT))) != (prevstate & ((1<<JP_LEFT)|(1<<JP_RIGHT)))) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 curaxis=0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 if (curstate & (1<<JP_LEFT)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 curaxis=-128;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 } else if (curstate & (1<<JP_RIGHT)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 curaxis=127;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 SDL_PrivateJoystickAxis(joystick,0,curaxis);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 /* Y axis */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 if ((curstate & ((1<<JP_UP)|(1<<JP_DOWN))) != (prevstate & ((1<<JP_UP)|(1<<JP_DOWN)))) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 curaxis=0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 if (curstate & (1<<JP_UP)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 curaxis=-128;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 } else if (curstate & (1<<JP_DOWN)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 curaxis=127;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 SDL_PrivateJoystickAxis(joystick,1,curaxis);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 /* Buttons */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 for (i=0;i<JP_NUM_BUTTONS;i++) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 int button;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 button=1<<jp_buttons[i];
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 if ((curstate & button) && !(prevstate & button)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 if (!(curstate & button) && (prevstate & button)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 atarijoysticks[numjoystick].prevstate = curstate;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 break;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 case PORTA_JOY0:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 case PORTA_JOY1:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 case PORTB_JOY0:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 case PORTB_JOY1:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418 int fire_shift=0,dir_shift=0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 if (numjoystick==PORTA_JOY0) { fire_shift=0; dir_shift=0; }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421 if (numjoystick==PORTA_JOY1) { fire_shift=1; dir_shift=4; }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 if (numjoystick==PORTB_JOY0) { fire_shift=2; dir_shift=8; }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 if (numjoystick==PORTB_JOY1) { fire_shift=3; dir_shift=12; }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 curstate = (jp_directions>>dir_shift) & 15;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 curstate |= ((jp_fires>>fire_shift) & 1)<<4;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428 if (curstate != prevstate) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429 /* X axis */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 if ((curstate & (PORT_JS_LEFT|PORT_JS_RIGHT)) != (prevstate & (PORT_JS_LEFT|PORT_JS_RIGHT))) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 curaxis=0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 if (curstate & PORT_JS_LEFT) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433 curaxis=-128;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434 } else if (curstate & PORT_JS_RIGHT) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 curaxis=127;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 SDL_PrivateJoystickAxis(joystick,0,curaxis);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 /* Y axis */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440 if ((curstate & (PORT_JS_UP|PORT_JS_DOWN)) != (prevstate & (PORT_JS_UP|PORT_JS_DOWN))) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441 curaxis=0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 if (curstate & PORT_JS_UP) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 curaxis=-128;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444 } else if (curstate & PORT_JS_DOWN) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 curaxis=127;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447 SDL_PrivateJoystickAxis(joystick,1,curaxis);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
448 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 /* Button */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 if ((curstate & PORT_JS_FIRE) && !(prevstate & PORT_JS_FIRE)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451 SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453 if (!(curstate & PORT_JS_FIRE) && (prevstate & PORT_JS_FIRE)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454 SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 atarijoysticks[numjoystick].prevstate = curstate;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 break;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460 case PORTA_LP:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
462 int i;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 curstate = jp_lightpens[0]>>1;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
465 curstate |= (jp_lightpens[1]>>1)<<15;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466 curstate |= (jp_fires & 3)<<30;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468 if (curstate != prevstate) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 /* X axis */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 SDL_PrivateJoystickAxis(joystick,0,(jp_lightpens[0]>>8)-128);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 /* Y axis */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 SDL_PrivateJoystickAxis(joystick,1,(jp_lightpens[1]>>8)-128);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 /* Buttons */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 for (i=0;i<2;i++) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 int button;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 button=1<<(30+i);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 if ((curstate & button) && !(prevstate & button)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480 SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 if (!(curstate & button) && (prevstate & button)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
483 SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487 atarijoysticks[numjoystick].prevstate = curstate;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 break;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
490 case PORTA_ANPAD:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 case PORTB_ANPAD:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 int numpaddle, i;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 numpaddle=0<<1;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 if (numjoystick==PORTB_ANPAD) numpaddle=1<<1;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
497
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498 curstate = jp_paddles[numpaddle]>>1;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499 curstate |= (jp_paddles[numpaddle+1]>>1)<<15;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 curstate |= ((jp_fires>>numpaddle) & 3)<<30;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 if (curstate != prevstate) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503 /* X axis */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
504 SDL_PrivateJoystickAxis(joystick,0,(jp_paddles[numpaddle]>>8)-128);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 /* Y axis */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506 SDL_PrivateJoystickAxis(joystick,1,(jp_paddles[numpaddle+1]>>8)-128);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 /* Buttons */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508 for (i=0;i<2;i++) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509 int button;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 button=1<<(30+i);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 if ((curstate & button) && !(prevstate & button)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516 if (!(curstate & button) && (prevstate & button)) {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521 atarijoysticks[numjoystick].prevstate = curstate;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 break;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 #if 0
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525 case PARA_JOY0:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526 case PARA_JOY1:
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 break;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528 #endif
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529 };
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 return;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534 void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
535 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536 return;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 void SDL_SYS_JoystickQuit(void)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 SDL_numjoysticks=0;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542 return;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543 }
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545 /*--- Joypad I/O read/write interface ---*/
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
547 #define JOYPAD_IO_BASE (0xffff9200)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
548 struct JOYPAD_IO_S {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
549 Uint16 fires;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
550 Uint16 directions;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
551 Uint16 dummy1[6];
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 Uint16 paddles[4];
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553 Uint16 dummy2[4];
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554 Uint16 lightpens[2];
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 };
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556 #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE))
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558 static void UpdateJoypads(void)
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559 {
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
560 Uint16 tmp;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
561
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 /*--- This function is called in supervisor mode ---*/
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 /* Update joysticks */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 jp_fires = (~(JOYPAD_IO.fires)) & 15;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566 jp_directions = (~(JOYPAD_IO.directions));
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 /* Update lightpen */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 tmp = JOYPAD_IO.lightpens[0] & 1023;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 jp_lightpens[0] = (tmp<<6) | (tmp>>4);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571 tmp = JOYPAD_IO.lightpens[1] & 1023;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572 jp_lightpens[1] = (tmp<<6) | (tmp>>4);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 /* Update paddles */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 tmp = (JOYPAD_IO.paddles[0] & 255);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 jp_paddles[0] = (tmp<<8) | tmp;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577 tmp = (JOYPAD_IO.paddles[1] & 255);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 jp_paddles[1] = (tmp<<8) | tmp;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 tmp = (JOYPAD_IO.paddles[2] & 255);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580 jp_paddles[2] = (tmp<<8) | tmp;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 tmp = (JOYPAD_IO.paddles[3] & 255);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 jp_paddles[3] = (tmp<<8) | tmp;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584 /* Update joypad 0 */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 JOYPAD_IO.directions=0xfffe;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586 jp_joypads[0]=((~(JOYPAD_IO.fires)) & 3)<<(16);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587 JOYPAD_IO.directions=0xfffe;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 jp_joypads[0] |= ((~(JOYPAD_IO.directions))>>8) & 15;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 JOYPAD_IO.directions=0xfffd;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+2);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592 JOYPAD_IO.directions=0xfffd;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593 jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<4;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
595 JOYPAD_IO.directions=0xfffb;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+4);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 JOYPAD_IO.directions=0xfffb;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598 jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<8;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600 JOYPAD_IO.directions=0xfff7;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+6);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 JOYPAD_IO.directions=0xfff7;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
603 jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<12;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
604
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605 /* Update joypad 1 */
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 JOYPAD_IO.directions=0xffef;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607 jp_joypads[1]=((~(JOYPAD_IO.fires)) & (3<<2))<<(16-2);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 JOYPAD_IO.directions=0xffef;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
609 jp_joypads[1] |= ((~(JOYPAD_IO.directions))>>12) & 15;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
610
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611 JOYPAD_IO.directions=0xffdf;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
612 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
613 JOYPAD_IO.directions=0xffdf;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614 jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<4;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
615
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
616 JOYPAD_IO.directions=0xffbf;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
617 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+2);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
618 JOYPAD_IO.directions=0xffbf;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
619 jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<8;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
620
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621 JOYPAD_IO.directions=0xff7f;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
622 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+4);
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623 JOYPAD_IO.directions=0xff7f;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
624 jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<12;
8a86bdf34f0f Added Atari joystick support (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
625 }