mirror of
https://github.com/SourMesen/Mesen.git
synced 2025-04-02 10:52:48 -04:00
GCC support - Fixed warnings/compilation errors (Core & Utilities now compile under GCC, but code is incomplete)
This commit is contained in:
parent
f3b3a8eed5
commit
5b565bfeeb
36 changed files with 234 additions and 74 deletions
|
@ -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<int quality,int range>
|
||||
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)) ); }
|
||||
|
|
|
@ -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
|
||||
};
|
|
@ -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));
|
||||
}
|
||||
|
|
17
Core/CPU.h
17
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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "CodeDataLogger.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);
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <thread>
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include "CPU.h"
|
||||
|
||||
class DisassemblyInfo;
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
#include "stdafx.h"
|
||||
|
||||
extern enum AddrMode;
|
||||
#include "CPU.h"
|
||||
|
||||
class DisassemblyInfo
|
||||
{
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include <thread>
|
||||
using std::thread;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include <thread>
|
||||
using std::thread;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include "MessageManager.h"
|
||||
#include "MapperFactory.h"
|
||||
|
|
|
@ -163,7 +163,7 @@ uint32_t MemoryManager::ToAbsoluteChrAddress(uint16_t vramAddr)
|
|||
void MemoryManager::StreamState(bool saving)
|
||||
{
|
||||
StreamArray<uint8_t>(_internalRAM, MemoryManager::InternalRAMSize);
|
||||
for(int i = 0; i < 4; i++) {
|
||||
for(int i = 0; i < 2; i++) {
|
||||
StreamArray<uint8_t>(_nametableRAM[i], MemoryManager::NameTableScreenSize);
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
#include "stdafx.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "MessageManager.h"
|
||||
|
||||
IMessageManager* MessageManager::_messageManager = nullptr;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <algorithm>
|
||||
#include "../Utilities/FolderUtilities.h"
|
||||
#include "../Utilities/ZIPReader.h"
|
||||
#include "../Utilities/CRC32.h"
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
class SquareChannel : public ApuEnvelope
|
||||
{
|
||||
private:
|
||||
const vector<const vector<uint8_t>> _dutySequences = { {
|
||||
const vector<vector<uint8_t>> _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 },
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include "VideoDecoder.h"
|
||||
#include "EmulationSettings.h"
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
#pragma once
|
||||
#include "stdafx.h"
|
||||
#include "VirtualController.h"
|
||||
#include "ControlManager.h"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <memory>
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#include "stdafx.h"
|
||||
#include <shlobj.h>
|
||||
#ifdef WIN32
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#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<string> FolderUtilities::GetFolders(string rootFolder)
|
||||
{
|
||||
vector<string> folders;
|
||||
#ifdef _WIN32
|
||||
#ifdef WIN32
|
||||
HANDLE hFind;
|
||||
WIN32_FIND_DATA data;
|
||||
|
||||
|
@ -117,11 +122,13 @@ vector<string> FolderUtilities::GetFolders(string rootFolder)
|
|||
|
||||
vector<string> FolderUtilities::GetFilesInFolder(string rootFolder, string mask, bool recursive)
|
||||
{
|
||||
vector<string> files;
|
||||
|
||||
#ifdef WIN32
|
||||
HANDLE hFind;
|
||||
WIN32_FIND_DATA data;
|
||||
|
||||
vector<string> folders;
|
||||
vector<string> files;
|
||||
if(rootFolder[rootFolder.size() - 1] != '/' && rootFolder[rootFolder.size() - 1] != '\\') {
|
||||
rootFolder += "/";
|
||||
}
|
||||
|
@ -143,6 +150,7 @@ vector<string> 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;
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
#include "stdafx.h"
|
||||
#include <assert.h>
|
||||
#include "SimpleLock.h"
|
||||
#include <Windows.h>
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#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;
|
||||
|
|
|
@ -8,6 +8,8 @@ private:
|
|||
uint32_t _lockCount;
|
||||
atomic_flag _lock;
|
||||
|
||||
uint32_t GetThreadId();
|
||||
|
||||
public:
|
||||
SimpleLock();
|
||||
~SimpleLock();
|
||||
|
|
|
@ -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 <winsock2.h>
|
||||
#include <Windows.h>
|
||||
#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> Socket::Accept()
|
||||
{
|
||||
return shared_ptr<Socket>(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
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
#include "stdafx.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#ifdef WIN32
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <time.h>
|
||||
#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);
|
||||
}
|
||||
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
|
|
@ -11,5 +11,4 @@ class Timer
|
|||
Timer();
|
||||
void Reset();
|
||||
double GetElapsedMS();
|
||||
uint32_t Timer::GetElapsedTicks();
|
||||
};
|
|
@ -1,8 +1,10 @@
|
|||
#include "stdafx.h"
|
||||
#include "UPnPPortMapper.h"
|
||||
|
||||
#ifdef WIN32
|
||||
#include <winsock2.h>
|
||||
#include <natupnp.h>
|
||||
#include <ws2tcpip.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
#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
|
|
@ -1,4 +1,5 @@
|
|||
#include "stdafx.h"
|
||||
#include <string.h>
|
||||
#include "ZIPReader.h"
|
||||
|
||||
ZIPReader::ZIPReader()
|
||||
|
|
Loading…
Add table
Reference in a new issue