diff --git a/cmd/psx/main.go b/cmd/psx/main.go index 7fc0f2f..01e2b82 100644 --- a/cmd/psx/main.go +++ b/cmd/psx/main.go @@ -51,8 +51,10 @@ func splitMemoryCard(base string, smc *psx.MemoryCard) error { for { // Copy the directory frame and data block tmc.HeaderBlock.DirectoryFrame[j] = df - if df.LinkOrder != psx.LastLink { + if df.LinkOrder != psx.LastLink && tmc.HeaderBlock.DirectoryFrame[j].LinkOrder != uint16(j+1) { + // Block has moved during the copy tmc.HeaderBlock.DirectoryFrame[j].LinkOrder = uint16(j + 1) + tmc.HeaderBlock.DirectoryFrame[j].UpdateChecksum() } tmc.DataBlock[j] = smc.DataBlock[i] diff --git a/memcard.go b/memcard.go index 01a80bb..13650f2 100644 --- a/memcard.go +++ b/memcard.go @@ -70,6 +70,12 @@ type directoryFrame struct { Checksum byte } +func (d *directoryFrame) UpdateChecksum() { + h := XOR() + binary.Write(h, binary.LittleEndian, d.directoryFrameFields) + d.Checksum = h.Sum(nil)[0] +} + type unusedFrame struct { AvailableBlocks byte Reserved [3]byte