Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
Fix psv loader
  • Loading branch information
Nekotekina committed Feb 7, 2017
1 parent 8c4ba32 commit ead67d8
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 2 deletions.
185 changes: 185 additions & 0 deletions Utilities/event.h
@@ -1,8 +1,193 @@
#pragma once

#include <functional>
#include <deque>
#include <list>

#include "Atomic.h"

template <typename T, T Mod = T::__state_enum_max, typename Under = std::underlying_type_t<T>>
T operator ++(T& value, int)
{
return std::exchange(value, static_cast<T>(value < T{} || value >= Mod ? static_cast<Under>(0) : static_cast<Under>(value) + 1));
}

template <typename T, T Mod = T::__state_enum_max, typename Under = std::underlying_type_t<T>>
T operator --(T& value, int)
{
return std::exchange(value, static_cast<T>(value <= T{} || value >= static_cast<Under>(Mod) - 1 ? static_cast<Under>(Mod) - 1 : static_cast<Under>(value) - 1));
}

template <typename T, typename CRT, std::size_t Size = static_cast<std::underlying_type_t<T>>(T::__state_enum_max)>
class state_machine
{
using under = std::underlying_type_t<T>;
using ftype = void(CRT::*)(T);

atomic_t<T> m_value;

template <std::size_t... Ind>
static inline ftype transition_map(std::integer_sequence<std::size_t, Ind...>, T state)
{
// Constantly initialized list of functions
static constexpr ftype map[Size]{&CRT::template transition<static_cast<T>(Ind)>...};

// Unsafe table lookup (TODO)
return map[static_cast<under>(state)];
}

// "Convert" variable argument to template argument
static inline ftype transition_get(T state)
{
return transition_map(std::make_index_sequence<Size>(), state);
}

public:
constexpr state_machine()
: m_value{T{}}
{
}

constexpr state_machine(T state)
: m_value{state}
{
}

// Get current state
T state_get() const
{
return m_value;
}

// Unconditionally set state
void state_set(T state)
{
T _old = m_value.exchange(state);

if (_old != state)
{
(static_cast<CRT*>(this)->*transition_get(state))(_old);
}
}

// Conditionally set state (optimized)
explicit_bool_t state_test_and_set(T expected, T state)
{
if (m_value == expected && m_value.compare_and_swap_test(expected, state))
{
(static_cast<CRT*>(this)->*transition_get(state))(expected);
return true;
}

return false;
}

// Conditionally set state (list version)
explicit_bool_t state_test_and_set(std::initializer_list<T> expected, T state)
{
T _old;

if (m_value.atomic_op([&](T& value)
{
for (T x : expected)
{
if (value == x)
{
_old = std::exchange(value, state);
return true;
}
}

return false;
}))
{
(static_cast<CRT*>(this)->*transition_get(state))(_old);
return true;
}

return false;
}

// Unconditionally set next state
void state_next()
{
T _old, state = m_value.op_fetch([&](T& value)
{
_old = value++;
});

(static_cast<CRT*>(this)->*transition_get(state))(_old);
}

// Unconditionally set previous state
void state_prev()
{
T _old, state = m_value.op_fetch([&](T& value)
{
_old = value--;
});

(static_cast<CRT*>(this)->*transition_get(state))(_old);
}

// Get number of states
static constexpr std::size_t size()
{
return Size;
}
};

//enum class test_state
//{
// on,
// off,
// la,
//
// __state_enum_max // 3
//};
//
//struct test_machine final : state_machine<test_state, test_machine>
//{
// template <test_state>
// void transition(test_state old_state);
//
// void on()
// {
// state_set(test_state::on);
// }
//
// void off()
// {
// state_set(test_state::off);
// }
//
// void test()
// {
// state_next();
// }
//};
//
//template <>
//void test_machine::transition<test_state::on>(test_state)
//{
// LOG_SUCCESS(GENERAL, "ON");
//}
//
//template <>
//void test_machine::transition<test_state::off>(test_state)
//{
// LOG_SUCCESS(GENERAL, "OFF");
//}
//
//
//template <>
//void test_machine::transition<test_state::la>(test_state)
//{
// on();
// off();
// test();
//}

enum class event_result
{
skip,
Expand Down
4 changes: 4 additions & 0 deletions rpcs3/Emu/Cell/Modules/cellSaveData.cpp
Expand Up @@ -12,6 +12,10 @@

logs::channel cellSaveData("cellSaveData", logs::level::notice);

SaveDialogBase::~SaveDialogBase()
{
}

// cellSaveData aliases (only for cellSaveData.cpp)
using PSetList = vm::ptr<CellSaveDataSetList>;
using PSetBuf = vm::ptr<CellSaveDataSetBuf>;
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/Modules/cellSaveData.h
Expand Up @@ -292,7 +292,7 @@ struct SaveDataEntry
class SaveDialogBase
{
public:
virtual ~SaveDialogBase() = default;
virtual ~SaveDialogBase();

virtual s32 ShowSaveDataList(std::vector<SaveDataEntry>& save_entries, s32 focused, vm::ptr<CellSaveDataListSet> listSet) = 0;
};
1 change: 1 addition & 0 deletions rpcs3/Emu/Io/KeyboardHandler.h
Expand Up @@ -266,6 +266,7 @@ class KeyboardHandlerBase

public:
virtual void Init(const u32 max_connect) = 0;

virtual ~KeyboardHandlerBase() = default;

void Key(const u32 code, bool pressed)
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/PSP2/ARMv7Module.cpp
Expand Up @@ -375,7 +375,7 @@ void arm_load_exec(const arm_exec_object& elf)
{
if (prog.p_type == 0x1 /* LOAD */ && prog.p_memsz)
{
if (!vm::falloc(prog.p_vaddr, prog.p_memsz, vm::main))
if (!vm::falloc(prog.p_vaddr & ~0xfff, prog.p_memsz + (prog.p_vaddr & 0xfff), vm::main))
{
fmt::throw_exception("vm::falloc() failed (addr=0x%x, size=0x%x)", prog.p_vaddr, prog.p_memsz);
}
Expand Down

0 comments on commit ead67d8

Please sign in to comment.