Skip to content

Commit

Permalink
UNROM 512 flash memory fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ClusterM committed Jul 15, 2024
1 parent 406d4e6 commit 578f0d0
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
14 changes: 11 additions & 3 deletions FamicomDumper/FlashWriters/FlashWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,10 +89,16 @@ public void Write(string filename, IEnumerable<int>? 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
Expand All @@ -99,7 +107,7 @@ public void Write(string filename, IEnumerable<int>? 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)
Expand Down
55 changes: 48 additions & 7 deletions FamicomDumper/FlashWriters/Unrom512Writer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"));
}
Expand Down

0 comments on commit 578f0d0

Please sign in to comment.