Added joystick support. Probably needs more work

This commit is contained in:
teuf
2001-04-17 21:59:48 +00:00
parent eb4e911dd8
commit 22653ebef9
3 changed files with 403 additions and 85 deletions

View File

@@ -1,4 +1,3 @@
#ifdef __LINUX__ // AH
#include <stdio.h>
#include <unistd.h>
@@ -82,7 +81,6 @@ LPDIRECTINPUTDEVICE MouseInput;
LPDIRECTINPUTDEVICE KeyboardInput;
LPDIRECTINPUTDEVICE7 JoystickInput[4];
DIJOYSTATE js[4];
#endif // __LINUX__
DWORD X1Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
DWORD X2Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
@@ -101,17 +99,29 @@ DWORD S02Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
DWORD S11Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
DWORD S12Disable[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
#endif // __LINUX__
DWORD CurrentJoy=0;
#ifdef __LINUX__
extern signed long JoyMaxX;
extern signed long JoyMaxY;
extern signed long JoyMinX;
extern signed long JoyMinY;
extern signed long JoyX;
extern signed long JoyY;
SDL_Joystick *JoystickInput[4];
#endif //__LINUX__
DWORD BitDepth;
BYTE BackColor=0;
DEVMODE mode;
int DTimerCheck;
float MouseMinX=0;
/*float MouseMinX=0;
float MouseMaxX=256;
float MouseMinY=0;
float MouseMaxY=223;
float MouseMaxY=223;*/
int MouseX;
int MouseY;
float MouseMoveX;
@@ -144,7 +154,9 @@ DWORD InputEn=0;
BOOL InputAcquire(void)
{
#ifdef __LINUX__ // AH
STUB_FUNCTION;
// STUB_FUNCTION;
InputEn=1;
return TRUE;
#else // __WIN32__
if(JoystickInput[0]) JoystickInput[0]->Acquire();
if(JoystickInput[1]) JoystickInput[1]->Acquire();
@@ -154,14 +166,17 @@ BOOL InputAcquire(void)
if(MouseInput) MouseInput->Acquire();
if(KeyboardInput) KeyboardInput->Acquire();
InputEn=1;
return TRUE;
return TRUE;
#endif // __LINUX__
}
BOOL InputDeAcquire(void)
{
#ifdef __LINUX__ // AH
STUB_FUNCTION;
// STUB_FUNCTION;
InputEn=0;
return TRUE;
#else // __WIN32__
if(MouseInput) { MouseInput->Unacquire(); }
if(KeyboardInput) KeyboardInput->Unacquire();
@@ -169,9 +184,10 @@ BOOL InputDeAcquire(void)
if(JoystickInput[1]) JoystickInput[1]->Unacquire();
if(JoystickInput[2]) JoystickInput[2]->Unacquire();
if(JoystickInput[3]) JoystickInput[3]->Unacquire();
#endif // __LINUX__
InputEn=0;
return TRUE;
return TRUE;
#endif // __LINUX__
}
unsigned char keyboardhit=0;
@@ -201,30 +217,84 @@ void ProcessKeyBuf(int scancode);
int Main_Proc(void)
{
// TODO: Main event loop
SDL_Event event;
// TODO: Main event loop
SDL_Event event;
Uint8 JoyButton;
//STUB_FUNCTION;
while (SDL_PollEvent(&event)) {
switch(event.type)
{
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_LSHIFT ||
event.key.keysym.sym == SDLK_RSHIFT)
shiftptr = 1;
if (event.key.keysym.scancode-8 > 0) {
if (pressed[event.key.keysym.scancode-8]!=2)
pressed[event.key.keysym.scancode-8]=1;
ProcessKeyBuf(event.key.keysym.sym);
}
break;
//STUB_FUNCTION;
while (SDL_PollEvent(&event)) {
switch(event.type)
{
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_LSHIFT ||
event.key.keysym.sym == SDLK_RSHIFT)
shiftptr = 1;
if (event.key.keysym.scancode-8 > 0) {
if (pressed[event.key.keysym.scancode-8]!=2)
pressed[event.key.keysym.scancode-8]=1;
ProcessKeyBuf(event.key.keysym.sym);
}
break;
case SDL_KEYUP:
if (event.key.keysym.sym == SDLK_LSHIFT ||
event.key.keysym.sym == SDLK_RSHIFT)
shiftptr = 0;
if (event.key.keysym.scancode-8 > 0)
pressed[event.key.keysym.scancode-8]=0;
break;
case SDL_KEYUP:
if (event.key.keysym.sym == SDLK_LSHIFT ||
event.key.keysym.sym == SDLK_RSHIFT)
shiftptr = 0;
if (event.key.keysym.scancode-8 > 0)
pressed[event.key.keysym.scancode-8]=0;
break;
case SDL_MOUSEMOTION:
MouseX = event.motion.x;
MouseY = event.motion.y;
break;
case SDL_MOUSEBUTTONDOWN:
MouseButton = MouseButton | event.button.button;
break;
case SDL_MOUSEBUTTONUP:
MouseButton = MouseButton & ~event.button.button;
break;
case SDL_JOYAXISMOTION:
CurrentJoy = event.jaxis.which;
if( event.jaxis.axis == 0) {
if (event.jaxis.value < JoyMinX) {
pressed[0x100 + CurrentJoy*32 + 1] = 1;
printf("Joystick left : %d\n", event.jaxis.value);
} else if (event.jaxis.value > JoyMaxX) {
pressed[0x100 + CurrentJoy*32 + 0] = 1;
printf("Joystick right : %d\n", event.jaxis.value);
} else {
pressed[0x100 + CurrentJoy*32 + 1] = 0;
pressed[0x100 + CurrentJoy*32 + 0] = 0;
}
}
if( event.jaxis.axis == 1) {
if (event.jaxis.value < JoyMinY) {
pressed[0x100 + CurrentJoy*32 + 3] = 1;
printf("Joystick up : %d\n", event.jaxis.value);
} else if (event.jaxis.value > JoyMaxY) {
pressed[0x100 + CurrentJoy*32 + 2] = 1;
printf("Joystick down : %d\n", event.jaxis.value);
} else {
pressed[0x100 + CurrentJoy*32 + 3] = 0;
pressed[0x100 + CurrentJoy*32 + 2] = 0;
}
}
break;
case SDL_JOYBUTTONDOWN:
CurrentJoy = event.jbutton.which;
JoyButton = event.jbutton.button;
pressed[0x100 + CurrentJoy*32 + 16 + JoyButton] = 1;
printf("Button %u pressed on joystick %u\n", JoyButton, CurrentJoy);
break;
case SDL_JOYBUTTONUP:
pressed[0x100 + CurrentJoy*32 + 16 + JoyButton] = 0;
break;
default: break;
}
}
return TRUE;
@@ -776,8 +846,64 @@ ReInitSound()
#ifdef __LINUX__ // AH
BOOL InitJoystickInput(void)
{
STUB_FUNCTION;
return TRUE;
int i;
SDL_Event *event;
STUB_FUNCTION;
for (i=0; i<4; i++)
JoystickInput[i]=NULL;
// If it is possible to use SDL_NumJoysticks
// before initialising SDL_INIT_JOYSTICK then
// this call can be replaced with SDL_InitSubSystem
if (!SDL_NumJoysticks()) {
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
return;
}
SDL_JoystickEventState(SDL_ENABLE);
for (i=0; i<SDL_NumJoysticks(); i++)
JoystickInput[i]=SDL_JoystickOpen(i);
/* if your joystick doesn't work correctly, you may want to
* change these values
*/
JoyMaxX = 100;
JoyMinX = -100;
JoyMaxY = 100;
JoyMinY = -100;
/*the goal of this piece of code is to autocalibrate the joystick
* but for the moment it segfaults
*/
/*
JoyMaxX = 0;
JoyMinX = 0;
JoyMaxY = 0;
JoyMinY = 0;
JoyX = 0;
JoyY = 0;
while ((JoyX == 0) || (JoyY == 0)) {
SDL_WaitEvent(event);
if (event->type == SDL_JOYAXISMOTION) {
if (event->jaxis.axis == 0) {
JoyX = event->jaxis.value;
if (JoyX < 0) JoyX = -JoyX;
JoyMaxX = 2*JoyX;
JoyMinX = -2*JoyX;
}
if (event->jaxis.axis == 1) {
JoyY = event->jaxis.value;
if (JoyY < 0) JoyY = -JoyY;
JoyMaxY = 2*JoyY;
JoyMinY = -2*JoyY;
}
}
}
printf("Joystick initialised\n");
printf("MinX : %d MaxX : %d\n", JoyMinX, JoyMaxX);
printf("MinY : %d MaxY : %d\n", JoyMinY, JoyMaxY);
*/
return TRUE;
}
#else // __WIN32__
BOOL FAR PASCAL InitJoystickInput(LPCDIDEVICEINSTANCE pdinst, LPVOID pvRef)
@@ -983,9 +1109,10 @@ DirectX 7.0a or higher located at www.microsoft.com/directx \0");
BOOL InitInput()
{
char message1[256];
#ifdef __LINUX__ // AH
STUB_FUNCTION;
char message1[256];
#ifdef __LINUX__ // AH
STUB_FUNCTION;
InitJoystickInput();
#else // __WIN32__
HRESULT hr;
@@ -1192,7 +1319,6 @@ int startgame(void)
}
/* Need to handle situations where BPP is not what we can handle */
SDL_WM_SetCaption ("ZSNES Linux","ZSNES");
SDL_ShowCursor(0);
@@ -1602,7 +1728,7 @@ SM_CYSCREEN )-WindowHeight);
ShowWindow(hMainWindow, SW_SHOWNORMAL);
SetWindowText(hMainWindow,"ZSNESWIN");
InitInput();
InitJoystickInput();
InitSound();
TestJoy();
}
@@ -1742,9 +1868,10 @@ void UpdateSound(void *userdata, Uint8 *stream, int len)
if (T36HZEnabled) {
Buffer[i]=0;
} else {
if(DSPBuffer[i]>32767)Buffer[i]=32767;
else if(DSPBuffer[i]<-32767)Buffer[i]=-32767;
else Buffer[i]=DSPBuffer[i];
// if(DSPBuffer[i]>32767)Buffer[i]=32767;
// else if(DSPBuffer[i]<-32767)Buffer[i]=-32767;
// else Buffer[i]=DSPBuffer[i];
Buffer[i]=DSPBuffer[i] & 0xFFFF;
}
}
@@ -1781,7 +1908,7 @@ void UpdateVFrame(void)
//STUB_FUNCTION;
Main_Proc();
WinUpdateDevices();
// WinUpdateDevices();
CheckTimers();
if (DTimerCheck == 1)