Add support for negative and overflow sectors in image creation

This commit is contained in:
2025-10-23 11:21:47 +01:00
parent 23873fb2f5
commit e2d4ea76b8
55 changed files with 223 additions and 150 deletions

View File

@@ -158,8 +158,9 @@ public partial class AtariLynx : IByteAddressableImage
public IEnumerable<SectorTagType> SupportedSectorTags => Array.Empty<SectorTagType>();
/// <inheritdoc />
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint sectorSize) => Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint negativeSectors, uint overflowSectors, uint sectorSize) =>
Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
/// <inheritdoc />
public bool Close()

View File

@@ -168,8 +168,9 @@ public partial class GameBoy : IByteAddressableImage
public IEnumerable<SectorTagType> SupportedSectorTags => Array.Empty<SectorTagType>();
/// <inheritdoc />
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint sectorSize) => Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint negativeSectors, uint overflowSectors, uint sectorSize) =>
Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
/// <inheritdoc />
public bool Close()

View File

@@ -148,8 +148,9 @@ public partial class GameBoyAdvance : IByteAddressableImage
public IEnumerable<SectorTagType> SupportedSectorTags => Array.Empty<SectorTagType>();
/// <inheritdoc />
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint sectorSize) => Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint negativeSectors, uint overflowSectors, uint sectorSize) =>
Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
/// <inheritdoc />
public bool Close()

View File

@@ -139,8 +139,7 @@ public partial class MasterSystem : IByteAddressableImage
MetadataMediaType = MetadataMediaType.LinearMedia
};
Header header =
Marshal.ByteArrayToStructureBigEndian<Header>(_data, headerPosition, Marshal.SizeOf<Header>());
Header header = Marshal.ByteArrayToStructureBigEndian<Header>(_data, headerPosition, Marshal.SizeOf<Header>());
var sb = new StringBuilder();
@@ -252,8 +251,9 @@ public partial class MasterSystem : IByteAddressableImage
public IEnumerable<SectorTagType> SupportedSectorTags => Array.Empty<SectorTagType>();
/// <inheritdoc />
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint sectorSize) => Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint negativeSectors, uint overflowSectors, uint sectorSize) =>
Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
/// <inheritdoc />
public bool Close()

View File

@@ -75,9 +75,9 @@ public class Nes : IByteAddressableImage
if(stream.Length < 16) return false;
stream.Position = 0;
byte[] magicBytes = new byte[4];
var magicBytes = new byte[4];
stream.EnsureRead(magicBytes, 0, 8);
uint magic = BitConverter.ToUInt32(magicBytes, 0);
var magic = BitConverter.ToUInt32(magicBytes, 0);
return magic == 0x1A53454E;
}
@@ -93,9 +93,9 @@ public class Nes : IByteAddressableImage
if(stream.Length < 16) return ErrorNumber.InvalidArgument;
stream.Position = 0;
byte[] header = new byte[16];
var header = new byte[16];
stream.EnsureRead(header, 0, 8);
uint magic = BitConverter.ToUInt32(header, 0);
var magic = BitConverter.ToUInt32(header, 0);
if(magic != 0x1A53454E) return ErrorNumber.InvalidArgument;
@@ -294,8 +294,9 @@ public class Nes : IByteAddressableImage
public IEnumerable<SectorTagType> SupportedSectorTags => Array.Empty<SectorTagType>();
/// <inheritdoc />
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint sectorSize) => Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint negativeSectors, uint overflowSectors, uint sectorSize) =>
Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
/// <inheritdoc />
public bool Close()
@@ -314,7 +315,7 @@ public class Nes : IByteAddressableImage
return false;
}
byte[] header = new byte[16];
var header = new byte[16];
if(_nesHeaderInfo is null)
{
@@ -682,16 +683,16 @@ public class Nes : IByteAddressableImage
return ErrorNumber.ReadOnly;
}
bool foundRom = false;
bool foundChrRom = false;
bool foundInstRom = false;
bool foundProm = false;
bool foundRam = false;
bool foundChrRam = false;
bool foundNvram = false;
bool foundChrNvram = false;
bool foundMapper = false;
bool foundSubMapper = false;
var foundRom = false;
var foundChrRom = false;
var foundInstRom = false;
var foundProm = false;
var foundRam = false;
var foundChrRam = false;
var foundNvram = false;
var foundChrNvram = false;
var foundMapper = false;
var foundSubMapper = false;
// Sanitize
foreach(LinearMemoryDevice map in mappings.Devices)

View File

@@ -819,8 +819,9 @@ public partial class Nintendo64 : IByteAddressableImage
public IEnumerable<SectorTagType> SupportedSectorTags => Array.Empty<SectorTagType>();
/// <inheritdoc />
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint sectorSize) => Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint negativeSectors, uint overflowSectors, uint sectorSize) =>
Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
/// <inheritdoc />
public bool Close()

View File

@@ -383,8 +383,9 @@ public partial class SegaMegaDrive : IByteAddressableImage
public IEnumerable<SectorTagType> SupportedSectorTags => Array.Empty<SectorTagType>();
/// <inheritdoc />
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint sectorSize) => Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint negativeSectors, uint overflowSectors, uint sectorSize) =>
Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
/// <inheritdoc />
public bool Close()

View File

@@ -62,7 +62,7 @@ public class SuperNintendo : IByteAddressableImage
return false;
Header header;
byte[] headerBytes = new byte[48];
var headerBytes = new byte[48];
switch(stream.Length)
{
@@ -110,8 +110,8 @@ public class SuperNintendo : IByteAddressableImage
// Not sure but seems to be a multiple of at least this
if(stream.Length % 32768 != 0) return ErrorNumber.InvalidArgument;
bool found = false;
byte[] headerBytes = new byte[48];
var found = false;
var headerBytes = new byte[48];
switch(stream.Length)
{
@@ -271,8 +271,9 @@ public class SuperNintendo : IByteAddressableImage
public IEnumerable<SectorTagType> SupportedSectorTags => Array.Empty<SectorTagType>();
/// <inheritdoc />
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint sectorSize) => Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
uint negativeSectors, uint overflowSectors, uint sectorSize) =>
Create(path, mediaType, options, (long)sectors) == ErrorNumber.NoError;
/// <inheritdoc />
public bool Close()
@@ -375,7 +376,7 @@ public class SuperNintendo : IByteAddressableImage
bool hasFlash = _header is { OldMakerCode: 0x33, ExpansionFlashSize: > 0 };
bool hasBattery = chipset is 2 or 5 or 6 or 9 or 0xA;
int devices = 1;
var devices = 1;
if(hasRam) devices++;
@@ -398,8 +399,8 @@ public class SuperNintendo : IByteAddressableImage
}
};
int pos = 1;
ulong addr = (ulong)_data.Length;
var pos = 1;
var addr = (ulong)_data.Length;
if(hasRam)
{
@@ -539,10 +540,10 @@ public class SuperNintendo : IByteAddressableImage
return ErrorNumber.ReadOnly;
}
bool foundRom = false;
bool foundRam = false;
bool foundExtraRam = false;
bool foundFlash = false;
var foundRom = false;
var foundRam = false;
var foundExtraRam = false;
var foundFlash = false;
// Sanitize
foreach(LinearMemoryDevice map in mappings.Devices)