-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ISaveRam implementation for AppleII, fix bug which caused DiskIIC…
…ontroller to not be correctly stated
- Loading branch information
1 parent
9ae5f78
commit 8737203
Showing
11 changed files
with
142 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/BizHawk.Emulation.Cores/Computers/AppleII/AppleII.ISaveRam.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System; | ||
using System.IO; | ||
|
||
using BizHawk.Common; | ||
using BizHawk.Emulation.Common; | ||
|
||
namespace BizHawk.Emulation.Cores.Computers.AppleII | ||
{ | ||
public partial class AppleII : ISaveRam | ||
{ | ||
private byte[][] _diskDeltas; | ||
|
||
private void InitSaveRam() | ||
{ | ||
_diskDeltas = new byte[DiskCount][]; | ||
} | ||
|
||
public bool SaveRamModified => true; | ||
|
||
public byte[] CloneSaveRam() | ||
{ | ||
using var ms = new MemoryStream(); | ||
using var bw = new BinaryWriter(ms); | ||
|
||
SaveDelta(); | ||
bw.Write(DiskCount); | ||
for (var i = 0; i < DiskCount; i++) | ||
{ | ||
bw.WriteByteBuffer(_diskDeltas[i]); | ||
} | ||
|
||
return ms.ToArray(); | ||
} | ||
|
||
public void StoreSaveRam(byte[] data) | ||
{ | ||
using var ms = new MemoryStream(data, false); | ||
using var br = new BinaryReader(ms); | ||
|
||
var ndisks = br.ReadInt32(); | ||
|
||
if (ndisks != DiskCount) | ||
{ | ||
throw new InvalidOperationException("Disk count mismatch!"); | ||
} | ||
|
||
for (var i = 0; i < DiskCount; i++) | ||
{ | ||
_diskDeltas[i] = br.ReadByteBuffer(returnNull: true); | ||
} | ||
|
||
LoadDelta(true); | ||
} | ||
|
||
private void SaveDelta() | ||
{ | ||
_machine.DiskIIController.Drive1.DeltaUpdate((original, current) => | ||
{ | ||
_diskDeltas[CurrentDisk] = DeltaSerializer.GetDelta<byte>(original, current).ToArray(); | ||
}); | ||
} | ||
|
||
private void LoadDelta(bool maybeDifferent) | ||
{ | ||
_machine.DiskIIController.Drive1.DeltaUpdate((original, current) => | ||
{ | ||
if (_diskDeltas[CurrentDisk] is not null) | ||
{ | ||
DeltaSerializer.ApplyDelta<byte>(original, current, _diskDeltas[CurrentDisk]); | ||
} | ||
else if (maybeDifferent) | ||
{ | ||
original.AsSpan().CopyTo(current); | ||
} | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters