2013-07-06 02:49:38 +03:00
|
|
|
#pragma once
|
2014-07-11 21:59:13 +10:00
|
|
|
#include "Emu/SysCalls/SC_FUNC.h"
|
2014-08-25 18:56:13 +04:00
|
|
|
#include "Emu/IdManager.h"
|
2014-08-23 18:51:51 +04:00
|
|
|
#include "ErrorCodes.h"
|
2014-07-21 19:58:03 +04:00
|
|
|
#include "LogBase.h"
|
2013-07-06 02:49:38 +03:00
|
|
|
|
2015-02-18 19:22:06 +03:00
|
|
|
class Module;
|
|
|
|
|
|
2013-07-06 02:49:38 +03:00
|
|
|
struct ModuleFunc
|
|
|
|
|
{
|
|
|
|
|
u32 id;
|
2015-02-18 19:22:06 +03:00
|
|
|
Module* module;
|
2015-02-20 20:58:15 +03:00
|
|
|
ps3_func_caller func;
|
2015-01-28 15:59:16 +03:00
|
|
|
vm::ptr<void()> lle_func;
|
2013-07-06 02:49:38 +03:00
|
|
|
|
2015-02-20 20:58:15 +03:00
|
|
|
ModuleFunc(u32 id, Module* module, ps3_func_caller func, vm::ptr<void()> lle_func = vm::ptr<void()>::make(0))
|
2013-07-06 02:49:38 +03:00
|
|
|
: id(id)
|
2015-02-18 19:22:06 +03:00
|
|
|
, module(module)
|
2013-07-06 02:49:38 +03:00
|
|
|
, func(func)
|
2014-11-29 15:16:53 +02:00
|
|
|
, lle_func(lle_func)
|
2013-07-06 02:49:38 +03:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2014-03-06 15:40:50 +04:00
|
|
|
struct SFuncOp
|
|
|
|
|
{
|
|
|
|
|
u32 crc;
|
|
|
|
|
u32 mask;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct SFunc
|
|
|
|
|
{
|
2015-02-19 22:17:30 +03:00
|
|
|
u32 index;
|
2014-04-27 20:41:51 -07:00
|
|
|
const char* name;
|
2014-04-10 00:54:32 +02:00
|
|
|
std::vector<SFuncOp> ops;
|
2014-03-31 12:04:34 +02:00
|
|
|
u64 group;
|
|
|
|
|
u32 found;
|
2014-03-06 15:40:50 +04:00
|
|
|
};
|
|
|
|
|
|
2014-08-23 18:51:51 +04:00
|
|
|
class StaticFuncManager;
|
|
|
|
|
|
2014-07-21 19:58:03 +04:00
|
|
|
class Module : public LogBase
|
2013-07-06 02:49:38 +03:00
|
|
|
{
|
2014-02-02 22:47:17 +02:00
|
|
|
std::string m_name;
|
2013-07-06 02:49:38 +03:00
|
|
|
bool m_is_loaded;
|
2015-02-18 19:22:06 +03:00
|
|
|
void(*m_init)();
|
2013-07-06 02:49:38 +03:00
|
|
|
|
2014-08-22 20:54:53 +04:00
|
|
|
IdManager& GetIdManager() const;
|
2014-08-23 18:51:51 +04:00
|
|
|
void PushNewFuncSub(SFunc* func);
|
2014-08-22 20:54:53 +04:00
|
|
|
|
2015-02-18 19:22:06 +03:00
|
|
|
Module() = delete;
|
2013-07-06 02:49:38 +03:00
|
|
|
|
2015-02-18 19:22:06 +03:00
|
|
|
public:
|
|
|
|
|
Module(const char* name, void(*init)());
|
2013-07-06 02:49:38 +03:00
|
|
|
|
2014-05-02 08:30:32 +02:00
|
|
|
Module(Module &other) = delete;
|
2015-02-18 19:22:06 +03:00
|
|
|
Module(Module &&other) = delete;
|
2014-05-02 08:30:32 +02:00
|
|
|
|
|
|
|
|
Module &operator =(Module &other) = delete;
|
2015-02-18 19:22:06 +03:00
|
|
|
Module &operator =(Module &&other) = delete;
|
2014-05-02 08:30:32 +02:00
|
|
|
|
2014-04-15 17:12:15 +03:00
|
|
|
~Module();
|
|
|
|
|
|
2015-02-18 19:22:06 +03:00
|
|
|
std::function<void()> on_load;
|
|
|
|
|
std::function<void()> on_unload;
|
|
|
|
|
std::function<void()> on_stop;
|
|
|
|
|
|
|
|
|
|
void Init();
|
2013-07-06 02:49:38 +03:00
|
|
|
void Load();
|
2015-02-18 19:22:06 +03:00
|
|
|
void Unload();
|
2013-07-06 02:49:38 +03:00
|
|
|
|
|
|
|
|
void SetLoaded(bool loaded = true);
|
|
|
|
|
bool IsLoaded() const;
|
|
|
|
|
|
2014-07-21 19:58:03 +04:00
|
|
|
virtual const std::string& GetName() const override;
|
2014-02-02 22:47:17 +02:00
|
|
|
void SetName(const std::string& name);
|
2013-07-06 02:49:38 +03:00
|
|
|
|
|
|
|
|
public:
|
2014-01-19 05:14:11 +02:00
|
|
|
bool CheckID(u32 id) const;
|
2014-12-24 02:38:13 +03:00
|
|
|
|
|
|
|
|
template<typename T> bool CheckId(u32 id, std::shared_ptr<T>& data)
|
2014-01-19 05:14:11 +02:00
|
|
|
{
|
|
|
|
|
ID* id_data;
|
|
|
|
|
|
|
|
|
|
if(!CheckID(id, id_data)) return false;
|
2013-07-06 02:49:38 +03:00
|
|
|
|
2014-10-01 12:45:43 +03:00
|
|
|
data = id_data->GetData()->get<T>();
|
2013-07-06 02:49:38 +03:00
|
|
|
|
2014-01-19 05:14:11 +02:00
|
|
|
return true;
|
|
|
|
|
}
|
2014-02-22 04:53:06 +02:00
|
|
|
|
2014-12-24 02:38:13 +03:00
|
|
|
template<typename T> bool CheckId(u32 id, std::shared_ptr<T>& data, IDType& type)
|
2014-02-22 04:53:06 +02:00
|
|
|
{
|
|
|
|
|
ID* id_data;
|
|
|
|
|
|
|
|
|
|
if(!CheckID(id, id_data)) return false;
|
|
|
|
|
|
2014-10-01 12:45:43 +03:00
|
|
|
data = id_data->GetData()->get<T>();
|
|
|
|
|
type = id_data->GetType();
|
2014-02-22 04:53:06 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-12-24 02:38:13 +03:00
|
|
|
|
2014-01-19 05:14:11 +02:00
|
|
|
bool CheckID(u32 id, ID*& _id) const;
|
2013-07-06 02:49:38 +03:00
|
|
|
|
2014-01-19 05:14:11 +02:00
|
|
|
template<typename T>
|
2014-12-24 02:38:13 +03:00
|
|
|
u32 GetNewId(std::shared_ptr<T>& data, IDType type = TYPE_OTHER)
|
2014-01-19 05:14:11 +02:00
|
|
|
{
|
2014-08-22 20:54:53 +04:00
|
|
|
return GetIdManager().GetNewID<T>(GetName(), data, type);
|
2014-01-19 05:14:11 +02:00
|
|
|
}
|
2013-08-03 12:40:03 +03:00
|
|
|
|
2014-08-24 00:40:04 +04:00
|
|
|
bool RemoveId(u32 id);
|
|
|
|
|
|
2015-02-20 20:58:15 +03:00
|
|
|
template<void* func, typename T> __forceinline u32 AddFunc(const u32 nid, T _func);
|
|
|
|
|
template<void* func, typename T> __forceinline u32 AddFunc(const char* name, T _func);
|
|
|
|
|
template<void* func, typename T> __forceinline u32 AddFuncSub(const char group[8], const u64 ops[], const char* name, T _func);
|
2013-07-06 02:49:38 +03:00
|
|
|
};
|
|
|
|
|
|
2015-02-18 19:28:09 +03:00
|
|
|
u32 add_ps3_func(ModuleFunc func);
|
2015-02-18 19:22:06 +03:00
|
|
|
ModuleFunc* get_ps3_func_by_nid(u32 nid, u32* out_index = nullptr);
|
|
|
|
|
ModuleFunc* get_ps3_func_by_index(u32 index);
|
|
|
|
|
void execute_ps3_func_by_index(PPUThread& CPU, u32 id);
|
|
|
|
|
void clear_ps3_functions();
|
|
|
|
|
u32 get_function_id(const char* name);
|
2014-07-06 01:30:28 +02:00
|
|
|
|
2015-02-20 20:58:15 +03:00
|
|
|
template<void* func, typename T>
|
2015-02-20 16:58:40 +03:00
|
|
|
__forceinline u32 Module::AddFunc(const u32 nid, T _func)
|
2013-11-24 02:01:57 +02:00
|
|
|
{
|
2015-02-20 16:58:40 +03:00
|
|
|
return add_ps3_func(ModuleFunc(nid, this, ppu_func_detail::_bind_func<func>(_func)));
|
2013-11-24 02:01:57 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-20 20:58:15 +03:00
|
|
|
template<void* func, typename T>
|
2015-02-20 16:58:40 +03:00
|
|
|
__forceinline u32 Module::AddFunc(const char* name, T _func)
|
2014-07-06 01:30:28 +02:00
|
|
|
{
|
2015-02-20 16:58:40 +03:00
|
|
|
return AddFunc<func>(get_function_id(name), _func);
|
2014-07-06 01:30:28 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-20 20:58:15 +03:00
|
|
|
template<void* func, typename T>
|
2015-02-20 16:58:40 +03:00
|
|
|
__forceinline u32 Module::AddFuncSub(const char group[8], const u64 ops[], const char* name, T _func)
|
2014-03-06 15:40:50 +04:00
|
|
|
{
|
|
|
|
|
SFunc* sf = new SFunc;
|
2015-02-20 16:58:40 +03:00
|
|
|
sf->index = AddFunc<func>(name, _func);
|
2014-03-06 15:40:50 +04:00
|
|
|
sf->name = name;
|
2014-03-31 12:04:34 +02:00
|
|
|
sf->group = *(u64*)group;
|
|
|
|
|
sf->found = 0;
|
2014-03-06 15:40:50 +04:00
|
|
|
|
|
|
|
|
// TODO: check for self-inclusions, use CRC
|
|
|
|
|
for (u32 i = 0; ops[i]; i++)
|
|
|
|
|
{
|
|
|
|
|
SFuncOp op;
|
|
|
|
|
op.mask = ops[i] >> 32;
|
2014-08-31 00:41:01 +04:00
|
|
|
op.crc = (u32)ops[i];
|
2014-03-31 12:04:34 +02:00
|
|
|
if (op.mask) op.crc &= op.mask;
|
2014-09-04 13:21:23 +04:00
|
|
|
op.mask = re32(op.mask);
|
|
|
|
|
op.crc = re32(op.crc);
|
2014-04-10 00:54:32 +02:00
|
|
|
sf->ops.push_back(op);
|
2014-03-06 15:40:50 +04:00
|
|
|
}
|
2015-02-20 16:58:40 +03:00
|
|
|
|
2014-08-23 18:51:51 +04:00
|
|
|
PushNewFuncSub(sf);
|
2015-02-20 16:58:40 +03:00
|
|
|
|
|
|
|
|
return sf->index;
|
2014-03-06 15:40:50 +04:00
|
|
|
}
|
2014-08-23 18:51:51 +04:00
|
|
|
|
|
|
|
|
#define REG_SUB(module, group, name, ...) \
|
|
|
|
|
static const u64 name ## _table[] = {__VA_ARGS__ , 0}; \
|
2015-02-20 20:58:15 +03:00
|
|
|
if (name ## _table[0]) module.AddFuncSub<_targ(name)>(group, name ## _table, #name, name)
|
2014-08-23 18:51:51 +04:00
|
|
|
|
2015-02-20 20:58:15 +03:00
|
|
|
#define REG_FUNC(module, name) module.AddFunc<_targ(name)>(#name, name)
|
2014-08-23 18:51:51 +04:00
|
|
|
|
2015-02-19 14:18:28 +03:00
|
|
|
#define UNIMPLEMENTED_FUNC(module) module.Error("%s", __FUNCTION__)
|