Skip to content

Commit

Permalink
Direct access to IF register (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
kremi151 committed Aug 12, 2020
1 parent 44d0ef5 commit 3b1bc36
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/source/emulator/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ bool CPU::doInterrupts() {
if (instrContext.cpuState == CPUState::STOPPED) {
return false;
}
u8 _if = memory->read8BitsAt(FB_REG_IF) & 0x1fu;
u8 &_if = ioRegisters.getIF();
_if %= 0x1fu;
u8 _ie = memory->read8BitsAt(FB_REG_IE) & 0x1fu;
u8 _intr = _if & _ie & 0x1f;
if (!_intr) {
Expand All @@ -294,8 +295,7 @@ bool CPU::doInterrupts() {

instrContext.progCounter = addr;
debug_print_4("Do interrupt at 0x%04X\n", addr);
_if &= ~bitMask;
memory->write8BitsTo(FB_REG_IF, _if); // TODO: Investigate "Timer doesn't work" error from ROM output
_if &= ~bitMask; // Writes directly to io_registry
// TODO: Interrupt Service Routine should take 5 cycles
return true;
}
Expand Down Expand Up @@ -373,8 +373,8 @@ void CPU::doTimers(u8 clocks) {

void CPU::requestInterrupt(InterruptType type) {
//fprintf(stdout, "#req int %d\n", type);
u8 _if = memory->read8BitsAt(FB_REG_IF);
memory->write8BitsTo(FB_REG_IF, _if | getInterruptBitMask(type));
u8 &_if = ioRegisters.getIF();
_if |= getInterruptBitMask(type);
}

void CPU::setProgramCounter(u16 offset) {
Expand Down
5 changes: 5 additions & 0 deletions core/source/emulator/io_registers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ using namespace FunkyBoy;

#define FB_REG_OFFSET_P1 (FB_REG_P1 - 0xFF00)
#define FB_REG_OFFSET_DIV (FB_REG_DIV - 0xFF00)
#define FB_REG_OFFSET_IF (FB_REG_IF - 0xFF00)
#define FB_REG_OFFSET_STAT (FB_REG_STAT - 0xFF00)
#define FB_REG_OFFSET_LY (FB_REG_LY - 0xFF00)

Expand Down Expand Up @@ -155,4 +156,8 @@ void io_registers::updateLCD(bool lcdOn, GPUMode gpuMode, u8 ly) {

u8 &io_registers::getP1() {
return *(hwIO + FB_REG_OFFSET_P1);
}

u8 &io_registers::getIF() {
return *(hwIO + FB_REG_OFFSET_IF);
}
1 change: 1 addition & 0 deletions core/source/emulator/io_registers.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ namespace FunkyBoy {
void updateLCD(bool lcdOn, GPUMode gpuMode, u8 ly);

u8 &getP1();
u8 &getIF();

friend class CPU;
};
Expand Down

0 comments on commit 3b1bc36

Please sign in to comment.