mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-11-09 13:07:15 +00:00
Another stab at keyboard scanning. Better, but not perfect...
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
9190b29b4b
commit
07d44966ac
@ -217,29 +217,29 @@ namespace EightBit {
|
||||
void loadBootRom(const std::string& path);
|
||||
void loadGameRom(const std::string& path);
|
||||
|
||||
void pressUp(bool pressed = true) { triggerKeypadInterrupt(m_upPressed = pressed); }
|
||||
void releaseUp() { pressUp(false); }
|
||||
void pressRight() { m_p14 = m_p10 = false; triggerKeypadInterrupt(); }
|
||||
void releaseRight() { m_p14 = m_p10 = true; }
|
||||
|
||||
void pressDown(bool pressed = true) { triggerKeypadInterrupt(m_downPressed = pressed); }
|
||||
void releaseDown() { pressDown(false); }
|
||||
void pressLeft() { m_p14 = m_p11 = false, triggerKeypadInterrupt(); }
|
||||
void releaseLeft() { m_p14 = m_p11 = true; }
|
||||
|
||||
void pressLeft(bool pressed = true) { triggerKeypadInterrupt(m_leftPressed = pressed); }
|
||||
void releaseLeft() { pressLeft(false); }
|
||||
void pressUp() { m_p14 = m_p12 = false, triggerKeypadInterrupt(); }
|
||||
void releaseUp() { m_p14 = m_p12 = true; }
|
||||
|
||||
void pressRight(bool pressed = true) { triggerKeypadInterrupt(m_rightPressed = pressed); }
|
||||
void releaseRight() { pressRight(false); }
|
||||
void pressDown() { m_p14 = m_p13 = false, triggerKeypadInterrupt(); }
|
||||
void releaseDown() { m_p14 = m_p13 = true; }
|
||||
|
||||
void pressA(bool pressed = true) { triggerKeypadInterrupt(m_aPressed = pressed); }
|
||||
void releaseA() { pressA(false); }
|
||||
void pressA() { m_p15 = m_p10 = false, triggerKeypadInterrupt(); }
|
||||
void releaseA() { m_p15 = m_p10 = true; }
|
||||
|
||||
void pressB(bool pressed = true) { triggerKeypadInterrupt(m_bPressed = pressed); }
|
||||
void releaseB() { pressB(false); }
|
||||
void pressB() { m_p15 = m_p11 = false, triggerKeypadInterrupt(); }
|
||||
void releaseB() { m_p15 = m_p11 = true; }
|
||||
|
||||
void pressSelect(bool pressed = true) { triggerKeypadInterrupt(m_selectPressed = pressed); }
|
||||
void releaseSelect() { pressSelect(false); }
|
||||
void pressSelect() { m_p15 = m_p12 = false, triggerKeypadInterrupt(); }
|
||||
void releaseSelect() { m_p15 = m_p12 = true; }
|
||||
|
||||
void pressStart(bool pressed = true) { triggerKeypadInterrupt(m_startPressed = pressed); }
|
||||
void releaseStart() { pressStart(false); }
|
||||
void pressStart() { m_p15 = m_p13 = false, triggerKeypadInterrupt(); }
|
||||
void releaseStart() { m_p15 = m_p13 = true; }
|
||||
|
||||
protected:
|
||||
virtual uint8_t& reference(uint16_t address, bool& rom) {
|
||||
@ -304,14 +304,15 @@ namespace EightBit {
|
||||
std::array<bool, 4> m_soundChannelEnabled;
|
||||
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;
|
||||
bool m_scanP15;
|
||||
bool m_scanP14;
|
||||
|
||||
bool m_p15; // misc keys
|
||||
bool m_p14; // direction keys
|
||||
bool m_p13; // down/start
|
||||
bool m_p12; // up/select
|
||||
bool m_p11; // left/b
|
||||
bool m_p10; // right/a
|
||||
|
||||
void checkTimer(int cycles);
|
||||
|
||||
@ -325,9 +326,8 @@ namespace EightBit {
|
||||
mask(ADDRESS().word, masking);
|
||||
}
|
||||
|
||||
void triggerKeypadInterrupt(bool pressed) {
|
||||
if (pressed)
|
||||
triggerInterrupt(Interrupts::KeypadPressed);
|
||||
void triggerKeypadInterrupt() {
|
||||
triggerInterrupt(Interrupts::KeypadPressed);
|
||||
}
|
||||
|
||||
void Bus_WrittenByte(uint16_t address);
|
||||
|
@ -23,15 +23,14 @@ EightBit::GameBoy::Bus::Bus()
|
||||
m_timerCounter(0),
|
||||
m_timerRate(0),
|
||||
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)
|
||||
{
|
||||
m_scanP15(false),
|
||||
m_scanP14(false),
|
||||
m_p15(true),
|
||||
m_p14(true),
|
||||
m_p13(true),
|
||||
m_p12(true),
|
||||
m_p11(true),
|
||||
m_p10(true) {
|
||||
ReadingByte.connect(std::bind(&GameBoy::Bus::Bus_ReadingByte, this, std::placeholders::_1));
|
||||
WrittenByte.connect(std::bind(&GameBoy::Bus::Bus_WrittenByte, this, std::placeholders::_1));
|
||||
m_divCounter.word = 0xabcc;
|
||||
@ -75,15 +74,19 @@ void EightBit::GameBoy::Bus::Bus_ReadingByte(const uint16_t address) {
|
||||
|
||||
// Port/Mode Registers
|
||||
case P1: {
|
||||
auto direction = m_rightPressed || m_leftPressed || m_upPressed || m_downPressed;
|
||||
auto button = m_aPressed || m_bPressed || m_selectPressed || m_startPressed;
|
||||
auto p14 = m_scanP14 && !m_p14;
|
||||
auto p15 = m_scanP15 && !m_p15;
|
||||
auto live = p14 || p15;
|
||||
auto p10 = live && !m_p10;
|
||||
auto p11 = live && !m_p11;
|
||||
auto p12 = live && !m_p12;
|
||||
auto p13 = live && !m_p13;
|
||||
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)
|
||||
(int)!p10
|
||||
| ((int)!p11 << 1)
|
||||
| ((int)!p12 << 2)
|
||||
| ((int)!p13 << 3)
|
||||
| Processor::Bit4 | Processor::Bit5
|
||||
| Processor::Bit6 | Processor::Bit7);
|
||||
}
|
||||
break;
|
||||
@ -232,6 +235,11 @@ void EightBit::GameBoy::Bus::Bus_WrittenByte(const uint16_t address) {
|
||||
if (!handled) {
|
||||
switch (address) {
|
||||
|
||||
case BASE + P1:
|
||||
m_scanP14 = (value & Processor::Bit4) == 0;
|
||||
m_scanP15 = (value & Processor::Bit5) == 0;
|
||||
break;
|
||||
|
||||
case BASE + SB: // R/W
|
||||
case BASE + SC: // R/W
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user