Jump to content
OGXbox.com

Controller Status In Assembly


damanloox
 Share

Recommended Posts

Can you expand on your reasoning a bit? Are you wanting to get device packets during arbitrary execution? Are you avoiding kernel calls?

The Xbox doesn't store controller states in memory, you must request and poll peripheral states every time you want to check (SMBus->MCPX (southbridge)->USB hub (controller ports 0-4)->controller (also a USB hub)->port 0). If you want to utilize kernel driver calls and you're not compiling against the XTL then you're going to need to lookup the function addresses and the lookup must be dynamic every time because of the differing kernel versions on the Xbox. If you want to avoid the kernel then you can check how the devs that wrote the cromwell BIOS managed talking to the southbridge/USB host controller/USB devices (fairly certain they wrote multiple drivers)

 

This is bare minimum to fetch controller states with the kernel

#include <xtl.h>

void WaitAnyControllerStateChange(XINPUT_STATE* ControllerState)
{
	int Changed = 0;

	//Setup controller input
	XDEVICE_PREALLOC_TYPE DeviceTypes[] = {	{XDEVICE_TYPE_GAMEPAD, 4} }; //4 = polling on all ports
	XInitDevices(sizeof(DeviceTypes) / sizeof(XDEVICE_PREALLOC_TYPE), DeviceTypes); //init device stack
	Sleep(500); //have to sleep, it takes almost half a second to initialize the XInput library..

	//open handles to each port
	HANDLE Controllers[4];
	Controllers[0] = XInputOpen(XDEVICE_TYPE_GAMEPAD, XDEVICE_PORT0, XDEVICE_NO_SLOT, 0);
	Controllers[1] = XInputOpen(XDEVICE_TYPE_GAMEPAD, XDEVICE_PORT1, XDEVICE_NO_SLOT, 0);
	Controllers[2] = XInputOpen(XDEVICE_TYPE_GAMEPAD, XDEVICE_PORT2, XDEVICE_NO_SLOT, 0);
	Controllers[3] = XInputOpen(XDEVICE_TYPE_GAMEPAD, XDEVICE_PORT3, XDEVICE_NO_SLOT, 0);

	DWORD Insertions = 0;
	DWORD Removals = 0;
	while(1)
	{
		if (XGetDeviceChanges(XDEVICE_TYPE_GAMEPAD, &Insertions, &Removals)) //check connection state changes
		{
			//something changed, refresh controller handles
			for(int i = 0; i < 4; i++)
			{
				if (Controllers[i] != 0)
					XInputClose(Controllers[i]); //close any current handles (system doesnt dealloc them itself)
			}
			//open new handles
			Controllers[0] = XInputOpen(XDEVICE_TYPE_GAMEPAD, XDEVICE_PORT0, XDEVICE_NO_SLOT, 0);
			Controllers[1] = XInputOpen(XDEVICE_TYPE_GAMEPAD, XDEVICE_PORT1, XDEVICE_NO_SLOT, 0);
			Controllers[2] = XInputOpen(XDEVICE_TYPE_GAMEPAD, XDEVICE_PORT2, XDEVICE_NO_SLOT, 0);
			Controllers[3] = XInputOpen(XDEVICE_TYPE_GAMEPAD, XDEVICE_PORT3, XDEVICE_NO_SLOT, 0);
		}

		//poll controller states on all ports
		for(int i = 0; i < 4; i++)
		{
			if (Controllers[i] != 0) //check bad handle
			{
				if (XInputGetState(Controllers[i], ControllerState) == ERROR_SUCCESS) //check input state changes
				{
					Changed = 1;
					break; //something changed, return state
				}
			}
		}
		if (Changed) break;
	}
}

void main()
{
	XINPUT_STATE ControllerState = { 0 };
	WaitAnyControllerStateChange(&ControllerState);
	/*
		process state data...
	*/
}

 

No one is going to be able to give you some quick code to poll controller state because it's not a simple thing to do

Edited by feudalnate
Link to comment
Share on other sites

No one is going to be able to give you some quick code to poll controller state because it's not a simple thing to do

That's what I was afraid of ;)

Thanks. I wanted to see if there's an "easy" way of including controller status in bios "patcher" (one that enables xiso) to allow startup of different dashboards (based on button pressed). I know there are applications for that - just wanted to avoid long chains of applications being started. I'll have a look at cromwell sources but I have a feeling it's not going to be.. worth it ;)

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

Board Life Status


Board startup date: April 23, 2017 12:45:48
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.