diff --git a/rpcs3/Emu/Cell/SPUInterpreter.h b/rpcs3/Emu/Cell/SPUInterpreter.h index b9f12316fc..5acd50b0d4 100644 --- a/rpcs3/Emu/Cell/SPUInterpreter.h +++ b/rpcs3/Emu/Cell/SPUInterpreter.h @@ -1238,8 +1238,10 @@ private: } void AI(u32 rt, u32 ra, s32 i10) { - const __u32x4 imm = {i10, i10, i10, i10}; - CPU.GPR[rt]._m128i = _mm_add_epi32(CPU.GPR[ra]._m128i, imm.m128i); + CPU.GPR[rt]._i32[0] = CPU.GPR[ra]._i32[0] + i10; + CPU.GPR[rt]._i32[1] = CPU.GPR[ra]._i32[1] + i10; + CPU.GPR[rt]._i32[2] = CPU.GPR[ra]._i32[2] + i10; + CPU.GPR[rt]._i32[3] = CPU.GPR[ra]._i32[3] + i10; } void AHI(u32 rt, u32 ra, s32 i10) { diff --git a/rpcs3/Emu/GS/GL/GLGSRender.cpp b/rpcs3/Emu/GS/GL/GLGSRender.cpp index 91f5e0dad2..0fbb8f2eeb 100644 --- a/rpcs3/Emu/GS/GL/GLGSRender.cpp +++ b/rpcs3/Emu/GS/GL/GLGSRender.cpp @@ -1058,8 +1058,6 @@ void GLGSRender::Flip() u32 height = re(buffers[m_gcm_current_buffer].height); u32 addr = GetAddress(re(buffers[m_gcm_current_buffer].offset), CELL_GCM_LOCATION_LOCAL); - glRotated(90, 1, 0, 0); - if(Memory.IsGoodAddr(addr)) { //TODO diff --git a/rpcs3/Emu/SysCalls/Modules/sys_io.cpp b/rpcs3/Emu/SysCalls/Modules/sys_io.cpp index db6e727c0e..9485b6f440 100644 --- a/rpcs3/Emu/SysCalls/Modules/sys_io.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sys_io.cpp @@ -13,6 +13,7 @@ void sys_io_init() sys_io.AddFunc(0x8b72cda1, cellPadGetData); sys_io.AddFunc(0x6bc09c61, cellPadGetDataExtra); sys_io.AddFunc(0xf65544ee, cellPadSetActDirect); + sys_io.AddFunc(0x3aaad464, cellPadGetInfo); sys_io.AddFunc(0xa703a51d, cellPadGetInfo2); sys_io.AddFunc(0x578e3c98, cellPadSetPortSetting); diff --git a/rpcs3/Emu/SysCalls/SysCalls.h b/rpcs3/Emu/SysCalls/SysCalls.h index b779f0b68e..7dfb90e6cf 100644 --- a/rpcs3/Emu/SysCalls/SysCalls.h +++ b/rpcs3/Emu/SysCalls/SysCalls.h @@ -240,6 +240,7 @@ extern int cellPadClearBuf(u32 port_no); extern int cellPadGetData(u32 port_no, u32 data_addr); extern int cellPadGetDataExtra(u32 port_no, u32 device_type_addr, u32 data_addr); extern int cellPadSetActDirect(u32 port_no, u32 param_addr); +extern int cellPadGetInfo(u32 info_addr); extern int cellPadGetInfo2(u32 info_addr); extern int cellPadSetPortSetting(u32 port_no, u32 port_setting); diff --git a/rpcs3/Emu/SysCalls/lv2/SC_Memory.cpp b/rpcs3/Emu/SysCalls/lv2/SC_Memory.cpp index 412571f29d..be8a6ecb5d 100644 --- a/rpcs3/Emu/SysCalls/lv2/SC_Memory.cpp +++ b/rpcs3/Emu/SysCalls/lv2/SC_Memory.cpp @@ -80,7 +80,28 @@ int sys_mmapper_allocate_address(u32 size, u64 flags, u32 alignment, u32 alloc_a { sc_mem.Warning("sys_mmapper_allocate_address(size=0x%x, flags=0x%llx, alignment=0x%x, alloc_addr=0x%x)", size, flags, alignment, alloc_addr); - Memory.Write32(alloc_addr, Memory.Alloc(size, alignment)); + if(!Memory.IsGoodAddr(alloc_addr)) return CELL_EFAULT; + + if(!alignment) + alignment = 1; + + u32 addr; + + switch(flags & (SYS_MEMORY_PAGE_SIZE_1M | SYS_MEMORY_PAGE_SIZE_64K)) + { + default: + case SYS_MEMORY_PAGE_SIZE_1M: + if(Memory.AlignAddr(size, alignment) & 0xfffff) return CELL_EALIGN; + addr = Memory.Alloc(size, 0x100000); + break; + + case SYS_MEMORY_PAGE_SIZE_64K: + if(Memory.AlignAddr(size, alignment) & 0xffff) return CELL_EALIGN; + addr = Memory.Alloc(size, 0x10000); + break; + } + + Memory.Write32(alloc_addr, addr); return CELL_OK; } @@ -91,7 +112,22 @@ int sys_mmapper_allocate_memory(u32 size, u64 flags, u32 mem_id_addr) if(!Memory.IsGoodAddr(mem_id_addr)) return CELL_EFAULT; - u64 addr = Memory.Alloc(size, 4); + u32 addr; + switch(flags & (SYS_MEMORY_PAGE_SIZE_1M | SYS_MEMORY_PAGE_SIZE_64K)) + { + case SYS_MEMORY_PAGE_SIZE_1M: + if(size & 0xfffff) return CELL_EALIGN; + addr = Memory.Alloc(size, 0x100000); + break; + + case SYS_MEMORY_PAGE_SIZE_64K: + if(size & 0xffff) return CELL_EALIGN; + addr = Memory.Alloc(size, 0x10000); + break; + + default: + return CELL_EINVAL; + } if(!addr) return CELL_ENOMEM; diff --git a/rpcs3/Emu/SysCalls/lv2/SC_Pad.cpp b/rpcs3/Emu/SysCalls/lv2/SC_Pad.cpp index a052cd041b..54f4878e00 100644 --- a/rpcs3/Emu/SysCalls/lv2/SC_Pad.cpp +++ b/rpcs3/Emu/SysCalls/lv2/SC_Pad.cpp @@ -24,6 +24,16 @@ struct CellPadData u16 button[CELL_PAD_MAX_CODES]; }; +struct CellPadInfo +{ + u32 max_connect; + u32 now_connect; + u32 system_info; + u16 vendor_id[CELL_MAX_PADS]; + u16 product_id[CELL_MAX_PADS]; + u8 status[CELL_MAX_PADS]; +}; + struct CellPadInfo2 { u32 max_connect; @@ -142,6 +152,35 @@ int cellPadSetActDirect(u32 port_no, u32 param_addr) return CELL_OK; } +int cellPadGetInfo(u32 info_addr) +{ + sys_io.Log("cellPadGetInfo(info_addr=0x%x)", info_addr); + if(!Emu.GetPadManager().IsInited()) return CELL_PAD_ERROR_UNINITIALIZED; + + CellPadInfo info; + memset(&info, 0, sizeof(CellPadInfo)); + + const PadInfo& rinfo = Emu.GetPadManager().GetInfo(); + info.max_connect = re(rinfo.max_connect); + info.now_connect = re(rinfo.now_connect); + info.system_info = re(rinfo.system_info); + + const Array& pads = Emu.GetPadManager().GetPads(); + + for(u32 i=0; i= pads.GetCount()) break; + + info.status[i] = re(pads[i].m_port_status); + info.product_id[i] = 0xdead; //TODO + info.vendor_id[i] = 0xbeaf; //TODO + } + + Memory.WriteData(info_addr, info); + + return CELL_OK; +} + int cellPadGetInfo2(u32 info_addr) { sys_io.Log("cellPadGetInfo2(info_addr=0x%x)", info_addr); diff --git a/rpcs3/Gui/GameViewer.cpp b/rpcs3/Gui/GameViewer.cpp index 14dc7ad303..30f7371c6d 100644 --- a/rpcs3/Gui/GameViewer.cpp +++ b/rpcs3/Gui/GameViewer.cpp @@ -8,7 +8,7 @@ GameViewer::GameViewer(wxWindow* parent) : wxListView(parent) LoadSettings(); m_columns.Show(this); - m_path = wxGetCwd(); //TODO + m_path = wxGetCwd() + "\\dev_hdd0\\game\\"; //TODO Connect(GetId(), wxEVT_COMMAND_LIST_ITEM_ACTIVATED, wxListEventHandler(GameViewer::DClick)); @@ -34,16 +34,13 @@ void GameViewer::LoadGames() if(!dir.HasSubDirs()) return; wxString buf; - if(!dir.GetFirst(&buf)) return; - if(wxDirExists(buf)) m_games.Add(buf); - - for(;;) + for(bool ok = dir.GetFirst(&buf); ok; ok = dir.GetNext(&buf)) { - if(!dir.GetNext(&buf)) break; - if(wxDirExists(buf)) m_games.Add(buf); + if(wxDirExists(m_path + buf)) + m_games.Add(buf); } - //ConLog.Write("path: %s", m_path); + //ConLog.Write("path: %s", m_path.c_str()); //ConLog.Write("folders count: %d", m_games.GetCount()); } @@ -52,7 +49,7 @@ void GameViewer::LoadPSF() m_game_data.Clear(); for(uint i=0; i - -#include "scetool/scetool.cpp" -#include "unpkg/unpkg.c" - -BEGIN_EVENT_TABLE(MainFrame, FrameBase) - EVT_CLOSE(MainFrame::OnQuit) -END_EVENT_TABLE() - -enum IDs -{ - id_boot_elf = 0x555, - id_boot_self, - id_boot_game, - id_boot_pkg, - id_sys_pause, - id_sys_stop, - id_sys_send_open_menu, - id_sys_send_exit, - id_config_emu, - id_config_vfs_manager, - id_config_vhdd_manager, - id_tools_compiler, - id_tools_memory_viewer, - id_help_about, - id_update_dbg, -}; - -wxString GetPaneName() -{ - static int pane_num = 0; - - return wxString::Format("Pane_%d", pane_num++); -} - +#include "stdafx.h" +#include "MainFrame.h" +#include "CompilerELF.h" +#include "MemoryViewer.h" + +#include "git-version.h" +#include "Emu/System.h" +#include "Ini.h" +#include "Emu/GS/sysutil_video.h" +#include "Gui/VHDDManager.h" +#include "Gui/VFSManager.h" +#include "Gui/AboutDialog.h" +#include + +#include "scetool/scetool.cpp" +#include "unpkg/unpkg.c" + +BEGIN_EVENT_TABLE(MainFrame, FrameBase) + EVT_CLOSE(MainFrame::OnQuit) +END_EVENT_TABLE() + +enum IDs +{ + id_boot_elf = 0x555, + id_boot_self, + id_boot_game, + id_boot_pkg, + id_sys_pause, + id_sys_stop, + id_sys_send_open_menu, + id_sys_send_exit, + id_config_emu, + id_config_vfs_manager, + id_config_vhdd_manager, + id_tools_compiler, + id_tools_memory_viewer, + id_help_about, + id_update_dbg, +}; + +wxString GetPaneName() +{ + static int pane_num = 0; + + return wxString::Format("Pane_%d", pane_num++); +} + bool wxMoveDir(wxString sFrom, wxString sTo) { if (sFrom[sFrom.Len() - 1] != '\\' && sFrom[sFrom.Len() - 1] != '/') sFrom += wxFILE_SEP_PATH; @@ -84,795 +84,795 @@ bool wxMoveDir(wxString sFrom, wxString sTo) } ::wxRmdir(sFrom); return true; -} - -MainFrame::MainFrame() - : FrameBase(nullptr, wxID_ANY, "", "MainFrame", wxSize(800, 600)) - , m_aui_mgr(this) - , m_sys_menu_opened(false) -{ - -#ifdef _DEBUG - SetLabel(wxString::Format(_PRGNAME_ " git-" RPCS3_GIT_VERSION)); -#else - SetLabel(wxString::Format(_PRGNAME_ " " _PRGVER_)); -#endif - - wxMenuBar& menubar(*new wxMenuBar()); - - wxMenu& menu_boot(*new wxMenu()); - wxMenu& menu_sys(*new wxMenu()); - wxMenu& menu_conf(*new wxMenu()); - wxMenu& menu_tools(*new wxMenu()); - wxMenu& menu_help(*new wxMenu()); - - menubar.Append(&menu_boot, "Boot"); - menubar.Append(&menu_sys, "System"); - menubar.Append(&menu_conf, "Config"); - menubar.Append(&menu_tools, "Tools"); - menubar.Append(&menu_help, "Help"); - - menu_boot.Append(id_boot_game, "Boot game"); - menu_boot.Append(id_boot_pkg, "Install PKG"); - menu_boot.AppendSeparator(); - menu_boot.Append(id_boot_elf, "Boot ELF"); - menu_boot.Append(id_boot_self, "Boot SELF"); - - menu_sys.Append(id_sys_pause, "Pause")->Enable(false); - menu_sys.Append(id_sys_stop, "Stop\tCtrl + S")->Enable(false); - menu_sys.AppendSeparator(); - menu_sys.Append(id_sys_send_open_menu, "Send open system menu cmd")->Enable(false); - menu_sys.Append(id_sys_send_exit, "Send exit cmd")->Enable(false); - - menu_conf.Append(id_config_emu, "Settings"); - menu_conf.AppendSeparator(); - menu_conf.Append(id_config_vfs_manager, "Virtual File System Manager"); - menu_conf.Append(id_config_vhdd_manager, "Virtual HDD Manager"); - - menu_tools.Append(id_tools_compiler, "ELF Compiler"); - menu_tools.Append(id_tools_memory_viewer, "Memory Viewer"); - - menu_help.Append(id_help_about, "About..."); - - SetMenuBar(&menubar); - - m_game_viewer = new GameViewer(this); - AddPane(m_game_viewer, "Game List", wxAUI_DOCK_BOTTOM); - - Connect( id_boot_game, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::BootGame) ); - Connect( id_boot_pkg, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::BootPkg) ); - Connect( id_boot_elf, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::BootElf) ); - Connect( id_boot_self, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::BootSelf) ); - - Connect( id_sys_pause, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::Pause) ); - Connect( id_sys_stop, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::Stop) ); - Connect( id_sys_send_open_menu, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::SendOpenCloseSysMenu) ); - Connect( id_sys_send_exit, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::SendExit) ); - - Connect( id_config_emu, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::Config) ); - Connect( id_config_vfs_manager, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::ConfigVFS) ); - Connect( id_config_vhdd_manager,wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::ConfigVHDD) ); - - Connect( id_tools_compiler, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OpenELFCompiler)); - Connect( id_tools_memory_viewer,wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OpenMemoryViewer)); - - Connect( id_help_about, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::AboutDialogHandler) ); - - Connect( id_update_dbg, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::UpdateUI) ); - - m_app_connector.Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(MainFrame::OnKeyDown), (wxObject*)0, this); - m_app_connector.Connect(wxEVT_DBG_COMMAND, wxCommandEventHandler(MainFrame::UpdateUI), (wxObject*)0, this); -} - -MainFrame::~MainFrame() -{ - m_aui_mgr.UnInit(); -} - -void MainFrame::AddPane(wxWindow* wind, const wxString& caption, int flags) -{ - wind->SetSize(-1, 300); - m_aui_mgr.AddPane(wind, wxAuiPaneInfo().Name(GetPaneName()).Caption(caption).Direction(flags).CloseButton(false).MaximizeButton()); -} - -void MainFrame::DoSettings(bool load) -{ - IniEntry ini; - ini.Init("Settings", "MainFrameAui"); - - if(load) - { - m_aui_mgr.LoadPerspective(ini.LoadValue(m_aui_mgr.SavePerspective())); - } - else - { - ini.SaveValue(m_aui_mgr.SavePerspective()); - } -} - -void MainFrame::BootGame(wxCommandEvent& WXUNUSED(event)) -{ - bool stopped = false; - - if(Emu.IsRunning()) - { - Emu.Pause(); - stopped = true; - } - - wxDirDialog ctrl(this, L"Select game folder", wxEmptyString); - - if(ctrl.ShowModal() == wxID_CANCEL) - { - if(stopped) Emu.Resume(); - return; - } - - Emu.Stop(); - - wxString elf[6] = { - "\\PS3_GAME\\USRDIR\\BOOT.BIN", - "\\USRDIR\\BOOT.BIN", - "\\BOOT.BIN", - "\\PS3_GAME\\USRDIR\\EBOOT.BIN", - "\\USRDIR\\EBOOT.BIN", - "\\EBOOT.BIN" - }; - - for(int i=0;i<6;i++) - { - if(wxFile::Access(ctrl.GetPath() + elf[i], wxFile::read)) - { - ConLog.Write("SELF: booting..."); - - Emu.Stop(); - - wxString fileIn = ctrl.GetPath()+elf[i]; - wxString fileOut = (ctrl.GetPath()+elf[i])+".elf"; - - // Check if the data really needs to be decrypted. - if(!wxFileExists(fileIn)) - { - ConLog.Error("Could not open game boot file!"); - return; - } - - wxFile f(fileIn); - // Get the key version. - f.Seek(0x08); - be_t key_version; - f.Read(&key_version, sizeof(key_version)); - - if(key_version.ToBE() == const_se_t::value) - { - ConLog.Warning("Debug SELF detected! Removing fake header..."); - - // Get the real elf offset. - f.Seek(0x10); - be_t elf_offset; - f.Read(&elf_offset, sizeof(elf_offset)); - - // Start at the real elf offset. - f.Seek(elf_offset); - - wxFile out(fileOut, wxFile::write); - - // Copy the data. - char buf[2048]; - while (ssize_t size = f.Read(buf, 2048)) - out.Write(buf, size); - } - else - { - if (!scetool_decrypt((scetool::s8 *)fileIn.mb_str(), (scetool::s8 *)fileOut.mb_str())) - { - ConLog.Write("Could not decrypt game boot file"); - return; - } - } - - f.Close(); - - Emu.SetPath(fileOut); - Emu.Load(); - if (!wxRemoveFile(fileOut)) - ConLog.Warning("Could not delete the decrypted ELF file"); - - ConLog.Write("Game: boot done."); - return; - } - } - - ConLog.Error("Ps3 executable not found in selected folder (%s)", ctrl.GetPath().mb_str()); - return; -} - - -void MainFrame::BootPkg(wxCommandEvent& WXUNUSED(event)) -{ - bool stopped = false; - - if(Emu.IsRunning()) - { - Emu.Pause(); - stopped = true; - } - - wxFileDialog ctrl (this, L"Select PKG", wxEmptyString, wxEmptyString, "*.*", - wxFD_OPEN | wxFD_FILE_MUST_EXIST); - - if(ctrl.ShowModal() == wxID_CANCEL) - { - if(stopped) Emu.Resume(); - return; - } - - ConLog.Write("PKG: extracting..."); - - Emu.Stop(); - - wxString fileName = ctrl.GetPath(); - pkg_unpack((const char *)fileName.mb_str()); - - if (!wxRemoveFile(ctrl.GetPath()+".dec")) - ConLog.Warning("Could not delete the decoded DEC file"); - - // Copy the PKG to dev_hdd0 and format the path to be identical to the PS3. - wxString gamePath = "\\dev_hdd0\\game\\"; - pkg_header *header; - pkg_info((const char *)fileName.mb_str(), &header); - - // Get the PKG title ID from the header and format it (should match TITLE ID from PARAM.SFO). - wxString titleID_full (header->title_id); - wxString titleID = titleID_full.SubString(7, 15); - - // Travel to bin folder. - wxSetWorkingDirectory(wxGetCwd() + "\\..\\"); - - // Save the main dir. - wxString mainDir = wxGetCwd(); - - // Set PKG dir. - wxString oldPkgDir = wxT(wxGetCwd() + "\\" + titleID_full); - wxString newPkgDir = wxT(wxGetCwd() + gamePath + titleID); - - // Move the final folder. - wxMoveDir(oldPkgDir, newPkgDir); - - // Save the title ID. - Emu.SetTitleID(titleID); - - ConLog.Write("PKG: extract done."); - - // Travel to the installed PKG. - wxSetWorkingDirectory(newPkgDir); - - wxString elf[6] = { - "\\PS3_GAME\\USRDIR\\BOOT.BIN", - "\\USRDIR\\BOOT.BIN", - "\\BOOT.BIN", - "\\PS3_GAME\\USRDIR\\EBOOT.BIN", - "\\USRDIR\\EBOOT.BIN", - "\\EBOOT.BIN" - }; - - for(int i=0;i<6;i++) - { - if(wxFile::Access(wxGetCwd() + elf[i], wxFile::read)) - { - ConLog.Write("SELF: booting..."); - - wxString fileIn = wxGetCwd()+elf[i]; - wxString fileOut = (wxGetCwd()+elf[i])+".elf"; - - // Check if the data really needs to be decrypted. - if(!wxFileExists(fileIn)) - { - ConLog.Error("Could not open game boot file!"); - return; - } - - wxFile f(fileIn); - // Get the key version. - f.Seek(0x08); - be_t key_version; - f.Read(&key_version, sizeof(key_version)); - - if(key_version.ToBE() == const_se_t::value) - { - ConLog.Warning("Debug SELF detected! Removing fake header..."); - - // Get the real elf offset. - f.Seek(0x10); - be_t elf_offset; - f.Read(&elf_offset, sizeof(elf_offset)); - - // Start at the real elf offset. - f.Seek(elf_offset); - - wxFile out(fileOut, wxFile::write); - - // Copy the data. - char buf[2048]; - while (ssize_t size = f.Read(buf, 2048)) - out.Write(buf, size); - } - else - { - if (!scetool_decrypt((scetool::s8 *)fileIn.mb_str(), (scetool::s8 *)fileOut.mb_str())) - { - ConLog.Write("Could not decrypt game boot file"); - return; - } - } - - f.Close(); - - // Set the working directory back. - wxSetWorkingDirectory(mainDir); - - Emu.SetPath(fileOut); - Emu.Load(); - if (!wxRemoveFile(fileOut)) - ConLog.Warning("Could not delete the decrypted ELF file"); - - ConLog.Write("Game: boot done."); - return; - } - } -} - -void MainFrame::BootElf(wxCommandEvent& WXUNUSED(event)) -{ - bool stopped = false; - - if(Emu.IsRunning()) - { - Emu.Pause(); - stopped = true; - } - - wxFileDialog ctrl(this, L"Select ELF", wxEmptyString, wxEmptyString, "*.*", - wxFD_OPEN | wxFD_FILE_MUST_EXIST); - - if(ctrl.ShowModal() == wxID_CANCEL) - { - if(stopped) Emu.Resume(); - return; - } - - ConLog.Write("ELF: booting..."); - - Emu.Stop(); - - Emu.SetPath(ctrl.GetPath()); - Emu.Load(); - - ConLog.Write("ELF: boot done."); -} - -void MainFrame::BootSelf(wxCommandEvent& WXUNUSED(event)) -{ - bool stopped = false; - - if(Emu.IsRunning()) - { - Emu.Pause(); - stopped = true; - } - - wxFileDialog ctrl(this, L"Select SELF", wxEmptyString, wxEmptyString, "*.*", - wxFD_OPEN | wxFD_FILE_MUST_EXIST); - - if(ctrl.ShowModal() == wxID_CANCEL) - { - if(stopped) Emu.Resume(); - return; - } - - ConLog.Write("SELF: booting..."); - - Emu.Stop(); - - wxString fileIn = ctrl.GetPath(); - wxString fileOut = ctrl.GetPath()+".elf"; - - // Check if the data really needs to be decrypted. - if(!wxFileExists(fileIn)) - { - ConLog.Error("Could not open SELF file!"); - return; - } - - wxFile f(fileIn); - // Get the key version. - f.Seek(0x08); - be_t key_version; - f.Read(&key_version, sizeof(key_version)); - - if(key_version.ToBE() == const_se_t::value) - { - ConLog.Warning("Debug SELF detected! Removing fake header..."); - - // Get the real elf offset. - f.Seek(0x10); - be_t elf_offset; - f.Read(&elf_offset, sizeof(elf_offset)); - - // Start at the real elf offset. - f.Seek(elf_offset); - - wxFile out(fileOut, wxFile::write); - - // Copy the data. - char buf[2048]; - while (ssize_t size = f.Read(buf, 2048)) - out.Write(buf, size); - } - else - { - if (!scetool_decrypt((scetool::s8 *)fileIn.mb_str(), (scetool::s8 *)fileOut.mb_str())) - { - ConLog.Write("SELF: Could not decrypt file"); - return; - } - } - - f.Close(); - - Emu.SetPath(fileOut); - Emu.Load(); - if (!wxRemoveFile(fileOut)) - ConLog.Warning("Could not delete the decrypted ELF file"); - - ConLog.Write("SELF: boot done."); -} - -void MainFrame::Pause(wxCommandEvent& WXUNUSED(event)) -{ - if(Emu.IsReady()) - { - Emu.Run(); - } - else if(Emu.IsPaused()) - { - Emu.Resume(); - } - else if(Emu.IsRunning()) - { - Emu.Pause(); - } -} - -void MainFrame::Stop(wxCommandEvent& WXUNUSED(event)) -{ - Emu.Stop(); -} - -void MainFrame::SendExit(wxCommandEvent& event) -{ - Emu.GetCallbackManager().m_exit_callback.Handle(0x0101, 0); -} - -void MainFrame::SendOpenCloseSysMenu(wxCommandEvent& event) -{ - Emu.GetCallbackManager().m_exit_callback.Handle(m_sys_menu_opened ? 0x0132 : 0x0131, 0); - m_sys_menu_opened = !m_sys_menu_opened; - wxCommandEvent ce; - UpdateUI(ce); -} - -void MainFrame::Config(wxCommandEvent& WXUNUSED(event)) -{ - //TODO - - bool paused = false; - - if(Emu.IsRunning()) - { - Emu.Pause(); - paused = true; - } - - wxDialog diag(this, wxID_ANY, "Settings", wxDefaultPosition); - - wxBoxSizer* s_panel(new wxBoxSizer(wxHORIZONTAL)); - wxBoxSizer* s_subpanel1(new wxBoxSizer(wxVERTICAL)); - wxBoxSizer* s_subpanel2(new wxBoxSizer(wxVERTICAL)); - - wxStaticBoxSizer* s_round_cpu( new wxStaticBoxSizer( wxVERTICAL, &diag, _("CPU") ) ); - wxStaticBoxSizer* s_round_cpu_decoder( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Decoder") ) ); - - wxStaticBoxSizer* s_round_gs( new wxStaticBoxSizer( wxVERTICAL, &diag, _("GS") ) ); - wxStaticBoxSizer* s_round_gs_render( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Render") ) ); - wxStaticBoxSizer* s_round_gs_res( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Default resolution") ) ); - wxStaticBoxSizer* s_round_gs_aspect( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Default aspect ratio") ) ); - - wxStaticBoxSizer* s_round_io( new wxStaticBoxSizer( wxVERTICAL, &diag, _("IO") ) ); - wxStaticBoxSizer* s_round_pad_handler( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Pad Handler") ) ); - wxStaticBoxSizer* s_round_keyboard_handler( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Keyboard Handler") ) ); - wxStaticBoxSizer* s_round_mouse_handler( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Mouse Handler") ) ); - - wxComboBox* cbox_cpu_decoder = new wxComboBox(&diag, wxID_ANY); - wxComboBox* cbox_gs_render = new wxComboBox(&diag, wxID_ANY); - wxComboBox* cbox_gs_resolution = new wxComboBox(&diag, wxID_ANY); - wxComboBox* cbox_gs_aspect = new wxComboBox(&diag, wxID_ANY); - wxComboBox* cbox_pad_handler = new wxComboBox(&diag, wxID_ANY); - wxComboBox* cbox_keyboard_handler = new wxComboBox(&diag, wxID_ANY); - wxComboBox* cbox_mouse_handler = new wxComboBox(&diag, wxID_ANY); - - wxCheckBox* chbox_cpu_ignore_rwerrors = new wxCheckBox(&diag, wxID_ANY, "Ignore Read/Write errors"); - wxCheckBox* chbox_gs_dump_depth = new wxCheckBox(&diag, wxID_ANY, "Dump Depth Buffer"); - wxCheckBox* chbox_gs_dump_color = new wxCheckBox(&diag, wxID_ANY, "Dump Color Buffers"); - wxCheckBox* chbox_gs_vsync = new wxCheckBox(&diag, wxID_ANY, "VSync"); - - //cbox_cpu_decoder->Append("DisAsm"); - cbox_cpu_decoder->Append("Interpreter & DisAsm"); - cbox_cpu_decoder->Append("Interpreter"); - - for(int i=1; iAppend(wxString::Format("%dx%d", ResolutionTable[i].width, ResolutionTable[i].height)); - } - - cbox_gs_aspect->Append("4:3"); - cbox_gs_aspect->Append("16:9"); - - cbox_gs_render->Append("Null"); - cbox_gs_render->Append("OpenGL"); - //cbox_gs_render->Append("Software"); - - cbox_pad_handler->Append("Null"); - cbox_pad_handler->Append("Windows"); - //cbox_pad_handler->Append("DirectInput"); - - cbox_keyboard_handler->Append("Null"); - cbox_keyboard_handler->Append("Windows"); - //cbox_keyboard_handler->Append("DirectInput"); - - cbox_mouse_handler->Append("Null"); - cbox_mouse_handler->Append("Windows"); - //cbox_mouse_handler->Append("DirectInput"); - - chbox_cpu_ignore_rwerrors->SetValue(Ini.CPUIgnoreRWErrors.GetValue()); - chbox_gs_dump_depth->SetValue(Ini.GSDumpDepthBuffer.GetValue()); - chbox_gs_dump_color->SetValue(Ini.GSDumpColorBuffers.GetValue()); - chbox_gs_vsync->SetValue(Ini.GSVSyncEnable.GetValue()); - - cbox_cpu_decoder->SetSelection(Ini.CPUDecoderMode.GetValue() ? Ini.CPUDecoderMode.GetValue() - 1 : 0); - cbox_gs_render->SetSelection(Ini.GSRenderMode.GetValue()); - cbox_gs_resolution->SetSelection(ResolutionIdToNum(Ini.GSResolution.GetValue()) - 1); - cbox_gs_aspect->SetSelection(Ini.GSAspectRatio.GetValue() - 1); - cbox_pad_handler->SetSelection(Ini.PadHandlerMode.GetValue()); - cbox_keyboard_handler->SetSelection(Ini.KeyboardHandlerMode.GetValue()); - cbox_mouse_handler->SetSelection(Ini.MouseHandlerMode.GetValue()); - - s_round_cpu_decoder->Add(cbox_cpu_decoder, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_cpu->Add(s_round_cpu_decoder, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_cpu->Add(chbox_cpu_ignore_rwerrors, wxSizerFlags().Border(wxALL, 5).Expand()); - - s_round_gs_render->Add(cbox_gs_render, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_gs_res->Add(cbox_gs_resolution, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_gs_aspect->Add(cbox_gs_aspect, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_gs->Add(s_round_gs_render, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_gs->Add(s_round_gs_res, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_gs->Add(s_round_gs_aspect, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_gs->Add(chbox_gs_dump_depth, wxSizerFlags().Border(wxALL, 5)); - s_round_gs->Add(chbox_gs_dump_color, wxSizerFlags().Border(wxALL, 5)); - s_round_gs->Add(chbox_gs_vsync, wxSizerFlags().Border(wxALL, 5)); - - s_round_pad_handler->Add(cbox_pad_handler, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_keyboard_handler->Add(cbox_keyboard_handler, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_mouse_handler->Add(cbox_mouse_handler, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_io->Add(s_round_pad_handler, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_io->Add(s_round_keyboard_handler, wxSizerFlags().Border(wxALL, 5).Expand()); - s_round_io->Add(s_round_mouse_handler, wxSizerFlags().Border(wxALL, 5).Expand()); - - wxBoxSizer* s_b_panel(new wxBoxSizer(wxHORIZONTAL)); - - s_b_panel->Add(new wxButton(&diag, wxID_OK), wxSizerFlags().Border(wxALL, 5).Center()); - s_b_panel->Add(new wxButton(&diag, wxID_CANCEL), wxSizerFlags().Border(wxALL, 5).Center()); - - //wxBoxSizer* s_conf_panel(new wxBoxSizer(wxHORIZONTAL)); - - s_subpanel1->Add(s_round_cpu, wxSizerFlags().Border(wxALL, 5).Expand()); - s_subpanel1->Add(s_round_gs, wxSizerFlags().Border(wxALL, 5).Expand()); - s_subpanel2->Add(s_round_io, wxSizerFlags().Border(wxALL, 5).Expand()); - s_subpanel1->Add(s_b_panel, wxSizerFlags().Border(wxALL, 8).Expand()); - - s_subpanel2->AddSpacer(180); - s_panel->Add(s_subpanel1, wxSizerFlags().Border(wxALL, 5).Expand()); - s_panel->Add(s_subpanel2, wxSizerFlags().Border(wxALL, 5).Expand()); - - diag.SetSizerAndFit( s_panel ); - - if(diag.ShowModal() == wxID_OK) - { - Ini.CPUDecoderMode.SetValue(cbox_cpu_decoder->GetSelection() + 1); - Ini.CPUIgnoreRWErrors.SetValue(chbox_cpu_ignore_rwerrors->GetValue()); - Ini.GSRenderMode.SetValue(cbox_gs_render->GetSelection()); - Ini.GSResolution.SetValue(ResolutionNumToId(cbox_gs_resolution->GetSelection() + 1)); - Ini.GSAspectRatio.SetValue(cbox_gs_aspect->GetSelection() + 1); - Ini.GSVSyncEnable.SetValue(chbox_gs_vsync->GetValue()); - Ini.GSDumpDepthBuffer.SetValue(chbox_gs_dump_depth->GetValue()); - Ini.GSDumpColorBuffers.SetValue(chbox_gs_dump_color->GetValue()); - Ini.PadHandlerMode.SetValue(cbox_pad_handler->GetSelection()); - Ini.KeyboardHandlerMode.SetValue(cbox_keyboard_handler->GetSelection()); - Ini.MouseHandlerMode.SetValue(cbox_mouse_handler->GetSelection()); - - Ini.Save(); - } - - if(paused) Emu.Resume(); -} - -void MainFrame::ConfigVFS(wxCommandEvent& WXUNUSED(event)) -{ - VFSManagerDialog(this).ShowModal(); -} - -void MainFrame::ConfigVHDD(wxCommandEvent& WXUNUSED(event)) -{ - VHDDManagerDialog(this).ShowModal(); -} - -void MainFrame::OpenELFCompiler(wxCommandEvent& WXUNUSED(event)) -{ - (new CompilerELF(this)) -> Show(); -} - -void MainFrame::OpenMemoryViewer(wxCommandEvent& WXUNUSED(event)) -{ - (new MemoryViewerPanel(this)) -> Show(); -} - -void MainFrame::AboutDialogHandler(wxCommandEvent& WXUNUSED(event)) -{ - AboutDialog(this).ShowModal(); -} - -void MainFrame::UpdateUI(wxCommandEvent& event) -{ - event.Skip(); - - bool is_running, is_stopped, is_ready; - - if(event.GetEventType() == wxEVT_DBG_COMMAND) - { - switch(event.GetId()) - { - case DID_START_EMU: - case DID_STARTED_EMU: - is_running = true; - is_stopped = false; - is_ready = false; - break; - - case DID_STOP_EMU: - case DID_STOPPED_EMU: - is_running = false; - is_stopped = true; - is_ready = false; - m_sys_menu_opened = false; - break; - - case DID_PAUSE_EMU: - case DID_PAUSED_EMU: - is_running = false; - is_stopped = false; - is_ready = false; - break; - - case DID_RESUME_EMU: - case DID_RESUMED_EMU: - is_running = true; - is_stopped = false; - is_ready = false; - break; - - case DID_READY_EMU: - is_running = false; - is_stopped = false; - is_ready = true; - break; - - case DID_REGISTRED_CALLBACK: - is_running = Emu.IsRunning(); - is_stopped = Emu.IsStopped(); - is_ready = Emu.IsReady(); - break; - - default: - return; - } - } - else - { - is_running = Emu.IsRunning(); - is_stopped = Emu.IsStopped(); - is_ready = Emu.IsReady(); - } - - wxMenuBar& menubar( *GetMenuBar() ); - wxMenuItem& pause = *menubar.FindItem( id_sys_pause ); - wxMenuItem& stop = *menubar.FindItem( id_sys_stop ); - wxMenuItem& send_exit = *menubar.FindItem( id_sys_send_exit ); - wxMenuItem& send_open_menu = *menubar.FindItem( id_sys_send_open_menu ); - pause.SetText(is_running ? "Pause\tCtrl + P" : is_ready ? "Start\tCtrl + C" : "Resume\tCtrl + C"); - pause.Enable(!is_stopped); - stop.Enable(!is_stopped); - //send_exit.Enable(false); - bool enable_commands = !is_stopped && Emu.GetCallbackManager().m_exit_callback.m_callbacks.GetCount(); - - send_open_menu.SetText(wxString::Format("Send %s system menu cmd", m_sys_menu_opened ? "close" : "open")); - send_open_menu.Enable(enable_commands); - send_exit.Enable(enable_commands); - - //m_aui_mgr.Update(); - - //wxCommandEvent refit( wxEVT_COMMAND_MENU_SELECTED, id_update_dbg ); - //GetEventHandler()->AddPendingEvent( refit ); -} - -void MainFrame::OnQuit(wxCloseEvent& event) -{ - DoSettings(false); - TheApp->Exit(); -} - -struct state_hdr -{ - u32 magic; - u16 version; - u32 mem_count; - u32 mem_offset; - u32 mem_size; - u32 hle_count; - u32 hle_offset; -}; - -static const u32 state_magic = *(u32*)"R3SS"; -static const u32 state_version = 0x1000; - -void MakeSaveState(wxFile& f) -{ - const ArrayF& mb = Memory.MemoryBlocks; - - state_hdr state; - memset(&state, 0, sizeof(state_hdr)); - - state.magic = state_magic; - state.version = state_version; - state.mem_count = mb.GetCount(); - //state.hle_count = mb.GetCount(); - - state.mem_offset = sizeof(state_hdr) + 4; - - f.Seek(state.mem_offset); - for(u32 i=0; iEnable(false); + menu_sys.Append(id_sys_stop, "Stop\tCtrl + S")->Enable(false); + menu_sys.AppendSeparator(); + menu_sys.Append(id_sys_send_open_menu, "Send open system menu cmd")->Enable(false); + menu_sys.Append(id_sys_send_exit, "Send exit cmd")->Enable(false); + + menu_conf.Append(id_config_emu, "Settings"); + menu_conf.AppendSeparator(); + menu_conf.Append(id_config_vfs_manager, "Virtual File System Manager"); + menu_conf.Append(id_config_vhdd_manager, "Virtual HDD Manager"); + + menu_tools.Append(id_tools_compiler, "ELF Compiler"); + menu_tools.Append(id_tools_memory_viewer, "Memory Viewer"); + + menu_help.Append(id_help_about, "About..."); + + SetMenuBar(&menubar); + + m_game_viewer = new GameViewer(this); + AddPane(m_game_viewer, "Game List", wxAUI_DOCK_BOTTOM); + + Connect( id_boot_game, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::BootGame) ); + Connect( id_boot_pkg, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::BootPkg) ); + Connect( id_boot_elf, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::BootElf) ); + Connect( id_boot_self, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::BootSelf) ); + + Connect( id_sys_pause, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::Pause) ); + Connect( id_sys_stop, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::Stop) ); + Connect( id_sys_send_open_menu, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::SendOpenCloseSysMenu) ); + Connect( id_sys_send_exit, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::SendExit) ); + + Connect( id_config_emu, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::Config) ); + Connect( id_config_vfs_manager, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::ConfigVFS) ); + Connect( id_config_vhdd_manager,wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::ConfigVHDD) ); + + Connect( id_tools_compiler, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OpenELFCompiler)); + Connect( id_tools_memory_viewer,wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OpenMemoryViewer)); + + Connect( id_help_about, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::AboutDialogHandler) ); + + Connect( id_update_dbg, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::UpdateUI) ); + + m_app_connector.Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(MainFrame::OnKeyDown), (wxObject*)0, this); + m_app_connector.Connect(wxEVT_DBG_COMMAND, wxCommandEventHandler(MainFrame::UpdateUI), (wxObject*)0, this); +} + +MainFrame::~MainFrame() +{ + m_aui_mgr.UnInit(); +} + +void MainFrame::AddPane(wxWindow* wind, const wxString& caption, int flags) +{ + wind->SetSize(-1, 300); + m_aui_mgr.AddPane(wind, wxAuiPaneInfo().Name(GetPaneName()).Caption(caption).Direction(flags).CloseButton(false).MaximizeButton()); +} + +void MainFrame::DoSettings(bool load) +{ + IniEntry ini; + ini.Init("Settings", "MainFrameAui"); + + if(load) + { + m_aui_mgr.LoadPerspective(ini.LoadValue(m_aui_mgr.SavePerspective())); + } + else + { + ini.SaveValue(m_aui_mgr.SavePerspective()); + } +} + +void MainFrame::BootGame(wxCommandEvent& WXUNUSED(event)) +{ + bool stopped = false; + + if(Emu.IsRunning()) + { + Emu.Pause(); + stopped = true; + } + + wxDirDialog ctrl(this, L"Select game folder", wxEmptyString); + + if(ctrl.ShowModal() == wxID_CANCEL) + { + if(stopped) Emu.Resume(); + return; + } + + Emu.Stop(); + + wxString elf[6] = { + "\\PS3_GAME\\USRDIR\\BOOT.BIN", + "\\USRDIR\\BOOT.BIN", + "\\BOOT.BIN", + "\\PS3_GAME\\USRDIR\\EBOOT.BIN", + "\\USRDIR\\EBOOT.BIN", + "\\EBOOT.BIN" + }; + + for(int i=0;i<6;i++) + { + if(wxFile::Access(ctrl.GetPath() + elf[i], wxFile::read)) + { + ConLog.Write("SELF: booting..."); + + Emu.Stop(); + + wxString fileIn = ctrl.GetPath()+elf[i]; + wxString fileOut = (ctrl.GetPath()+elf[i])+".elf"; + + // Check if the data really needs to be decrypted. + if(!wxFileExists(fileIn)) + { + ConLog.Error("Could not open game boot file!"); + return; + } + + wxFile f(fileIn); + // Get the key version. + f.Seek(0x08); + be_t key_version; + f.Read(&key_version, sizeof(key_version)); + + if(key_version.ToBE() == const_se_t::value) + { + ConLog.Warning("Debug SELF detected! Removing fake header..."); + + // Get the real elf offset. + f.Seek(0x10); + be_t elf_offset; + f.Read(&elf_offset, sizeof(elf_offset)); + + // Start at the real elf offset. + f.Seek(elf_offset); + + wxFile out(fileOut, wxFile::write); + + // Copy the data. + char buf[2048]; + while (ssize_t size = f.Read(buf, 2048)) + out.Write(buf, size); + } + else + { + if (!scetool_decrypt((scetool::s8 *)fileIn.mb_str(), (scetool::s8 *)fileOut.mb_str())) + { + ConLog.Write("Could not decrypt game boot file"); + return; + } + } + + f.Close(); + + Emu.SetPath(fileOut); + Emu.Load(); + if (!wxRemoveFile(fileOut)) + ConLog.Warning("Could not delete the decrypted ELF file"); + + ConLog.Write("Game: boot done."); + return; + } + } + + ConLog.Error("Ps3 executable not found in selected folder (%s)", ctrl.GetPath().mb_str()); + return; +} + + +void MainFrame::BootPkg(wxCommandEvent& WXUNUSED(event)) +{ + bool stopped = false; + + if(Emu.IsRunning()) + { + Emu.Pause(); + stopped = true; + } + + wxFileDialog ctrl (this, L"Select PKG", wxEmptyString, wxEmptyString, "*.*", + wxFD_OPEN | wxFD_FILE_MUST_EXIST); + + if(ctrl.ShowModal() == wxID_CANCEL) + { + if(stopped) Emu.Resume(); + return; + } + + ConLog.Write("PKG: extracting..."); + + Emu.Stop(); + + wxString fileName = ctrl.GetPath(); + pkg_unpack((const char *)fileName.mb_str()); + + if (!wxRemoveFile(ctrl.GetPath()+".dec")) + ConLog.Warning("Could not delete the decoded DEC file"); + + // Copy the PKG to dev_hdd0 and format the path to be identical to the PS3. + wxString gamePath = "\\dev_hdd0\\game\\"; + pkg_header *header; + pkg_info((const char *)fileName.mb_str(), &header); + + // Get the PKG title ID from the header and format it (should match TITLE ID from PARAM.SFO). + wxString titleID_full (header->title_id); + wxString titleID = titleID_full.SubString(7, 15); + + // Travel to bin folder. + wxSetWorkingDirectory(wxGetCwd() + "\\..\\"); + + // Save the main dir. + wxString mainDir = wxGetCwd(); + + // Set PKG dir. + wxString oldPkgDir = wxT(wxGetCwd() + "\\" + titleID_full); + wxString newPkgDir = wxT(wxGetCwd() + gamePath + titleID); + + // Move the final folder. + wxMoveDir(oldPkgDir, newPkgDir); + + // Save the title ID. + Emu.SetTitleID(titleID); + + ConLog.Write("PKG: extract done."); + + // Travel to the installed PKG. + wxSetWorkingDirectory(newPkgDir); + + wxString elf[6] = { + "\\PS3_GAME\\USRDIR\\BOOT.BIN", + "\\USRDIR\\BOOT.BIN", + "\\BOOT.BIN", + "\\PS3_GAME\\USRDIR\\EBOOT.BIN", + "\\USRDIR\\EBOOT.BIN", + "\\EBOOT.BIN" + }; + + for(int i=0;i<6;i++) + { + if(wxFile::Access(wxGetCwd() + elf[i], wxFile::read)) + { + ConLog.Write("SELF: booting..."); + + wxString fileIn = wxGetCwd()+elf[i]; + wxString fileOut = (wxGetCwd()+elf[i])+".elf"; + + // Check if the data really needs to be decrypted. + if(!wxFileExists(fileIn)) + { + ConLog.Error("Could not open game boot file!"); + return; + } + + wxFile f(fileIn); + // Get the key version. + f.Seek(0x08); + be_t key_version; + f.Read(&key_version, sizeof(key_version)); + + if(key_version.ToBE() == const_se_t::value) + { + ConLog.Warning("Debug SELF detected! Removing fake header..."); + + // Get the real elf offset. + f.Seek(0x10); + be_t elf_offset; + f.Read(&elf_offset, sizeof(elf_offset)); + + // Start at the real elf offset. + f.Seek(elf_offset); + + wxFile out(fileOut, wxFile::write); + + // Copy the data. + char buf[2048]; + while (ssize_t size = f.Read(buf, 2048)) + out.Write(buf, size); + } + else + { + if (!scetool_decrypt((scetool::s8 *)fileIn.mb_str(), (scetool::s8 *)fileOut.mb_str())) + { + ConLog.Write("Could not decrypt game boot file"); + return; + } + } + + f.Close(); + + // Set the working directory back. + wxSetWorkingDirectory(mainDir); + + Emu.SetPath(fileOut); + Emu.Load(); + if (!wxRemoveFile(fileOut)) + ConLog.Warning("Could not delete the decrypted ELF file"); + + ConLog.Write("Game: boot done."); + return; + } + } +} + +void MainFrame::BootElf(wxCommandEvent& WXUNUSED(event)) +{ + bool stopped = false; + + if(Emu.IsRunning()) + { + Emu.Pause(); + stopped = true; + } + + wxFileDialog ctrl(this, L"Select ELF", wxEmptyString, wxEmptyString, "*.*", + wxFD_OPEN | wxFD_FILE_MUST_EXIST); + + if(ctrl.ShowModal() == wxID_CANCEL) + { + if(stopped) Emu.Resume(); + return; + } + + ConLog.Write("ELF: booting..."); + + Emu.Stop(); + + Emu.SetPath(ctrl.GetPath()); + Emu.Load(); + + ConLog.Write("ELF: boot done."); +} + +void MainFrame::BootSelf(wxCommandEvent& WXUNUSED(event)) +{ + bool stopped = false; + + if(Emu.IsRunning()) + { + Emu.Pause(); + stopped = true; + } + + wxFileDialog ctrl(this, L"Select SELF", wxEmptyString, wxEmptyString, "*.*", + wxFD_OPEN | wxFD_FILE_MUST_EXIST); + + if(ctrl.ShowModal() == wxID_CANCEL) + { + if(stopped) Emu.Resume(); + return; + } + + ConLog.Write("SELF: booting..."); + + Emu.Stop(); + + wxString fileIn = ctrl.GetPath(); + wxString fileOut = ctrl.GetPath()+".elf"; + + // Check if the data really needs to be decrypted. + if(!wxFileExists(fileIn)) + { + ConLog.Error("Could not open SELF file!"); + return; + } + + wxFile f(fileIn); + // Get the key version. + f.Seek(0x08); + be_t key_version; + f.Read(&key_version, sizeof(key_version)); + + if(key_version.ToBE() == const_se_t::value) + { + ConLog.Warning("Debug SELF detected! Removing fake header..."); + + // Get the real elf offset. + f.Seek(0x10); + be_t elf_offset; + f.Read(&elf_offset, sizeof(elf_offset)); + + // Start at the real elf offset. + f.Seek(elf_offset); + + wxFile out(fileOut, wxFile::write); + + // Copy the data. + char buf[2048]; + while (ssize_t size = f.Read(buf, 2048)) + out.Write(buf, size); + } + else + { + if (!scetool_decrypt((scetool::s8 *)fileIn.mb_str(), (scetool::s8 *)fileOut.mb_str())) + { + ConLog.Write("SELF: Could not decrypt file"); + return; + } + } + + f.Close(); + + Emu.SetPath(fileOut); + Emu.Load(); + //if (!wxRemoveFile(fileOut)) + // ConLog.Warning("Could not delete the decrypted ELF file"); + + ConLog.Write("SELF: boot done."); +} + +void MainFrame::Pause(wxCommandEvent& WXUNUSED(event)) +{ + if(Emu.IsReady()) + { + Emu.Run(); + } + else if(Emu.IsPaused()) + { + Emu.Resume(); + } + else if(Emu.IsRunning()) + { + Emu.Pause(); + } +} + +void MainFrame::Stop(wxCommandEvent& WXUNUSED(event)) +{ + Emu.Stop(); +} + +void MainFrame::SendExit(wxCommandEvent& event) +{ + Emu.GetCallbackManager().m_exit_callback.Handle(0x0101, 0); +} + +void MainFrame::SendOpenCloseSysMenu(wxCommandEvent& event) +{ + Emu.GetCallbackManager().m_exit_callback.Handle(m_sys_menu_opened ? 0x0132 : 0x0131, 0); + m_sys_menu_opened = !m_sys_menu_opened; + wxCommandEvent ce; + UpdateUI(ce); +} + +void MainFrame::Config(wxCommandEvent& WXUNUSED(event)) +{ + //TODO + + bool paused = false; + + if(Emu.IsRunning()) + { + Emu.Pause(); + paused = true; + } + + wxDialog diag(this, wxID_ANY, "Settings", wxDefaultPosition); + + wxBoxSizer* s_panel(new wxBoxSizer(wxHORIZONTAL)); + wxBoxSizer* s_subpanel1(new wxBoxSizer(wxVERTICAL)); + wxBoxSizer* s_subpanel2(new wxBoxSizer(wxVERTICAL)); + + wxStaticBoxSizer* s_round_cpu( new wxStaticBoxSizer( wxVERTICAL, &diag, _("CPU") ) ); + wxStaticBoxSizer* s_round_cpu_decoder( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Decoder") ) ); + + wxStaticBoxSizer* s_round_gs( new wxStaticBoxSizer( wxVERTICAL, &diag, _("GS") ) ); + wxStaticBoxSizer* s_round_gs_render( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Render") ) ); + wxStaticBoxSizer* s_round_gs_res( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Default resolution") ) ); + wxStaticBoxSizer* s_round_gs_aspect( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Default aspect ratio") ) ); + + wxStaticBoxSizer* s_round_io( new wxStaticBoxSizer( wxVERTICAL, &diag, _("IO") ) ); + wxStaticBoxSizer* s_round_pad_handler( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Pad Handler") ) ); + wxStaticBoxSizer* s_round_keyboard_handler( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Keyboard Handler") ) ); + wxStaticBoxSizer* s_round_mouse_handler( new wxStaticBoxSizer( wxVERTICAL, &diag, _("Mouse Handler") ) ); + + wxComboBox* cbox_cpu_decoder = new wxComboBox(&diag, wxID_ANY); + wxComboBox* cbox_gs_render = new wxComboBox(&diag, wxID_ANY); + wxComboBox* cbox_gs_resolution = new wxComboBox(&diag, wxID_ANY); + wxComboBox* cbox_gs_aspect = new wxComboBox(&diag, wxID_ANY); + wxComboBox* cbox_pad_handler = new wxComboBox(&diag, wxID_ANY); + wxComboBox* cbox_keyboard_handler = new wxComboBox(&diag, wxID_ANY); + wxComboBox* cbox_mouse_handler = new wxComboBox(&diag, wxID_ANY); + + wxCheckBox* chbox_cpu_ignore_rwerrors = new wxCheckBox(&diag, wxID_ANY, "Ignore Read/Write errors"); + wxCheckBox* chbox_gs_dump_depth = new wxCheckBox(&diag, wxID_ANY, "Dump Depth Buffer"); + wxCheckBox* chbox_gs_dump_color = new wxCheckBox(&diag, wxID_ANY, "Dump Color Buffers"); + wxCheckBox* chbox_gs_vsync = new wxCheckBox(&diag, wxID_ANY, "VSync"); + + //cbox_cpu_decoder->Append("DisAsm"); + cbox_cpu_decoder->Append("Interpreter & DisAsm"); + cbox_cpu_decoder->Append("Interpreter"); + + for(int i=1; iAppend(wxString::Format("%dx%d", ResolutionTable[i].width, ResolutionTable[i].height)); + } + + cbox_gs_aspect->Append("4:3"); + cbox_gs_aspect->Append("16:9"); + + cbox_gs_render->Append("Null"); + cbox_gs_render->Append("OpenGL"); + //cbox_gs_render->Append("Software"); + + cbox_pad_handler->Append("Null"); + cbox_pad_handler->Append("Windows"); + //cbox_pad_handler->Append("DirectInput"); + + cbox_keyboard_handler->Append("Null"); + cbox_keyboard_handler->Append("Windows"); + //cbox_keyboard_handler->Append("DirectInput"); + + cbox_mouse_handler->Append("Null"); + cbox_mouse_handler->Append("Windows"); + //cbox_mouse_handler->Append("DirectInput"); + + chbox_cpu_ignore_rwerrors->SetValue(Ini.CPUIgnoreRWErrors.GetValue()); + chbox_gs_dump_depth->SetValue(Ini.GSDumpDepthBuffer.GetValue()); + chbox_gs_dump_color->SetValue(Ini.GSDumpColorBuffers.GetValue()); + chbox_gs_vsync->SetValue(Ini.GSVSyncEnable.GetValue()); + + cbox_cpu_decoder->SetSelection(Ini.CPUDecoderMode.GetValue() ? Ini.CPUDecoderMode.GetValue() - 1 : 0); + cbox_gs_render->SetSelection(Ini.GSRenderMode.GetValue()); + cbox_gs_resolution->SetSelection(ResolutionIdToNum(Ini.GSResolution.GetValue()) - 1); + cbox_gs_aspect->SetSelection(Ini.GSAspectRatio.GetValue() - 1); + cbox_pad_handler->SetSelection(Ini.PadHandlerMode.GetValue()); + cbox_keyboard_handler->SetSelection(Ini.KeyboardHandlerMode.GetValue()); + cbox_mouse_handler->SetSelection(Ini.MouseHandlerMode.GetValue()); + + s_round_cpu_decoder->Add(cbox_cpu_decoder, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_cpu->Add(s_round_cpu_decoder, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_cpu->Add(chbox_cpu_ignore_rwerrors, wxSizerFlags().Border(wxALL, 5).Expand()); + + s_round_gs_render->Add(cbox_gs_render, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_gs_res->Add(cbox_gs_resolution, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_gs_aspect->Add(cbox_gs_aspect, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_gs->Add(s_round_gs_render, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_gs->Add(s_round_gs_res, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_gs->Add(s_round_gs_aspect, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_gs->Add(chbox_gs_dump_depth, wxSizerFlags().Border(wxALL, 5)); + s_round_gs->Add(chbox_gs_dump_color, wxSizerFlags().Border(wxALL, 5)); + s_round_gs->Add(chbox_gs_vsync, wxSizerFlags().Border(wxALL, 5)); + + s_round_pad_handler->Add(cbox_pad_handler, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_keyboard_handler->Add(cbox_keyboard_handler, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_mouse_handler->Add(cbox_mouse_handler, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_io->Add(s_round_pad_handler, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_io->Add(s_round_keyboard_handler, wxSizerFlags().Border(wxALL, 5).Expand()); + s_round_io->Add(s_round_mouse_handler, wxSizerFlags().Border(wxALL, 5).Expand()); + + wxBoxSizer* s_b_panel(new wxBoxSizer(wxHORIZONTAL)); + + s_b_panel->Add(new wxButton(&diag, wxID_OK), wxSizerFlags().Border(wxALL, 5).Center()); + s_b_panel->Add(new wxButton(&diag, wxID_CANCEL), wxSizerFlags().Border(wxALL, 5).Center()); + + //wxBoxSizer* s_conf_panel(new wxBoxSizer(wxHORIZONTAL)); + + s_subpanel1->Add(s_round_cpu, wxSizerFlags().Border(wxALL, 5).Expand()); + s_subpanel1->Add(s_round_gs, wxSizerFlags().Border(wxALL, 5).Expand()); + s_subpanel2->Add(s_round_io, wxSizerFlags().Border(wxALL, 5).Expand()); + s_subpanel1->Add(s_b_panel, wxSizerFlags().Border(wxALL, 8).Expand()); + + s_subpanel2->AddSpacer(180); + s_panel->Add(s_subpanel1, wxSizerFlags().Border(wxALL, 5).Expand()); + s_panel->Add(s_subpanel2, wxSizerFlags().Border(wxALL, 5).Expand()); + + diag.SetSizerAndFit( s_panel ); + + if(diag.ShowModal() == wxID_OK) + { + Ini.CPUDecoderMode.SetValue(cbox_cpu_decoder->GetSelection() + 1); + Ini.CPUIgnoreRWErrors.SetValue(chbox_cpu_ignore_rwerrors->GetValue()); + Ini.GSRenderMode.SetValue(cbox_gs_render->GetSelection()); + Ini.GSResolution.SetValue(ResolutionNumToId(cbox_gs_resolution->GetSelection() + 1)); + Ini.GSAspectRatio.SetValue(cbox_gs_aspect->GetSelection() + 1); + Ini.GSVSyncEnable.SetValue(chbox_gs_vsync->GetValue()); + Ini.GSDumpDepthBuffer.SetValue(chbox_gs_dump_depth->GetValue()); + Ini.GSDumpColorBuffers.SetValue(chbox_gs_dump_color->GetValue()); + Ini.PadHandlerMode.SetValue(cbox_pad_handler->GetSelection()); + Ini.KeyboardHandlerMode.SetValue(cbox_keyboard_handler->GetSelection()); + Ini.MouseHandlerMode.SetValue(cbox_mouse_handler->GetSelection()); + + Ini.Save(); + } + + if(paused) Emu.Resume(); +} + +void MainFrame::ConfigVFS(wxCommandEvent& WXUNUSED(event)) +{ + VFSManagerDialog(this).ShowModal(); +} + +void MainFrame::ConfigVHDD(wxCommandEvent& WXUNUSED(event)) +{ + VHDDManagerDialog(this).ShowModal(); +} + +void MainFrame::OpenELFCompiler(wxCommandEvent& WXUNUSED(event)) +{ + (new CompilerELF(this)) -> Show(); +} + +void MainFrame::OpenMemoryViewer(wxCommandEvent& WXUNUSED(event)) +{ + (new MemoryViewerPanel(this)) -> Show(); +} + +void MainFrame::AboutDialogHandler(wxCommandEvent& WXUNUSED(event)) +{ + AboutDialog(this).ShowModal(); +} + +void MainFrame::UpdateUI(wxCommandEvent& event) +{ + event.Skip(); + + bool is_running, is_stopped, is_ready; + + if(event.GetEventType() == wxEVT_DBG_COMMAND) + { + switch(event.GetId()) + { + case DID_START_EMU: + case DID_STARTED_EMU: + is_running = true; + is_stopped = false; + is_ready = false; + break; + + case DID_STOP_EMU: + case DID_STOPPED_EMU: + is_running = false; + is_stopped = true; + is_ready = false; + m_sys_menu_opened = false; + break; + + case DID_PAUSE_EMU: + case DID_PAUSED_EMU: + is_running = false; + is_stopped = false; + is_ready = false; + break; + + case DID_RESUME_EMU: + case DID_RESUMED_EMU: + is_running = true; + is_stopped = false; + is_ready = false; + break; + + case DID_READY_EMU: + is_running = false; + is_stopped = false; + is_ready = true; + break; + + case DID_REGISTRED_CALLBACK: + is_running = Emu.IsRunning(); + is_stopped = Emu.IsStopped(); + is_ready = Emu.IsReady(); + break; + + default: + return; + } + } + else + { + is_running = Emu.IsRunning(); + is_stopped = Emu.IsStopped(); + is_ready = Emu.IsReady(); + } + + wxMenuBar& menubar( *GetMenuBar() ); + wxMenuItem& pause = *menubar.FindItem( id_sys_pause ); + wxMenuItem& stop = *menubar.FindItem( id_sys_stop ); + wxMenuItem& send_exit = *menubar.FindItem( id_sys_send_exit ); + wxMenuItem& send_open_menu = *menubar.FindItem( id_sys_send_open_menu ); + pause.SetText(is_running ? "Pause\tCtrl + P" : is_ready ? "Start\tCtrl + C" : "Resume\tCtrl + C"); + pause.Enable(!is_stopped); + stop.Enable(!is_stopped); + //send_exit.Enable(false); + bool enable_commands = !is_stopped && Emu.GetCallbackManager().m_exit_callback.m_callbacks.GetCount(); + + send_open_menu.SetText(wxString::Format("Send %s system menu cmd", m_sys_menu_opened ? "close" : "open")); + send_open_menu.Enable(enable_commands); + send_exit.Enable(enable_commands); + + //m_aui_mgr.Update(); + + //wxCommandEvent refit( wxEVT_COMMAND_MENU_SELECTED, id_update_dbg ); + //GetEventHandler()->AddPendingEvent( refit ); +} + +void MainFrame::OnQuit(wxCloseEvent& event) +{ + DoSettings(false); + TheApp->Exit(); +} + +struct state_hdr +{ + u32 magic; + u16 version; + u32 mem_count; + u32 mem_offset; + u32 mem_size; + u32 hle_count; + u32 hle_offset; +}; + +static const u32 state_magic = *(u32*)"R3SS"; +static const u32 state_version = 0x1000; + +void MakeSaveState(wxFile& f) +{ + const ArrayF& mb = Memory.MemoryBlocks; + + state_hdr state; + memset(&state, 0, sizeof(state_hdr)); + + state.magic = state_magic; + state.version = state_version; + state.mem_count = mb.GetCount(); + //state.hle_count = mb.GetCount(); + + state.mem_offset = sizeof(state_hdr) + 4; + + f.Seek(state.mem_offset); + for(u32 i=0; i= sizeof(m_entries[i].name) || c == '\0') + break; } - m_table[m_table.GetCount() - 1].Append(c); - } - - if(m_table.GetCount() != psfhdr.psf_entries_num) - { - if(m_show_log) ConLog.Error("PSF error: Entries loaded with error! [%d - %d]", m_table.GetCount(), psfhdr.psf_entries_num); - m_table.Clear(); - return false; } return true; } -struct PsfHelper +bool PSFLoader::LoadDataTable() { - static wxString ReadString(vfsStream& f, const u32 size) + for(u32 i=0; iFormat(); + if(PsfEntry* entry = SearchEntry("TITLE")) m_info.name = entry->Format(); + if(PsfEntry* entry = SearchEntry("APP_VER")) m_info.app_ver = entry->Format(); + if(PsfEntry* entry = SearchEntry("CATEGORY")) m_info.category = entry->Format(); + if(PsfEntry* entry = SearchEntry("PS3_SYSTEM_VER")) m_info.fw = entry->Format(); + if(PsfEntry* entry = SearchEntry("SOUND_FORMAT")) m_info.sound_format = entry->FormatInteger(); + if(PsfEntry* entry = SearchEntry("RESOLUTION")) m_info.resolution = entry->FormatInteger(); + if(PsfEntry* entry = SearchEntry("PARENTAL_LEVEL")) m_info.parental_lvl = entry->FormatInteger(); + if(m_info.serial.Length() == 9) { diff --git a/rpcs3/Loader/PSF.h b/rpcs3/Loader/PSF.h index c665734408..1deb1e639a 100644 --- a/rpcs3/Loader/PSF.h +++ b/rpcs3/Loader/PSF.h @@ -6,7 +6,7 @@ struct PsfHeader u32 psf_magic; u32 psf_version; u32 psf_offset_key_table; - u32 psf_offset_values_table; + u32 psf_offset_data_table; u32 psf_entries_num; bool CheckMagic() const { return psf_magic == *(u32*)"\0PSF"; } @@ -14,13 +14,44 @@ struct PsfHeader struct PsfDefTbl { - u16 psf_name_tbl_offset; - u16 psf_data_type; - u32 psf_data_size; - u32 psf_data_fsize; + u16 psf_key_table_offset; + u16 psf_param_fmt; + u32 psf_param_len; + u32 psf_param_max_len; u32 psf_data_tbl_offset; }; +struct PsfEntry +{ + char name[128]; + u16 fmt; + char param[4096]; + + std::string Format() const + { + switch(fmt) + { + default: + case 0x0400: + case 0x0402: + return FormatString(); + + case 0x0404: + return wxString::Format("0x%x", FormatInteger()).c_str(); + } + } + + u32 FormatInteger() const + { + return *(u32*)param; + } + + char* FormatString() const + { + return (char*)param; + } +}; + class PSFLoader { vfsStream& psf_f; @@ -29,14 +60,19 @@ class PSFLoader public: PSFLoader(vfsStream& f); - wxArrayString m_table; + Array m_entries; + + PsfEntry* SearchEntry(const std::string& key); + + //wxArrayString m_table; GameInfo m_info; PsfHeader psfhdr; + Array m_psfindxs; virtual bool Load(bool show = true); virtual bool Close(); private: bool LoadHdr(); bool LoadKeyTable(); - bool LoadValuesTable(); + bool LoadDataTable(); }; \ No newline at end of file