Added SRAM save game functionality

This commit is contained in:
2026-05-15 00:19:45 +01:00
parent c416bea9ac
commit 787e403232
3 changed files with 84 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ namespace Desktop
public double FrameTime { get; private set; } = 0;
public double FramesPerSecond { get; private set; } = 0;
private string _currentRomName = "No ROM";
private string _currentRomPath = "";
private Stopwatch _stopwatch = new System.Diagnostics.Stopwatch();
public bool IsRunning { get; private set; } = false;
@@ -181,7 +182,6 @@ namespace Desktop
{
IsRunning = false;
}
private async void LoadRomAndStart(string filePath)
{
StopEmulator();
@@ -190,20 +190,59 @@ namespace Desktop
await _emulatorTask;
}
// 1. SAVE THE PREVIOUS GAME!
SaveCurrentSram();
// 2. Load the file
byte[] rom = File.ReadAllBytes(filePath);
// 3. Jam it into the Sega Mapper
_machine.LoadCartridge(rom);
// 4. Update the path tracking
_currentRomPath = filePath;
_currentRomName = Path.GetFileNameWithoutExtension(filePath);
this.Text = $"Parsons Master System - {_currentRomName}";
// 5. Turn the power on!
// 5. LOAD THE NEW SAVE DATA!
string savPath = Path.ChangeExtension(_currentRomPath, ".sav");
_machine.MemoryBus.LoadSaveData(savPath);
// 6. Turn the power on!
StartEmulator();
}
//private async void LoadRomAndStart(string filePath)
//{
// StopEmulator();
// if (_emulatorTask != null)
// {
// await _emulatorTask;
// }
// // 2. Load the file
// byte[] rom = File.ReadAllBytes(filePath);
// // 3. Jam it into the Sega Mapper
// _machine.LoadCartridge(rom);
// _currentRomName = Path.GetFileNameWithoutExtension(filePath);
// this.Text = $"Parsons Master System - {_currentRomName}";
// // 5. Turn the power on!
// StartEmulator();
//}
private void SaveCurrentSram()
{
if (!string.IsNullOrEmpty(_currentRomPath) && _machine != null)
{
// Swaps ".sms" for ".sav"
string savPath = Path.ChangeExtension(_currentRomPath, ".sav");
_machine.MemoryBus.SaveSaveData(savPath);
}
}
private void PopulateIncludedRomsMenu()
{
// The folder you used for Golden Axe Warrior
@@ -264,7 +303,7 @@ namespace Desktop
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Environment.Exit(0);
this.Close();
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
@@ -308,6 +347,7 @@ namespace Desktop
private void ParsonsForm1_FormClosing(object sender, FormClosingEventArgs e)
{
IsRunning = false;
SaveCurrentSram();
_audioPlayer?.Stop();
}
}

10
Desktop/ROMS/zexdoc.sav Normal file

File diff suppressed because one or more lines are too long