diff --git a/FamicomDumper/FlashWriters/FlashWriter.cs b/FamicomDumper/FlashWriters/FlashWriter.cs index 55ec1cf..1f83bfc 100644 --- a/FamicomDumper/FlashWriters/FlashWriter.cs +++ b/FamicomDumper/FlashWriters/FlashWriter.cs @@ -15,6 +15,8 @@ namespace com.clusterrr.Famicom.Dumper.FlashWriters public enum FlashEraseMode { Chip, Sector } public record FlashInfo { + public byte? ManufactorerId; + public ushort? DeviceId; public int DeviceSize; public int MaximumNumberOfBytesInMultiProgram; public EraseBlockRegionInfo[]? Regions; @@ -87,10 +89,16 @@ public void Write(string filename, IEnumerable? badSectors = null, bool sil Init(); InitBanking(); var flash = GetFlashInfo(); - if (flash.DeviceSize > 4 * 1024 * 1024) + if (flash.ManufactorerId != null) + Console.WriteLine($"Manufactorer ID: {flash.ManufactorerId:X2}"); + if (flash.DeviceId != null) + Console.WriteLine($"Device ID: {flash.DeviceId:X2}"); + if (flash.DeviceSize == 0) + Console.WriteLine("Dvice size: unknown"); + else if (flash.DeviceSize > 4 * 1024 * 1024) Console.WriteLine($"Device size: {flash.DeviceSize / 1024 / 1024} MByte / {flash.DeviceSize / 1024 / 1024 * 8} Mbit"); else - Console.WriteLine($"Device size: {flash.DeviceSize / 1024 } KByte / {flash.DeviceSize / 1024 * 8} Kbit"); + Console.WriteLine($"Device size: {flash.DeviceSize / 1024} KByte / {flash.DeviceSize / 1024 * 8} Kbit"); if (flash.MaximumNumberOfBytesInMultiProgram > 0) { #if DEBUG @@ -99,7 +107,7 @@ public void Write(string filename, IEnumerable? badSectors = null, bool sil if (dumper.ProtocolVersion >= 3) dumper.SetMaximumNumberOfBytesInMultiProgram((uint)flash.MaximumNumberOfBytesInMultiProgram); } - if (PRG.Length > flash.DeviceSize) + if (flash.DeviceSize != 0 && PRG.Length > flash.DeviceSize) throw new InvalidDataException("This ROM is too big for this cartridge"); if (NeedEnlarge) diff --git a/FamicomDumper/FlashWriters/Unrom512Writer.cs b/FamicomDumper/FlashWriters/Unrom512Writer.cs index d3e660a..428eebe 100644 --- a/FamicomDumper/FlashWriters/Unrom512Writer.cs +++ b/FamicomDumper/FlashWriters/Unrom512Writer.cs @@ -48,16 +48,53 @@ protected override FlashInfo GetFlashInfo() WriteFlashCmd(0x5555, 0x90); var id = dumper.ReadCpu(0x8000, 2); - int flashSize = id[1] switch - { - 0xB5 => 128 * 1024, - 0xB6 => 256 * 1024, - 0xB7 => 512 * 1024, - _ => 0 - }; + int flashSize; + switch (id[0]) + { + case 0xBF: // Microchip + flashSize = id[1] switch + { + 0xB5 => 128 * 1024, // SST39SF010A + 0xB6 => 256 * 1024, // SST39SF020A + 0xB7 => 512 * 1024, // SST39SF040 + _ => 0, + }; + break; + case 0x01: // AMD + flashSize = id[1] switch + { + 0xD9 => 128 * 1024, // Am29F100 (top) + 0xDF => 128 * 1024, // Am29F100 (botton) + 0x20 => 128 * 1024, // Am29F010 + 0x51 => 256 * 1024, // Am29F200 (too) + 0x57 => 256 * 1024, // Am29F200 (bottom) + 0xB0 => 256 * 1024, // Am29F002 (top) + 0x34 => 256 * 1024, // Am29F002 (bottom) + 0xA4 => 512 * 1024, // Am29F040 + 0xD5 => 1024 * 1024, // Am29F080 + 0xAD => 2 * 1024 * 1024, // Am29F016 + _ => 0, + }; + break; + case 0x9D: // PMC + flashSize = id[1] switch + { + 0x1B => 64 * 1024, // Pm39LV512 + 0x1C => 128 * 1024, // Pm39LV010 + 0x3D => 256 * 1024, // Pm39LV020 + 0x3E => 512 * 1024, // Pm39LV040 + _ => 0, + }; + break; + default: + flashSize = 0; + break; + } ResetFlash(); return new FlashInfo() { + ManufactorerId = id[0], + DeviceId = id[1], DeviceSize = flashSize, MaximumNumberOfBytesInMultiProgram = 0, Regions = null @@ -84,6 +121,10 @@ public override void PrintFlashInfo() { ResetFlash(); var flash = GetFlashInfo(); + if (flash.ManufactorerId != null) + Console.WriteLine($"Manufactorer ID: {flash.ManufactorerId:X2}"); + if (flash.DeviceId != null) + Console.WriteLine($"Device ID: {flash.DeviceId:X2}"); var deviceSize = flash.DeviceSize; Console.WriteLine($"Device size: " + (deviceSize > 0 ? $"{deviceSize / 1024} KByte / {deviceSize / 1024 * 8} Kbit" : "unknown")); }