1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <sys/farptr.h>
33 #include "dos-joystick.h"
42 #define JOY_RIGHT 0x80
47 static int32 joybuttons=0;
50 static uint32 joyxcenter;
51 static uint32 joyycenter;
53 static void ConfigJoystick(void);
54 volatile int soundjoyer=0;
55 volatile int soundjoyeron=0;
57 /* Crude method to detect joystick. */
58 static int DetectJoystick(void)
65 if((inportb(0x201)&3)==(b&3))
71 void UpdateJoyData(void)
76 joybuttons=((inportb(0x201)&0xF0)^0xF0)>>4;
108 if(joybuttons&joyBMap[y]) ret|=(1<<y)<<((joy-1)<<3);
110 if(joyx<=joyxcenter*.25) ret|=JOY_LEFT<<((joy-1)<<3);
111 else if(joyx>=joyxcenter*1.75) ret|=JOY_RIGHT<<((joy-1)<<3);
112 if(joyy<=joyycenter*.25) ret|=JOY_UP<<((joy-1)<<3);
113 else if(joyy>=joyycenter*1.75) ret|=JOY_DOWN<<((joy-1)<<3);
118 int InitJoysticks(void)
121 if(!DetectJoystick())
123 printf("Joystick not detected!\n");
138 if(!(joyBMap[0]|joyBMap[1]|joyBMap[2]|joyBMap[3]))
143 static void BConfig(int b)
148 while(time(0)< (st+4) )
152 if(joybuttons) c=joybuttons;
153 else if(c && !joybuttons)
162 void KillJoysticks(void)
167 static void ConfigJoystick(void)
169 static char *genb="** Press button for ";
171 printf("\n\n Joystick button configuration:\n\n");
172 printf(" Push and release the button to map to the virtual joystick.\n");
173 printf(" If you do not wish to assign a button, wait a few seconds\n");
174 printf(" and the configuration will continue.\n\n");
175 printf(" Press enter to continue...\n");
178 printf("%s\"Select\".\n",genb);
181 printf("%s\"Start\".\n",genb);
184 printf("%s\"B\".\n",genb);
187 printf("%s\"A\".\n",genb);