Skip to content

Commit

Permalink
Read P1 directly (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
kremi151 committed Aug 11, 2020
1 parent e127cb6 commit e50d0db
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/source/emulator/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ inline u8 getInterruptBitMask(InterruptType type) {
}

void CPU::doJoypad() {
u8 oldP1 = memory->read8BitsAt(FB_REG_P1) & 0b00001111u;
u8 oldP1 = ioRegisters->getP1() & 0b00001111u;
u8 newP1 = ioRegisters->updateJoypad() & 0b00001111u;
bool isNotPressed = oldP1 & newP1;
if (!isNotPressed && joypadWasNotPressed) {
Expand Down
4 changes: 4 additions & 0 deletions core/source/emulator/io_registers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,8 @@ void io_registers::updateLCD(bool lcdOn, GPUMode gpuMode, u8 ly) {
*(hwIO + FB_REG_OFFSET_STAT) = stat;

*(hwIO + FB_REG_OFFSET_LY) = ly;
}

u8 &io_registers::getP1() {
return *(hwIO + FB_REG_OFFSET_P1);
}
2 changes: 2 additions & 0 deletions core/source/emulator/io_registers.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ namespace FunkyBoy {
u8 updateJoypad();
void updateLCD(bool lcdOn, GPUMode gpuMode, u8 ly);

u8 &getP1();

friend class CPU;
};

Expand Down

0 comments on commit e50d0db

Please sign in to comment.