Skip to content

Commit

Permalink
Recalculate checksum if the link order is updated
Browse files Browse the repository at this point in the history
Fixes #2
  • Loading branch information
bodgit committed May 19, 2021
1 parent 6a6db11 commit 607e53f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cmd/psx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
6 changes: 6 additions & 0 deletions memcard.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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
Expand Down

0 comments on commit 607e53f

Please sign in to comment.