diff --git a/rpcs3/Emu/Cell/PPUThread.cpp b/rpcs3/Emu/Cell/PPUThread.cpp index 5673ab3c8a..ca9e18f938 100644 --- a/rpcs3/Emu/Cell/PPUThread.cpp +++ b/rpcs3/Emu/Cell/PPUThread.cpp @@ -3350,6 +3350,7 @@ bool ppu_initialize(const ppu_module& info, bool check_only) { "sys_game_watchdog_clear", reinterpret_cast(ppu_execute_syscall) }, { "sys_game_get_system_sw_version", reinterpret_cast(ppu_execute_syscall) }, { "sys_game_board_storage_read", reinterpret_cast(ppu_execute_syscall) }, + { "sys_game_board_storage_write", reinterpret_cast(ppu_execute_syscall) }, { "sys_game_get_rtc_status", reinterpret_cast(ppu_execute_syscall) }, { "__trap", reinterpret_cast(&ppu_trap) }, { "__error", reinterpret_cast(&ppu_error) }, diff --git a/rpcs3/Emu/Cell/lv2/lv2.cpp b/rpcs3/Emu/Cell/lv2/lv2.cpp index 1d1a9978e0..987b97e5e3 100644 --- a/rpcs3/Emu/Cell/lv2/lv2.cpp +++ b/rpcs3/Emu/Cell/lv2/lv2.cpp @@ -459,7 +459,7 @@ const std::array, 1024> g_ppu_sysc NULL_FUNC(sys_sm_get_tzpb), //408 (0x198) PM NULL_FUNC(sys_sm_get_fan_policy), //409 (0x199) PM BIND_SYSC(_sys_game_board_storage_read), //410 (0x19A) - NULL_FUNC(sys_game_board_storage_write), //411 (0x19B) + BIND_SYSC(_sys_game_board_storage_write), //411 (0x19B) BIND_SYSC(_sys_game_get_rtc_status), //412 (0x19C) null_func,//BIND_SYSC(sys_...), //413 (0x19D) ROOT null_func,//BIND_SYSC(sys_...), //414 (0x19E) ROOT diff --git a/rpcs3/Emu/Cell/lv2/sys_game.cpp b/rpcs3/Emu/Cell/lv2/sys_game.cpp index 359ae6f277..dbdfce95f6 100644 --- a/rpcs3/Emu/Cell/lv2/sys_game.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_game.cpp @@ -1,9 +1,10 @@ #include "stdafx.h" #include "util/sysinfo.hpp" +#include "util/v128.hpp" #include "Emu/Memory/vm_ptr.h" #include "Emu/Cell/ErrorCodes.h" #include "Emu/System.h" - +#include "Emu/system_utils.hpp" #include "Emu/IdManager.h" #include "Utilities/Thread.h" @@ -11,6 +12,62 @@ LOG_CHANNEL(sys_game); +struct board_storage +{ +public: + bool read(u8* buffer) + { + if (!buffer) + return false; + + const auto data = storage.load(); + memcpy(buffer, &data, size); + + return true; + } + + bool write(u8* buffer) + { + if (!buffer) + return false; + + storage.store(read_from_ptr>(buffer)); + written = true; + + return true; + } + + board_storage() + { + if (fs::file file; file.open(file_path, fs::read)) + file.read(&storage.raw(), size); + else + memset(&storage.raw(), 0, size); + } + + board_storage(const board_storage&) = delete; + + board_storage& operator =(const board_storage&) = delete; + + ~board_storage() + { + if (written) + { + if (fs::file file; file.open(file_path, fs::create + fs::write + fs::lock)) + { + file.write(&storage.raw(), size); + file.trunc(size); + } + } + } + +private: + atomic_be_t storage; + bool written = false; + const std::string file_path = rpcs3::utils::get_hdd1_dir() + "/caches/board_storage.bin"; + static constexpr size_t size = sizeof(v128); +}; + struct watchdog_t { struct alignas(8) control_t @@ -167,8 +224,21 @@ error_code _sys_game_board_storage_read(vm::ptr buffer1, vm::ptr buffer2 return CELL_EFAULT; } - memset(buffer1.get_ptr(), 0, 16); - *buffer2 = 0; + *buffer2 = g_fxo->get().read(buffer1.get_ptr()) ? 0x00 : 0xFF; + + return CELL_OK; +} + +error_code _sys_game_board_storage_write(vm::ptr buffer1, vm::ptr buffer2) +{ + sys_game.trace("sys_game_board_storage_write(buffer1=*0x%x, buffer2=*0x%x)", buffer1, buffer2); + + if (!buffer1 || !buffer2) + { + return CELL_EFAULT; + } + + *buffer2 = g_fxo->get().write(buffer1.get_ptr()) ? 0x00 : 0xFF; return CELL_OK; } diff --git a/rpcs3/Emu/Cell/lv2/sys_game.h b/rpcs3/Emu/Cell/lv2/sys_game.h index db6a1f5bc8..7ac3cd2768 100644 --- a/rpcs3/Emu/Cell/lv2/sys_game.h +++ b/rpcs3/Emu/Cell/lv2/sys_game.h @@ -7,4 +7,5 @@ error_code _sys_game_watchdog_stop(); error_code _sys_game_watchdog_clear(); u64 _sys_game_get_system_sw_version(); error_code _sys_game_board_storage_read(vm::ptr buffer1, vm::ptr buffer2); +error_code _sys_game_board_storage_write(vm::ptr buffer1, vm::ptr buffer2); error_code _sys_game_get_rtc_status(vm::ptr status); diff --git a/rpcs3/Emu/Cell/lv2/sys_ss.cpp b/rpcs3/Emu/Cell/lv2/sys_ss.cpp index f647f49087..c559e2083a 100644 --- a/rpcs3/Emu/Cell/lv2/sys_ss.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_ss.cpp @@ -181,8 +181,7 @@ error_code sys_ss_appliance_info_manager(u32 code, vm::ptr buffer) { // AIM_get_open_ps_id be_t psid[2] = { +g_cfg.sys.console_psid_high, +g_cfg.sys.console_psid_low }; - u8* psid_bytes = reinterpret_cast(psid); - std::memcpy(buffer.get_ptr(), psid_bytes, 16); + std::memcpy(buffer.get_ptr(), psid, 16); break; } case 0x19006: diff --git a/rpcs3/Emu/Io/usio.cpp b/rpcs3/Emu/Io/usio.cpp index 9493ee2713..5c237c793b 100644 --- a/rpcs3/Emu/Io/usio.cpp +++ b/rpcs3/Emu/Io/usio.cpp @@ -140,7 +140,6 @@ void usb_device_usio::save_backup() const u64 file_size = g_fxo->get().backup_memory.size(); - usio_backup_file.seek(0, fs::seek_set); usio_backup_file.write(g_fxo->get().backup_memory.data(), file_size); usio_backup_file.trunc(file_size); } diff --git a/rpcs3/Emu/system_config.h b/rpcs3/Emu/system_config.h index 9e7525ca5e..ce30858cb7 100644 --- a/rpcs3/Emu/system_config.h +++ b/rpcs3/Emu/system_config.h @@ -285,9 +285,8 @@ struct cfg_root : cfg::node cfg::_enum keyboard_type{ this, "Keyboard Type", CellKbMappingType{0} }; // CELL_KB_MAPPING_101 = US cfg::_enum enter_button_assignment{ this, "Enter button assignment", enter_button_assign::cross }; cfg::_int<-60*60*24*365*100LL, 60*60*24*365*100LL> console_time_offset{ this, "Console time offset (s)", 0 }; // console time offset, limited to +/-100years - cfg::uint<0,umax> console_psid_high{ this, "PSID high"}; - cfg::uint<0,umax> console_psid_low{ this, "PSID low"}; - + cfg::uint<0, umax> console_psid_high{this, "PSID high"}; + cfg::uint<0, umax> console_psid_low{this, "PSID low"}; } sys{ this }; struct node_net : cfg::node