diff --git a/Core/CPU.cpp b/Core/CPU.cpp index e2aa2777..f7ae952c 100644 --- a/Core/CPU.cpp +++ b/Core/CPU.cpp @@ -1,6 +1,5 @@ #include "stdafx.h" #include "CPU.h" -#include "Timer.h" uint64_t CPU::CycleCount = 0; uint32_t CPU::CyclePenalty = 0; diff --git a/Core/Console.cpp b/Core/Console.cpp index 09851905..baf3d822 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "Console.h" -#include "Timer.h" +#include "../Utilities/Timer.h" uint32_t Console::Flags = 0; uint32_t Console::CurrentFPS = 0; diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index 33df9640..894afb5c 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -124,7 +124,6 @@ Create Create - diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index c66de22c..c81552dc 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -95,9 +95,6 @@ - - Header Files - Source Files diff --git a/Core/MemoryManager.h b/Core/MemoryManager.h index 913c06c7..81d9a70b 100644 --- a/Core/MemoryManager.h +++ b/Core/MemoryManager.h @@ -40,14 +40,5 @@ class MemoryManager uint8_t ReadVRAM(uint16_t addr); void WriteVRAM(uint16_t addr, uint8_t value); - - char* GetTestResult() - { - char *buffer = new char[0x2000]; - for(int i = 0; i < 0x1000; i++) { - buffer[i] = Read(0x6004 + i); - } - return buffer; - } }; diff --git a/Core/stdafx.h b/Core/stdafx.h index 20447b7f..5b1d73fe 100644 --- a/Core/stdafx.h +++ b/Core/stdafx.h @@ -1,8 +1,3 @@ -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// - #pragma once #include "targetver.h" @@ -23,10 +18,6 @@ #include #include -#include - -#include - using std::vector; using std::shared_ptr; using std::unique_ptr; @@ -35,4 +26,4 @@ using std::ifstream; using std::ofstream; using std::wstring; using std::exception; -using std::atomic; +using std::max; \ No newline at end of file diff --git a/GUI/MainWindow.cpp b/GUI/MainWindow.cpp index 8b0fe9ce..d321c1ea 100644 --- a/GUI/MainWindow.cpp +++ b/GUI/MainWindow.cpp @@ -1,8 +1,8 @@ #include "stdafx.h" #include "Resource.h" #include "MainWindow.h" -#include "..\Core\Console.h" -#include "..\Core\Timer.h" +#include "../Core/Console.h" +#include "../Utilities/Timer.h" #include "InputManager.h" using namespace DirectX; @@ -16,13 +16,8 @@ namespace NES { return false; } - if(!_renderer.Initialize(_hInstance, _hWnd)) { - return false; - } - - if(_soundManager.Initialize(_hWnd)) { - return false; - } + _renderer.reset(new Renderer(_hWnd)); + _soundManager.reset(new SoundManager(_hWnd)); return true; } @@ -62,9 +57,9 @@ namespace NES { int MainWindow::Run() { - //#if _DEBUG - CreateConsole(); - //#endif + #if _DEBUG + CreateConsole(); + #endif Initialize(); @@ -86,7 +81,7 @@ namespace NES { DispatchMessage(&msg); } } else { - _renderer.Render(); + _renderer->Render(); } std::this_thread::sleep_for(std::chrono::duration(1)); } @@ -204,7 +199,7 @@ namespace NES { void MainWindow::Stop(bool powerOff) { - _soundManager.Reset(); + _soundManager->Reset(); if(_console) { _console->Stop(); if(powerOff) { @@ -225,7 +220,7 @@ namespace NES { void MainWindow::Reset() { if(_console) { - _soundManager.Reset(); + _soundManager->Reset(); _console->Reset(); } } diff --git a/GUI/MainWindow.h b/GUI/MainWindow.h index acb7e0d3..12cc985a 100644 --- a/GUI/MainWindow.h +++ b/GUI/MainWindow.h @@ -11,8 +11,8 @@ namespace NES { HINSTANCE _hInstance; HWND _hWnd; int _nCmdShow; - Renderer _renderer; - SoundManager _soundManager; + unique_ptr _renderer; + unique_ptr _soundManager; unique_ptr _console; unique_ptr _emuThread; wstring _currentROM; @@ -45,8 +45,6 @@ namespace NES { void InitializeOptions(); - - public: MainWindow(HINSTANCE hInstance, int nCmdShow) : _hInstance(hInstance), _nCmdShow(nCmdShow) { diff --git a/GUI/Renderer.cpp b/GUI/Renderer.cpp index 69daf8d9..066fa68c 100644 --- a/GUI/Renderer.cpp +++ b/GUI/Renderer.cpp @@ -5,20 +5,35 @@ namespace NES { - bool Renderer::Initialize(HINSTANCE hInstance, HWND hWnd) { + Renderer::Renderer(HWND hWnd) + { PPU::RegisterVideoDevice(this); - _hInst = hInstance; _hWnd = hWnd; if(FAILED(InitDevice())) { CleanupDevice(); - return false; - } else { - return true; } } + Renderer::~Renderer() + { + CleanupDevice(); + } + + void Renderer::CleanupDevice() + { + if(_pImmediateContext) _pImmediateContext->ClearState(); + + if(_pRenderTargetView) _pRenderTargetView->Release(); + if(_samplerState) _samplerState->Release(); + + if(_pSwapChain) _pSwapChain->Release(); + if(_pImmediateContext1) _pImmediateContext1->Release(); + if(_pd3dDevice1) _pd3dDevice1->Release(); + if(_pd3dDevice) _pd3dDevice->Release(); + } + //-------------------------------------------------------------------------------------- // Create Direct3D device and swap chain //-------------------------------------------------------------------------------------- @@ -202,23 +217,6 @@ namespace NES return S_OK; } - - //-------------------------------------------------------------------------------------- - // Clean up the objects we've created - //-------------------------------------------------------------------------------------- - void Renderer::CleanupDevice() - { - if(_pImmediateContext) _pImmediateContext->ClearState(); - - if(_pRenderTargetView) _pRenderTargetView->Release(); - if(_samplerState) _samplerState->Release(); - - if(_pSwapChain) _pSwapChain->Release(); - if(_pImmediateContext1) _pImmediateContext1->Release(); - if(_pd3dDevice1) _pd3dDevice1->Release(); - if(_pd3dDevice) _pd3dDevice->Release(); - } - ID3D11ShaderResourceView* Renderer::GetDisplayBufferShaderResourceView() { UINT screenwidth = 256, screenheight = 240; diff --git a/GUI/Renderer.h b/GUI/Renderer.h index fee04e2e..d930e197 100644 --- a/GUI/Renderer.h +++ b/GUI/Renderer.h @@ -6,15 +6,9 @@ using namespace DirectX; namespace NES { - struct SimpleVertex - { - XMFLOAT3 Pos; - }; - class Renderer : IVideoDevice { private: - HINSTANCE _hInst = nullptr; HWND _hWnd = nullptr; D3D_DRIVER_TYPE _driverType = D3D_DRIVER_TYPE_NULL; @@ -44,7 +38,8 @@ namespace NES { ID3D11ShaderResourceView* GetDisplayBufferShaderResourceView(); public: - bool Initialize(HINSTANCE hInst, HWND hWnd); + Renderer(HWND hWnd); + ~Renderer(); void Render(); diff --git a/GUI/SoundManager.cpp b/GUI/SoundManager.cpp index 20b73bf1..4202164a 100644 --- a/GUI/SoundManager.cpp +++ b/GUI/SoundManager.cpp @@ -1,11 +1,15 @@ #include "stdafx.h" #include "SoundManager.h" -SoundManager::SoundManager() +SoundManager::SoundManager(HWND hwnd) { + APU::RegisterAudioDevice(this); + _directSound = 0; _primaryBuffer = 0; _secondaryBuffer = 0; + + InitializeDirectSound(hwnd); } SoundManager::~SoundManager() @@ -13,19 +17,6 @@ SoundManager::~SoundManager() Release(); } -bool SoundManager::Initialize(HWND hwnd) -{ - APU::RegisterAudioDevice(this); - bool result; - - result = InitializeDirectSound(hwnd); - if(!result) { - return false; - } - - return true; -} - bool SoundManager::InitializeDirectSound(HWND hwnd) { HRESULT result; diff --git a/GUI/SoundManager.h b/GUI/SoundManager.h index b20f2811..9b44c6a0 100644 --- a/GUI/SoundManager.h +++ b/GUI/SoundManager.h @@ -6,10 +6,9 @@ class SoundManager : public IAudioDevice { public: - SoundManager(); + SoundManager(HWND hWnd); ~SoundManager(); - bool Initialize(HWND hWnd); void Release(); void PlayBuffer(int16_t *soundBuffer, uint32_t bufferSize); void Play(); diff --git a/NES.sln b/NES.sln index 0140f01f..ae44bcb9 100644 --- a/NES.sln +++ b/NES.sln @@ -10,6 +10,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GUI", "GUI\GUI.vcxproj", "{ {78FEF1A1-6DF1-4CBB-A373-AE6FA7CE5CE0} = {78FEF1A1-6DF1-4CBB-A373-AE6FA7CE5CE0} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Utilities", "Utilities\Utilities.vcxproj", "{B5330148-E8C7-46BA-B54E-69BE59EA337D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -24,6 +26,10 @@ Global {6675D943-322A-4045-B16C-4756FD32CAF2}.Debug|Win32.Build.0 = Debug|Win32 {6675D943-322A-4045-B16C-4756FD32CAF2}.Release|Win32.ActiveCfg = Release|Win32 {6675D943-322A-4045-B16C-4756FD32CAF2}.Release|Win32.Build.0 = Release|Win32 + {B5330148-E8C7-46BA-B54E-69BE59EA337D}.Debug|Win32.ActiveCfg = Debug|Win32 + {B5330148-E8C7-46BA-B54E-69BE59EA337D}.Debug|Win32.Build.0 = Debug|Win32 + {B5330148-E8C7-46BA-B54E-69BE59EA337D}.Release|Win32.ActiveCfg = Release|Win32 + {B5330148-E8C7-46BA-B54E-69BE59EA337D}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Core/Timer.h b/Utilities/Timer.h similarity index 100% rename from Core/Timer.h rename to Utilities/Timer.h diff --git a/Utilities/Utilities.vcxproj b/Utilities/Utilities.vcxproj new file mode 100644 index 00000000..cd2ac75d --- /dev/null +++ b/Utilities/Utilities.vcxproj @@ -0,0 +1,87 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {B5330148-E8C7-46BA-B54E-69BE59EA337D} + Win32Proj + Utilities + + + + StaticLibrary + true + v120 + Unicode + + + StaticLibrary + false + v120 + true + Unicode + + + + + + + + + + + + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + + + + Create + Create + + + + + + \ No newline at end of file diff --git a/Utilities/Utilities.vcxproj.filters b/Utilities/Utilities.vcxproj.filters new file mode 100644 index 00000000..54889a34 --- /dev/null +++ b/Utilities/Utilities.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + \ No newline at end of file diff --git a/Utilities/stdafx.cpp b/Utilities/stdafx.cpp new file mode 100644 index 00000000..64004251 --- /dev/null +++ b/Utilities/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// Utilities.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/Utilities/stdafx.h b/Utilities/stdafx.h new file mode 100644 index 00000000..a36ca21b --- /dev/null +++ b/Utilities/stdafx.h @@ -0,0 +1,7 @@ +#pragma once + +#include "targetver.h" + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers + +#include diff --git a/Utilities/targetver.h b/Utilities/targetver.h new file mode 100644 index 00000000..87c0086d --- /dev/null +++ b/Utilities/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include