2015-07-02 03:17:14 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include "../Core/MessageManager.h"
|
|
|
|
#include "../Core/Console.h"
|
|
|
|
#include "../Windows/Renderer.h"
|
|
|
|
#include "../Windows/SoundManager.h"
|
2015-07-11 01:07:24 +00:00
|
|
|
#include "../Windows/WindowsKeyManager.h"
|
2015-07-02 03:17:14 +00:00
|
|
|
#include "../Core/GameServer.h"
|
|
|
|
#include "../Core/GameClient.h"
|
|
|
|
#include "../Core/ClientConnectionData.h"
|
|
|
|
#include "../Core/SaveStateManager.h"
|
2015-07-05 23:05:33 +00:00
|
|
|
#include "../Core/CheatManager.h"
|
2015-07-11 01:07:24 +00:00
|
|
|
#include "../Core/StandardController.h"
|
2015-07-18 00:58:57 +00:00
|
|
|
#include "../Core/EmulationSettings.h"
|
2015-07-24 03:16:31 +00:00
|
|
|
#include "../Core/VideoDecoder.h"
|
2015-07-02 03:17:14 +00:00
|
|
|
|
|
|
|
static NES::Renderer *_renderer = nullptr;
|
|
|
|
static SoundManager *_soundManager = nullptr;
|
2015-07-11 01:07:24 +00:00
|
|
|
static vector<shared_ptr<StandardController>> _inputDevices;
|
2015-07-02 03:17:14 +00:00
|
|
|
static HWND _windowHandle = nullptr;
|
|
|
|
static HWND _viewerHandle = nullptr;
|
2015-07-11 12:27:22 +00:00
|
|
|
static string _returnString;
|
2015-07-02 03:17:14 +00:00
|
|
|
|
|
|
|
typedef void (__stdcall *NotificationListenerCallback)(int);
|
|
|
|
|
|
|
|
namespace InteropEmu {
|
|
|
|
class InteropNotificationListener : public INotificationListener
|
|
|
|
{
|
|
|
|
NotificationListenerCallback _callback;
|
|
|
|
public:
|
|
|
|
InteropNotificationListener(NotificationListenerCallback callback)
|
|
|
|
{
|
|
|
|
_callback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProcessNotification(ConsoleNotificationType type)
|
|
|
|
{
|
|
|
|
_callback((int)type);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
extern "C" {
|
2015-07-11 12:27:22 +00:00
|
|
|
DllExport void __stdcall InitializeEmu(char* homeFolder, HWND windowHandle, HWND dxViewerHandle)
|
2015-07-02 03:17:14 +00:00
|
|
|
{
|
2015-07-05 23:21:49 +00:00
|
|
|
FolderUtilities::SetHomeFolder(homeFolder);
|
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
_windowHandle = windowHandle;
|
|
|
|
_viewerHandle = dxViewerHandle;
|
|
|
|
|
|
|
|
_renderer = new NES::Renderer(_viewerHandle);
|
|
|
|
_soundManager = new SoundManager(_windowHandle);
|
2015-07-11 01:07:24 +00:00
|
|
|
|
|
|
|
ControlManager::RegisterKeyManager(new WindowsKeyManager(_windowHandle));
|
|
|
|
|
|
|
|
for(int i = 0; i < 4; i++) {
|
|
|
|
_inputDevices.push_back(shared_ptr<StandardController>(new StandardController(i)));
|
|
|
|
}
|
2015-07-02 03:17:14 +00:00
|
|
|
}
|
|
|
|
|
2015-07-11 12:27:22 +00:00
|
|
|
DllExport void __stdcall LoadROM(char* filename) { Console::LoadROM(filename); }
|
|
|
|
DllExport void __stdcall AddKnowGameFolder(char* folder) { FolderUtilities::AddKnowGameFolder(folder); }
|
2015-07-06 02:23:44 +00:00
|
|
|
|
2015-07-11 01:07:24 +00:00
|
|
|
DllExport void __stdcall AddKeyMappings(uint32_t port, KeyMapping mapping) { _inputDevices[port]->AddKeyMappings(mapping); }
|
|
|
|
DllExport void __stdcall ClearKeyMappings(uint32_t port) { _inputDevices[port]->ClearKeyMappings(); }
|
|
|
|
|
|
|
|
DllExport uint32_t __stdcall GetPressedKey() { return ControlManager::GetPressedKey(); }
|
2015-07-11 12:27:22 +00:00
|
|
|
DllExport const char* __stdcall GetKeyName(uint32_t keyCode)
|
|
|
|
{
|
|
|
|
_returnString = ControlManager::GetKeyName(keyCode);
|
|
|
|
return _returnString.c_str();
|
|
|
|
}
|
|
|
|
DllExport uint32_t __stdcall GetKeyCode(char* keyName) { return ControlManager::GetKeyCode(keyName); }
|
2015-07-11 01:07:24 +00:00
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
DllExport void __stdcall Run()
|
|
|
|
{
|
|
|
|
if(Console::GetInstance()) {
|
|
|
|
Console::GetInstance()->Run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-18 00:58:57 +00:00
|
|
|
DllExport void __stdcall Resume() { EmulationSettings::ClearFlags(EmulationFlags::Paused); }
|
|
|
|
DllExport int __stdcall IsPaused() { return EmulationSettings::CheckFlag(EmulationFlags::Paused); }
|
2015-07-02 03:17:14 +00:00
|
|
|
DllExport void __stdcall Stop()
|
|
|
|
{
|
|
|
|
if(Console::GetInstance()) {
|
|
|
|
Console::GetInstance()->Stop();
|
|
|
|
}
|
|
|
|
}
|
2015-07-11 12:27:22 +00:00
|
|
|
DllExport const char* __stdcall GetROMPath()
|
2015-07-05 23:05:33 +00:00
|
|
|
{
|
2015-07-11 12:27:22 +00:00
|
|
|
_returnString = Console::GetROMPath();
|
|
|
|
return _returnString.c_str();
|
2015-07-05 23:05:33 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
DllExport void __stdcall Reset() { Console::Reset(); }
|
|
|
|
|
|
|
|
DllExport void __stdcall StartServer(uint16_t port) { GameServer::StartServer(port); }
|
|
|
|
DllExport void __stdcall StopServer() { GameServer::StopServer(); }
|
|
|
|
DllExport int __stdcall IsServerRunning() { return GameServer::Started(); }
|
|
|
|
|
2015-07-11 12:27:22 +00:00
|
|
|
DllExport void __stdcall Connect(char* host, uint16_t port, char* playerName, uint8_t* avatarData, uint32_t avatarSize)
|
2015-07-02 03:17:14 +00:00
|
|
|
{
|
|
|
|
shared_ptr<ClientConnectionData> connectionData(new ClientConnectionData(
|
|
|
|
host,
|
|
|
|
port,
|
|
|
|
playerName,
|
|
|
|
avatarData,
|
|
|
|
avatarSize
|
|
|
|
));
|
|
|
|
|
|
|
|
GameClient::Connect(connectionData);
|
|
|
|
}
|
|
|
|
|
|
|
|
DllExport void __stdcall Disconnect() { GameClient::Disconnect(); }
|
|
|
|
DllExport int __stdcall IsConnected() { return GameClient::Connected(); }
|
|
|
|
|
|
|
|
DllExport void __stdcall Pause()
|
|
|
|
{
|
|
|
|
if(!IsConnected()) {
|
2015-07-18 00:58:57 +00:00
|
|
|
EmulationSettings::SetFlags(EmulationFlags::Paused);
|
2015-07-02 03:17:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DllExport void __stdcall Release()
|
|
|
|
{
|
2015-07-21 03:20:41 +00:00
|
|
|
Console::Release();
|
2015-07-02 03:17:14 +00:00
|
|
|
GameServer::StopServer();
|
|
|
|
GameClient::Disconnect();
|
|
|
|
MessageManager::RegisterMessageManager(nullptr);
|
|
|
|
delete _renderer;
|
|
|
|
delete _soundManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
DllExport void __stdcall Render() { _renderer->Render(); }
|
2015-07-24 03:16:31 +00:00
|
|
|
DllExport void __stdcall TakeScreenshot() { VideoDecoder::GetInstance()->TakeScreenshot(FolderUtilities::GetFilename(Console::GetROMPath(), false)); }
|
2015-07-02 03:17:14 +00:00
|
|
|
|
|
|
|
DllExport INotificationListener* __stdcall RegisterNotificationCallback(NotificationListenerCallback callback)
|
|
|
|
{
|
|
|
|
INotificationListener* listener = new InteropNotificationListener(callback);
|
|
|
|
MessageManager::RegisterNotificationListener(listener);
|
|
|
|
return listener;
|
|
|
|
}
|
|
|
|
DllExport void __stdcall UnregisterNotificationCallback(INotificationListener *listener) { MessageManager::UnregisterNotificationListener(listener); }
|
|
|
|
|
2015-07-11 12:27:22 +00:00
|
|
|
DllExport void __stdcall DisplayMessage(char* title, char* message) { MessageManager::DisplayMessage(title, message); }
|
2015-07-05 23:05:33 +00:00
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
DllExport void __stdcall SaveState(uint32_t stateIndex) { SaveStateManager::SaveState(stateIndex); }
|
|
|
|
DllExport uint32_t __stdcall LoadState(uint32_t stateIndex) { return SaveStateManager::LoadState(stateIndex); }
|
|
|
|
DllExport int64_t __stdcall GetStateInfo(uint32_t stateIndex) { return SaveStateManager::GetStateInfo(stateIndex); }
|
|
|
|
|
2015-07-11 12:27:22 +00:00
|
|
|
DllExport void __stdcall MoviePlay(char* filename) { Movie::Play(filename); }
|
|
|
|
DllExport void __stdcall MovieRecord(char* filename, int reset) { Movie::Record(filename, reset != 0); }
|
2015-07-02 03:17:14 +00:00
|
|
|
DllExport void __stdcall MovieStop() { Movie::Stop(); }
|
|
|
|
DllExport int __stdcall MoviePlaying() { return Movie::Playing(); }
|
|
|
|
DllExport int __stdcall MovieRecording() { return Movie::Recording(); }
|
2015-07-05 23:05:33 +00:00
|
|
|
|
|
|
|
DllExport void __stdcall CheatAddCustom(uint32_t address, uint8_t value, int32_t compareValue, int isRelativeAddress) { CheatManager::AddCustomCode(address, value, compareValue, isRelativeAddress != 0); }
|
|
|
|
DllExport void __stdcall CheatAddGameGenie(char* code) { CheatManager::AddGameGenieCode(code); }
|
|
|
|
DllExport void __stdcall CheatAddProActionRocky(uint32_t code) { CheatManager::AddProActionRockyCode(code); }
|
|
|
|
DllExport void __stdcall CheatClear() { CheatManager::ClearCodes(); }
|
2015-07-18 00:58:57 +00:00
|
|
|
|
|
|
|
DllExport void __stdcall SetFlags(uint32_t flags) { EmulationSettings::SetFlags(flags); }
|
|
|
|
DllExport void __stdcall ClearFlags(uint32_t flags) { EmulationSettings::ClearFlags(flags); }
|
|
|
|
DllExport void __stdcall SetChannelVolume(uint32_t channel, double volume) { EmulationSettings::SetChannelVolume((AudioChannel)channel, volume); }
|
|
|
|
DllExport void __stdcall SetAudioLatency(uint32_t msLatency) { EmulationSettings::SetAudioLatency(msLatency); }
|
2015-07-22 03:05:27 +00:00
|
|
|
DllExport void __stdcall SetNesModel(uint32_t model) { EmulationSettings::SetNesModel((NesModel)model); }
|
2015-07-24 03:16:31 +00:00
|
|
|
DllExport void __stdcall SetOverscanDimensions(uint32_t left, uint32_t right, uint32_t top, uint32_t bottom) { EmulationSettings::SetOverscanDimensions(left, right, top, bottom); }
|
2015-07-18 00:58:57 +00:00
|
|
|
|
2015-07-02 03:17:14 +00:00
|
|
|
}
|
|
|
|
}
|