From 5b565bfeeb976f15d505a16831bcc4d1d99e76a2 Mon Sep 17 00:00:00 2001 From: Souryo Date: Fri, 28 Aug 2015 21:01:18 -0400 Subject: [PATCH] GCC support - Fixed warnings/compilation errors (Core & Utilities now compile under GCC, but code is incomplete) --- BlipBuffer/Blip_Buffer.h | 12 +++-- Core/BaseMapper.h | 7 ++- Core/Breakpoint.h | 2 +- Core/CPU.h | 17 +++---- Core/CheatManager.cpp | 6 ++- Core/CodeDataLogger.cpp | 2 - Core/ControlManager.h | 2 +- Core/Debugger.cpp | 6 +-- Core/Disassembler.cpp | 1 - Core/Disassembler.h | 1 + Core/DisassemblyInfo.h | 3 +- Core/GameClient.cpp | 1 - Core/GameClientConnection.cpp | 11 +++-- Core/GameConnection.cpp | 7 ++- Core/GameConnection.h | 2 +- Core/GameServer.cpp | 1 - Core/GameServerConnection.cpp | 16 +++++-- Core/MMC5.h | 4 +- Core/MapperFactory.cpp | 1 - Core/MemoryManager.cpp | 2 +- Core/MessageManager.cpp | 1 + Core/Nanjing.h | 2 +- Core/PPU.cpp | 2 + Core/ROMLoader.h | 1 + Core/SquareChannel.h | 2 +- Core/VideoDecoder.cpp | 1 - Core/VirtualController.cpp | 1 - Core/stdafx.h | 2 +- Utilities/FolderUtilities.cpp | 19 ++++++-- Utilities/SimpleLock.cpp | 20 +++++++-- Utilities/SimpleLock.h | 2 + Utilities/Socket.cpp | 85 ++++++++++++++++++++++++++++++++++- Utilities/Timer.cpp | 39 +++++++++++++--- Utilities/Timer.h | 1 - Utilities/UPnPPortMapper.cpp | 25 +++++++++-- Utilities/ZIPReader.cpp | 1 + 36 files changed, 234 insertions(+), 74 deletions(-) diff --git a/BlipBuffer/Blip_Buffer.h b/BlipBuffer/Blip_Buffer.h index 8972bb7e..f961630b 100644 --- a/BlipBuffer/Blip_Buffer.h +++ b/BlipBuffer/Blip_Buffer.h @@ -3,6 +3,12 @@ // Blip_Buffer 0.4.0 +#if defined(_MSC_VER) + #define EXPORT __declspec(dllexport) +#else + #define EXPORT +#endif + #ifndef BLIP_BUFFER_H #define BLIP_BUFFER_H @@ -13,7 +19,7 @@ typedef long blip_time_t; typedef short blip_sample_t; enum { blip_sample_max = 32767 }; -class __declspec(dllexport) Blip_Buffer { +class EXPORT Blip_Buffer { public: typedef const char* blargg_err_t; @@ -133,7 +139,7 @@ private: int const blip_res = 1 << BLIP_PHASE_BITS; class blip_eq_t; - class __declspec(dllexport) Blip_Synth_ { + class EXPORT Blip_Synth_ { double volume_unit_; short* const impulses; int const width; @@ -159,7 +165,7 @@ const int blip_high_quality = 16; // by finding the difference between the maximum and minimum expected // amplitudes (max - min). template -class __declspec(dllexport) Blip_Synth { +class EXPORT Blip_Synth { public: // Set overall volume of waveform void volume( double v ) { impl.volume_unit( v * (1.0 / (range < 0 ? -range : range)) ); } diff --git a/Core/BaseMapper.h b/Core/BaseMapper.h index f30980c9..a3c225b8 100644 --- a/Core/BaseMapper.h +++ b/Core/BaseMapper.h @@ -335,6 +335,8 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat case ConsoleNotificationType::CheatRemoved: ApplyCheats(); break; + default: + break; } } @@ -452,8 +454,7 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat //Used by MMC3/MMC5/etc } - #pragma region Debugger Helper Functions - + //Debugger Helper Functions void GetPrgCopy(uint8_t **buffer) { *buffer = new uint8_t[_prgSize]; @@ -526,6 +527,4 @@ class BaseMapper : public IMemoryHandler, public Snapshotable, public INotificat return memoryRanges; } - - #pragma endregion }; \ No newline at end of file diff --git a/Core/Breakpoint.h b/Core/Breakpoint.h index ef80ec31..04746f0d 100644 --- a/Core/Breakpoint.h +++ b/Core/Breakpoint.h @@ -14,7 +14,7 @@ public: Breakpoint(BreakpointType type, uint32_t addr, bool isAbsoluteAddr); ~Breakpoint(); - bool Breakpoint::Matches(uint32_t memoryAddr, uint32_t absoluteAddr) + bool Matches(uint32_t memoryAddr, uint32_t absoluteAddr) { return _enabled && ((memoryAddr == _addr && !_isAbsoluteAddr) || (absoluteAddr == _addr && _isAbsoluteAddr)); } diff --git a/Core/CPU.h b/Core/CPU.h index d8c42a06..ccc96975 100644 --- a/Core/CPU.h +++ b/Core/CPU.h @@ -227,6 +227,7 @@ private: case AddrMode::AbsXW: return GetAbsXAddr(true); case AddrMode::AbsY: return GetAbsYAddr(false); case AddrMode::AbsYW: return GetAbsYAddr(true); + default: break; } throw std::runtime_error("invalid addressing mode"); } @@ -503,7 +504,7 @@ private: } } - #pragma region OP Codes + //OP Codes void LDA() { SetA(GetOperandValue()); } void LDX() { SetX(GetOperandValue()); } void LDY() { SetY(GetOperandValue()); } @@ -654,10 +655,8 @@ private: GetOperandValue(); } - #pragma endregion - - #pragma region Unofficial OpCodes - + + //Unofficial OpCodes void SLO() { //ASL & ORA @@ -787,10 +786,8 @@ private: SetX(value); } - #pragma endregion - - #pragma region Unimplemented/Incorrect Unofficial OP codes - + + //Unimplemented/Incorrect Unofficial OP codes void HLT() { //normally freezes the cpu, we can probably assume nothing will ever call this @@ -831,8 +828,6 @@ private: SetSP(A()); } - #pragma endregion - protected: void StreamState(bool saving); diff --git a/Core/CheatManager.cpp b/Core/CheatManager.cpp index 88e69b38..66dfda0a 100644 --- a/Core/CheatManager.cpp +++ b/Core/CheatManager.cpp @@ -97,12 +97,14 @@ void CheatManager::AddCode(CodeInfo &code) void CheatManager::AddGameGenieCode(string code) { - Instance->AddCode(Instance->GetGGCodeInfo(code)); + CodeInfo info = Instance->GetGGCodeInfo(code); + Instance->AddCode(info); } void CheatManager::AddProActionRockyCode(uint32_t code) { - Instance->AddCode(Instance->GetPARCodeInfo(code)); + CodeInfo info = Instance->GetPARCodeInfo(code); + Instance->AddCode(info); } void CheatManager::AddCustomCode(uint32_t address, uint8_t value, int32_t compareValue, bool isRelativeAddress) diff --git a/Core/CodeDataLogger.cpp b/Core/CodeDataLogger.cpp index 8d8d9268..2941cc17 100644 --- a/Core/CodeDataLogger.cpp +++ b/Core/CodeDataLogger.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include "CodeDataLogger.h" diff --git a/Core/ControlManager.h b/Core/ControlManager.h index b7ad0ffc..66776072 100644 --- a/Core/ControlManager.h +++ b/Core/ControlManager.h @@ -23,7 +23,7 @@ class ControlManager : public Snapshotable, public IMemoryHandler void RefreshAllPorts(); uint8_t GetControllerState(uint8_t port); - bool ControlManager::HasFourScoreAdapter(); + bool HasFourScoreAdapter(); void RefreshStateBuffer(uint8_t port); uint8_t GetPortValue(uint8_t port); diff --git a/Core/Debugger.cpp b/Core/Debugger.cpp index 7ebef74d..05dc70bc 100644 --- a/Core/Debugger.cpp +++ b/Core/Debugger.cpp @@ -1,5 +1,3 @@ -#pragma once - #include "stdafx.h" #include #include "MessageManager.h" @@ -168,7 +166,7 @@ void Debugger::ProcessStepConditions(uint32_t addr) if(_stepOut && _lastInstruction == 0x60) { //RTS found, set StepCount to 2 to break on the following instruction Step(2); - } else if(_stepOverAddr != -1 && addr == _stepOverAddr) { + } else if(_stepOverAddr != -1 && addr == (uint32_t)_stepOverAddr) { Step(1); } else if(_stepCycleCount != -1 && abs(_cpu->GetCycleCount() - _stepCycleCount) < 100 && _cpu->GetCycleCount() >= _stepCycleCount) { Step(1); @@ -181,6 +179,8 @@ void Debugger::BreakOnBreakpoint(MemoryOperationType type, uint32_t addr) switch(type) { case MemoryOperationType::Read: breakpointType = BreakpointType::Read; break; case MemoryOperationType::Write: breakpointType = BreakpointType::Write; break; + + default: case MemoryOperationType::ExecOpCode: case MemoryOperationType::ExecOperand: breakpointType = BreakpointType::Execute; break; } diff --git a/Core/Disassembler.cpp b/Core/Disassembler.cpp index af045fa4..1e45cc9c 100644 --- a/Core/Disassembler.cpp +++ b/Core/Disassembler.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include "Disassembler.h" #include "DisassemblyInfo.h" -#include "CPU.h" Disassembler::Disassembler(uint8_t* internalRAM, uint8_t* prgROM, uint32_t prgSize) { diff --git a/Core/Disassembler.h b/Core/Disassembler.h index 3a8361ef..7113dd8a 100644 --- a/Core/Disassembler.h +++ b/Core/Disassembler.h @@ -1,5 +1,6 @@ #pragma once #include "stdafx.h" +#include "CPU.h" class DisassemblyInfo; diff --git a/Core/DisassemblyInfo.h b/Core/DisassemblyInfo.h index 6a7b57ad..4d4edc0c 100644 --- a/Core/DisassemblyInfo.h +++ b/Core/DisassemblyInfo.h @@ -1,7 +1,6 @@ #pragma once #include "stdafx.h" - -extern enum AddrMode; +#include "CPU.h" class DisassemblyInfo { diff --git a/Core/GameClient.cpp b/Core/GameClient.cpp index 105fb1df..7758259e 100644 --- a/Core/GameClient.cpp +++ b/Core/GameClient.cpp @@ -1,4 +1,3 @@ -#pragma once #include "stdafx.h" #include using std::thread; diff --git a/Core/GameClientConnection.cpp b/Core/GameClientConnection.cpp index 7d738d39..d415ac6d 100644 --- a/Core/GameClientConnection.cpp +++ b/Core/GameClientConnection.cpp @@ -1,4 +1,3 @@ -#pragma once #include "stdafx.h" #include "GameClientConnection.h" #include "HandShakeMessage.h" @@ -31,7 +30,8 @@ GameClientConnection::~GameClientConnection() void GameClientConnection::SendHandshake() { - SendNetMessage(HandShakeMessage(_connectionData->PlayerName, _connectionData->AvatarData, _connectionData->AvatarSize)); + HandShakeMessage message(_connectionData->PlayerName, _connectionData->AvatarData, _connectionData->AvatarSize); + SendNetMessage(message); } void GameClientConnection::InitializeVirtualControllers() @@ -78,7 +78,7 @@ void GameClientConnection::ProcessMessage(NetMessage* message) gameInfo = (GameInformationMessage*)message; if(gameInfo->GetPort() != _controllerPort) { _controllerPort = gameInfo->GetPort(); - MessageManager::DisplayMessage(string("Connected as player ") + std::to_string(_controllerPort + 1)); + MessageManager::DisplayMessage("Net Play", string("Connected as player ") + std::to_string(_controllerPort + 1)); } DisposeVirtualControllers(); @@ -90,6 +90,8 @@ void GameClientConnection::ProcessMessage(NetMessage* message) EmulationSettings::ClearFlags(EmulationFlags::Paused); } + break; + default: break; } } @@ -99,7 +101,8 @@ void GameClientConnection::SendInput() if(_gameLoaded) { uint8_t inputState = _controlDevice->GetButtonState().ToByte(); if(_lastInputSent != inputState) { - SendNetMessage(InputDataMessage(inputState)); + InputDataMessage message(inputState); + SendNetMessage(message); _lastInputSent = inputState; } } diff --git a/Core/GameConnection.cpp b/Core/GameConnection.cpp index 7d1eabeb..cb9a92d2 100644 --- a/Core/GameConnection.cpp +++ b/Core/GameConnection.cpp @@ -1,4 +1,3 @@ -#pragma once #include "stdafx.h" #include "GameConnection.h" #include "HandShakeMessage.h" @@ -22,9 +21,9 @@ void GameConnection::ReadSocket() } } -bool GameConnection::ExtractMessage(char *buffer, uint32_t &messageLength) +bool GameConnection::ExtractMessage(void *buffer, uint32_t &messageLength) { - messageLength = *(uint32_t*)_readBuffer; + messageLength = _readBuffer[0] | (_readBuffer[1] << 8) | (_readBuffer[2] << 16) | (_readBuffer[3] << 24); if(messageLength > 100000) { std::cout << "Invalid data received, closing connection" << std::endl; @@ -75,7 +74,7 @@ bool GameConnection::ConnectionError() void GameConnection::ProcessMessages() { NetMessage* message; - while(message = ReadMessage()) { + while((message = ReadMessage()) != nullptr) { //Loop until all messages have been processed message->Initialize(); ProcessMessage(message); diff --git a/Core/GameConnection.h b/Core/GameConnection.h index 7e2493b4..08b5080b 100644 --- a/Core/GameConnection.h +++ b/Core/GameConnection.h @@ -19,7 +19,7 @@ protected: private: void ReadSocket(); - bool ExtractMessage(char *buffer, uint32_t &messageLength); + bool ExtractMessage(void *buffer, uint32_t &messageLength); NetMessage* ReadMessage(); virtual void ProcessMessage(NetMessage* message) = 0; diff --git a/Core/GameServer.cpp b/Core/GameServer.cpp index 54a8b769..1ab9fad9 100644 --- a/Core/GameServer.cpp +++ b/Core/GameServer.cpp @@ -1,4 +1,3 @@ -#pragma once #include "stdafx.h" #include using std::thread; diff --git a/Core/GameServerConnection.cpp b/Core/GameServerConnection.cpp index 8e3d8489..e6627a67 100644 --- a/Core/GameServerConnection.cpp +++ b/Core/GameServerConnection.cpp @@ -1,4 +1,3 @@ -#pragma once #include "stdafx.h" #include "MessageManager.h" #include "GameServerConnection.h" @@ -49,19 +48,22 @@ void GameServerConnection::SendGameState() char* buffer = new char[size]; state.read(buffer, size); - SendNetMessage(SaveStateMessage(buffer, size, true)); + SaveStateMessage message(buffer, size, true); + SendNetMessage(message); delete[] buffer; } void GameServerConnection::SendGameInformation() { - SendNetMessage(GameInformationMessage(Console::GetROMPath(), _controllerPort, EmulationSettings::CheckFlag(EmulationFlags::Paused))); + GameInformationMessage message(Console::GetROMPath(), _controllerPort, EmulationSettings::CheckFlag(EmulationFlags::Paused)); + SendNetMessage(message); } void GameServerConnection::SendMovieData(uint8_t state, uint8_t port) { if(_handshakeCompleted) { - SendNetMessage(MovieDataMessage(state, port)); + MovieDataMessage message(state, port); + SendNetMessage(message); } } @@ -95,11 +97,15 @@ void GameServerConnection::ProcessMessage(NetMessage* message) } break; case MessageType::InputData: + { uint8_t state = ((InputDataMessage*)message)->GetInputState(); if(_inputData.size() == 0 || state != _inputData.back()) { _inputData.push_back(state); } break; + } + default: + break; } } @@ -115,5 +121,7 @@ void GameServerConnection::ProcessNotification(ConsoleNotificationType type) SendGameInformation(); SendGameState(); break; + default: + break; } } \ No newline at end of file diff --git a/Core/MMC5.h b/Core/MMC5.h index 8aa09c75..f1580cbc 100644 --- a/Core/MMC5.h +++ b/Core/MMC5.h @@ -134,7 +134,7 @@ private: _spriteFetch = IsSpriteFetch(); _largeSprites = PPU::GetControlFlags().LargeSprites; - bool chrA = forceA || _largeSprites && _spriteFetch || !_largeSprites && _lastChrReg <= 0x5127; + bool chrA = forceA || (_largeSprites && _spriteFetch) || (!_largeSprites && _lastChrReg <= 0x5127); if(_chrMode == 0) { SetPpuMemoryMapping(0x0000, 0x1FFF, _chrBanks[chrA ? 0x07 : 0x0B] << 3); } else if(_chrMode == 1) { @@ -346,7 +346,7 @@ protected: uint8_t value = InternalReadRam(0x5C00 + _exAttributeLastNametableFetch); //"The pattern fetches ignore the standard CHR banking bits, and instead use the top two bits of $5130 and the bottom 6 bits from Expansion RAM to choose a 4KB bank to select the tile from." - _exAttrSelectedChrBank = (value & 0x3F | (_chrUpperBits << 6)) % (_chrSize / 0x1000); + _exAttrSelectedChrBank = ((value & 0x3F) | (_chrUpperBits << 6)) % (_chrSize / 0x1000); //Return a byte containing the same palette 4 times - this allows the PPU to select the right palette no matter the shift value uint8_t palette = (value & 0xC0) >> 6; diff --git a/Core/MapperFactory.cpp b/Core/MapperFactory.cpp index 0c0f2bb6..f7c142d2 100644 --- a/Core/MapperFactory.cpp +++ b/Core/MapperFactory.cpp @@ -1,4 +1,3 @@ -#pragma once #include "stdafx.h" #include "MessageManager.h" #include "MapperFactory.h" diff --git a/Core/MemoryManager.cpp b/Core/MemoryManager.cpp index 08f4c8f0..adb5f267 100644 --- a/Core/MemoryManager.cpp +++ b/Core/MemoryManager.cpp @@ -163,7 +163,7 @@ uint32_t MemoryManager::ToAbsoluteChrAddress(uint16_t vramAddr) void MemoryManager::StreamState(bool saving) { StreamArray(_internalRAM, MemoryManager::InternalRAMSize); - for(int i = 0; i < 4; i++) { + for(int i = 0; i < 2; i++) { StreamArray(_nametableRAM[i], MemoryManager::NameTableScreenSize); } } \ No newline at end of file diff --git a/Core/MessageManager.cpp b/Core/MessageManager.cpp index 645781aa..217949cc 100644 --- a/Core/MessageManager.cpp +++ b/Core/MessageManager.cpp @@ -1,5 +1,6 @@ #include "stdafx.h" +#include #include "MessageManager.h" IMessageManager* MessageManager::_messageManager = nullptr; diff --git a/Core/Nanjing.h b/Core/Nanjing.h index 27c1f523..c57f6812 100644 --- a/Core/Nanjing.h +++ b/Core/Nanjing.h @@ -12,7 +12,7 @@ private: void UpdateState() { - uint8_t prgPage = _registers[0] & 0x0F | ((_registers[2] & 0x0F) << 4); + uint8_t prgPage = (_registers[0] & 0x0F) | ((_registers[2] & 0x0F) << 4); _autoSwitchCHR = (_registers[0] & 0x80) == 0x80; diff --git a/Core/PPU.cpp b/Core/PPU.cpp index 1b270d29..ed4d39a8 100644 --- a/Core/PPU.cpp +++ b/Core/PPU.cpp @@ -151,6 +151,8 @@ void PPU::WriteRAM(uint16_t addr, uint8_t value) case PPURegisters::SpriteDMA: CPU::RunDMATransfer(_spriteRAM, _state.SpriteRamAddr, value); break; + default: + break; } } diff --git a/Core/ROMLoader.h b/Core/ROMLoader.h index 2a05bd99..31ed921c 100644 --- a/Core/ROMLoader.h +++ b/Core/ROMLoader.h @@ -1,6 +1,7 @@ #pragma once #include "stdafx.h" +#include #include "../Utilities/FolderUtilities.h" #include "../Utilities/ZIPReader.h" #include "../Utilities/CRC32.h" diff --git a/Core/SquareChannel.h b/Core/SquareChannel.h index f02451f2..cb935b54 100644 --- a/Core/SquareChannel.h +++ b/Core/SquareChannel.h @@ -8,7 +8,7 @@ class SquareChannel : public ApuEnvelope { private: - const vector> _dutySequences = { { + const vector> _dutySequences = { { { 0, 1, 0, 0, 0, 0, 0, 0 }, { 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 1, 1, 1, 1, 0, 0, 0 }, diff --git a/Core/VideoDecoder.cpp b/Core/VideoDecoder.cpp index 04b6e327..a5421660 100644 --- a/Core/VideoDecoder.cpp +++ b/Core/VideoDecoder.cpp @@ -1,4 +1,3 @@ -#pragma once #include "stdafx.h" #include "VideoDecoder.h" #include "EmulationSettings.h" diff --git a/Core/VirtualController.cpp b/Core/VirtualController.cpp index 6f11fbbc..1c808820 100644 --- a/Core/VirtualController.cpp +++ b/Core/VirtualController.cpp @@ -1,4 +1,3 @@ -#pragma once #include "stdafx.h" #include "VirtualController.h" #include "ControlManager.h" diff --git a/Core/stdafx.h b/Core/stdafx.h index a8f3618f..1445e124 100644 --- a/Core/stdafx.h +++ b/Core/stdafx.h @@ -1,7 +1,7 @@ #pragma once #include - +#include #include #include diff --git a/Utilities/FolderUtilities.cpp b/Utilities/FolderUtilities.cpp index 5ff160c1..06237a36 100644 --- a/Utilities/FolderUtilities.cpp +++ b/Utilities/FolderUtilities.cpp @@ -1,5 +1,8 @@ #include "stdafx.h" -#include +#ifdef WIN32 + #include +#endif + #include #include "FolderUtilities.h" #include "UTF8Util.h" @@ -16,7 +19,7 @@ void FolderUtilities::SetHomeFolder(string homeFolder) string FolderUtilities::GetHomeFolder() { if(_homeFolder.size() == 0) { - throw std::exception("Home folder not specified"); + throw std::runtime_error("Home folder not specified"); } return _homeFolder; } @@ -86,13 +89,15 @@ string FolderUtilities::GetScreenshotFolder() void FolderUtilities::CreateFolder(string folder) { +#ifdef WIN32 CreateDirectory(utf8::utf8::decode(folder).c_str(), nullptr); +#endif } vector FolderUtilities::GetFolders(string rootFolder) { vector folders; -#ifdef _WIN32 +#ifdef WIN32 HANDLE hFind; WIN32_FIND_DATA data; @@ -117,11 +122,13 @@ vector FolderUtilities::GetFolders(string rootFolder) vector FolderUtilities::GetFilesInFolder(string rootFolder, string mask, bool recursive) { + vector files; + +#ifdef WIN32 HANDLE hFind; WIN32_FIND_DATA data; vector folders; - vector files; if(rootFolder[rootFolder.size() - 1] != '/' && rootFolder[rootFolder.size() - 1] != '\\') { rootFolder += "/"; } @@ -143,6 +150,7 @@ vector FolderUtilities::GetFilesInFolder(string rootFolder, string mask, FindClose(hFind); } } +#endif return files; } @@ -180,7 +188,10 @@ string FolderUtilities::CombinePath(string folder, string filename) int64_t FolderUtilities::GetFileModificationTime(string filepath) { +#ifdef WIN32 WIN32_FILE_ATTRIBUTE_DATA fileAttrData = {0}; GetFileAttributesEx(utf8::utf8::decode(filepath).c_str(), GetFileExInfoStandard, &fileAttrData); return ((int64_t)fileAttrData.ftLastWriteTime.dwHighDateTime << 32) | (int64_t)fileAttrData.ftLastWriteTime.dwLowDateTime; +#endif + return 0; } \ No newline at end of file diff --git a/Utilities/SimpleLock.cpp b/Utilities/SimpleLock.cpp index 217530f0..21a0338d 100644 --- a/Utilities/SimpleLock.cpp +++ b/Utilities/SimpleLock.cpp @@ -1,6 +1,9 @@ #include "stdafx.h" +#include #include "SimpleLock.h" -#include +#ifdef WIN32 + #include +#endif SimpleLock::SimpleLock() { @@ -13,11 +16,20 @@ SimpleLock::~SimpleLock() { } +uint32_t SimpleLock::GetThreadId() +{ +#ifdef WIN32 + return GetCurrentThreadId(); +#elif + return std::thread::id; +#endif +} + void SimpleLock::Acquire() { - if(_lockCount == 0 || _holderThreadID != GetCurrentThreadId()) { + if(_lockCount == 0 || _holderThreadID != GetThreadId()) { while(_lock.test_and_set()); - _holderThreadID = GetCurrentThreadId(); + _holderThreadID = GetThreadId(); _lockCount = 1; } else { //Same thread can acquire the same lock multiple times @@ -43,7 +55,7 @@ void SimpleLock::WaitForRelease() void SimpleLock::Release() { - if(_lockCount > 0 && _holderThreadID == GetCurrentThreadId()) { + if(_lockCount > 0 && _holderThreadID == GetThreadId()) { _lockCount--; if(_lockCount == 0) { _holderThreadID = ~0; diff --git a/Utilities/SimpleLock.h b/Utilities/SimpleLock.h index 58623e5d..78d836d4 100644 --- a/Utilities/SimpleLock.h +++ b/Utilities/SimpleLock.h @@ -8,6 +8,8 @@ private: uint32_t _lockCount; atomic_flag _lock; + uint32_t GetThreadId(); + public: SimpleLock(); ~SimpleLock(); diff --git a/Utilities/Socket.cpp b/Utilities/Socket.cpp index eea17d14..dba17aa3 100644 --- a/Utilities/Socket.cpp +++ b/Utilities/Socket.cpp @@ -1,11 +1,12 @@ #include "stdafx.h" +#include "UPnPPortMapper.h" +#include "Socket.h" +#ifdef WIN32 #pragma comment(lib,"ws2_32.lib") //Winsock Library #define WIN32_LEAN_AND_MEAN #include #include -#include "UPnPPortMapper.h" -#include "Socket.h" Socket::Socket() { @@ -221,3 +222,83 @@ int Socket::Recv(char *buf, int len, int flags) return returnVal; } + +#else + +Socket::Socket() +{ + +} + +Socket::Socket(uintptr_t socket) +{ + +} + +Socket::~Socket() +{ + +} + +void Socket::SetSocketOptions() +{ + +} + +void Socket::SetConnectionErrorFlag() +{ + +} + +void Socket::Close() +{ + +} + +bool Socket::ConnectionError() +{ + return true; +} + +void Socket::Bind(uint16_t port) +{ + +} + +bool Socket::Connect(const char* hostname, uint16_t port) +{ + return false; +} + +void Socket::Listen(int backlog) +{ + +} + +shared_ptr Socket::Accept() +{ + return shared_ptr(new Socket()); +} + +int Socket::Send(char *buf, int len, int flags) +{ + return len; +} + +void Socket::BufferedSend(char *buf, int len) +{ + +} + +void Socket::SendBuffer() +{ + +} + +int Socket::Recv(char *buf, int len, int flags) +{ + return len; +} + + +#endif diff --git a/Utilities/Timer.cpp b/Utilities/Timer.cpp index dc890241..4c3596e6 100644 --- a/Utilities/Timer.cpp +++ b/Utilities/Timer.cpp @@ -1,8 +1,15 @@ #include "stdafx.h" -#include +#ifdef WIN32 + #include +#else + #include +#endif + #include "Timer.h" +#ifdef WIN32 + Timer::Timer() { LARGE_INTEGER li; @@ -30,9 +37,29 @@ double Timer::GetElapsedMS() return double(li.QuadPart - _start) / _frequency; } -uint32_t Timer::GetElapsedTicks() +#else + +Timer::Timer() { - LARGE_INTEGER li; - QueryPerformanceCounter(&li); - return uint32_t(li.QuadPart - _start); -} \ No newline at end of file + Reset(); +} + +void Timer::Reset() +{ + timespec start; + clock_gettime(CLOCK_MONOTONIC, &start); + + _start = start.tv_sec * 1000000000 + start.tv_nsec; +} + +double Timer::GetElapsedMS() +{ + timespec end; + clock_gettime(CLOCK_MONOTONIC, &end); + + uint64_t currentTime = end.tv_sec * 1000000000 + end.tv_nsec; + + return (double)(currentTime - _start) / 1000000.0; +} + +#endif \ No newline at end of file diff --git a/Utilities/Timer.h b/Utilities/Timer.h index c8433485..76873d14 100644 --- a/Utilities/Timer.h +++ b/Utilities/Timer.h @@ -11,5 +11,4 @@ class Timer Timer(); void Reset(); double GetElapsedMS(); - uint32_t Timer::GetElapsedTicks(); }; \ No newline at end of file diff --git a/Utilities/UPnPPortMapper.cpp b/Utilities/UPnPPortMapper.cpp index 37daacdd..e2a7dd2a 100644 --- a/Utilities/UPnPPortMapper.cpp +++ b/Utilities/UPnPPortMapper.cpp @@ -1,8 +1,10 @@ #include "stdafx.h" +#include "UPnPPortMapper.h" + +#ifdef WIN32 #include #include #include -#include "UPnPPortMapper.h" bool UPnPPortMapper::AddNATPortMapping(uint16_t internalPort, uint16_t externalPort, IPProtocol protocol) { @@ -34,7 +36,7 @@ bool UPnPPortMapper::AddNATPortMapping(uint16_t internalPort, uint16_t externalP std::cout << "Attempting to automatically forward port via UPnP..." << std::endl; wstring localIP = GetLocalIP(); - BSTR desc = SysAllocString(L"NESEmu for NetPlay"); + BSTR desc = SysAllocString(L"Mesen NetPlay"); BSTR clientStr = SysAllocString(localIP.c_str()); hResult = spmc->Add(externalPort, proto, internalPort, clientStr, true, desc, &spm); SysFreeString(clientStr); @@ -123,4 +125,21 @@ wstring UPnPPortMapper::GetLocalIP() return localIP; } - \ No newline at end of file +#else + +bool UPnPPortMapper::AddNATPortMapping(uint16_t internalPort, uint16_t externalPort, IPProtocol protocol) +{ + return false; +} + +bool UPnPPortMapper::RemoveNATPortMapping(uint16_t externalPort, IPProtocol protocol) +{ + return false; +} + +wstring UPnPPortMapper::GetLocalIP() +{ + return L""; +} + +#endif \ No newline at end of file diff --git a/Utilities/ZIPReader.cpp b/Utilities/ZIPReader.cpp index 3965e541..febd73a9 100644 --- a/Utilities/ZIPReader.cpp +++ b/Utilities/ZIPReader.cpp @@ -1,4 +1,5 @@ #include "stdafx.h" +#include #include "ZIPReader.h" ZIPReader::ZIPReader()