// Module for DirectInput
#include "burner.h"
#include <math.h>
#include <vector>
#include <xtl.h>
#include "xbinput.h"
extern XBGAMEPAD g_Gamepads[4];
extern int resetGame;
extern int dipSwitches;
extern int CursorSpeed;
extern int DelayValid();
struct Button  {
	std::string name;
	unsigned int code;
	int ControllerButton;
};

struct Controller {
	std::vector <Button> buttons;
};

bool ButtonAPressed1 = false;
bool ButtonBPressed1 = false;
bool ButtonXPressed1 = false;
bool ButtonYPressed1 = false;
bool ButtonLeftPressed1 = false;
bool ButtonRightPressed1 = false;
bool ButtonBlackPressed1 = false;
bool ButtonWhitePressed1 = false;
int turboA1 = 0;
int turboB1 = 0;
int turboX1 = 0;
int turboY1 = 0;
int turboBk1 = 0;
int turboW1 = 0;
int turboL1 = 0;
int turboR1 = 0;
bool ButtonAPressed2 = false;
bool ButtonBPressed2 = false;
bool ButtonXPressed2 = false;
bool ButtonYPressed2 = false;
bool ButtonLeftPressed2 = false;
bool ButtonRightPressed2 = false;
bool ButtonBlackPressed2 = false;
bool ButtonWhitePressed2 = false;
int turboA2 = 0;
int turboB2 = 0;
int turboX2 = 0;
int turboY2 = 0;
int turboBk2 = 0;
int turboW2 = 0;
int turboL2 = 0;
int turboR2 = 0;
bool ButtonAPressed3 = false;
bool ButtonBPressed3 = false;
bool ButtonXPressed3 = false;
bool ButtonYPressed3 = false;
bool ButtonLeftPressed3 = false;
bool ButtonRightPressed3 = false;
bool ButtonBlackPressed3 = false;
bool ButtonWhitePressed3 = false;
int turboA3 = 0;
int turboB3 = 0;
int turboX3 = 0;
int turboY3 = 0;
int turboBk3 = 0;
int turboW3 = 0;
int turboL3 = 0;
int turboR3 = 0;
bool ButtonAPressed4 = false;
bool ButtonBPressed4 = false;
bool ButtonXPressed4 = false;
bool ButtonYPressed4 = false;
bool ButtonLeftPressed4 = false;
bool ButtonRightPressed4 = false;
bool ButtonBlackPressed4 = false;
bool ButtonWhitePressed4 = false;
int turboA4 = 0;
int turboB4 = 0;
int turboX4 = 0;
int turboY4 = 0;
int turboBk4 = 0;
int turboW4 = 0;
int turboL4 = 0;
int turboR4 = 0;

struct Turbo { 
	int turboA;
	int turboB;
	int turboX;
	int turboY;
	int turboLeft;
	int turboRight;
	int turboBlack;
	int turboWhite;
}; 
extern Turbo tButtons[4];
extern int turboSpeed;
struct ArcadeSetting {
	std::string name;
	int code;
	int count;
};
extern std::vector<ArcadeSetting> arcadeSettings;

extern Controller controllers[4];
extern "C" int dprintf(char *format, ...);

int DinpInit()
{
	return 0;
}

int DinpExit()
{
	return 0;
}

int DinpSetCooperativeLevel(bool bExclusive, bool bForeGround)
{
	return 0;
}

int DinpStart()
{
	return 0;
}

int DinpState(int nCode)
{
	if(!DelayValid())
		return 0;

	if (nCode < 0) {
		return 0;
	}

	if(nCode == 0x3D) {
		if (resetGame > 0) {
			resetGame--;
			return 1;
		}
		else {
			return 0;
		}
	}

	for(int i = 0; i < arcadeSettings.size(); i++) {
		if(nCode == arcadeSettings[i].code) {
			if (arcadeSettings[i].count > 0) {
				arcadeSettings[i].count--;
				return 1;
			}
			else {
				return 0;
			}
		}
	}

	//Controller 1
	if(nCode == 0xC8) {
		if (g_Gamepads[0].fY1 > 0 || g_Gamepads[0].wButtons & XINPUT_GAMEPAD_DPAD_UP)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0xD0) {
		if (g_Gamepads[0].fY1 < 0 || g_Gamepads[0].wButtons & XINPUT_GAMEPAD_DPAD_DOWN)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0xCB) {
		if (g_Gamepads[0].fX1 < 0 || g_Gamepads[0].wButtons & XINPUT_GAMEPAD_DPAD_LEFT)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0xCD) {
		if (g_Gamepads[0].fX1 > 0 || g_Gamepads[0].wButtons & XINPUT_GAMEPAD_DPAD_RIGHT)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x17) {
		if (g_Gamepads[0].fY2 > 0)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x25) {
		if (g_Gamepads[0].fY2 < 0)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x24) {
		if (g_Gamepads[0].fX2 < 0)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x26) {
		if (g_Gamepads[0].fX2 > 0)
			return 1;
		else 
			return 0; 
	}

	for(int q = 0; q < controllers[0].buttons.size(); q++) {
		if(nCode == controllers[0].buttons[q].code) {
			if(controllers[0].buttons[q].ControllerButton != -1) {
				if(controllers[0].buttons[q].ControllerButton == 8) {
					if (g_Gamepads[0].wButtons & XINPUT_GAMEPAD_BACK)
						return 1;
					else 
						return 0; 
				}
				else if(controllers[0].buttons[q].ControllerButton == 9) {
					if (g_Gamepads[0].wButtons & XINPUT_GAMEPAD_START)
						return 1;
					else 
						return 0; 
				}
				else {
					if(controllers[0].buttons[q].ControllerButton == 0) {
						if(tButtons[0].turboA) {
							if(ButtonAPressed1) {
								turboA1++;
								if(turboA1 > 100)
									turboA1 = 0;
								if((turboA1 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[0].bAnalogButtons[0])
								return 1;
							else 
								return 0;
						}
					}
					
					if(controllers[0].buttons[q].ControllerButton == 1) {
						if(tButtons[0].turboB) {
							if(ButtonBPressed1) {
								turboB1++;
								if(turboB1 > 100)
									turboB1 = 0;
								if((turboB1 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[0].bAnalogButtons[1])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[0].buttons[q].ControllerButton == 2) {
						if(tButtons[0].turboX) {
							if(ButtonXPressed1) {
								turboX1++;
								if(turboX1 > 100)
									turboX1 = 0;
								if((turboX1 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[0].bAnalogButtons[2])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[0].buttons[q].ControllerButton == 3) {
						if(tButtons[0].turboY) {
							if(ButtonYPressed1) {
								turboY1++;
								if(turboY1 > 100)
									turboY1 = 0;
								if((turboY1 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[0].bAnalogButtons[3])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[0].buttons[q].ControllerButton == 4) {
						if(tButtons[0].turboBlack) {
							if(ButtonBlackPressed1) {
								turboBk1++;
								if(turboBk1 > 100)
									turboBk1 = 0;
								if((turboBk1 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[0].bAnalogButtons[4])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[0].buttons[q].ControllerButton == 5) {
						if(tButtons[0].turboWhite) {
							if(ButtonWhitePressed1) {
								turboW1++;
								if(turboW1 > 100)
									turboW1 = 0;
								if((turboW1 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[0].bAnalogButtons[5])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[0].buttons[q].ControllerButton == 6) {
						if(tButtons[0].turboLeft) {
							if(ButtonLeftPressed1) {
								turboL1++;
								if(turboL1 > 100)
									turboL1 = 0;
								if((turboL1 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[0].bAnalogButtons[6])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[0].buttons[q].ControllerButton == 7) {
						if(tButtons[0].turboRight) {
							if(ButtonRightPressed1) {
								turboR1++;
								if(turboR1 > 100)
									turboR1 = 0;
								if((turboR1 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[0].bAnalogButtons[7])
								return 1;
							else 
								return 0;
						}
					}

				}
			}
		}
	}

	//Controller 2
	if(nCode == 0x4002) {
		if (g_Gamepads[1].fY1 > 0 || g_Gamepads[1].wButtons & XINPUT_GAMEPAD_DPAD_UP)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x4003) {
		if (g_Gamepads[1].fY1 < 0 || g_Gamepads[1].wButtons & XINPUT_GAMEPAD_DPAD_DOWN)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x4000) {
		if (g_Gamepads[1].fX1 < 0 || g_Gamepads[1].wButtons & XINPUT_GAMEPAD_DPAD_LEFT)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x4001) {
		if (g_Gamepads[1].fX1 > 0 || g_Gamepads[1].wButtons & XINPUT_GAMEPAD_DPAD_RIGHT)
			return 1;
		else 
			return 0; 
	}
	
	if(nCode == 0x27) {
		if (g_Gamepads[1].fY2 > 0)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x28) {
		if (g_Gamepads[1].fY2 < 0)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x29) {
		if (g_Gamepads[1].fX2 < 0)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x2A) {
		if (g_Gamepads[1].fX2 > 0)
			return 1;
		else 
			return 0; 
	}
	
	for(int q = 0; q < controllers[1].buttons.size(); q++) {
		if(nCode == controllers[1].buttons[q].code) {
			if(controllers[1].buttons[q].ControllerButton != -1) {
				if(controllers[1].buttons[q].ControllerButton == 8) {
					if (g_Gamepads[1].wButtons & XINPUT_GAMEPAD_BACK)
						return 1;
					else 
						return 0; 
				}
				else if(controllers[1].buttons[q].ControllerButton == 9) {
					if (g_Gamepads[1].wButtons & XINPUT_GAMEPAD_START)
						return 1;
					else 
						return 0; 
				}
				else {
					if(controllers[1].buttons[q].ControllerButton == 0) {
						if(tButtons[1].turboA) {
							if(ButtonAPressed2) {
								turboA2++;
								if(turboA2 > 100)
									turboA2 = 0;
								if((turboA2 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[1].bAnalogButtons[0])
								return 1;
							else 
								return 0;
						}
					}
					
					if(controllers[1].buttons[q].ControllerButton == 1) {
						if(tButtons[1].turboB) {
							if(ButtonBPressed2) {
								turboB2++;
								if(turboB2 > 100)
									turboB2 = 0;
								if((turboB2 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[1].bAnalogButtons[1])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[1].buttons[q].ControllerButton == 2) {
						if(tButtons[1].turboX) {
							if(ButtonXPressed2) {
								turboX2++;
								if(turboX2 > 100)
									turboX2 = 0;
								if((turboX2 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[1].bAnalogButtons[2])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[1].buttons[q].ControllerButton == 3) {
						if(tButtons[1].turboY) {
							if(ButtonYPressed2) {
								turboY2++;
								if(turboY2 > 100)
									turboY2 = 0;
								if((turboY2 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[1].bAnalogButtons[3])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[1].buttons[q].ControllerButton == 4) {
						if(tButtons[1].turboBlack) {
							if(ButtonBlackPressed2) {
								turboBk2++;
								if(turboBk2 > 100)
									turboBk2 = 0;
								if((turboBk2 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[1].bAnalogButtons[4])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[1].buttons[q].ControllerButton == 5) {
						if(tButtons[1].turboWhite) {
							if(ButtonWhitePressed2) {
								turboW2++;
								if(turboW2 > 100)
									turboW2 = 0;
								if((turboW2 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[1].bAnalogButtons[5])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[1].buttons[q].ControllerButton == 6) {
						if(tButtons[1].turboLeft) {
							if(ButtonLeftPressed2) {
								turboL2++;
								if(turboL2 > 100)
									turboL2 = 0;
								if((turboL2 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[1].bAnalogButtons[6])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[1].buttons[q].ControllerButton == 7) {
						if(tButtons[1].turboRight) {
							if(ButtonRightPressed2) {
								turboR2++;
								if(turboR2 > 100)
									turboR2 = 0;
								if((turboR2 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[1].bAnalogButtons[7])
								return 1;
							else 
								return 0;
						}
					}

				}
			}
		}
	}

	//Controller 3
	if(nCode == 0x4102) {
		if (g_Gamepads[2].fY1 > 0 || g_Gamepads[2].wButtons & XINPUT_GAMEPAD_DPAD_UP)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x4103) {
		if (g_Gamepads[2].fY1 < 0 || g_Gamepads[2].wButtons & XINPUT_GAMEPAD_DPAD_DOWN)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x4100) {
		if (g_Gamepads[2].fX1 < 0 || g_Gamepads[2].wButtons & XINPUT_GAMEPAD_DPAD_LEFT)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x4101) {
		if (g_Gamepads[2].fX1 > 0 || g_Gamepads[2].wButtons & XINPUT_GAMEPAD_DPAD_RIGHT)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x33) {
		if (g_Gamepads[2].fY2 > 0)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x34) {
		if (g_Gamepads[2].fY2 < 0)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x35) {
		if (g_Gamepads[2].fX2 < 0)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x36) {
		if (g_Gamepads[2].fX2 > 0)
			return 1;
		else 
			return 0; 
	}
	
	for(int q = 0; q < controllers[2].buttons.size(); q++) {
		if(nCode == controllers[2].buttons[q].code) {
			if(controllers[2].buttons[q].ControllerButton != -1) {
				if(controllers[2].buttons[q].ControllerButton == 8) {
					if (g_Gamepads[2].wButtons & XINPUT_GAMEPAD_BACK)
						return 1;
					else 
						return 0; 
				}
				else if(controllers[2].buttons[q].ControllerButton == 9) {
					if (g_Gamepads[2].wButtons & XINPUT_GAMEPAD_START)
						return 1;
					else 
						return 0; 
				}
				else {
					if(controllers[2].buttons[q].ControllerButton == 0) {
						if(tButtons[2].turboA) {
							if(ButtonAPressed3) {
								turboA3++;
								if(turboA3 > 100)
									turboA3 = 0;
								if((turboA3 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[2].bAnalogButtons[0])
								return 1;
							else 
								return 0;
						}
					}
					
					if(controllers[2].buttons[q].ControllerButton == 1) {
						if(tButtons[2].turboB) {
							if(ButtonBPressed3) {
								turboB3++;
								if(turboB3 > 100)
									turboB3 = 0;
								if((turboB3 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[2].bAnalogButtons[1])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[2].buttons[q].ControllerButton == 2) {
						if(tButtons[2].turboX) {
							if(ButtonXPressed3) {
								turboX3++;
								if(turboX3 > 100)
									turboX3 = 0;
								if((turboX3 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[2].bAnalogButtons[2])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[2].buttons[q].ControllerButton == 3) {
						if(tButtons[2].turboY) {
							if(ButtonYPressed3) {
								turboY3++;
								if(turboY3 > 100)
									turboY3 = 0;
								if((turboY3 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[2].bAnalogButtons[3])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[2].buttons[q].ControllerButton == 4) {
						if(tButtons[2].turboBlack) {
							if(ButtonBlackPressed3) {
								turboBk3++;
								if(turboBk3 > 100)
									turboBk3 = 0;
								if((turboBk3 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[2].bAnalogButtons[4])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[2].buttons[q].ControllerButton == 5) {
						if(tButtons[2].turboWhite) {
							if(ButtonWhitePressed3) {
								turboW3++;
								if(turboW3 > 100)
									turboW3 = 0;
								if((turboW3 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[2].bAnalogButtons[5])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[2].buttons[q].ControllerButton == 6) {
						if(tButtons[2].turboLeft) {
							if(ButtonLeftPressed3) {
								turboL3++;
								if(turboL3 > 100)
									turboL3 = 0;
								if((turboL3 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[2].bAnalogButtons[6])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[2].buttons[q].ControllerButton == 7) {
						if(tButtons[2].turboRight) {
							if(ButtonRightPressed3) {
								turboR3++;
								if(turboR3 > 100)
									turboR3 = 0;
								if((turboR3 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[2].bAnalogButtons[7])
								return 1;
							else 
								return 0;
						}
					}

				}
			}
		}
	}


	//Controller 4
	if(nCode == 0x4202) {
		if (g_Gamepads[3].fY1 > 0 || g_Gamepads[3].wButtons & XINPUT_GAMEPAD_DPAD_UP)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x4203) {
		if (g_Gamepads[3].fY1 < 0 || g_Gamepads[3].wButtons & XINPUT_GAMEPAD_DPAD_DOWN)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x4200) {
		if (g_Gamepads[3].fX1 < 0 || g_Gamepads[3].wButtons & XINPUT_GAMEPAD_DPAD_LEFT)
			return 1;
		else 
			return 0; 
	}

	if(nCode == 0x4201) {
		if (g_Gamepads[3].fX1 > 0 || g_Gamepads[3].wButtons & XINPUT_GAMEPAD_DPAD_RIGHT)
			return 1;
		else 
			return 0; 
	}
	
	for(int q = 0; q < controllers[3].buttons.size(); q++) {
		if(nCode == controllers[3].buttons[q].code) {
			if(controllers[3].buttons[q].ControllerButton != -1) {
				if(controllers[3].buttons[q].ControllerButton == 8) {
					if (g_Gamepads[3].wButtons & XINPUT_GAMEPAD_BACK)
						return 1;
					else 
						return 0; 
				}
				else if(controllers[3].buttons[q].ControllerButton == 9) {
					if (g_Gamepads[3].wButtons & XINPUT_GAMEPAD_START)
						return 1;
					else 
						return 0; 
				}
				else {
					if(controllers[3].buttons[q].ControllerButton == 0) {
						if(tButtons[3].turboA) {
							if(ButtonAPressed4) {
								turboA4++;
								if(turboA4 > 100)
									turboA4 = 0;
								if((turboA4 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[3].bAnalogButtons[0])
								return 1;
							else 
								return 0;
						}
					}
					
					if(controllers[3].buttons[q].ControllerButton == 1) {
						if(tButtons[3].turboB) {
							if(ButtonBPressed4) {
								turboB4++;
								if(turboB4 > 100)
									turboB4 = 0;
								if((turboB4 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[3].bAnalogButtons[1])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[3].buttons[q].ControllerButton == 2) {
						if(tButtons[3].turboX) {
							if(ButtonXPressed4) {
								turboX4++;
								if(turboX4 > 100)
									turboX4 = 0;
								if((turboX4 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[3].bAnalogButtons[2])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[3].buttons[q].ControllerButton == 3) {
						if(tButtons[3].turboY) {
							if(ButtonYPressed4) {
								turboY4++;
								if(turboY4 > 100)
									turboY4 = 0;
								if((turboY4 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[3].bAnalogButtons[3])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[3].buttons[q].ControllerButton == 4) {
						if(tButtons[3].turboBlack) {
							if(ButtonBlackPressed4) {
								turboBk4++;
								if(turboBk4 > 100)
									turboBk4 = 0;
								if((turboBk4 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[3].bAnalogButtons[4])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[3].buttons[q].ControllerButton == 5) {
						if(tButtons[3].turboWhite) {
							if(ButtonWhitePressed4) {
								turboW4++;
								if(turboW4 > 100)
									turboW4 = 0;
								if((turboW4 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[3].bAnalogButtons[5])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[3].buttons[q].ControllerButton == 6) {
						if(tButtons[3].turboLeft) {
							if(ButtonLeftPressed4) {
								turboL4++;
								if(turboL4 > 100)
									turboL4 = 0;
								if((turboL4 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[3].bAnalogButtons[6])
								return 1;
							else 
								return 0;
						}
					}

					if(controllers[3].buttons[q].ControllerButton == 7) {
						if(tButtons[3].turboRight) {
							if(ButtonRightPressed4) {
								turboR4++;
								if(turboR4 > 100)
									turboR4 = 0;
								if((turboR4 % turboSpeed) == 0)
									return 1;
								else
									return 0;
							}
							else {
								return 0;
							}
						}
						else {
							if (g_Gamepads[3].bAnalogButtons[7])
								return 1;
							else 
								return 0;
						}
					}

				}
			}
		}
	}
	return 0;
}

int DinpJoyAxis(int i, int nAxis)
{
	return 0;
}

int DinpMouseAxis(int i, int nAxis)
{
	if(nAxis == 1)
		return (g_Gamepads[0].fY1 * -1) * CursorSpeed;
	else
		return g_Gamepads[0].fX1 * CursorSpeed;
}

int DinpFind(bool CreateBaseline)
{
	return 0;
}

int DinpGetControlName(int nCode, TCHAR* pszDeviceName, TCHAR* pszControlName)
{
	return 0;
}

struct InputInOut Control = { DinpInit, DinpExit, DinpSetCooperativeLevel, DinpStart, DinpState, DinpJoyAxis, DinpMouseAxis, DinpFind, DinpGetControlName, NULL, _T("DirectInput7 input") };
