Add P1 (i.e. keyboard) support. Interestingly, gets Tetris *much* further.

Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
Adrian.Conlon 2017-09-15 00:53:56 +01:00
parent 32d1085ecb
commit e1b838355e
2 changed files with 55 additions and 3 deletions

View File

@ -217,6 +217,30 @@ namespace EightBit {
void loadBootRom(const std::string& path); void loadBootRom(const std::string& path);
void loadGameRom(const std::string& path); void loadGameRom(const std::string& path);
void pressUp() { m_upPressed = true; }
void releaseUp() { m_upPressed = false; }
void pressDown() { m_downPressed = true; }
void releaseDown() { m_downPressed = false; }
void pressLeft() { m_leftPressed = true; }
void releaseLeft() { m_leftPressed = false; }
void pressRight() { m_rightPressed = true; }
void releaseRight() { m_rightPressed = false; }
void pressA() { m_aPressed = true; }
void releaseA() { m_aPressed = false; }
void pressB() { m_bPressed = true; }
void releaseB() { m_bPressed = false; }
void pressSelect() { m_selectPressed = true; }
void releaseSelect() { m_selectPressed = false; }
void pressStart() { m_startPressed = true; }
void releaseStart() { m_startPressed = false; }
protected: protected:
virtual uint8_t& reference(uint16_t address, bool& rom) { virtual uint8_t& reference(uint16_t address, bool& rom) {
@ -280,6 +304,15 @@ namespace EightBit {
std::array<bool, 4> m_soundChannelEnabled; std::array<bool, 4> m_soundChannelEnabled;
bool m_soundEnabled; bool m_soundEnabled;
bool m_upPressed;
bool m_downPressed;
bool m_leftPressed;
bool m_rightPressed;
bool m_aPressed;
bool m_bPressed;
bool m_selectPressed;
bool m_startPressed;
void checkTimer(int cycles); void checkTimer(int cycles);
void validateCartridgeType(); void validateCartridgeType();

View File

@ -22,7 +22,16 @@ EightBit::GameBoy::Bus::Bus()
m_ramBank(0), m_ramBank(0),
m_timerCounter(0), m_timerCounter(0),
m_timerRate(0), m_timerRate(0),
m_dmaTransferActive(false) { m_dmaTransferActive(false),
m_upPressed(false),
m_downPressed(false),
m_leftPressed(false),
m_rightPressed(false),
m_aPressed(false),
m_bPressed(false),
m_selectPressed(false),
m_startPressed(false)
{
ReadingByte.connect(std::bind(&GameBoy::Bus::Bus_ReadingByte, this, std::placeholders::_1)); ReadingByte.connect(std::bind(&GameBoy::Bus::Bus_ReadingByte, this, std::placeholders::_1));
ReadByte.connect(std::bind(&GameBoy::Bus::Bus_ReadByte, this, std::placeholders::_1)); ReadByte.connect(std::bind(&GameBoy::Bus::Bus_ReadByte, this, std::placeholders::_1));
WritingByte.connect(std::bind(&GameBoy::Bus::Bus_WritingByte, this, std::placeholders::_1)); WritingByte.connect(std::bind(&GameBoy::Bus::Bus_WritingByte, this, std::placeholders::_1));
@ -67,8 +76,18 @@ void EightBit::GameBoy::Bus::Bus_ReadingByte(const uint16_t address) {
switch (ioRegister) { switch (ioRegister) {
// Port/Mode Registers // Port/Mode Registers
case P1: case P1: {
mask(Processor::Mask5); auto direction = m_rightPressed || m_leftPressed || m_upPressed || m_downPressed;
auto button = m_aPressed || m_bPressed || m_selectPressed || m_startPressed;
pokeRegister(P1,
(int)!(m_rightPressed || m_aPressed)
| ((int)!(m_leftPressed || m_bPressed) << 1)
| ((int)!(m_upPressed || m_selectPressed) << 2)
| ((int)!(m_downPressed || m_startPressed) << 3)
| (direction << 4)
| (button << 5)
| Processor::Bit6 | Processor::Bit7);
}
break; break;
case SB: case SB:
break; break;