diff --git a/LR35902/inc/Disassembler.h b/LR35902/inc/Disassembler.h index 3c6dfca..1825be5 100644 --- a/LR35902/inc/Disassembler.h +++ b/LR35902/inc/Disassembler.h @@ -1,6 +1,8 @@ #pragma once +#include #include +#include #include namespace EightBit { diff --git a/LR35902/inc/Display.h b/LR35902/inc/Display.h index 5baaca9..2486280 100644 --- a/LR35902/inc/Display.h +++ b/LR35902/inc/Display.h @@ -4,16 +4,17 @@ #include #include -#include - -#include "GameBoyBus.h" -#include "AbstractColourPalette.h" #include "ObjectAttribute.h" namespace EightBit { + + class Ram; + namespace GameBoy { + class AbstractColourPalette; class CharacterDefinition; + class Bus; class Display { public: diff --git a/LR35902/inc/GameBoyBus.h b/LR35902/inc/GameBoyBus.h index 716d1e7..b92b65b 100644 --- a/LR35902/inc/GameBoyBus.h +++ b/LR35902/inc/GameBoyBus.h @@ -7,6 +7,7 @@ #include #include +#include "LR35902.h" #include "IoRegisters.h" namespace EightBit { @@ -32,6 +33,7 @@ namespace EightBit { Bus(); + LR35902& CPU() { return m_cpu; } Ram& VRAM() { return m_videoRam; } Ram& OAMRAM() { return m_oamRam; } IoRegisters& IO() { return m_ioPorts; } @@ -51,6 +53,8 @@ namespace EightBit { virtual uint8_t& reference(uint16_t address, bool& rom); private: + LR35902 m_cpu; + Rom m_bootRom; // 0x0000 - 0x00ff std::vector m_gameRomBanks; // 0x0000 - 0x3fff, 0x4000 - 0x7fff (switchable) Ram m_videoRam; // 0x8000 - 0x9fff diff --git a/LR35902/inc/LR35902.h b/LR35902/inc/LR35902.h index 6059d07..9b4e357 100644 --- a/LR35902/inc/LR35902.h +++ b/LR35902/inc/LR35902.h @@ -4,12 +4,13 @@ #include #include - -#include "GameBoyBus.h" -#include "Display.h" +#include namespace EightBit { namespace GameBoy { + + class Bus; + class LR35902 : public IntelProcessor { public: enum StatusBits { diff --git a/LR35902/inc/ObjectAttribute.h b/LR35902/inc/ObjectAttribute.h index ec1fa88..5ee2e49 100644 --- a/LR35902/inc/ObjectAttribute.h +++ b/LR35902/inc/ObjectAttribute.h @@ -2,22 +2,17 @@ #include -#include #include namespace EightBit { + + class Ram; + namespace GameBoy { class ObjectAttribute { public: - ObjectAttribute() {} - ObjectAttribute(Ram& ram, uint16_t address, int height) { - m_positionY = ram.peek(address); - m_positionX = ram.peek(address + 1); - m_pattern = ram.peek(address + 2); - if (height == 16) - m_pattern >>= 1; - m_flags = ram.peek(address + 3); - } + ObjectAttribute(); + ObjectAttribute(Ram& ram, uint16_t address, int height); uint8_t positionY() const { return m_positionY; } uint8_t positionX() const { return m_positionX; } diff --git a/LR35902/src/Disassembler.cpp b/LR35902/src/Disassembler.cpp index ab9d951..46c2c98 100644 --- a/LR35902/src/Disassembler.cpp +++ b/LR35902/src/Disassembler.cpp @@ -7,6 +7,7 @@ #include "Memory.h" #include "LR35902.h" +#include "IoRegisters.h" EightBit::GameBoy::Disassembler::Disassembler() { // Disable exceptions where too many format arguments are available diff --git a/LR35902/src/Display.cpp b/LR35902/src/Display.cpp index bdd399b..b071be4 100644 --- a/LR35902/src/Display.cpp +++ b/LR35902/src/Display.cpp @@ -1,9 +1,11 @@ #include "stdafx.h" #include "Display.h" -#include "Processor.h" #include "CharacterDefinition.h" #include "ObjectAttribute.h" +#include "GameBoyBus.h" +#include "AbstractColourPalette.h" +#include #include EightBit::GameBoy::Display::Display(const AbstractColourPalette* colours, Bus& bus, Ram& oam, Ram& vram) diff --git a/LR35902/src/GameBoyBus.cpp b/LR35902/src/GameBoyBus.cpp index c3dac39..6db0db9 100644 --- a/LR35902/src/GameBoyBus.cpp +++ b/LR35902/src/GameBoyBus.cpp @@ -2,7 +2,8 @@ #include "GameBoyBus.h" EightBit::GameBoy::Bus::Bus() -: m_bootRom(0x100), +: m_cpu(*this), + m_bootRom(0x100), m_gameRomBanks(1), m_videoRam(0x2000), m_ramBanks(0), @@ -24,6 +25,7 @@ EightBit::GameBoy::Bus::Bus() void EightBit::GameBoy::Bus::reset() { m_ioPorts.reset(); + m_cpu.initialise(); } void EightBit::GameBoy::Bus::loadBootRom(const std::string& path) { diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index a4cce4f..462b22a 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -1,5 +1,7 @@ #include "stdafx.h" #include "LR35902.h" +#include "GameBoyBus.h" +#include "Display.h" // based on http://www.z80.info/decoding.htm diff --git a/LR35902/src/LR35902.vcxproj b/LR35902/src/LR35902.vcxproj index 0a9022e..2cf1be4 100644 --- a/LR35902/src/LR35902.vcxproj +++ b/LR35902/src/LR35902.vcxproj @@ -157,6 +157,7 @@ + Create diff --git a/LR35902/src/LR35902.vcxproj.filters b/LR35902/src/LR35902.vcxproj.filters index 43ba6c9..43caeaa 100644 --- a/LR35902/src/LR35902.vcxproj.filters +++ b/LR35902/src/LR35902.vcxproj.filters @@ -67,5 +67,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/LR35902/src/Makefile b/LR35902/src/Makefile index a8f6f5f..1504407 100644 --- a/LR35902/src/Makefile +++ b/LR35902/src/Makefile @@ -2,7 +2,7 @@ LIB = liblr35902.a CXXFLAGS = -Wall -std=c++11 -pipe -I ../inc -I ../../inc -CXXFILES = CharacterDefinition.cpp Disassembler.cpp Display.cpp GameBoyBus.cpp LR35902.cpp Profiler.cpp +CXXFILES = CharacterDefinition.cpp Disassembler.cpp Display.cpp GameBoyBus.cpp IoRegisters.cpp LR35902.cpp ObjectAttribute.cpp Profiler.cpp CXXOBJECTS = $(CXXFILES:.cpp=.o) diff --git a/LR35902/src/ObjectAttribute.cpp b/LR35902/src/ObjectAttribute.cpp new file mode 100644 index 0000000..ae67f75 --- /dev/null +++ b/LR35902/src/ObjectAttribute.cpp @@ -0,0 +1,16 @@ +#include "stdafx.h" +#include "ObjectAttribute.h" + +#include + +EightBit::GameBoy::ObjectAttribute::ObjectAttribute() { +} + +EightBit::GameBoy::ObjectAttribute::ObjectAttribute(Ram& ram, uint16_t address, int height) { + m_positionY = ram.peek(address); + m_positionX = ram.peek(address + 1); + m_pattern = ram.peek(address + 2); + if (height == 16) + m_pattern >>= 1; + m_flags = ram.peek(address + 3); +} diff --git a/LR35902/src/stdafx.h b/LR35902/src/stdafx.h index ff93290..3aa34e4 100644 --- a/LR35902/src/stdafx.h +++ b/LR35902/src/stdafx.h @@ -28,7 +28,11 @@ #include #include #include +#include #include +#include +#include +#include #ifdef _MSC_VER #include