⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 joystick.cpp

📁 nes游戏模拟器
💻 CPP
字号:
// 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -