mirror of
				https://github.com/RetroDECK/Duckstation.git
				synced 2025-04-10 19:15:14 +00:00 
			
		
		
		
	Add option to dump the contents of RAM to a file
This commit is contained in:
		
							parent
							
								
									0aefdf4753
								
							
						
					
					
						commit
						4e62b32d60
					
				|  | @ -1228,6 +1228,15 @@ void UpdateMemoryCards() | |||
|   } | ||||
| } | ||||
| 
 | ||||
| bool DumpRAM(const char* filename) | ||||
| { | ||||
|   auto fp = FileSystem::OpenManagedCFile(filename, "wb"); | ||||
|   if (!fp) | ||||
|     return false; | ||||
| 
 | ||||
|   return std::fwrite(Bus::g_ram, Bus::RAM_SIZE, 1, fp.get()) == 1; | ||||
| } | ||||
| 
 | ||||
| bool HasMedia() | ||||
| { | ||||
|   return g_cdrom.HasMedia(); | ||||
|  | @ -1333,7 +1342,8 @@ bool RemoveMediaPathFromPlaylist(u32 index) | |||
| 
 | ||||
|   if (GetMediaPlaylistIndex() == index) | ||||
|   { | ||||
|     g_host_interface->AddFormattedOSDMessage(10.0f, "Removing current media from playlist, removing media from CD-ROM."); | ||||
|     g_host_interface->AddFormattedOSDMessage(10.0f, | ||||
|                                              "Removing current media from playlist, removing media from CD-ROM."); | ||||
|     g_cdrom.RemoveMedia(); | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -104,6 +104,9 @@ void UpdateControllerSettings(); | |||
| void ResetControllers(); | ||||
| void UpdateMemoryCards(); | ||||
| 
 | ||||
| /// Dumps RAM to a file.
 | ||||
| bool DumpRAM(const char* filename); | ||||
| 
 | ||||
| bool HasMedia(); | ||||
| bool InsertMedia(const char* path); | ||||
| void RemoveMedia(); | ||||
|  |  | |||
|  | @ -662,6 +662,13 @@ void MainWindow::connectSignals() | |||
|     else | ||||
|       m_host_interface->stopDumpingAudio(); | ||||
|   }); | ||||
|   connect(m_ui.actionDumpRAM, &QAction::triggered, [this]() { | ||||
|     const QString filename = QFileDialog::getSaveFileName(this, tr("Destination File")); | ||||
|     if (filename.isEmpty()) | ||||
|       return; | ||||
| 
 | ||||
|     m_host_interface->dumpRAM(filename); | ||||
|   }); | ||||
|   SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowVRAM, "Debug", "ShowVRAM"); | ||||
|   SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowGPUState, "Debug", "ShowGPUState"); | ||||
|   SettingWidgetBinder::BindWidgetToBoolSetting(m_host_interface, m_ui.actionDebugShowCDROMState, "Debug", | ||||
|  |  | |||
|  | @ -149,9 +149,10 @@ | |||
|     <addaction name="menuCPUExecutionMode"/> | ||||
|     <addaction name="menuRenderer"/> | ||||
|     <addaction name="separator"/> | ||||
|     <addaction name="actionDumpAudio"/> | ||||
|     <addaction name="actionDebugDumpCPUtoVRAMCopies"/> | ||||
|     <addaction name="actionDebugDumpVRAMtoCPUCopies"/> | ||||
|     <addaction name="actionDumpAudio"/> | ||||
|     <addaction name="actionDumpRAM"/> | ||||
|     <addaction name="separator"/> | ||||
|     <addaction name="actionDebugShowVRAM"/> | ||||
|     <addaction name="actionDebugShowGPUState"/> | ||||
|  | @ -484,6 +485,11 @@ | |||
|     <string>Dump Audio</string> | ||||
|    </property> | ||||
|   </action> | ||||
|   <action name="actionDumpRAM"> | ||||
|    <property name="text"> | ||||
|     <string>Dump RAM...</string> | ||||
|    </property> | ||||
|   </action> | ||||
|   <action name="actionDebugShowGPUState"> | ||||
|    <property name="checkable"> | ||||
|     <bool>true</bool> | ||||
|  |  | |||
|  | @ -1026,6 +1026,24 @@ void QtHostInterface::stopDumpingAudio() | |||
|   StopDumpingAudio(); | ||||
| } | ||||
| 
 | ||||
| void QtHostInterface::dumpRAM(const QString& filename) | ||||
| { | ||||
|   if (!isOnWorkerThread()) | ||||
|   { | ||||
|     QMetaObject::invokeMethod(this, "dumpRAM", Q_ARG(const QString&, filename)); | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (System::IsShutdown()) | ||||
|     return; | ||||
| 
 | ||||
|   const std::string filename_str = filename.toStdString(); | ||||
|   if (System::DumpRAM(filename_str.c_str())) | ||||
|     ReportFormattedMessage("RAM dumped to '%s'", filename_str.c_str()); | ||||
|   else | ||||
|     ReportFormattedMessage("Failed to dump RAM to '%s'", filename_str.c_str()); | ||||
| } | ||||
| 
 | ||||
| void QtHostInterface::saveScreenshot() | ||||
| { | ||||
|   if (!isOnWorkerThread()) | ||||
|  |  | |||
|  | @ -151,6 +151,7 @@ public Q_SLOTS: | |||
|   void setAudioOutputMuted(bool muted); | ||||
|   void startDumpingAudio(); | ||||
|   void stopDumpingAudio(); | ||||
|   void dumpRAM(const QString& filename); | ||||
|   void saveScreenshot(); | ||||
|   void redrawDisplayWindow(); | ||||
|   void toggleFullscreen(); | ||||
|  |  | |||
|  | @ -904,6 +904,7 @@ void SDLHostInterface::DrawQuickSettingsMenu() | |||
| 
 | ||||
| void SDLHostInterface::DrawDebugMenu() | ||||
| { | ||||
|   const bool system_valid = System::IsValid(); | ||||
|   Settings::DebugSettings& debug_settings = g_settings.debugging; | ||||
|   bool settings_changed = false; | ||||
| 
 | ||||
|  | @ -931,6 +932,9 @@ void SDLHostInterface::DrawDebugMenu() | |||
|   settings_changed |= ImGui::MenuItem("Dump CPU to VRAM Copies", nullptr, &debug_settings.dump_cpu_to_vram_copies); | ||||
|   settings_changed |= ImGui::MenuItem("Dump VRAM to CPU Copies", nullptr, &debug_settings.dump_vram_to_cpu_copies); | ||||
| 
 | ||||
|   if (ImGui::MenuItem("Dump RAM...", nullptr, nullptr, system_valid)) | ||||
|     DoDumpRAM(); | ||||
| 
 | ||||
|   ImGui::Separator(); | ||||
| 
 | ||||
|   settings_changed |= ImGui::MenuItem("Show VRAM", nullptr, &debug_settings.show_vram); | ||||
|  | @ -1511,6 +1515,22 @@ void SDLHostInterface::DoChangeDisc() | |||
|   System::ResetPerformanceCounters(); | ||||
| } | ||||
| 
 | ||||
| void SDLHostInterface::DoDumpRAM() | ||||
| { | ||||
|   Assert(!System::IsShutdown()); | ||||
| 
 | ||||
|   nfdchar_t* path = nullptr; | ||||
|   if (!NFD_SaveDialog("bin", nullptr, &path) || !path || std::strlen(path) == 0) | ||||
|     return; | ||||
| 
 | ||||
|   if (System::DumpRAM(path)) | ||||
|     AddFormattedOSDMessage(5.0f, "Dumped RAM to '%s'", path); | ||||
|   else | ||||
|     AddFormattedOSDMessage(10.0f, "Failed to dump RAM to '%s'", path); | ||||
| 
 | ||||
|   System::ResetPerformanceCounters(); | ||||
| } | ||||
| 
 | ||||
| void SDLHostInterface::Run() | ||||
| { | ||||
|   while (!m_quit_request) | ||||
|  |  | |||
|  | @ -79,6 +79,7 @@ private: | |||
|   void DrawImGuiWindows() override; | ||||
|   void DoStartDisc(); | ||||
|   void DoChangeDisc(); | ||||
|   void DoDumpRAM(); | ||||
| 
 | ||||
|   void HandleSDLEvent(const SDL_Event* event); | ||||
|   void ProcessEvents(); | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Connor McLaughlin
						Connor McLaughlin