From ead67d8e670e1d2cda85863345f1c68b71ebee77 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Tue, 24 Jan 2017 15:29:58 +0300 Subject: [PATCH] Minor changes Fix psv loader --- Utilities/event.h | 185 ++++++++++++++++++++++++ rpcs3/Emu/Cell/Modules/cellSaveData.cpp | 4 + rpcs3/Emu/Cell/Modules/cellSaveData.h | 2 +- rpcs3/Emu/Io/KeyboardHandler.h | 1 + rpcs3/Emu/PSP2/ARMv7Module.cpp | 2 +- 5 files changed, 192 insertions(+), 2 deletions(-) diff --git a/Utilities/event.h b/Utilities/event.h index 8078bfccf3..ab9e690b58 100644 --- a/Utilities/event.h +++ b/Utilities/event.h @@ -1,8 +1,193 @@ #pragma once + #include #include #include +#include "Atomic.h" + +template > +T operator ++(T& value, int) +{ + return std::exchange(value, static_cast(value < T{} || value >= Mod ? static_cast(0) : static_cast(value) + 1)); +} + +template > +T operator --(T& value, int) +{ + return std::exchange(value, static_cast(value <= T{} || value >= static_cast(Mod) - 1 ? static_cast(Mod) - 1 : static_cast(value) - 1)); +} + +template >(T::__state_enum_max)> +class state_machine +{ + using under = std::underlying_type_t; + using ftype = void(CRT::*)(T); + + atomic_t m_value; + + template + static inline ftype transition_map(std::integer_sequence, T state) + { + // Constantly initialized list of functions + static constexpr ftype map[Size]{&CRT::template transition(Ind)>...}; + + // Unsafe table lookup (TODO) + return map[static_cast(state)]; + } + + // "Convert" variable argument to template argument + static inline ftype transition_get(T state) + { + return transition_map(std::make_index_sequence(), 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(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(this)->*transition_get(state))(expected); + return true; + } + + return false; + } + + // Conditionally set state (list version) + explicit_bool_t state_test_and_set(std::initializer_list 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(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(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(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 +//{ +// template +// 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) +//{ +// LOG_SUCCESS(GENERAL, "ON"); +//} +// +//template <> +//void test_machine::transition(test_state) +//{ +// LOG_SUCCESS(GENERAL, "OFF"); +//} +// +// +//template <> +//void test_machine::transition(test_state) +//{ +// on(); +// off(); +// test(); +//} + enum class event_result { skip, diff --git a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp index 96a4c628c2..15c8287cd5 100644 --- a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp @@ -12,6 +12,10 @@ logs::channel cellSaveData("cellSaveData", logs::level::notice); +SaveDialogBase::~SaveDialogBase() +{ +} + // cellSaveData aliases (only for cellSaveData.cpp) using PSetList = vm::ptr; using PSetBuf = vm::ptr; diff --git a/rpcs3/Emu/Cell/Modules/cellSaveData.h b/rpcs3/Emu/Cell/Modules/cellSaveData.h index c1e9915666..5c9abd330a 100644 --- a/rpcs3/Emu/Cell/Modules/cellSaveData.h +++ b/rpcs3/Emu/Cell/Modules/cellSaveData.h @@ -292,7 +292,7 @@ struct SaveDataEntry class SaveDialogBase { public: - virtual ~SaveDialogBase() = default; + virtual ~SaveDialogBase(); virtual s32 ShowSaveDataList(std::vector& save_entries, s32 focused, vm::ptr listSet) = 0; }; diff --git a/rpcs3/Emu/Io/KeyboardHandler.h b/rpcs3/Emu/Io/KeyboardHandler.h index 06065a5bed..1ccc0e54b4 100644 --- a/rpcs3/Emu/Io/KeyboardHandler.h +++ b/rpcs3/Emu/Io/KeyboardHandler.h @@ -266,6 +266,7 @@ protected: public: virtual void Init(const u32 max_connect) = 0; + virtual ~KeyboardHandlerBase() = default; void Key(const u32 code, bool pressed) diff --git a/rpcs3/Emu/PSP2/ARMv7Module.cpp b/rpcs3/Emu/PSP2/ARMv7Module.cpp index 17cbb01688..c0d0def891 100644 --- a/rpcs3/Emu/PSP2/ARMv7Module.cpp +++ b/rpcs3/Emu/PSP2/ARMv7Module.cpp @@ -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); }