joystick.cpp

来自「nes游戏模拟器」· C++ 代码 · 共 58 行

CPP
58 行
字号
// Joystick.cpp

#include "Joystick.h"

Joystick::Joystick(unsigned int PortValue)
{
	if ((PortValue != 0x4016) || (PortValue != 0x4017))
		Port = 0x4016;
	else
		Port = PortValue;

	Strobe();
}


void Joystick::Strobe()
{
	BitIndex = 0;
}

void Joystick::write(unsigned char value)
{
	if (((value & 1) == 1) && (StrobeOnNext == false))
		StrobeOnNext = true;
	else if (((value & 1) == 0) && (StrobeOnNext == true))
	{
		Strobe();
		StrobeOnNext = false;
	}
}

unsigned char Joystick::read()
{
	char BitReturn = BitStream[BitIndex];
	BitIndex++;

	// Check to see if read past the joysticks data.  Not likely that this
	// will happen but its possible.
	if (BitIndex >= 24)
		Strobe();

	return BitReturn;
}

char Joystick::GetButton(int button)
{
	return BitStream[button];
}

void Joystick::SetButton(int button)
{
	BitStream[button] = 1;
}

void Joystick::ClearButton(int button)
{
	BitStream[button] = 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?