diff --git a/Core/APU.cpp b/Core/APU.cpp index 9799a482..1830dfe0 100644 --- a/Core/APU.cpp +++ b/Core/APU.cpp @@ -8,6 +8,7 @@ #include "ApuFrameCounter.h" #include "EmulationSettings.h" #include "SoundMixer.h" +#include "MemoryManager.h" APU* APU::Instance = nullptr; diff --git a/Core/ArkanoidController.cpp b/Core/ArkanoidController.cpp index 7f117eef..32ca210c 100644 --- a/Core/ArkanoidController.cpp +++ b/Core/ArkanoidController.cpp @@ -3,6 +3,7 @@ #include "ControlManager.h" #include "PPU.h" #include "GameServerConnection.h" +#include "IKeyManager.h" void ArkanoidController::StreamState(bool saving) { diff --git a/Core/BizhawkMovie.cpp b/Core/BizhawkMovie.cpp index fea87000..14b76388 100644 --- a/Core/BizhawkMovie.cpp +++ b/Core/BizhawkMovie.cpp @@ -2,6 +2,7 @@ #include "BizhawkMovie.h" #include "VsControlManager.h" #include "FDS.h" +#include "PPU.h" BizhawkMovie::BizhawkMovie() { diff --git a/Core/CPU.cpp b/Core/CPU.cpp index 9c92ef81..5f3d0fd0 100644 --- a/Core/CPU.cpp +++ b/Core/CPU.cpp @@ -6,6 +6,7 @@ #include "TraceLogger.h" #include "Debugger.h" #include "NsfMapper.h" +#include "MemoryManager.h" CPU* CPU::Instance = nullptr; @@ -176,6 +177,40 @@ void CPU::BRK() { _prevRunIrq = false; } +void CPU::MemoryWrite(uint16_t addr, uint8_t value) +{ + _cpuWrite = true;; + _writeAddr = addr; + IncCycleCount(); + while(_dmcDmaRunning) { + IncCycleCount(); + } + _memoryManager->Write(addr, value); + + //DMA DMC might have started after a write to $4015, stall CPU if needed + while(_dmcDmaRunning) { + IncCycleCount(); + } + _cpuWrite = false; +} + +uint8_t CPU::MemoryRead(uint16_t addr, MemoryOperationType operationType) { + IncCycleCount(); + while(_dmcDmaRunning) { + //Stall CPU until we can process a DMC read + if((addr != 0x4016 && addr != 0x4017 && (_cycleCount & 0x01)) || _dmcCounter == 1) { + //While the CPU is stalled, reads are performed on the current address + //Reads are only performed every other cycle? This fixes "dma_2007_read" test + //This behavior causes the $4016/7 data corruption when a DMC is running. + //When reading $4016/7, only the last read counts (because this only occurs to low-to-high transitions, i.e once in this case) + _memoryManager->Read(addr); + } + IncCycleCount(); + } + uint8_t value = _memoryManager->Read(addr, operationType); + return value; +} + uint16_t CPU::FetchOperand() { switch(_instAddrMode) { diff --git a/Core/CPU.h b/Core/CPU.h index 7e09adae..cf27b8ae 100644 --- a/Core/CPU.h +++ b/Core/CPU.h @@ -1,11 +1,12 @@ #pragma once #include "stdafx.h" -#include "MemoryManager.h" #include "Snapshotable.h" -#include "EmulationSettings.h" #include "Types.h" +enum class NesModel; +class MemoryManager; + namespace PSFlags { enum PSFlags : uint8_t @@ -135,39 +136,8 @@ private: return ((valA + valB) & 0xFF00) != (valA & 0xFF00); } - void MemoryWrite(uint16_t addr, uint8_t value) - { - _cpuWrite = true;; - _writeAddr = addr; - IncCycleCount(); - while(_dmcDmaRunning) { - IncCycleCount(); - } - _memoryManager->Write(addr, value); - - //DMA DMC might have started after a write to $4015, stall CPU if needed - while (_dmcDmaRunning) { - IncCycleCount(); - } - _cpuWrite = false; - } - - uint8_t MemoryRead(uint16_t addr, MemoryOperationType operationType = MemoryOperationType::Read) { - IncCycleCount(); - while(_dmcDmaRunning) { - //Stall CPU until we can process a DMC read - if((addr != 0x4016 && addr != 0x4017 && (_cycleCount & 0x01)) || _dmcCounter == 1) { - //While the CPU is stalled, reads are performed on the current address - //Reads are only performed every other cycle? This fixes "dma_2007_read" test - //This behavior causes the $4016/7 data corruption when a DMC is running. - //When reading $4016/7, only the last read counts (because this only occurs to low-to-high transitions, i.e once in this case) - _memoryManager->Read(addr); - } - IncCycleCount(); - } - uint8_t value = _memoryManager->Read(addr, operationType); - return value; - } + void MemoryWrite(uint16_t addr, uint8_t value); + uint8_t MemoryRead(uint16_t addr, MemoryOperationType operationType = MemoryOperationType::Read); uint16_t MemoryReadWord(uint16_t addr, MemoryOperationType operationType = MemoryOperationType::Read) { uint8_t lo = MemoryRead(addr, operationType); diff --git a/Core/Console.cpp b/Core/Console.cpp index 88acf187..e546b288 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -1,6 +1,11 @@ #include "stdafx.h" #include #include "Console.h" +#include "CPU.h" +#include "PPU.h" +#include "APU.h" +#include "MemoryManager.h" +#include "AutoSaveManager.h" #include "BaseMapper.h" #include "ControlManager.h" #include "VsControlManager.h" diff --git a/Core/Console.h b/Core/Console.h index 80f10e8b..1e9ad7d4 100644 --- a/Core/Console.h +++ b/Core/Console.h @@ -2,18 +2,19 @@ #include "stdafx.h" #include -#include "CPU.h" -#include "PPU.h" -#include "APU.h" -#include "MemoryManager.h" -#include "ControlManager.h" #include "../Utilities/SimpleLock.h" -#include "AutoSaveManager.h" #include "RomData.h" class Debugger; class BaseMapper; class RewindManager; +class APU; +class CPU; +class PPU; +class MemoryManager; +class ControlManager; +class AutoSaveManager; +enum class NesModel; class Console { diff --git a/Core/ControlManager.cpp b/Core/ControlManager.cpp index 828089b6..eb4f8069 100644 --- a/Core/ControlManager.cpp +++ b/Core/ControlManager.cpp @@ -7,6 +7,9 @@ #include "EmulationSettings.h" #include "Console.h" #include "GameServerConnection.h" +#include "MemoryManager.h" +#include "PPU.h" +#include "IKeyManager.h" unique_ptr ControlManager::_keyManager = nullptr; shared_ptr ControlManager::_controlDevices[2] = { nullptr, nullptr }; diff --git a/Core/ControlManager.h b/Core/ControlManager.h index edd8ee4e..0ade7d20 100644 --- a/Core/ControlManager.h +++ b/Core/ControlManager.h @@ -1,15 +1,15 @@ #pragma once #include "stdafx.h" -#include "BaseControlDevice.h" -#include "IMemoryHandler.h" -#include "IGameBroadcaster.h" -#include "Snapshotable.h" #include "../Utilities/SimpleLock.h" -#include "IKeyManager.h" +#include "IMemoryHandler.h" +#include "Snapshotable.h" class BaseControlDevice; class Zapper; +class IGameBroadcaster; +class IKeyManager; +enum class MouseButton; struct MousePosition { diff --git a/Core/Debugger.cpp b/Core/Debugger.cpp index 53a39455..10990dab 100644 --- a/Core/Debugger.cpp +++ b/Core/Debugger.cpp @@ -17,6 +17,8 @@ #include "Assembler.h" #include "CodeRunner.h" #include "DisassemblyInfo.h" +#include "PPU.h" +#include "MemoryManager.h" Debugger* Debugger::Instance = nullptr; const int Debugger::BreakpointTypeCount; diff --git a/Core/DeltaModulationChannel.cpp b/Core/DeltaModulationChannel.cpp index 7778f91f..cb02fbc4 100644 --- a/Core/DeltaModulationChannel.cpp +++ b/Core/DeltaModulationChannel.cpp @@ -3,6 +3,7 @@ #include "APU.h" #include "CPU.h" #include "Console.h" +#include "MemoryManager.h" DeltaModulationChannel *DeltaModulationChannel::Instance = nullptr; diff --git a/Core/DisassemblyInfo.cpp b/Core/DisassemblyInfo.cpp index 53a3a50c..0f88ea7c 100644 --- a/Core/DisassemblyInfo.cpp +++ b/Core/DisassemblyInfo.cpp @@ -1,8 +1,9 @@ #include "stdafx.h" +#include "../Utilities/HexUtilities.h" #include "DisassemblyInfo.h" #include "CPU.h" #include "LabelManager.h" -#include "../Utilities/HexUtilities.h" +#include "MemoryManager.h" string DisassemblyInfo::OPName[256]; AddrMode DisassemblyInfo::OPMode[256]; diff --git a/Core/FDS.cpp b/Core/FDS.cpp index 9370f4cb..30f4f3a7 100644 --- a/Core/FDS.cpp +++ b/Core/FDS.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "FDS.h" #include "FdsAudio.h" +#include "MemoryManager.h" FDS* FDS::Instance = nullptr; diff --git a/Core/FdsAudio.h b/Core/FdsAudio.h index 1e6e83fd..ca8a60b6 100644 --- a/Core/FdsAudio.h +++ b/Core/FdsAudio.h @@ -1,12 +1,13 @@ #pragma once #include "stdafx.h" +#include #include "Snapshotable.h" #include "EmulationSettings.h" #include "APU.h" #include "BaseFdsChannel.h" #include "ModChannel.h" -#include #include "BaseExpansionAudio.h" +#include "MemoryManager.h" class FdsAudio : public BaseExpansionAudio { diff --git a/Core/GameServer.cpp b/Core/GameServer.cpp index d763f4e3..2bf7e35b 100644 --- a/Core/GameServer.cpp +++ b/Core/GameServer.cpp @@ -5,6 +5,7 @@ using std::thread; #include "MessageManager.h" #include "GameServer.h" #include "Console.h" +#include "ControlManager.h" #include "../Utilities/Socket.h" #include "PlayerListMessage.h" diff --git a/Core/HdVideoFilter.cpp b/Core/HdVideoFilter.cpp index 06751c9d..9ff2c7d5 100644 --- a/Core/HdVideoFilter.cpp +++ b/Core/HdVideoFilter.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include "PPU.h" #include "HdNesPack.h" #include "HdVideoFilter.h" diff --git a/Core/JyCompany.h b/Core/JyCompany.h index 1ac454c3..abb9a37a 100644 --- a/Core/JyCompany.h +++ b/Core/JyCompany.h @@ -2,6 +2,7 @@ #include "stdafx.h" #include "BaseMapper.h" #include "CPU.h" +#include "MemoryManager.h" class JyCompany : public BaseMapper { diff --git a/Core/MMC5Audio.h b/Core/MMC5Audio.h index 976ddab3..ad4a4fac 100644 --- a/Core/MMC5Audio.h +++ b/Core/MMC5Audio.h @@ -4,6 +4,7 @@ #include "BaseExpansionAudio.h" #include "CPU.h" #include "Console.h" +#include "MemoryManager.h" class MMC5Square : public SquareChannel { diff --git a/Core/NsfMapper.cpp b/Core/NsfMapper.cpp index 155e4dfa..7705f915 100644 --- a/Core/NsfMapper.cpp +++ b/Core/NsfMapper.cpp @@ -2,6 +2,7 @@ #include "NsfMapper.h" #include "CPU.h" #include "Console.h" +#include "MemoryManager.h" NsfMapper* NsfMapper::_instance; diff --git a/Core/OekaKidsTablet.cpp b/Core/OekaKidsTablet.cpp index 2dbe0a39..0da7112f 100644 --- a/Core/OekaKidsTablet.cpp +++ b/Core/OekaKidsTablet.cpp @@ -2,6 +2,8 @@ #include "OekaKidsTablet.h" #include "ControlManager.h" #include "GameServerConnection.h" +#include "IKeyManager.h" +#include "IKeyManager.h" void OekaKidsTablet::StreamState(bool saving) { diff --git a/Core/RecordedRomTest.cpp b/Core/RecordedRomTest.cpp index 031a6792..85e8ae65 100644 --- a/Core/RecordedRomTest.cpp +++ b/Core/RecordedRomTest.cpp @@ -6,6 +6,7 @@ #include "MessageManager.h" #include "Debugger.h" #include "MovieManager.h" +#include "PPU.h" #include "../Utilities/FolderUtilities.h" #include "../Utilities/md5.h" #include "../Utilities/ZipWriter.h" diff --git a/Core/TraceLogger.cpp b/Core/TraceLogger.cpp index e97e140d..728258ef 100644 --- a/Core/TraceLogger.cpp +++ b/Core/TraceLogger.cpp @@ -5,6 +5,7 @@ #include "Console.h" #include "MemoryManager.h" #include "LabelManager.h" +#include "EmulationSettings.h" #include "../Utilities/HexUtilities.h" #include "../Utilities/FolderUtilities.h" diff --git a/Core/VideoDecoder.cpp b/Core/VideoDecoder.cpp index 971a681e..e5b85b50 100644 --- a/Core/VideoDecoder.cpp +++ b/Core/VideoDecoder.cpp @@ -9,6 +9,7 @@ #include "ScaleFilter.h" #include "VideoRenderer.h" #include "RewindManager.h" +#include "PPU.h" unique_ptr VideoDecoder::Instance; diff --git a/Core/Zapper.cpp b/Core/Zapper.cpp index 57700b2c..b21ff524 100644 --- a/Core/Zapper.cpp +++ b/Core/Zapper.cpp @@ -4,6 +4,7 @@ #include "PPU.h" #include "ControlManager.h" #include "GameServerConnection.h" +#include "IKeyManager.h" void Zapper::StreamState(bool saving) { diff --git a/TestHelper/TestHelper.cpp b/TestHelper/TestHelper.cpp index 37e98f11..1df6dbdc 100644 --- a/TestHelper/TestHelper.cpp +++ b/TestHelper/TestHelper.cpp @@ -23,6 +23,7 @@ #include "../Utilities/Timer.h" #include "../Core/MessageManager.h" #include "../Core/ControlManager.h" +#include "../Core/EmulationSettings.h" using namespace std; diff --git a/Windows/Renderer.cpp b/Windows/Renderer.cpp index 61b7b678..a641a4ae 100644 --- a/Windows/Renderer.cpp +++ b/Windows/Renderer.cpp @@ -1,17 +1,12 @@ #include "stdafx.h" -#include #include "Renderer.h" #include "DirectXTK/SpriteBatch.h" #include "DirectXTK/SpriteFont.h" -#include "DirectXTK/DDSTextureLoader.h" -#include "DirectXTK/WICTextureLoader.h" -#include "../Core/PPU.h" #include "../Core/VideoRenderer.h" #include "../Core/VideoDecoder.h" #include "../Core/EmulationSettings.h" #include "../Core/MessageManager.h" #include "../Utilities/UTF8Util.h" -#include "../Core/HdNesPack.h" using namespace DirectX;