Skip to content

Commit

Permalink
FIx to error that made packing worse
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-zhao committed Dec 21, 2021
1 parent cafea25 commit bad3834
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions editor/Cartridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ public byte[] MakeRom(bool log = true)
foreach (var assetToPack in assetsToPack.Where(x => x.Asset.Type == Game.Asset.Types.RawValue))
{
assetToPack.Asset.Restrictions.MinimumOffset = assetToPack.Asset.OriginalOffset;
assetToPack.Asset.Restrictions.MaximumOffset = assetToPack.Asset.OriginalOffset;
assetToPack.Asset.Restrictions.MaximumOffset = assetToPack.Asset.OriginalOffset + assetToPack.Data.Count;
}

// First we build a list of "free space". We include all the "original assets" so we will overwrite unused space. Missing "original" data makes us ignore it.
Expand Down Expand Up @@ -1522,7 +1522,7 @@ private void WriteAsset(AssetToPack item, ISet<IDataItem> writtenItems, HashSet<
offset = freeSpace.FindSpace(sizeNeeded, item.Asset.Restrictions);
item.DataItem.Offset = offset;
item.Data.CopyTo(memory, offset);
if (log) _logger($"- Wrote data for asset {item.Name} at {offset:X}, length {item.Data.Count} bytes");
if (log) _logger($"- Wrote data for asset {item.Name} at ${offset:X}, length {item.Data.Count} bytes");
freeSpace.Remove(offset, item.Data.Count);

writtenItems.Add(item.DataItem);
Expand Down
6 changes: 5 additions & 1 deletion editor/FreeSpace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public int FindSpace(int size, Cartridge.Game.LocationRestriction restriction)
// Same for the max
possibleSpans = possibleSpans
.Where(x => x.Start <= restriction.MaximumOffset)
.Select(x => new Span { Start = x.Start, End = Math.Min(restriction.MaximumOffset + size, x.End) });
.Select(x => new Span { Start = x.Start, End = Math.Min(restriction.MaximumOffset, x.End) });
}

if (!restriction.CanCrossBanks)
Expand All @@ -171,6 +171,10 @@ public int FindSpace(int size, Cartridge.Game.LocationRestriction restriction)
.FirstOrDefault();
if (span != null)
{
if (span.Start > 0x3ff20)
{
span.Start += 1;
}
return span.Start;
}

Expand Down

0 comments on commit bad3834

Please sign in to comment.