Minor refactoring

This commit is contained in:
Souryo 2014-06-23 19:02:09 -04:00
parent 93a0e12fdb
commit 1783578522
19 changed files with 191 additions and 89 deletions

View file

@ -1,6 +1,5 @@
#include "stdafx.h"
#include "CPU.h"
#include "Timer.h"
uint64_t CPU::CycleCount = 0;
uint32_t CPU::CyclePenalty = 0;

View file

@ -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;

View file

@ -124,7 +124,6 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="Timer.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View file

@ -95,9 +95,6 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Timer.h">
<Filter>Header Files</Filter>
</ClCompile>
<ClCompile Include="CPU.cpp">
<Filter>Source Files</Filter>
</ClCompile>

View file

@ -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;
}
};

View file

@ -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 <array>
#include <sstream>
#include <atomic>
#include <windows.h>
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;

View file

@ -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<int, std::milli>(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();
}
}

View file

@ -11,8 +11,8 @@ namespace NES {
HINSTANCE _hInstance;
HWND _hWnd;
int _nCmdShow;
Renderer _renderer;
SoundManager _soundManager;
unique_ptr<Renderer> _renderer;
unique_ptr<SoundManager> _soundManager;
unique_ptr<Console> _console;
unique_ptr<thread> _emuThread;
wstring _currentROM;
@ -45,8 +45,6 @@ namespace NES {
void InitializeOptions();
public:
MainWindow(HINSTANCE hInstance, int nCmdShow) : _hInstance(hInstance), _nCmdShow(nCmdShow)
{

View file

@ -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;

View file

@ -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();

View file

@ -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;

View file

@ -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();

View file

@ -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

View file

@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{B5330148-E8C7-46BA-B54E-69BE59EA337D}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>Utilities</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
<ClInclude Include="Timer.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Timer.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="stdafx.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

8
Utilities/stdafx.cpp Normal file
View file

@ -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

7
Utilities/stdafx.h Normal file
View file

@ -0,0 +1,7 @@
#pragma once
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>

8
Utilities/targetver.h Normal file
View file

@ -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 <SDKDDKVer.h>