diff --git a/src/cpu.cpp b/src/cpu.cpp index 3a842de..b8a24cd 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -36,7 +36,9 @@ int CPU::NOP() int CPU::LD_BC_u16() { // Load the next 2 bytes into BC - + // Left shift the first byte by 8 bits + // OR the second byte + reg_BC.dat = ((*mMap)[reg_PC.dat + 1] << 8) | (*mMap)[reg_PC.dat + 2]; reg_PC.dat += 3; printf("LD BC, u16"); return 12; @@ -45,6 +47,6 @@ int CPU::LD_BC_u16() int CPU::executeNextInstruction() { // Get the opcode - Byte opcode = *mMap[reg_PC.dat]; + Byte opcode = (*mMap)[reg_PC.dat]; return (this->*method_pointer[opcode])(); } \ No newline at end of file diff --git a/src/gameBoy.cpp b/src/gameBoy.cpp index 6d48521..5902b8e 100644 --- a/src/gameBoy.cpp +++ b/src/gameBoy.cpp @@ -13,6 +13,11 @@ GBE::GBE() // Unify the CPU and MemoryMap gbe_cpu->setMemory(gbe_mMap); + gbe_mMap->debugWriteMemory(0x0100, 0x00); + gbe_mMap->debugWriteMemory(0x0101, 0x01); + gbe_mMap->debugWriteMemory(0x0102, 0x02); + gbe_mMap->debugWriteMemory(0x0103, 0x03); + update(); } @@ -26,7 +31,7 @@ void GBE::update() while (cycles < gbe_cpu->clockSpeedPerFrame) { // Execute the next instruction - cycles += gbe_cpu->executeNextInstruction(0); + cycles += gbe_cpu->executeNextInstruction(); // updateTimers() // updateGraphics() // Do Interrupts() diff --git a/src/gameBoy.h b/src/gameBoy.h index 3a78295..f39be88 100644 --- a/src/gameBoy.h +++ b/src/gameBoy.h @@ -1,7 +1,7 @@ #pragma once #include "types.h" #include "cpu.h" -#include "memoryMap.h" +#include "mmap.h" // GBE stands for GameBoyEmulator diff --git a/src/mmap.cpp b/src/mmap.cpp index c80ec23..0b3ac1d 100644 --- a/src/mmap.cpp +++ b/src/mmap.cpp @@ -103,6 +103,10 @@ bool MemoryMap::writeMemory(Word address, Byte value) return true; } +void MemoryMap::debugWriteMemory(Word address, Byte value) { + romBank0[address] = value; +} + Byte MemoryMap::readMemory(Word address) { if (address < 0x4000) diff --git a/src/mmap.h b/src/mmap.h index 82fb9b7..1244188 100644 --- a/src/mmap.h +++ b/src/mmap.h @@ -96,6 +96,7 @@ class MemoryMap Byte* getInterruptEnableRegister() { return interruptEnableRegister; } bool writeMemory(Word address, Byte value); + void debugWriteMemory(Word address, Byte value); Byte readMemory(Word address); Byte operator[](Word address);