Source

gb_emulator / gb_emulator / include / gb_emulator / gb_input.h

Full commit
/*  Copyright © 2011 Chris Spencer <spencercw@gmail.com>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */

#ifndef GB_INPUT_H_8A505060_8A9E_11E0_926E_0002A5D5C51B
#define GB_INPUT_H_8A505060_8A9E_11E0_926E_0002A5D5C51B

#include <stdint.h>

#include <boost/thread/thread.hpp>

#include <Windows.h>
#include <XInput.h>

class Gb;

//! GameBoy input handler.
class GbInput
{
public:
	//! Constructor.
	/**
	 * \param gb The emulator context.
	 */
	GbInput(Gb &gb);

	//! Destructor.
	~GbInput();

	//! Handles input events.
	void poll();

	//! Translates the current input and modifies the appropriate registers.
	uint8_t translate();

	//! Displays a dialog to allow the user to open a ROM file.
	void openRomDialog();

private:
	enum Key
	{
		KEY_NONE   = 0x00,
		KEY_A      = 0x01,
		KEY_B      = 0x02,
		KEY_START  = 0x04,
		KEY_SELECT = 0x08,
		KEY_UP     = 0x10,
		KEY_DOWN   = 0x20,
		KEY_LEFT   = 0x40,
		KEY_RIGHT  = 0x80
	};

	Gb &gb_;

	uint8_t keys_;
	uint8_t joy_;
	uint8_t joyAxis_;

	XINPUT_STATE xInputState_;
	boost::mutex xInputMutex_;

	// Background input thread
	boost::thread inputThread_;
	void run();

	// Disabled operations
	GbInput(const GbInput &);
	GbInput & operator=(const GbInput &);
};

#endif