2014-05-10 11:09:28 +03:00
|
|
|
#ifndef _instance__hpp__included__
|
|
|
|
#define _instance__hpp__included__
|
|
|
|
|
2014-05-18 01:39:53 +03:00
|
|
|
#include <deque>
|
2014-05-18 00:38:58 +03:00
|
|
|
#include "core/command.hpp"
|
2014-05-18 02:20:23 +03:00
|
|
|
#include "core/controllerframe.hpp"
|
2014-05-10 14:48:08 +03:00
|
|
|
#include "core/emustatus.hpp"
|
2014-05-10 13:12:42 +03:00
|
|
|
#include "core/inthread.hpp"
|
2014-05-10 11:22:31 +03:00
|
|
|
#include "core/movie.hpp"
|
2014-05-18 00:55:11 +03:00
|
|
|
#include "core/moviedata.hpp"
|
2014-05-10 14:11:24 +03:00
|
|
|
#include "core/mbranch.hpp"
|
2014-05-18 01:58:05 +03:00
|
|
|
#include "core/memorymanip.hpp"
|
2014-05-10 11:41:08 +03:00
|
|
|
#include "core/memorywatch.hpp"
|
2014-05-10 14:36:54 +03:00
|
|
|
#include "core/multitrack.hpp"
|
2014-05-18 12:34:22 +03:00
|
|
|
#include "core/project.hpp"
|
2014-05-11 20:01:26 +03:00
|
|
|
#include "library/command.hpp"
|
2014-05-10 11:32:48 +03:00
|
|
|
#include "library/lua-base.hpp"
|
2014-05-10 11:22:31 +03:00
|
|
|
#include "library/memoryspace.hpp"
|
2014-05-10 11:54:15 +03:00
|
|
|
#include "library/settingvar.hpp"
|
2014-05-11 15:29:27 +03:00
|
|
|
#include "library/keyboard.hpp"
|
|
|
|
#include "library/keyboard-mapper.hpp"
|
2014-05-10 11:09:28 +03:00
|
|
|
|
2014-05-18 01:39:53 +03:00
|
|
|
/**
|
|
|
|
* Information about keypress.
|
|
|
|
*/
|
|
|
|
struct keypress_info
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Create null keypress (no modifiers, NULL key and released).
|
|
|
|
*/
|
|
|
|
keypress_info();
|
|
|
|
/**
|
|
|
|
* Create new keypress.
|
|
|
|
*/
|
|
|
|
keypress_info(keyboard::modifier_set mod, keyboard::key& _key, short _value);
|
|
|
|
/**
|
|
|
|
* Create new keypress (two keys).
|
|
|
|
*/
|
|
|
|
keypress_info(keyboard::modifier_set mod, keyboard::key& _key, keyboard::key& _key2, short _value);
|
|
|
|
/**
|
|
|
|
* Modifier set.
|
|
|
|
*/
|
|
|
|
keyboard::modifier_set modifiers;
|
|
|
|
/**
|
|
|
|
* The actual key (first)
|
|
|
|
*/
|
|
|
|
keyboard::key* key1;
|
|
|
|
/**
|
|
|
|
* The actual key (second)
|
|
|
|
*/
|
|
|
|
keyboard::key* key2;
|
|
|
|
/**
|
|
|
|
* Value for the press
|
|
|
|
*/
|
|
|
|
short value;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void functor_call_helper(void* args)
|
|
|
|
{
|
|
|
|
(*reinterpret_cast<T*>(args))();
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void functor_call_helper2(void* args)
|
|
|
|
{
|
|
|
|
(*reinterpret_cast<T*>(args))();
|
|
|
|
delete reinterpret_cast<T*>(args);
|
|
|
|
}
|
|
|
|
|
2014-05-10 11:09:28 +03:00
|
|
|
struct emulator_instance
|
|
|
|
{
|
2014-05-10 11:54:15 +03:00
|
|
|
emulator_instance();
|
2014-05-10 11:09:28 +03:00
|
|
|
movie_logic mlogic;
|
2014-05-10 11:22:31 +03:00
|
|
|
memory_space memory;
|
2014-05-10 11:32:48 +03:00
|
|
|
lua::state lua;
|
2014-05-13 18:43:05 +03:00
|
|
|
memwatch_set mwatch;
|
2014-05-13 09:06:14 +03:00
|
|
|
settingvar::group settings;
|
2014-05-10 11:54:15 +03:00
|
|
|
settingvar::cache setcache;
|
2014-05-10 13:12:42 +03:00
|
|
|
voice_commentary commentary;
|
2014-05-10 13:36:00 +03:00
|
|
|
subtitle_commentary subtitles;
|
2014-05-10 14:11:24 +03:00
|
|
|
movie_branches mbranch;
|
2014-05-10 14:36:54 +03:00
|
|
|
multitrack_edit mteditor;
|
2014-05-10 14:48:08 +03:00
|
|
|
_lsnes_status status_A;
|
|
|
|
_lsnes_status status_B;
|
|
|
|
_lsnes_status status_C;
|
|
|
|
triplebuffer::triplebuffer<_lsnes_status> status;
|
2014-05-11 15:29:27 +03:00
|
|
|
keyboard::keyboard keyboard;
|
|
|
|
keyboard::mapper mapper;
|
2014-05-11 20:01:26 +03:00
|
|
|
command::group command;
|
2014-05-18 00:38:58 +03:00
|
|
|
alias_binds_manager abindmanager;
|
2014-05-18 00:55:11 +03:00
|
|
|
rrdata nrrdata;
|
2014-05-18 01:58:05 +03:00
|
|
|
cart_mappings_refresher cmapper;
|
2014-05-18 02:20:23 +03:00
|
|
|
controller_state controls;
|
2014-05-18 12:34:22 +03:00
|
|
|
project_state project;
|
2014-05-18 01:39:53 +03:00
|
|
|
//Queue stuff.
|
|
|
|
threads::lock queue_lock;
|
|
|
|
threads::cv queue_condition;
|
|
|
|
std::deque<keypress_info> keypresses;
|
|
|
|
std::deque<std::string> commands;
|
|
|
|
std::deque<std::pair<void(*)(void*), void*>> functions;
|
|
|
|
volatile uint64_t functions_executed;
|
|
|
|
volatile uint64_t next_function;
|
|
|
|
volatile bool system_thread_available;
|
|
|
|
bool queue_function_run;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Queue keypress.
|
|
|
|
*
|
|
|
|
* - Can be called from any thread.
|
|
|
|
*
|
|
|
|
* Parameter k: The keypress to queue.
|
|
|
|
*/
|
|
|
|
void queue(const keypress_info& k) throw(std::bad_alloc);
|
|
|
|
/**
|
|
|
|
* Queue command.
|
|
|
|
*
|
|
|
|
* - Can be called from any thread.
|
|
|
|
*
|
|
|
|
* Parameter c: The command to queue.
|
|
|
|
*/
|
|
|
|
void queue(const std::string& c) throw(std::bad_alloc);
|
|
|
|
/**
|
|
|
|
* Queue function to be called in emulation thread.
|
|
|
|
*
|
|
|
|
* - Can be called from any thread (exception: Synchronous mode can not be used from emulation nor main threads).
|
|
|
|
*
|
|
|
|
* Parameter f: The function to execute.
|
|
|
|
* Parameter arg: Argument to pass to the function.
|
|
|
|
* Parameter sync: If true, execute function call synchronously, else asynchronously.
|
|
|
|
*/
|
|
|
|
void queue(void (*f)(void* arg), void* arg, bool sync) throw(std::bad_alloc);
|
|
|
|
/**
|
|
|
|
* Run all queues.
|
|
|
|
*/
|
|
|
|
void run_queues() throw();
|
|
|
|
/**
|
|
|
|
* Call function synchronously in emulation thread.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
void run(T fn)
|
|
|
|
{
|
|
|
|
queue(functor_call_helper<T>, &fn, true);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Queue asynchrous function in emulation thread.
|
|
|
|
*/
|
|
|
|
template<typename T> void run_async(T fn)
|
|
|
|
{
|
|
|
|
queue(functor_call_helper2<T>, new T(fn), false);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Run internal queues.
|
|
|
|
*/
|
|
|
|
void run_queue(bool unlocked) throw();
|
2014-05-10 11:09:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
extern emulator_instance lsnes_instance;
|
|
|
|
|
2014-05-10 13:55:07 +03:00
|
|
|
emulator_instance& CORE();
|
|
|
|
|
2014-05-10 11:09:28 +03:00
|
|
|
#endif
|